diff options
author | Marcus Asteborg <maastebo@microsoft.com> | 2022-07-07 07:35:16 +0300 |
---|---|---|
committer | Mark Harris <mark.hsj@gmail.com> | 2022-07-08 08:07:33 +0300 |
commit | 510e1029b45aa01a7047e5b3b82169be40911b96 (patch) | |
tree | 862a8e1b774311edb4b2beab2ede4b400623896d /cmake | |
parent | a80e9e9533d4edeaae282b82f77b8bd8a4903eca (diff) |
cmake - fix rtcd detection on x86 non windows
Signed-off-by: Mark Harris <mark.hsj@gmail.com>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/OpusFunctions.cmake | 30 | ||||
-rw-r--r-- | cmake/cpu_info_by_asm.c | 31 | ||||
-rw-r--r-- | cmake/cpu_info_by_c.c | 9 |
3 files changed, 62 insertions, 8 deletions
diff --git a/cmake/OpusFunctions.cmake b/cmake/OpusFunctions.cmake index fcf3351f..3f22ad81 100644 --- a/cmake/OpusFunctions.cmake +++ b/cmake/OpusFunctions.cmake @@ -142,14 +142,28 @@ function(opus_detect_neon COMPILER_SUPPORT_NEON) endfunction() function(opus_supports_cpu_detection RUNTIME_CPU_CAPABILITY_DETECTION) - if(MSVC) - check_include_file(intrin.h HAVE_INTRIN_H) - else() - check_include_file(cpuid.h HAVE_CPUID_H) - endif() - if(HAVE_INTRIN_H OR HAVE_CPUID_H) - set(RUNTIME_CPU_CAPABILITY_DETECTION 1 PARENT_SCOPE) - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)") + set(RUNTIME_CPU_CAPABILITY_DETECTION 0 PARENT_SCOPE) + if(OPUS_CPU_X86 OR OPUS_CPU_X64) + if(MSVC) + check_include_file(intrin.h HAVE_INTRIN_H) + if(HAVE_INTRIN_H) + # if intrin.h is available we assume __cpuid is there + set(RUNTIME_CPU_CAPABILITY_DETECTION 1 PARENT_SCOPE) + endif() + else() + include(CFeatureCheck) + c_feature_check(CPU_INFO_BY_ASM) + set(CPU_INFO_BY_ASM_SUPPORTED ${CPU_INFO_BY_ASM_SUPPORTED} PARENT_SCOPE) + check_include_file(cpuid.h HAVE_CPUID_H) + if(HAVE_CPUID_H) + c_feature_check(CPU_INFO_BY_C) + set(CPU_INFO_BY_C_SUPPORTED ${CPU_INFO_BY_C_SUPPORTED} PARENT_SCOPE) + endif() + if(CPU_INFO_BY_ASM_SUPPORTED OR CPU_INFO_BY_C_SUPPORTED) + set(RUNTIME_CPU_CAPABILITY_DETECTION 1 PARENT_SCOPE) + endif() + endif() + elseif(OPUS_CPU_ARM) # ARM cpu detection is implemented for Windows and anything # using a Linux kernel (such as Android). if (CMAKE_SYSTEM_NAME MATCHES "(Windows|Linux|Android)") diff --git a/cmake/cpu_info_by_asm.c b/cmake/cpu_info_by_asm.c new file mode 100644 index 00000000..1a70a815 --- /dev/null +++ b/cmake/cpu_info_by_asm.c @@ -0,0 +1,31 @@ +#include <stdio.h> +int main() { + unsigned int CPUInfo0; + unsigned int CPUInfo1; + unsigned int CPUInfo2; + unsigned int CPUInfo3; + unsigned int InfoType; +#if defined(__i386__) && defined(__PIC__) +/* %ebx is PIC register in 32-bit, so mustn't clobber it. */ + __asm__ __volatile__ ( + "xchg %%ebx, %1\n" + "cpuid\n" + "xchg %%ebx, %1\n": + "=a" (CPUInfo0), + "=r" (CPUInfo1), + "=c" (CPUInfo2), + "=d" (CPUInfo3) : + "0" (InfoType), "2" (0) + ); +#else + __asm__ __volatile__ ( + "cpuid": + "=a" (CPUInfo0), + "=b" (CPUInfo1), + "=c" (CPUInfo2), + "=d" (CPUInfo3) : + "0" (InfoType), "2" (0) + ); +#endif + return 0; +} diff --git a/cmake/cpu_info_by_c.c b/cmake/cpu_info_by_c.c new file mode 100644 index 00000000..117084eb --- /dev/null +++ b/cmake/cpu_info_by_c.c @@ -0,0 +1,9 @@ +#include <cpuid.h> +int main() { + unsigned int CPUInfo0; + unsigned int CPUInfo1; + unsigned int CPUInfo2; + unsigned int CPUInfo3; + unsigned int InfoType; + return __get_cpuid_count(InfoType, 0, &CPUInfo0, &CPUInfo1, &CPUInfo2, &CPUInfo3); +} |