OLD | NEW |
1 // Copyright 2011 Google Inc. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // This code is licensed under the same terms as WebM: | 3 // This code is licensed under the same terms as WebM: |
4 // Software License Agreement: http://www.webmproject.org/license/software/ | 4 // Software License Agreement: http://www.webmproject.org/license/software/ |
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ | 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ |
6 // ----------------------------------------------------------------------------- | 6 // ----------------------------------------------------------------------------- |
7 // | 7 // |
8 // CPU detection | 8 // CPU detection |
9 // | 9 // |
10 // Author: Christian Duvivier (cduvivier@google.com) | 10 // Author: Christian Duvivier (cduvivier@google.com) |
11 | 11 |
12 #include <stddef.h> // for NULL | 12 #include "./dsp.h" |
13 | 13 |
14 #include "./dsp.h" | 14 #if defined(__ANDROID__) |
| 15 #include <cpu-features.h> |
| 16 #endif |
15 | 17 |
16 #if defined(__cplusplus) || defined(c_plusplus) | 18 #if defined(__cplusplus) || defined(c_plusplus) |
17 extern "C" { | 19 extern "C" { |
18 #endif | 20 #endif |
19 | 21 |
20 //------------------------------------------------------------------------------ | 22 //------------------------------------------------------------------------------ |
21 // SSE2 detection. | 23 // SSE2 detection. |
22 // | 24 // |
23 | 25 |
24 #if defined(__pic__) && defined(__i386__) | 26 // apple/darwin gcc-4.0.1 defines __PIC__, but not __pic__ with -fPIC. |
25 static inline void GetCPUInfo(int cpu_info[4], int info_type) { | 27 #if (defined(__pic__) || defined(__PIC__)) && defined(__i386__) |
| 28 static WEBP_INLINE void GetCPUInfo(int cpu_info[4], int info_type) { |
26 __asm__ volatile ( | 29 __asm__ volatile ( |
27 "mov %%ebx, %%edi\n" | 30 "mov %%ebx, %%edi\n" |
28 "cpuid\n" | 31 "cpuid\n" |
29 "xchg %%edi, %%ebx\n" | 32 "xchg %%edi, %%ebx\n" |
30 : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) | 33 : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) |
31 : "a"(info_type)); | 34 : "a"(info_type)); |
32 } | 35 } |
33 #elif defined(__i386__) || defined(__x86_64__) | 36 #elif defined(__i386__) || defined(__x86_64__) |
34 static inline void GetCPUInfo(int cpu_info[4], int info_type) { | 37 static WEBP_INLINE void GetCPUInfo(int cpu_info[4], int info_type) { |
35 __asm__ volatile ( | 38 __asm__ volatile ( |
36 "cpuid\n" | 39 "cpuid\n" |
37 : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) | 40 : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) |
38 : "a"(info_type)); | 41 : "a"(info_type)); |
39 } | 42 } |
40 #elif defined(_MSC_VER) // Visual C++ | 43 #elif defined(WEBP_MSC_SSE2) |
41 #define GetCPUInfo __cpuid | 44 #define GetCPUInfo __cpuid |
42 #endif | 45 #endif |
43 | 46 |
44 #if defined(__i386__) || defined(__x86_64__) || defined(_MSC_VER) | 47 #if defined(__i386__) || defined(__x86_64__) || defined(WEBP_MSC_SSE2) |
45 static int x86CPUInfo(CPUFeature feature) { | 48 static int x86CPUInfo(CPUFeature feature) { |
46 int cpu_info[4]; | 49 int cpu_info[4]; |
47 GetCPUInfo(cpu_info, 1); | 50 GetCPUInfo(cpu_info, 1); |
48 if (feature == kSSE2) { | 51 if (feature == kSSE2) { |
49 return 0 != (cpu_info[3] & 0x04000000); | 52 return 0 != (cpu_info[3] & 0x04000000); |
50 } | 53 } |
51 if (feature == kSSE3) { | 54 if (feature == kSSE3) { |
52 return 0 != (cpu_info[2] & 0x00000001); | 55 return 0 != (cpu_info[2] & 0x00000001); |
53 } | 56 } |
54 return 0; | 57 return 0; |
55 } | 58 } |
56 VP8CPUInfo VP8GetCPUInfo = x86CPUInfo; | 59 VP8CPUInfo VP8GetCPUInfo = x86CPUInfo; |
| 60 #elif defined(WEBP_ANDROID_NEON) |
| 61 static int AndroidCPUInfo(CPUFeature feature) { |
| 62 const AndroidCpuFamily cpu_family = android_getCpuFamily(); |
| 63 const uint64_t cpu_features = android_getCpuFeatures(); |
| 64 if (feature == kNEON) { |
| 65 return (cpu_family == ANDROID_CPU_FAMILY_ARM && |
| 66 0 != (cpu_features & ANDROID_CPU_ARM_FEATURE_NEON)); |
| 67 } |
| 68 return 0; |
| 69 } |
| 70 VP8CPUInfo VP8GetCPUInfo = AndroidCPUInfo; |
57 #elif defined(__ARM_NEON__) | 71 #elif defined(__ARM_NEON__) |
58 // define a dummy function to enable turning off NEON at runtime by setting | 72 // define a dummy function to enable turning off NEON at runtime by setting |
59 // VP8DecGetCPUInfo = NULL | 73 // VP8DecGetCPUInfo = NULL |
60 static int armCPUInfo(CPUFeature feature) { | 74 static int armCPUInfo(CPUFeature feature) { |
| 75 (void)feature; |
61 return 1; | 76 return 1; |
62 } | 77 } |
63 VP8CPUInfo VP8GetCPUInfo = armCPUInfo; | 78 VP8CPUInfo VP8GetCPUInfo = armCPUInfo; |
64 #else | 79 #else |
65 VP8CPUInfo VP8GetCPUInfo = NULL; | 80 VP8CPUInfo VP8GetCPUInfo = NULL; |
66 #endif | 81 #endif |
67 | 82 |
68 #if defined(__cplusplus) || defined(c_plusplus) | 83 #if defined(__cplusplus) || defined(c_plusplus) |
69 } // extern "C" | 84 } // extern "C" |
70 #endif | 85 #endif |
OLD | NEW |