3dphotoshoot

annotate libs/libpng/pnggccrd.c @ 14:06dc8b9b4f89

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