diff options
| author | Pieter Wuille <[email protected]> | 2017-07-16 11:49:45 -0700 |
|---|---|---|
| committer | Pieter Wuille <[email protected]> | 2017-07-16 11:50:49 -0700 |
| commit | ef37f2033c4ae104585cd980141262f95d33166e (patch) | |
| tree | ac85cde527c515fbc9ca34e50ff424c5507804ff /src | |
| parent | Merge #10235: Track keypool entries as internal vs external in memory (diff) | |
| parent | Clarify entropy source (diff) | |
| download | discoin-ef37f2033c4ae104585cd980141262f95d33166e.tar.xz discoin-ef37f2033c4ae104585cd980141262f95d33166e.zip | |
Merge #10820: Use cpuid intrinsics instead of asm code
674848fe1 Clarify entropy source (Pieter Wuille)
a9e82f651 Use cpuid intrinsics instead of asm code (Pieter Wuille)
Pull request description:
Less platform-specific code is better.
Tree-SHA512: 14f1b9accd9882859acdf516d2ada7ccb0ad92a3b3edf95b9cb8a8e514d4b1748d4555bcfb560779792c4f664f920d681ae42e9cebd0e6410f13f94c3a8729a0
Diffstat (limited to 'src')
| -rw-r--r-- | src/random.cpp | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/random.cpp b/src/random.cpp index 67efc7d94..1ee6158e4 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -36,6 +36,10 @@ #include <mutex> +#if defined(__x86_64__) || defined(__amd64__) || defined(__i386__) +#include <cpuid.h> +#endif + #include <openssl/err.h> #include <openssl/rand.h> @@ -72,18 +76,9 @@ static bool rdrand_supported = false; static constexpr uint32_t CPUID_F1_ECX_RDRAND = 0x40000000; static void RDRandInit() { - uint32_t eax, ecx, edx; -#if defined(__i386__) && ( defined(__PIC__) || defined(__PIE__)) - // Avoid clobbering ebx, as that is used for PIC on x86. - uint32_t tmp; - __asm__ ("mov %%ebx, %1; cpuid; mov %1, %%ebx": "=a"(eax), "=g"(tmp), "=c"(ecx), "=d"(edx) : "a"(1)); -#else - uint32_t ebx; - __asm__ ("cpuid": "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(1)); -#endif - //! When calling cpuid function #1, ecx register will have this set if RDRAND is available. - if (ecx & CPUID_F1_ECX_RDRAND) { - LogPrintf("Using RdRand as entropy source\n"); + uint32_t eax, ebx, ecx, edx; + if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) && (ecx & CPUID_F1_ECX_RDRAND)) { + LogPrintf("Using RdRand as an additional entropy source\n"); rdrand_supported = true; } hwrand_initialized.store(true); |