[vlc-commits] Improve x86 cpuid

Rémi Denis-Courmont git at videolan.org
Tue Oct 25 18:56:07 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Oct 25 19:49:47 2011 +0300| [f942343d3a8b13578c882c4d4c6a1e74adb19384] | committer: Rémi Denis-Courmont

Improve x86 cpuid

There is no need for hoops around EBX for non-PIC code.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f942343d3a8b13578c882c4d4c6a1e74adb19384
---

 src/misc/cpu.c |   37 +++++++++++++++----------------------
 1 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/src/misc/cpu.c b/src/misc/cpu.c
index 39ac2e9..69b471b 100644
--- a/src/misc/cpu.c
+++ b/src/misc/cpu.c
@@ -105,28 +105,21 @@ void vlc_CPU_init (void)
      bool b_amd;
 
     /* Needed for x86 CPU capabilities detection */
-#   if defined( __x86_64__ )
-#       define cpuid( reg )                    \
-            asm volatile ( "cpuid\n\t"         \
-                         : "=a" ( i_eax ),     \
-                           "=b" ( i_ebx ),     \
-                           "=c" ( i_ecx ),     \
-                           "=d" ( i_edx )      \
-                         : "a"  ( reg )        \
-                         : "cc" );
-#   else
-#       define cpuid( reg )                    \
-            asm volatile ( "push %%ebx\n\t"    \
-                           "cpuid\n\t"         \
-                           "movl %%ebx,%1\n\t" \
-                           "pop %%ebx\n\t"     \
-                         : "=a" ( i_eax ),     \
-                           "=r" ( i_ebx ),     \
-                           "=c" ( i_ecx ),     \
-                           "=d" ( i_edx )      \
-                         : "a"  ( reg )        \
-                         : "cc" );
-#   endif
+# if defined (__i386__) && defined (__PIC__)
+#  define cpuid(reg) \
+     asm volatile ("xchgl %%ebx,%1\n\t" \
+                   "cpuid\n\t" \
+                   "xchgl %%ebx,%1\n\t" \
+                   : "=a" (i_eax), "=r" (i_ebx), "=c" (i_ecx), "=d" (i_edx) \
+                   : "a" (reg) \
+                   : "cc");
+# else
+#  define cpuid(reg) \
+     asm volatile ("cpuid\n\t" \
+                   : "=a" (i_eax), "=b" (i_ebx), "=c" (i_ecx), "=d" (i_edx) \
+                   : "a" (reg) \
+                   : "cc");
+# endif
      /* Check if the OS really supports the requested instructions */
 # if defined (__i386__) && !defined (__i486__) && !defined (__i586__) \
   && !defined (__i686__) && !defined (__pentium4__) \



More information about the vlc-commits mailing list