Commit 79ca23ec authored by Julian Calaby's avatar Julian Calaby Committed by Erik de Castro Lopo
Browse files

libFLAC/cpu.c: Eliminate a branch in cpu_info_x86

Inverting all the if statements allows us to move the common code of
setting all the registers to zero outside the #if statement.
parent e58a6e75
...@@ -457,25 +457,23 @@ void FLAC__cpu_info_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx ...@@ -457,25 +457,23 @@ void FLAC__cpu_info_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx
int cpuinfo[4]; int cpuinfo[4];
int ext = level & 0x80000000; int ext = level & 0x80000000;
__cpuid(cpuinfo, ext); __cpuid(cpuinfo, ext);
if((unsigned)cpuinfo[0] < level) { if((unsigned)cpuinfo[0] >= level) {
*eax = *ebx = *ecx = *edx = 0;
return;
}
cpu_id_ex (cpuinfo, ext); cpu_id_ex (cpuinfo, ext);
*eax = cpuinfo[0]; *ebx = cpuinfo[1]; *ecx = cpuinfo[2]; *edx = cpuinfo[3]; *eax = cpuinfo[0]; *ebx = cpuinfo[1]; *ecx = cpuinfo[2]; *edx = cpuinfo[3];
return;
}
#elif defined __GNUC__ && defined HAVE_CPUID_H #elif defined __GNUC__ && defined HAVE_CPUID_H
FLAC__uint32 ext = level & 0x80000000; FLAC__uint32 ext = level & 0x80000000;
__cpuid(ext, *eax, *ebx, *ecx, *edx); __cpuid(ext, *eax, *ebx, *ecx, *edx);
if (*eax < level) { if (*eax >= level) {
*eax = *ebx = *ecx = *edx = 0; __cpuid_count(level, 0, *eax, *ebx, *ecx, *edx);
return; return;
} }
__cpuid_count(level, 0, *eax, *ebx, *ecx, *edx);
#else
*eax = *ebx = *ecx = *edx = 0;
#endif #endif
*eax = *ebx = *ecx = *edx = 0;
} }
#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ #endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */
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