summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Calaby <julian.calaby@gmail.com>2016-06-27 22:37:45 +1000
committerErik de Castro Lopo <erikd@mega-nerd.com>2016-06-28 18:08:12 +1000
commit79ca23ece346e80e3f188e6192b8393d693fe31b (patch)
tree24cf695594354bcf956d5f2a4a5ffea0f6ce6e7b
parente58a6e75495a4d74c0f504066390aaa42b418682 (diff)
downloadflac-79ca23ece346e80e3f188e6192b8393d693fe31b.tar.gz
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.
-rw-r--r--src/libFLAC/cpu.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/libFLAC/cpu.c b/src/libFLAC/cpu.c
index a89d1627..592aee73 100644
--- a/src/libFLAC/cpu.c
+++ b/src/libFLAC/cpu.c
@@ -457,25 +457,23 @@ void FLAC__cpu_info_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx
int cpuinfo[4];
int ext = level & 0x80000000;
__cpuid(cpuinfo, ext);
- if((unsigned)cpuinfo[0] < level) {
- *eax = *ebx = *ecx = *edx = 0;
- return;
- }
+ if((unsigned)cpuinfo[0] >= level) {
+ 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
FLAC__uint32 ext = level & 0x80000000;
__cpuid(ext, *eax, *ebx, *ecx, *edx);
- if (*eax < level) {
- *eax = *ebx = *ecx = *edx = 0;
+ if (*eax >= level) {
+ __cpuid_count(level, 0, *eax, *ebx, *ecx, *edx);
+
return;
}
- __cpuid_count(level, 0, *eax, *ebx, *ecx, *edx);
-#else
- *eax = *ebx = *ecx = *edx = 0;
#endif
+ *eax = *ebx = *ecx = *edx = 0;
}
#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */