1 /* 2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved 3 * 4 * This source code is subject to the terms of the BSD 2 Clause License and 5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6 * was not distributed with this source code in the LICENSE file, you can 7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open 8 * Media Patent License 1.0 was not distributed with this source code in the 9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10 */ 11 12 #ifndef INCLUDE_LIBYUV_CPU_ID_H_ // NOLINT 13 #define INCLUDE_LIBYUV_CPU_ID_H_ 14 15 #include "libyuv/basic_types.h" 16 17 #ifdef __cplusplus 18 namespace libyuv { 19 extern "C" { 20 #endif 21 22 // TODO(fbarchard): Consider overlapping bits for different architectures. 23 // Internal flag to indicate cpuid requires initialization. 24 #define kCpuInit 0x1 25 26 // These flags are only valid on ARM processors. 27 static const int kCpuHasARM = 0x2; 28 static const int kCpuHasNEON = 0x4; 29 // 0x8 reserved for future ARM flag. 30 31 // These flags are only valid on x86 processors. 32 static const int kCpuHasX86 = 0x10; 33 static const int kCpuHasSSE2 = 0x20; 34 static const int kCpuHasSSSE3 = 0x40; 35 static const int kCpuHasSSE41 = 0x80; 36 static const int kCpuHasSSE42 = 0x100; 37 static const int kCpuHasAVX = 0x200; 38 static const int kCpuHasAVX2 = 0x400; 39 static const int kCpuHasERMS = 0x800; 40 static const int kCpuHasFMA3 = 0x1000; 41 // 0x2000, 0x4000, 0x8000 reserved for future X86 flags. 42 43 // These flags are only valid on MIPS processors. 44 static const int kCpuHasMIPS = 0x10000; 45 static const int kCpuHasMIPS_DSP = 0x20000; 46 static const int kCpuHasMIPS_DSPR2 = 0x40000; 47 48 // Internal function used to auto-init. 49 LIBYUV_API 50 int InitCpuFlags(void); 51 52 // Internal function for parsing /proc/cpuinfo. 53 LIBYUV_API 54 int ArmCpuCaps(const char* cpuinfo_name); 55 56 // Detect CPU has SSE2 etc. 57 // Test_flag parameter should be one of kCpuHas constants above. 58 // returns non-zero if instruction set is detected TestCpuFlag(int test_flag)59static __inline int TestCpuFlag(int test_flag) { 60 LIBYUV_API extern int cpu_info_; 61 return (cpu_info_ == kCpuInit ? InitCpuFlags() : cpu_info_) & test_flag; 62 } 63 64 // For testing, allow CPU flags to be disabled. 65 // ie MaskCpuFlags(~kCpuHasSSSE3) to disable SSSE3. 66 // MaskCpuFlags(-1) to enable all cpu specific optimizations. 67 // MaskCpuFlags(0) to disable all cpu specific optimizations. 68 LIBYUV_API 69 void MaskCpuFlags(int enable_flags); 70 71 // Low level cpuid for X86. Returns zeros on other CPUs. 72 // eax is the info type that you want. 73 // ecx is typically the cpu number, and should normally be zero. 74 LIBYUV_API 75 void CpuId(uint32 eax, uint32 ecx, uint32* cpu_info); 76 77 #ifdef __cplusplus 78 } // extern "C" 79 } // namespace libyuv 80 #endif 81 82 #endif // INCLUDE_LIBYUV_CPU_ID_H_ NOLINT 83