dsp/cpu.c(x86): check maximum supported cpuid feature

structured extended feature flags require eax = 7; avoids incorrectly
detecting avx2 on some older processors that support avx.
for completeness also check for value=1 support used by the other
checks.

from [1]:
INPUT EAX = 0: Returns CPUID’s Highest Value for Basic Processor
Information and the Vendor Identification String

[1]
http://www.intel.com/content/www/us/en/processors/processor-identification-cpuid-instruction-note.html

Change-Id: I60b20d661a978d551614dbf7acdc25db19cb6046
This commit is contained in:
James Zern 2015-04-28 17:46:07 -07:00
parent 6d4602b88a
commit 0e009366f8

View File

@ -79,7 +79,16 @@ static WEBP_INLINE uint64_t xgetbv(void) {
#if defined(__i386__) || defined(__x86_64__) || defined(WEBP_MSC_SSE2) #if defined(__i386__) || defined(__x86_64__) || defined(WEBP_MSC_SSE2)
static int x86CPUInfo(CPUFeature feature) { static int x86CPUInfo(CPUFeature feature) {
int max_cpuid_value;
int cpu_info[4]; int cpu_info[4];
// get the highest feature value cpuid supports
GetCPUInfo(cpu_info, 0);
max_cpuid_value = cpu_info[0];
if (max_cpuid_value < 1) {
return 0;
}
GetCPUInfo(cpu_info, 1); GetCPUInfo(cpu_info, 1);
if (feature == kSSE2) { if (feature == kSSE2) {
return 0 != (cpu_info[3] & 0x04000000); return 0 != (cpu_info[3] & 0x04000000);
@ -98,7 +107,7 @@ static int x86CPUInfo(CPUFeature feature) {
} }
} }
if (feature == kAVX2) { if (feature == kAVX2) {
if (x86CPUInfo(kAVX)) { if (x86CPUInfo(kAVX) && max_cpuid_value >= 7) {
GetCPUInfo(cpu_info, 7); GetCPUInfo(cpu_info, 7);
return ((cpu_info[1] & 0x00000020) == 0x00000020); return ((cpu_info[1] & 0x00000020) == 0x00000020);
} }