summaryrefslogtreecommitdiff
path: root/libavutil/x86/cpu.c
diff options
context:
space:
mode:
authorMans Rullgard <mans@mansr.com>2012-06-24 12:29:28 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-07-10 20:32:16 +0200
commite346176de9809afec3724139ee320b613f753062 (patch)
treebc26600a4bd00db28dc2100e80fc9228cfc5daa0 /libavutil/x86/cpu.c
parent96890c001f32943a8d5823ae553d6022bee8850b (diff)
x86: cpu: clean up check for cpuid instruction support
This adds macros for accessing the EFLAGS register and uses these instead of coding the entire check in inline asm. Signed-off-by: Mans Rullgard <mans@mansr.com>
Diffstat (limited to 'libavutil/x86/cpu.c')
-rw-r--r--libavutil/x86/cpu.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/libavutil/x86/cpu.c b/libavutil/x86/cpu.c
index d77f0fcc15..663fb93e52 100644
--- a/libavutil/x86/cpu.c
+++ b/libavutil/x86/cpu.c
@@ -37,6 +37,16 @@
#define xgetbv(index, eax, edx) \
__asm__ (".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c" (index))
+#define get_eflags(x) \
+ __asm__ volatile ("pushfl \n" \
+ "pop %0 \n" \
+ : "=r"(x))
+
+#define set_eflags(x) \
+ __asm__ volatile ("push %0 \n" \
+ "popfl \n" \
+ :: "r"(x))
+
/* Function to test if multimedia instructions are supported... */
int ff_get_cpu_flags_x86(void)
{
@@ -48,26 +58,12 @@ int ff_get_cpu_flags_x86(void)
#if ARCH_X86_32
x86_reg a, c;
- __asm__ volatile (
- /* See if CPUID instruction is supported ... */
- /* ... Get copies of EFLAGS into eax and ecx */
- "pushfl\n\t"
- "pop %0\n\t"
- "mov %0, %1\n\t"
-
- /* ... Toggle the ID bit in one copy and store */
- /* to the EFLAGS reg */
- "xor $0x200000, %0\n\t"
- "push %0\n\t"
- "popfl\n\t"
-
- /* ... Get the (hopefully modified) EFLAGS */
- "pushfl\n\t"
- "pop %0\n\t"
- : "=a" (a), "=c" (c)
- :
- : "cc"
- );
+
+ /* Check if CPUID is supported by attempting to toggle the ID bit in
+ * the EFLAGS register. */
+ get_eflags(a);
+ set_eflags(a ^ 0x200000);
+ get_eflags(c);
if (a == c)
return 0; /* CPUID not supported */