Commit 891091c6 authored by fbarchard@google.com's avatar fbarchard@google.com

cpu_id using one variable and make it more public how to set flags to disable SIMD

BUG=none
TEST=scale unittest in talk disables SSSE3
Review URL: http://webrtc-codereview.appspot.com/239018

git-svn-id: http://libyuv.googlecode.com/svn/trunk@47 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent 585a1261
...@@ -17,14 +17,15 @@ namespace libyuv { ...@@ -17,14 +17,15 @@ namespace libyuv {
static const int kCpuHasSSE2 = 1; static const int kCpuHasSSE2 = 1;
static const int kCpuHasSSSE3 = 2; static const int kCpuHasSSSE3 = 2;
// SIMD support on ARM processors // These flags are only valid on ARM processors
static const int kCpuHasNEON = 4; static const int kCpuHasNEON = 4;
// Detect CPU has SSE2 etc. // Detect CPU has SSE2 etc.
bool TestCpuFlag(int flag); bool TestCpuFlag(int flag);
// For testing, allow CPU flags to be disabled. // For testing, allow CPU flags to be disabled.
void MaskCpuFlagsForTest(int enable_flags); // ie MaskCpuFlags(~kCpuHasSSSE3) to disable SSSE3. -1 to enable all.
void MaskCpuFlags(int enable_flags);
} // namespace libyuv } // namespace libyuv
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
#include <intrin.h> #include <intrin.h>
#endif #endif
// Internal flag to indicate cpuid is initialized.
static const int kCpuInitialized = 16;
// TODO(fbarchard): Use cpuid.h when gcc 4.4 is used on OSX and Linux. // TODO(fbarchard): Use cpuid.h when gcc 4.4 is used on OSX and Linux.
#if (defined(__pic__) || defined(__APPLE__)) && defined(__i386__) #if (defined(__pic__) || defined(__APPLE__)) && defined(__i386__)
static inline void __cpuid(int cpu_info[4], int info_type) { static inline void __cpuid(int cpu_info[4], int info_type) {
...@@ -39,33 +42,33 @@ static inline void __cpuid(int cpu_info[4], int info_type) { ...@@ -39,33 +42,33 @@ static inline void __cpuid(int cpu_info[4], int info_type) {
namespace libyuv { namespace libyuv {
// CPU detect function for SIMD instruction sets. // CPU detect function for SIMD instruction sets.
static bool cpu_info_initialized_ = false;
static int cpu_info_ = 0; static int cpu_info_ = 0;
// Global lock for cpu initialization. // TODO(fbarchard): (cpu_info[2] & 0x10000000 ? kCpuHasAVX : 0)
static void InitCpuFlags() { static void InitCpuFlags() {
#ifdef CPU_X86 #ifdef CPU_X86
int cpu_info[4]; int cpu_info[4];
__cpuid(cpu_info, 1); __cpuid(cpu_info, 1);
cpu_info_ = (cpu_info[2] & 0x00000200 ? kCpuHasSSSE3 : 0) | cpu_info_ = (cpu_info[3] & 0x04000000 ? kCpuHasSSE2 : 0) |
(cpu_info[3] & 0x04000000 ? kCpuHasSSE2 : 0); (cpu_info[2] & 0x00000200 ? kCpuHasSSSE3 : 0) |
kCpuInitialized;
#elif defined(__ARM_NEON__) #elif defined(__ARM_NEON__)
// gcc -mfpu=neon defines __ARM_NEON__ // gcc -mfpu=neon defines __ARM_NEON__
// if code is specifically built for Neon-only, enable the flag. // Enable Neon if you want support for Neon and Arm, and use MaskCpuFlags
cpu_info_ |= kCpuHasNEON; // to disable Neon on devices that do not have it.
cpu_info_ = kCpuHasNEON | kCpuInitialized;
#else #else
cpu_info_ = 0; cpu_info_ = kCpuInitialized;
#endif #endif
cpu_info_initialized_ = true;
} }
void MaskCpuFlagsForTest(int enable_flags) { void MaskCpuFlags(int enable_flags) {
InitCpuFlags(); InitCpuFlags();
cpu_info_ &= enable_flags; cpu_info_ = (cpu_info_ & enable_flags) | kCpuInitialized;
} }
bool TestCpuFlag(int flag) { bool TestCpuFlag(int flag) {
if (!cpu_info_initialized_) { if (!cpu_info_) {
InitCpuFlags(); InitCpuFlags();
} }
return cpu_info_ & flag ? true : false; return cpu_info_ & flag ? true : false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment