1 // Copyright 2011 Google Inc. All Rights Reserved.
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 // -----------------------------------------------------------------------------
12 // Author: Christian Duvivier (cduvivier@google.com)
16 #if defined(__ANDROID__)
17 #include <cpu-features.h>
20 //------------------------------------------------------------------------------
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
) {
31 : "=a"(cpu_info
[0]), "=D"(cpu_info
[1]), "=c"(cpu_info
[2]), "=d"(cpu_info
[3])
34 #elif defined(__i386__) || defined(__x86_64__)
35 static WEBP_INLINE
void GetCPUInfo(int cpu_info
[4], int info_type
) {
38 : "=a"(cpu_info
[0]), "=b"(cpu_info
[1]), "=c"(cpu_info
[2]), "=d"(cpu_info
[3])
41 #elif defined(WEBP_MSC_SSE2)
42 #define GetCPUInfo __cpuid
45 #if defined(__i386__) || defined(__x86_64__) || defined(WEBP_MSC_SSE2)
46 static int x86CPUInfo(CPUFeature feature
) {
48 GetCPUInfo(cpu_info
, 1);
49 if (feature
== kSSE2
) {
50 return 0 != (cpu_info
[3] & 0x04000000);
52 if (feature
== kSSE3
) {
53 return 0 != (cpu_info
[2] & 0x00000001);
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
));
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
) {
76 VP8CPUInfo VP8GetCPUInfo
= armCPUInfo
;
78 VP8CPUInfo VP8GetCPUInfo
= NULL
;