istereo2

annotate libs/libpng/pnggccrd.c @ 32:622f61160016

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