istereo

annotate libs/libpng/pnggccrd.c @ 40:9e8fb79fd959

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