github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/webp/libwebp/src/dsp/cpu.c (about) 1 // Copyright 2011 Google Inc. All Rights Reserved. 2 // 3 // Use of this source code is governed by a BSD-style license 4 // that can be found in the COPYING file in the root of the source 5 // tree. An additional intellectual property rights grant can be found 6 // in the file PATENTS. All contributing project authors may 7 // be found in the AUTHORS file in the root of the source tree. 8 // ----------------------------------------------------------------------------- 9 // 10 // CPU detection 11 // 12 // Author: Christian Duvivier (cduvivier@google.com) 13 14 #include "./dsp.h" 15 16 #if defined(__ANDROID__) 17 #include <cpu-features.h> 18 #endif 19 20 //------------------------------------------------------------------------------ 21 // SSE2 detection. 22 // 23 24 // apple/darwin gcc-4.0.1 defines __PIC__, but not __pic__ with -fPIC. 25 #if (defined(__pic__) || defined(__PIC__)) && defined(__i386__) 26 static WEBP_INLINE void GetCPUInfo(int cpu_info[4], int info_type) { 27 __asm__ volatile ( 28 "mov %%ebx, %%edi\n" 29 "cpuid\n" 30 "xchg %%edi, %%ebx\n" 31 : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) 32 : "a"(info_type)); 33 } 34 #elif defined(__i386__) || defined(__x86_64__) 35 static WEBP_INLINE void GetCPUInfo(int cpu_info[4], int info_type) { 36 __asm__ volatile ( 37 "cpuid\n" 38 : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) 39 : "a"(info_type)); 40 } 41 #elif defined(WEBP_MSC_SSE2) 42 #define GetCPUInfo __cpuid 43 #endif 44 45 #if defined(__i386__) || defined(__x86_64__) || defined(WEBP_MSC_SSE2) 46 static int x86CPUInfo(CPUFeature feature) { 47 int cpu_info[4]; 48 GetCPUInfo(cpu_info, 1); 49 if (feature == kSSE2) { 50 return 0 != (cpu_info[3] & 0x04000000); 51 } 52 if (feature == kSSE3) { 53 return 0 != (cpu_info[2] & 0x00000001); 54 } 55 return 0; 56 } 57 VP8CPUInfo VP8GetCPUInfo = x86CPUInfo; 58 #elif defined(WEBP_ANDROID_NEON) 59 static int AndroidCPUInfo(CPUFeature feature) { 60 const AndroidCpuFamily cpu_family = android_getCpuFamily(); 61 const uint64_t cpu_features = android_getCpuFeatures(); 62 if (feature == kNEON) { 63 return (cpu_family == ANDROID_CPU_FAMILY_ARM && 64 0 != (cpu_features & ANDROID_CPU_ARM_FEATURE_NEON)); 65 } 66 return 0; 67 } 68 VP8CPUInfo VP8GetCPUInfo = AndroidCPUInfo; 69 #elif defined(__ARM_NEON__) 70 // define a dummy function to enable turning off NEON at runtime by setting 71 // VP8DecGetCPUInfo = NULL 72 static int armCPUInfo(CPUFeature feature) { 73 (void)feature; 74 return 1; 75 } 76 VP8CPUInfo VP8GetCPUInfo = armCPUInfo; 77 #else 78 VP8CPUInfo VP8GetCPUInfo = NULL; 79 #endif 80