Commit 78070bc1 authored by fbarchard@google.com's avatar fbarchard@google.com

Added CPUID change to detect AVX2.

BUG=98
TEST=none
Review URL: https://webrtc-codereview.appspot.com/839004

git-svn-id: http://libyuv.googlecode.com/svn/trunk@373 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent cad0ad30
Name: libyuv Name: libyuv
URL: http://code.google.com/p/libyuv/ URL: http://code.google.com/p/libyuv/
Version: 372 Version: 373
License: BSD License: BSD
License File: LICENSE License File: LICENSE
......
...@@ -31,7 +31,7 @@ static const int kCpuHasSSSE3 = 0x40; ...@@ -31,7 +31,7 @@ static const int kCpuHasSSSE3 = 0x40;
static const int kCpuHasSSE41 = 0x80; static const int kCpuHasSSE41 = 0x80;
static const int kCpuHasSSE42 = 0x100; static const int kCpuHasSSE42 = 0x100;
static const int kCpuHasAVX = 0x200; static const int kCpuHasAVX = 0x200;
// 0x400 reserved for AVX2. static const int kCpuHasAVX2 = 0x400;
// Detect CPU has SSE2 etc. // Detect CPU has SSE2 etc.
// Test_flag parameter should be one of kCpuHas constants above. // Test_flag parameter should be one of kCpuHas constants above.
......
...@@ -11,6 +11,6 @@ ...@@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 372 #define LIBYUV_VERSION 373
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
...@@ -58,6 +58,20 @@ void CpuId(int cpu_info[4], int) { ...@@ -58,6 +58,20 @@ void CpuId(int cpu_info[4], int) {
} }
#endif #endif
// Low level cpuid for X86. Returns zeros on other CPUs.
#if !defined(__CLR_VER) && defined(_M_IX86)
// TODO(fbarchard): Port to GCC and 64 bit Visual C.
#define HAS_XGETBV
// Return low 32 bits of BV - OS support for register saving.
__declspec(naked)
static uint32 XGetBV32(void) {
_asm _emit 0x0f
_asm _emit 0x01
_asm _emit 0xd0 // xgetbv
_asm ret
}
#endif
// based on libvpx arm_cpudetect.c // based on libvpx arm_cpudetect.c
// For Arm, but public to allow testing on any CPU // For Arm, but public to allow testing on any CPU
int ArmCpuCaps(const char* cpuinfo_name) { int ArmCpuCaps(const char* cpuinfo_name) {
...@@ -91,8 +105,17 @@ int InitCpuFlags() { ...@@ -91,8 +105,17 @@ int InitCpuFlags() {
((cpu_info[2] & 0x00000200) ? kCpuHasSSSE3 : 0) | ((cpu_info[2] & 0x00000200) ? kCpuHasSSSE3 : 0) |
((cpu_info[2] & 0x00080000) ? kCpuHasSSE41 : 0) | ((cpu_info[2] & 0x00080000) ? kCpuHasSSE41 : 0) |
((cpu_info[2] & 0x00100000) ? kCpuHasSSE42 : 0) | ((cpu_info[2] & 0x00100000) ? kCpuHasSSE42 : 0) |
// TODO(fbarchard): AVX test BV same as AVX2.
(((cpu_info[2] & 0x18000000) == 0x18000000) ? kCpuHasAVX : 0) | (((cpu_info[2] & 0x18000000) == 0x18000000) ? kCpuHasAVX : 0) |
kCpuInitialized | kCpuHasX86; kCpuInitialized | kCpuHasX86;
#ifdef HAS_XGETBV
if (cpu_info_ & kCpuHasAVX) {
__cpuid(cpu_info, 7);
if ((cpu_info[1] & 0x00000020) && ((XGetBV32() & 0x06) == 0x06)) {
cpu_info_ |= kCpuHasAVX2;
}
}
#endif
// environment variable overrides for testing. // environment variable overrides for testing.
if (getenv("LIBYUV_DISABLE_X86")) { if (getenv("LIBYUV_DISABLE_X86")) {
...@@ -113,6 +136,9 @@ int InitCpuFlags() { ...@@ -113,6 +136,9 @@ int InitCpuFlags() {
if (getenv("LIBYUV_DISABLE_AVX")) { if (getenv("LIBYUV_DISABLE_AVX")) {
cpu_info_ &= ~kCpuHasAVX; cpu_info_ &= ~kCpuHasAVX;
} }
if (getenv("LIBYUV_DISABLE_AVX2")) {
cpu_info_ &= ~kCpuHasAVX2;
}
if (getenv("LIBYUV_DISABLE_ASM")) { if (getenv("LIBYUV_DISABLE_ASM")) {
cpu_info_ = kCpuInitialized; cpu_info_ = kCpuInitialized;
} }
......
...@@ -37,6 +37,8 @@ TEST_F(libyuvTest, TestCpuHas) { ...@@ -37,6 +37,8 @@ TEST_F(libyuvTest, TestCpuHas) {
printf("Has SSE4.2 %x\n", has_sse42); printf("Has SSE4.2 %x\n", has_sse42);
int has_avx = TestCpuFlag(kCpuHasAVX); int has_avx = TestCpuFlag(kCpuHasAVX);
printf("Has AVX %x\n", has_avx); printf("Has AVX %x\n", has_avx);
int has_avx2 = TestCpuFlag(kCpuHasAVX2);
printf("Has AVX2 %x\n", has_avx2);
} }
#if defined(__i386__) || defined(__x86_64__) || \ #if defined(__i386__) || defined(__x86_64__) || \
......
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