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