1 /* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "cpu_features_wrapper.h" 12 13 // No CPU feature is available => straight C path. 14 int GetCPUInfoNoASM(CPUFeature feature) { 15 (void)feature; 16 return 0; 17 } 18 19 // Intrinsic for "cpuid". 20 #if defined(__pic__) && defined(__i386__) 21 static inline void cpuid(int cpu_info[4], int info_type) { 22 __asm__ volatile ( 23 "mov %%ebx, %%edi\n" 24 "cpuid\n" 25 "xchg %%edi, %%ebx\n" 26 : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) 27 : "a"(info_type)); 28 } 29 #elif defined(__i386__) || defined(__x86_64__) 30 static inline void cpuid(int cpu_info[4], int info_type) { 31 __asm__ volatile ( 32 "cpuid\n" 33 : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) 34 : "a"(info_type)); 35 } 36 #endif 37 38 #if defined(__i386__) || defined(__x86_64__) 39 // Actual feature detection for x86. 40 static int GetCPUInfo(CPUFeature feature) { 41 int cpu_info[4]; 42 cpuid(cpu_info, 1); 43 if (feature == kSSE2) { 44 return 0 != (cpu_info[3] & 0x04000000); 45 } 46 if (feature == kSSE3) { 47 return 0 != (cpu_info[2] & 0x00000001); 48 } 49 return 0; 50 } 51 #else 52 // Default to straight C for other platforms. 53 static int GetCPUInfo(CPUFeature feature) { 54 (void)feature; 55 return 0; 56 } 57 #endif 58 59 WebRtc_CPUInfo WebRtc_GetCPUInfo = GetCPUInfo; 60 WebRtc_CPUInfo WebRtc_GetCPUInfoNoASM = GetCPUInfoNoASM; 61