On Thu, 28 Sep 2000, Robert Hegemann wrote:

> Mark Powell schrieb am Don, 28 Sep 2000:
> > >   Hmm, you may dig in the Gogo sources. If I remember right
> > >   they allowed to turn on optimizations with something like
> > >   --use-mmx. This could be a way to do it in LAME too.
> > 
> > Surely Gabriel was referring to the MMX code always being present in the
> > binary. On an non-MMX CPU it would fall back to using the old non-MMX
> > code. Thus never executing an illegal instruction. Isn't this how
> > commercial applications handle it? Of course if this is a lot of work, for
> > little gain, then forgive me :)
> >   Cheers.
> 
>       Mark, I got that already, but I have no idea how to check
>       for the presence of a MMX CPU. If someone knows how to do
>       that, fine! Maybe there is some special x86 command that
>       allows to decide whether it is a MMX CPU or not.

Looking at the startup code of FreeBSD it seems quite complex to identify
CPU accurately. Of course we just require MMX. Linux will of course have
similar sort of code. Unfortunately FreeBSD doesn't make this info
available anywhere for configure to find.
  Using configure doesn't address this issue properly though. As you point
out some sort of x86 asm is the global solution.
  Intel provide some code to do this at:

ftp://download.intel.nl/support/processors/procid/cpuinfo.zip

This determines whether the CPU supports the CPUID instruction:

-----SOURCE/CPUINF32/CPUID.C-----
WORD wincpuidsupport() {
        int cpuid_support = 1;

        _asm {
        pushfd                                  // Get original EFLAGS
                pop             eax
                mov     ecx, eax
        xor     eax, 200000h    // Flip ID bit in EFLAGS
        push    eax                             // Save new EFLAGS value
on
                                                        //   stack
        popfd                                   // Replace current EFLAGS
value
        pushfd                                  // Get new EFLAGS
        pop     eax                             // Store new EFLAGS in EAX
        xor     eax, ecx                // Can not toggle ID bit,
        jnz     support                 // Processor=80486
                
                mov cpuid_support,0             // Clear support flag
support:
      }
        
        return cpuid_support;

} // wincpuidsupport()
-----

i.e. if bit 21 of EFLAGS is writable then the CPU supports CPUID.
Once you've determined support you can use the undocumented(?) CPUID
instruction:

#define CPU_ID _asm _emit 0x0f _asm _emit 0xa2

Another function in that file wincpufeatures() will also find the CPU's
features using CPUID(0) and CPUID(1). It returns the 32bit features value
from the CPUID(1) instruction. According to the FreeBSD
/usr/src/sys/i386/i386/identcpu.c, bit 23 determines whether MMX is
supported.
  There's then the additional detection of Cyrix, AMD etc. which may cause
complications. AMD have a similar 32 bit features value which also uses
bit 23 to indicate MMX support.
  The AMD specific stuff and all the Intel supported stuff is better
explained at:

http://www.amd.com/products/cpg/athlon/techdocs/pdf/20734.pdf

  Like you I used to a lot of 68000 programming. Writing games and such on
the Atari ST. Since moving to the UNIX world I've had little use for
it. System admin is almost exclusively in perl with a bit of C for good
measure. Never touched x86 code before :(
  Whether executing the CPUID will generally cause a privilege violation
on a UNIX box, I'm not yet sure.

>       As a quick fix we could implement that command line switch
>       for LAME.

Probably the simplest way of doing it :)
  Cheers.

Mark Powell - UNIX System Administrator - The University of Salford
Academic Information Services, Clifford Whitworth Building,
Salford University, Manchester, M5 4WT, UK.
Tel: +44 161 295 5936  Fax: +44 161 295 5888  www.pgp.com for PGP key



--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to