diff options
author | Jack Lloyd <[email protected]> | 2021-05-24 19:02:24 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2021-05-24 19:03:53 -0400 |
commit | 4aa1a8b403d4453e33106ba6667ab0f587e8f0f3 (patch) | |
tree | 4b2860efcbe12e3a4452e0dd08bbe96674501720 /src | |
parent | ead9ac7fa55468915ccbe516d19e3e61622bf77d (diff) |
Revamp x86 CPUID
Use the GCC intrinsics for gcc or clang
Remove use of _cpuidex for Intel C++ since it seems to be missing
in at least some situations (GH #2748)
Allow using the inline asm on x86-32 or x32 modes
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/utils/cpuid/cpuid_x86.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/lib/utils/cpuid/cpuid_x86.cpp b/src/lib/utils/cpuid/cpuid_x86.cpp index 7b99575ab..832e69871 100644 --- a/src/lib/utils/cpuid/cpuid_x86.cpp +++ b/src/lib/utils/cpuid/cpuid_x86.cpp @@ -32,13 +32,14 @@ void invoke_cpuid(uint32_t type, uint32_t out[4]) #if defined(BOTAN_BUILD_COMPILER_IS_MSVC) || defined(BOTAN_BUILD_COMPILER_IS_INTEL) __cpuid((int*)out, type); -#elif defined(BOTAN_TARGET_ARCH_IS_X86_64) && defined(BOTAN_USE_GCC_INLINE_ASM) +#elif defined(BOTAN_BUILD_COMPILER_IS_GCC) || defined(BOTAN_BUILD_COMPILER_IS_CLANG) + __get_cpuid(type, out, out+1, out+2, out+3); + +#elif defined(BOTAN_USE_GCC_INLINE_ASM) asm("cpuid\n\t" : "=a" (out[0]), "=b" (out[1]), "=c" (out[2]), "=d" (out[3]) : "0" (type)); -#elif defined(BOTAN_BUILD_COMPILER_IS_GCC) || defined(BOTAN_BUILD_COMPILER_IS_CLANG) - __get_cpuid(type, out, out+1, out+2, out+3); #else #warning "No way of calling x86 cpuid instruction for this compiler" clear_mem(out, 4); @@ -50,16 +51,14 @@ void invoke_cpuid_sublevel(uint32_t type, uint32_t level, uint32_t out[4]) #if defined(BOTAN_BUILD_COMPILER_IS_MSVC) __cpuidex((int*)out, type, level); -#elif defined(BOTAN_BUILD_COMPILER_IS_INTEL) - __cpuidex((int*)out, type, level); +#elif defined(BOTAN_BUILD_COMPILER_IS_GCC) || defined(BOTAN_BUILD_COMPILER_IS_CLANG) + __cpuid_count(type, level, out[0], out[1], out[2], out[3]); -#elif defined(BOTAN_TARGET_ARCH_IS_X86_64) && defined(BOTAN_USE_GCC_INLINE_ASM) +#elif defined(BOTAN_USE_GCC_INLINE_ASM) asm("cpuid\n\t" : "=a" (out[0]), "=b" (out[1]), "=c" (out[2]), "=d" (out[3]) \ : "0" (type), "2" (level)); -#elif defined(BOTAN_BUILD_COMPILER_IS_GCC) || defined(BOTAN_BUILD_COMPILER_IS_CLANG) - __cpuid_count(type, level, out[0], out[1], out[2], out[3]); #else #warning "No way of calling x86 cpuid instruction for this compiler" clear_mem(out, 4); |