Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | ; |
michael@0 | 2 | ; jcqnts2i.asm - sample data conversion and quantization (SSE2) |
michael@0 | 3 | ; |
michael@0 | 4 | ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
michael@0 | 5 | ; |
michael@0 | 6 | ; Based on |
michael@0 | 7 | ; x86 SIMD extension for IJG JPEG library |
michael@0 | 8 | ; Copyright (C) 1999-2006, MIYASAKA Masaru. |
michael@0 | 9 | ; For conditions of distribution and use, see copyright notice in jsimdext.inc |
michael@0 | 10 | ; |
michael@0 | 11 | ; This file should be assembled with NASM (Netwide Assembler), |
michael@0 | 12 | ; can *not* be assembled with Microsoft's MASM or any compatible |
michael@0 | 13 | ; assembler (including Borland's Turbo Assembler). |
michael@0 | 14 | ; NASM is available from http://nasm.sourceforge.net/ or |
michael@0 | 15 | ; http://sourceforge.net/project/showfiles.php?group_id=6208 |
michael@0 | 16 | ; |
michael@0 | 17 | ; [TAB8] |
michael@0 | 18 | |
michael@0 | 19 | %include "jsimdext.inc" |
michael@0 | 20 | %include "jdct.inc" |
michael@0 | 21 | |
michael@0 | 22 | ; -------------------------------------------------------------------------- |
michael@0 | 23 | SECTION SEG_TEXT |
michael@0 | 24 | BITS 32 |
michael@0 | 25 | ; |
michael@0 | 26 | ; Load data into workspace, applying unsigned->signed conversion |
michael@0 | 27 | ; |
michael@0 | 28 | ; GLOBAL(void) |
michael@0 | 29 | ; jsimd_convsamp_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col, |
michael@0 | 30 | ; DCTELEM * workspace); |
michael@0 | 31 | ; |
michael@0 | 32 | |
michael@0 | 33 | %define sample_data ebp+8 ; JSAMPARRAY sample_data |
michael@0 | 34 | %define start_col ebp+12 ; JDIMENSION start_col |
michael@0 | 35 | %define workspace ebp+16 ; DCTELEM * workspace |
michael@0 | 36 | |
michael@0 | 37 | align 16 |
michael@0 | 38 | global EXTN(jsimd_convsamp_sse2) |
michael@0 | 39 | |
michael@0 | 40 | EXTN(jsimd_convsamp_sse2): |
michael@0 | 41 | push ebp |
michael@0 | 42 | mov ebp,esp |
michael@0 | 43 | push ebx |
michael@0 | 44 | ; push ecx ; need not be preserved |
michael@0 | 45 | ; push edx ; need not be preserved |
michael@0 | 46 | push esi |
michael@0 | 47 | push edi |
michael@0 | 48 | |
michael@0 | 49 | pxor xmm6,xmm6 ; xmm6=(all 0's) |
michael@0 | 50 | pcmpeqw xmm7,xmm7 |
michael@0 | 51 | psllw xmm7,7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..} |
michael@0 | 52 | |
michael@0 | 53 | mov esi, JSAMPARRAY [sample_data] ; (JSAMPROW *) |
michael@0 | 54 | mov eax, JDIMENSION [start_col] |
michael@0 | 55 | mov edi, POINTER [workspace] ; (DCTELEM *) |
michael@0 | 56 | mov ecx, DCTSIZE/4 |
michael@0 | 57 | alignx 16,7 |
michael@0 | 58 | .convloop: |
michael@0 | 59 | mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) |
michael@0 | 60 | mov edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) |
michael@0 | 61 | |
michael@0 | 62 | movq xmm0, XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE] ; xmm0=(01234567) |
michael@0 | 63 | movq xmm1, XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE] ; xmm1=(89ABCDEF) |
michael@0 | 64 | |
michael@0 | 65 | mov ebx, JSAMPROW [esi+2*SIZEOF_JSAMPROW] ; (JSAMPLE *) |
michael@0 | 66 | mov edx, JSAMPROW [esi+3*SIZEOF_JSAMPROW] ; (JSAMPLE *) |
michael@0 | 67 | |
michael@0 | 68 | movq xmm2, XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE] ; xmm2=(GHIJKLMN) |
michael@0 | 69 | movq xmm3, XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE] ; xmm3=(OPQRSTUV) |
michael@0 | 70 | |
michael@0 | 71 | punpcklbw xmm0,xmm6 ; xmm0=(01234567) |
michael@0 | 72 | punpcklbw xmm1,xmm6 ; xmm1=(89ABCDEF) |
michael@0 | 73 | paddw xmm0,xmm7 |
michael@0 | 74 | paddw xmm1,xmm7 |
michael@0 | 75 | punpcklbw xmm2,xmm6 ; xmm2=(GHIJKLMN) |
michael@0 | 76 | punpcklbw xmm3,xmm6 ; xmm3=(OPQRSTUV) |
michael@0 | 77 | paddw xmm2,xmm7 |
michael@0 | 78 | paddw xmm3,xmm7 |
michael@0 | 79 | |
michael@0 | 80 | movdqa XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_DCTELEM)], xmm0 |
michael@0 | 81 | movdqa XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_DCTELEM)], xmm1 |
michael@0 | 82 | movdqa XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_DCTELEM)], xmm2 |
michael@0 | 83 | movdqa XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_DCTELEM)], xmm3 |
michael@0 | 84 | |
michael@0 | 85 | add esi, byte 4*SIZEOF_JSAMPROW |
michael@0 | 86 | add edi, byte 4*DCTSIZE*SIZEOF_DCTELEM |
michael@0 | 87 | dec ecx |
michael@0 | 88 | jnz short .convloop |
michael@0 | 89 | |
michael@0 | 90 | pop edi |
michael@0 | 91 | pop esi |
michael@0 | 92 | ; pop edx ; need not be preserved |
michael@0 | 93 | ; pop ecx ; need not be preserved |
michael@0 | 94 | pop ebx |
michael@0 | 95 | pop ebp |
michael@0 | 96 | ret |
michael@0 | 97 | |
michael@0 | 98 | ; -------------------------------------------------------------------------- |
michael@0 | 99 | ; |
michael@0 | 100 | ; Quantize/descale the coefficients, and store into coef_block |
michael@0 | 101 | ; |
michael@0 | 102 | ; This implementation is based on an algorithm described in |
michael@0 | 103 | ; "How to optimize for the Pentium family of microprocessors" |
michael@0 | 104 | ; (http://www.agner.org/assem/). |
michael@0 | 105 | ; |
michael@0 | 106 | ; GLOBAL(void) |
michael@0 | 107 | ; jsimd_quantize_sse2 (JCOEFPTR coef_block, DCTELEM * divisors, |
michael@0 | 108 | ; DCTELEM * workspace); |
michael@0 | 109 | ; |
michael@0 | 110 | |
michael@0 | 111 | %define RECIPROCAL(m,n,b) XMMBLOCK(DCTSIZE*0+(m),(n),(b),SIZEOF_DCTELEM) |
michael@0 | 112 | %define CORRECTION(m,n,b) XMMBLOCK(DCTSIZE*1+(m),(n),(b),SIZEOF_DCTELEM) |
michael@0 | 113 | %define SCALE(m,n,b) XMMBLOCK(DCTSIZE*2+(m),(n),(b),SIZEOF_DCTELEM) |
michael@0 | 114 | |
michael@0 | 115 | %define coef_block ebp+8 ; JCOEFPTR coef_block |
michael@0 | 116 | %define divisors ebp+12 ; DCTELEM * divisors |
michael@0 | 117 | %define workspace ebp+16 ; DCTELEM * workspace |
michael@0 | 118 | |
michael@0 | 119 | align 16 |
michael@0 | 120 | global EXTN(jsimd_quantize_sse2) |
michael@0 | 121 | |
michael@0 | 122 | EXTN(jsimd_quantize_sse2): |
michael@0 | 123 | push ebp |
michael@0 | 124 | mov ebp,esp |
michael@0 | 125 | ; push ebx ; unused |
michael@0 | 126 | ; push ecx ; unused |
michael@0 | 127 | ; push edx ; need not be preserved |
michael@0 | 128 | push esi |
michael@0 | 129 | push edi |
michael@0 | 130 | |
michael@0 | 131 | mov esi, POINTER [workspace] |
michael@0 | 132 | mov edx, POINTER [divisors] |
michael@0 | 133 | mov edi, JCOEFPTR [coef_block] |
michael@0 | 134 | mov eax, DCTSIZE2/32 |
michael@0 | 135 | alignx 16,7 |
michael@0 | 136 | .quantloop: |
michael@0 | 137 | movdqa xmm4, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_DCTELEM)] |
michael@0 | 138 | movdqa xmm5, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_DCTELEM)] |
michael@0 | 139 | movdqa xmm6, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_DCTELEM)] |
michael@0 | 140 | movdqa xmm7, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_DCTELEM)] |
michael@0 | 141 | movdqa xmm0,xmm4 |
michael@0 | 142 | movdqa xmm1,xmm5 |
michael@0 | 143 | movdqa xmm2,xmm6 |
michael@0 | 144 | movdqa xmm3,xmm7 |
michael@0 | 145 | psraw xmm4,(WORD_BIT-1) |
michael@0 | 146 | psraw xmm5,(WORD_BIT-1) |
michael@0 | 147 | psraw xmm6,(WORD_BIT-1) |
michael@0 | 148 | psraw xmm7,(WORD_BIT-1) |
michael@0 | 149 | pxor xmm0,xmm4 |
michael@0 | 150 | pxor xmm1,xmm5 |
michael@0 | 151 | pxor xmm2,xmm6 |
michael@0 | 152 | pxor xmm3,xmm7 |
michael@0 | 153 | psubw xmm0,xmm4 ; if (xmm0 < 0) xmm0 = -xmm0; |
michael@0 | 154 | psubw xmm1,xmm5 ; if (xmm1 < 0) xmm1 = -xmm1; |
michael@0 | 155 | psubw xmm2,xmm6 ; if (xmm2 < 0) xmm2 = -xmm2; |
michael@0 | 156 | psubw xmm3,xmm7 ; if (xmm3 < 0) xmm3 = -xmm3; |
michael@0 | 157 | |
michael@0 | 158 | paddw xmm0, XMMWORD [CORRECTION(0,0,edx)] ; correction + roundfactor |
michael@0 | 159 | paddw xmm1, XMMWORD [CORRECTION(1,0,edx)] |
michael@0 | 160 | paddw xmm2, XMMWORD [CORRECTION(2,0,edx)] |
michael@0 | 161 | paddw xmm3, XMMWORD [CORRECTION(3,0,edx)] |
michael@0 | 162 | pmulhuw xmm0, XMMWORD [RECIPROCAL(0,0,edx)] ; reciprocal |
michael@0 | 163 | pmulhuw xmm1, XMMWORD [RECIPROCAL(1,0,edx)] |
michael@0 | 164 | pmulhuw xmm2, XMMWORD [RECIPROCAL(2,0,edx)] |
michael@0 | 165 | pmulhuw xmm3, XMMWORD [RECIPROCAL(3,0,edx)] |
michael@0 | 166 | pmulhuw xmm0, XMMWORD [SCALE(0,0,edx)] ; scale |
michael@0 | 167 | pmulhuw xmm1, XMMWORD [SCALE(1,0,edx)] |
michael@0 | 168 | pmulhuw xmm2, XMMWORD [SCALE(2,0,edx)] |
michael@0 | 169 | pmulhuw xmm3, XMMWORD [SCALE(3,0,edx)] |
michael@0 | 170 | |
michael@0 | 171 | pxor xmm0,xmm4 |
michael@0 | 172 | pxor xmm1,xmm5 |
michael@0 | 173 | pxor xmm2,xmm6 |
michael@0 | 174 | pxor xmm3,xmm7 |
michael@0 | 175 | psubw xmm0,xmm4 |
michael@0 | 176 | psubw xmm1,xmm5 |
michael@0 | 177 | psubw xmm2,xmm6 |
michael@0 | 178 | psubw xmm3,xmm7 |
michael@0 | 179 | movdqa XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_DCTELEM)], xmm0 |
michael@0 | 180 | movdqa XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_DCTELEM)], xmm1 |
michael@0 | 181 | movdqa XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_DCTELEM)], xmm2 |
michael@0 | 182 | movdqa XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_DCTELEM)], xmm3 |
michael@0 | 183 | |
michael@0 | 184 | add esi, byte 32*SIZEOF_DCTELEM |
michael@0 | 185 | add edx, byte 32*SIZEOF_DCTELEM |
michael@0 | 186 | add edi, byte 32*SIZEOF_JCOEF |
michael@0 | 187 | dec eax |
michael@0 | 188 | jnz near .quantloop |
michael@0 | 189 | |
michael@0 | 190 | pop edi |
michael@0 | 191 | pop esi |
michael@0 | 192 | ; pop edx ; need not be preserved |
michael@0 | 193 | ; pop ecx ; unused |
michael@0 | 194 | ; pop ebx ; unused |
michael@0 | 195 | pop ebp |
michael@0 | 196 | ret |
michael@0 | 197 | |
michael@0 | 198 | ; For some reason, the OS X linker does not honor the request to align the |
michael@0 | 199 | ; segment unless we do this. |
michael@0 | 200 | align 16 |