nuclear@1: /* pnggccrd.c was removed from libpng-1.2.20. */ nuclear@1: nuclear@1: /* This code snippet is for use by configure's compilation test. */ nuclear@1: nuclear@1: #if (!defined _MSC_VER) && \ nuclear@1: defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \ nuclear@1: defined(PNG_MMX_CODE_SUPPORTED) nuclear@1: nuclear@1: int PNGAPI png_dummy_mmx_support(void); nuclear@1: nuclear@1: static int _mmx_supported = 2; // 0: no MMX; 1: MMX supported; 2: not tested nuclear@1: nuclear@1: int PNGAPI nuclear@1: png_dummy_mmx_support(void) __attribute__((noinline)); nuclear@1: nuclear@1: int PNGAPI nuclear@1: png_dummy_mmx_support(void) nuclear@1: { nuclear@1: int result; nuclear@1: #if defined(PNG_MMX_CODE_SUPPORTED) // superfluous, but what the heck nuclear@1: __asm__ __volatile__ ( nuclear@1: #if defined(__x86_64__) nuclear@1: "pushq %%rbx \n\t" // rbx gets clobbered by CPUID instruction nuclear@1: "pushq %%rcx \n\t" // so does rcx... nuclear@1: "pushq %%rdx \n\t" // ...and rdx (but rcx & rdx safe on Linux) nuclear@1: "pushfq \n\t" // save Eflag to stack nuclear@1: "popq %%rax \n\t" // get Eflag from stack into rax nuclear@1: "movq %%rax, %%rcx \n\t" // make another copy of Eflag in rcx nuclear@1: "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) nuclear@1: "pushq %%rax \n\t" // save modified Eflag back to stack nuclear@1: "popfq \n\t" // restore modified value to Eflag reg nuclear@1: "pushfq \n\t" // save Eflag to stack nuclear@1: "popq %%rax \n\t" // get Eflag from stack nuclear@1: "pushq %%rcx \n\t" // save original Eflag to stack nuclear@1: "popfq \n\t" // restore original Eflag nuclear@1: #else nuclear@1: "pushl %%ebx \n\t" // ebx gets clobbered by CPUID instruction nuclear@1: "pushl %%ecx \n\t" // so does ecx... nuclear@1: "pushl %%edx \n\t" // ...and edx (but ecx & edx safe on Linux) nuclear@1: "pushfl \n\t" // save Eflag to stack nuclear@1: "popl %%eax \n\t" // get Eflag from stack into eax nuclear@1: "movl %%eax, %%ecx \n\t" // make another copy of Eflag in ecx nuclear@1: "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) nuclear@1: "pushl %%eax \n\t" // save modified Eflag back to stack nuclear@1: "popfl \n\t" // restore modified value to Eflag reg nuclear@1: "pushfl \n\t" // save Eflag to stack nuclear@1: "popl %%eax \n\t" // get Eflag from stack nuclear@1: "pushl %%ecx \n\t" // save original Eflag to stack nuclear@1: "popfl \n\t" // restore original Eflag nuclear@1: #endif nuclear@1: "xorl %%ecx, %%eax \n\t" // compare new Eflag with original Eflag nuclear@1: "jz 0f \n\t" // if same, CPUID instr. is not supported nuclear@1: nuclear@1: "xorl %%eax, %%eax \n\t" // set eax to zero nuclear@1: // ".byte 0x0f, 0xa2 \n\t" // CPUID instruction (two-byte opcode) nuclear@1: "cpuid \n\t" // get the CPU identification info nuclear@1: "cmpl $1, %%eax \n\t" // make sure eax return non-zero value nuclear@1: "jl 0f \n\t" // if eax is zero, MMX is not supported nuclear@1: nuclear@1: "xorl %%eax, %%eax \n\t" // set eax to zero and... nuclear@1: "incl %%eax \n\t" // ...increment eax to 1. This pair is nuclear@1: // faster than the instruction "mov eax, 1" nuclear@1: "cpuid \n\t" // get the CPU identification info again nuclear@1: "andl $0x800000, %%edx \n\t" // mask out all bits but MMX bit (23) nuclear@1: "cmpl $0, %%edx \n\t" // 0 = MMX not supported nuclear@1: "jz 0f \n\t" // non-zero = yes, MMX IS supported nuclear@1: nuclear@1: "movl $1, %%eax \n\t" // set return value to 1 nuclear@1: "jmp 1f \n\t" // DONE: have MMX support nuclear@1: nuclear@1: "0: \n\t" // .NOT_SUPPORTED: target label for jump instructions nuclear@1: "movl $0, %%eax \n\t" // set return value to 0 nuclear@1: "1: \n\t" // .RETURN: target label for jump instructions nuclear@1: #if defined(__x86_64__) nuclear@1: "popq %%rdx \n\t" // restore rdx nuclear@1: "popq %%rcx \n\t" // restore rcx nuclear@1: "popq %%rbx \n\t" // restore rbx nuclear@1: #else nuclear@1: "popl %%edx \n\t" // restore edx nuclear@1: "popl %%ecx \n\t" // restore ecx nuclear@1: "popl %%ebx \n\t" // restore ebx nuclear@1: #endif nuclear@1: nuclear@1: // "ret \n\t" // DONE: no MMX support nuclear@1: // (fall through to standard C "ret") nuclear@1: nuclear@1: : "=a" (result) // output list nuclear@1: nuclear@1: : // any variables used on input (none) nuclear@1: nuclear@1: // no clobber list nuclear@1: // , "%ebx", "%ecx", "%edx" // GRR: we handle these manually nuclear@1: // , "memory" // if write to a variable gcc thought was in a reg nuclear@1: // , "cc" // "condition codes" (flag bits) nuclear@1: ); nuclear@1: _mmx_supported = result; nuclear@1: #else nuclear@1: _mmx_supported = 0; nuclear@1: #endif /* PNG_MMX_CODE_SUPPORTED */ nuclear@1: nuclear@1: return _mmx_supported; nuclear@1: } nuclear@1: #endif