| 1 | /* pnggccrd.c was removed from libpng-1.2.20. */ |
| 2 | |
| 3 | /* This code snippet is for use by configure's compilation test. */ |
| 4 | |
| 5 | #if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \ |
| 6 | defined(PNG_MMX_CODE_SUPPORTED) |
| 7 | int PNGAPI png_dummy_mmx_support(void); |
| 8 | |
| 9 | static int _mmx_supported = 2; // 0: no MMX; 1: MMX supported; 2: not tested |
| 10 | |
| 11 | int PNGAPI |
| 12 | png_dummy_mmx_support(void) __attribute__((noinline)); |
| 13 | |
| 14 | int PNGAPI |
| 15 | png_dummy_mmx_support(void) |
| 16 | { |
| 17 | int result; |
| 18 | #if defined(PNG_MMX_CODE_SUPPORTED) // superfluous, but what the heck |
| 19 | __asm__ __volatile__ ( |
| 20 | #if defined(__x86_64__) |
| 21 | "pushq %%rbx \n\t" // rbx gets clobbered by CPUID instruction |
| 22 | "pushq %%rcx \n\t" // so does rcx... |
| 23 | "pushq %%rdx \n\t" // ...and rdx (but rcx & rdx safe on Linux) |
| 24 | "pushfq \n\t" // save Eflag to stack |
| 25 | "popq %%rax \n\t" // get Eflag from stack into rax |
| 26 | "movq %%rax, %%rcx \n\t" // make another copy of Eflag in rcx |
| 27 | "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) |
| 28 | "pushq %%rax \n\t" // save modified Eflag back to stack |
| 29 | "popfq \n\t" // restore modified value to Eflag reg |
| 30 | "pushfq \n\t" // save Eflag to stack |
| 31 | "popq %%rax \n\t" // get Eflag from stack |
| 32 | "pushq %%rcx \n\t" // save original Eflag to stack |
| 33 | "popfq \n\t" // restore original Eflag |
| 34 | #else |
| 35 | "pushl %%ebx \n\t" // ebx gets clobbered by CPUID instruction |
| 36 | "pushl %%ecx \n\t" // so does ecx... |
| 37 | "pushl %%edx \n\t" // ...and edx (but ecx & edx safe on Linux) |
| 38 | "pushfl \n\t" // save Eflag to stack |
| 39 | "popl %%eax \n\t" // get Eflag from stack into eax |
| 40 | "movl %%eax, %%ecx \n\t" // make another copy of Eflag in ecx |
| 41 | "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) |
| 42 | "pushl %%eax \n\t" // save modified Eflag back to stack |
| 43 | "popfl \n\t" // restore modified value to Eflag reg |
| 44 | "pushfl \n\t" // save Eflag to stack |
| 45 | "popl %%eax \n\t" // get Eflag from stack |
| 46 | "pushl %%ecx \n\t" // save original Eflag to stack |
| 47 | "popfl \n\t" // restore original Eflag |
| 48 | #endif |
| 49 | "xorl %%ecx, %%eax \n\t" // compare new Eflag with original Eflag |
| 50 | "jz 0f \n\t" // if same, CPUID instr. is not supported |
| 51 | |
| 52 | "xorl %%eax, %%eax \n\t" // set eax to zero |
| 53 | // ".byte 0x0f, 0xa2 \n\t" // CPUID instruction (two-byte opcode) |
| 54 | "cpuid \n\t" // get the CPU identification info |
| 55 | "cmpl $1, %%eax \n\t" // make sure eax return non-zero value |
| 56 | "jl 0f \n\t" // if eax is zero, MMX is not supported |
| 57 | |
| 58 | "xorl %%eax, %%eax \n\t" // set eax to zero and... |
| 59 | "incl %%eax \n\t" // ...increment eax to 1. This pair is |
| 60 | // faster than the instruction "mov eax, 1" |
| 61 | "cpuid \n\t" // get the CPU identification info again |
| 62 | "andl $0x800000, %%edx \n\t" // mask out all bits but MMX bit (23) |
| 63 | "cmpl $0, %%edx \n\t" // 0 = MMX not supported |
| 64 | "jz 0f \n\t" // non-zero = yes, MMX IS supported |
| 65 | |
| 66 | "movl $1, %%eax \n\t" // set return value to 1 |
| 67 | "jmp 1f \n\t" // DONE: have MMX support |
| 68 | |
| 69 | "0: \n\t" // .NOT_SUPPORTED: target label for jump instructions |
| 70 | "movl $0, %%eax \n\t" // set return value to 0 |
| 71 | "1: \n\t" // .RETURN: target label for jump instructions |
| 72 | #if defined(__x86_64__) |
| 73 | "popq %%rdx \n\t" // restore rdx |
| 74 | "popq %%rcx \n\t" // restore rcx |
| 75 | "popq %%rbx \n\t" // restore rbx |
| 76 | #else |
| 77 | "popl %%edx \n\t" // restore edx |
| 78 | "popl %%ecx \n\t" // restore ecx |
| 79 | "popl %%ebx \n\t" // restore ebx |
| 80 | #endif |
| 81 | |
| 82 | // "ret \n\t" // DONE: no MMX support |
| 83 | // (fall through to standard C "ret") |
| 84 | |
| 85 | : "=a" (result) // output list |
| 86 | |
| 87 | : // any variables used on input (none) |
| 88 | |
| 89 | // no clobber list |
| 90 | // , "%ebx", "%ecx", "%edx" // GRR: we handle these manually |
| 91 | // , "memory" // if write to a variable gcc thought was in a reg |
| 92 | // , "cc" // "condition codes" (flag bits) |
| 93 | ); |
| 94 | _mmx_supported = result; |
| 95 | #else |
| 96 | _mmx_supported = 0; |
| 97 | #endif /* PNG_MMX_CODE_SUPPORTED */ |
| 98 | |
| 99 | return _mmx_supported; |
| 100 | } |
| 101 | #endif |