Logo Search packages:      
Sourcecode: djvulibre version File versions

int MMXControl::enable_mmx (  )  [static]

Detects and enable MMX or similar technologies. This function checks whether the CPU supports a vectorial instruction set (such as Intel's MMX) and enables them. Returns a boolean indicating whether such an instruction set is available. Speedups factors may vary.

Definition at line 135 of file MMX.cpp.

References mmxflag.

  int cpuflags = 0;
  const char *envvar = getenv("LIBDJVU_DISABLE_MMX");
  if (envvar && envvar[0] && envvar[0]!='0')
    return ((mmxflag = 0));
#if defined(MMX) && defined(__GNUC__) && defined(__i386__)
  // Detection of MMX for GCC
  __asm__ volatile ("pushl %%ebx\n\t"
                    "popl %%ecx\n\t"
                    "xorl %%edx,%%edx\n\t"
                    // Check that CPUID exists
                    "movl %%ecx,%%eax\n\t"
                    "xorl $0x200000,%%eax\n\t"
                    "pushl %%eax\n\t"
                    "popl %%eax\n\t"
                    "xorl %%ecx,%%eax\n\t"
                    "jz 1f\n\t"
                    "pushl %%ecx\n\t"
                    // Check that CR0:EM is clear
                    "smsw %%ax\n\t"
                    "andl $4,%%eax\n\t"
                    "jnz 1f\n\t"
                    // Execute CPUID
                    "movl $1,%%eax\n\t"
                    // EBX contains magic when -fPIC is on.
                "1:\tpopl %%ebx\n\t"
                    "movl %%edx, %0"
                    : "=m" (cpuflags) :
                    : "eax","ecx","edx");
#if defined(MMX) && defined(_MSC_VER) && defined(_M_IX86)
  // Detection of MMX for MSVC
  __asm {  pushfd
           pop     ecx
           xor     edx,edx
             ;// Check that CPUID exists
           mov     eax,ecx        
           xor     eax,0x200000
           push    eax
           pop     eax
           xor     eax,ecx
           jz      fini
           push    ecx
             ;// Check that CR0:EM is zero
           smsw    ax
           and     eax,4
           jnz     fini
             ;// Execute CPUID
           mov     eax,1
           _emit   0xf
           _emit   0xa2
           mov     cpuflags,edx
             ;// MSVC determines clobbered registers by scanning the assembly code.
             ;// Since it does not know CPUID, it would not know that EBX is clobbered
             ;// without the dummy instruction below...
           xor     ebx,ebx
  mmxflag = !!(cpuflags & 0x800000);
  return mmxflag;

Generated by  Doxygen 1.6.0   Back to index