[FFmpeg-devel] [PATCH]Use pushfl/popfl in cpuid.c

Reimar Döffinger Reimar.Doeffinger
Mon Nov 24 13:10:58 CET 2008


Hello,
On Mon, Nov 24, 2008 at 10:23:32AM -0000, M?ns Rullg?rd wrote:
> Reimar D?ffinger wrote:
> > On Mon, Nov 24, 2008 at 03:32:21AM +0100, Michael Niedermayer wrote:
> >> On Sun, Nov 23, 2008 at 08:42:11PM +0100, Reimar D?ffinger wrote:
> >> > On Sun, Nov 23, 2008 at 07:34:49PM +0100, Michael Niedermayer wrote:
> >> > > so it seems we are back to .byte 0x9C
> >> >
> >> > Hm, I'd be in favour of disabling the check on x86_64 and then going for
> >> > pushfl, or do you dislike that for some reason?
> >>
> >> IMHO if there is a cpuid flag on x86_64 (and i think there is but i
> >> didnt check) then it seems correct to check it ..
> >> but of course the argument, that all x86_64 cpus will likely support
> >> cpuid is pretty good as well, so i surely have no strong oppinion on
> >> this
> >
> > Well, I just checked, the x86_64 specification does not actually require
> > it it seems.
> 
> Has there been, or is there likely ever to be, an implementation without
> it?

No. But none of the solutions seems much better than the other.

> > How about
> > #ifdef ARCH_X86_64
> > #define PUSHF "pushfq\n\t"
> > #define POPF  "popfq\n\t"
> > #else
> > #define PUSHF "pushfl\n\t"
> > #define POPF  "popfl\n\t"
> > #endif
> > ?
> 
> Just make sure you test it on both.

Attached patch seems to work fine on x86_64 (make test passes).

Greetings,
Reimar D?ffinger
-------------- next part --------------
diff --git a/libavcodec/i386/cpuid.c b/libavcodec/i386/cpuid.c
index 2f2a669..cd33334 100644
--- a/libavcodec/i386/cpuid.c
+++ b/libavcodec/i386/cpuid.c
@@ -44,10 +44,17 @@ int mm_support(void)
     int max_std_level, max_ext_level, std_caps=0, ext_caps=0;
     x86_reg a, c;
 
+#ifdef ARCH_X86_64
+#define PUSHF "pushfq\n\t"
+#define POPF "popfq\n\t"
+#else
+#define PUSHF "pushfl\n\t"
+#define POPF "popfl\n\t"
+#endif
     __asm__ volatile (
         /* See if CPUID instruction is supported ... */
         /* ... Get copies of EFLAGS into eax and ecx */
-        "pushf\n\t"
+        PUSHF
         "pop %0\n\t"
         "mov %0, %1\n\t"
 
@@ -55,10 +62,10 @@ int mm_support(void)
         /*     to the EFLAGS reg */
         "xor $0x200000, %0\n\t"
         "push %0\n\t"
-        "popf\n\t"
+        POPF
 
         /* ... Get the (hopefully modified) EFLAGS */
-        "pushf\n\t"
+        PUSHF
         "pop %0\n\t"
         : "=a" (a), "=c" (c)
         :



More information about the ffmpeg-devel mailing list