media/libjpeg/simd/jimmxfst.asm

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 ;
michael@0 2 ; jimmxfst.asm - fast integer IDCT (MMX)
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 ; This file contains a fast, not so accurate integer implementation of
michael@0 18 ; the inverse DCT (Discrete Cosine Transform). The following code is
michael@0 19 ; based directly on the IJG's original jidctfst.c; see the jidctfst.c
michael@0 20 ; for more details.
michael@0 21 ;
michael@0 22 ; [TAB8]
michael@0 23
michael@0 24 %include "jsimdext.inc"
michael@0 25 %include "jdct.inc"
michael@0 26
michael@0 27 ; --------------------------------------------------------------------------
michael@0 28
michael@0 29 %define CONST_BITS 8 ; 14 is also OK.
michael@0 30 %define PASS1_BITS 2
michael@0 31
michael@0 32 %if IFAST_SCALE_BITS != PASS1_BITS
michael@0 33 %error "'IFAST_SCALE_BITS' must be equal to 'PASS1_BITS'."
michael@0 34 %endif
michael@0 35
michael@0 36 %if CONST_BITS == 8
michael@0 37 F_1_082 equ 277 ; FIX(1.082392200)
michael@0 38 F_1_414 equ 362 ; FIX(1.414213562)
michael@0 39 F_1_847 equ 473 ; FIX(1.847759065)
michael@0 40 F_2_613 equ 669 ; FIX(2.613125930)
michael@0 41 F_1_613 equ (F_2_613 - 256) ; FIX(2.613125930) - FIX(1)
michael@0 42 %else
michael@0 43 ; NASM cannot do compile-time arithmetic on floating-point constants.
michael@0 44 %define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n))
michael@0 45 F_1_082 equ DESCALE(1162209775,30-CONST_BITS) ; FIX(1.082392200)
michael@0 46 F_1_414 equ DESCALE(1518500249,30-CONST_BITS) ; FIX(1.414213562)
michael@0 47 F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065)
michael@0 48 F_2_613 equ DESCALE(2805822602,30-CONST_BITS) ; FIX(2.613125930)
michael@0 49 F_1_613 equ (F_2_613 - (1 << CONST_BITS)) ; FIX(2.613125930) - FIX(1)
michael@0 50 %endif
michael@0 51
michael@0 52 ; --------------------------------------------------------------------------
michael@0 53 SECTION SEG_CONST
michael@0 54
michael@0 55 ; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow)
michael@0 56 ; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw)
michael@0 57
michael@0 58 %define PRE_MULTIPLY_SCALE_BITS 2
michael@0 59 %define CONST_SHIFT (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS)
michael@0 60
michael@0 61 alignz 16
michael@0 62 global EXTN(jconst_idct_ifast_mmx)
michael@0 63
michael@0 64 EXTN(jconst_idct_ifast_mmx):
michael@0 65
michael@0 66 PW_F1414 times 4 dw F_1_414 << CONST_SHIFT
michael@0 67 PW_F1847 times 4 dw F_1_847 << CONST_SHIFT
michael@0 68 PW_MF1613 times 4 dw -F_1_613 << CONST_SHIFT
michael@0 69 PW_F1082 times 4 dw F_1_082 << CONST_SHIFT
michael@0 70 PB_CENTERJSAMP times 8 db CENTERJSAMPLE
michael@0 71
michael@0 72 alignz 16
michael@0 73
michael@0 74 ; --------------------------------------------------------------------------
michael@0 75 SECTION SEG_TEXT
michael@0 76 BITS 32
michael@0 77 ;
michael@0 78 ; Perform dequantization and inverse DCT on one block of coefficients.
michael@0 79 ;
michael@0 80 ; GLOBAL(void)
michael@0 81 ; jsimd_idct_ifast_mmx (void * dct_table, JCOEFPTR coef_block,
michael@0 82 ; JSAMPARRAY output_buf, JDIMENSION output_col)
michael@0 83 ;
michael@0 84
michael@0 85 %define dct_table(b) (b)+8 ; jpeg_component_info * compptr
michael@0 86 %define coef_block(b) (b)+12 ; JCOEFPTR coef_block
michael@0 87 %define output_buf(b) (b)+16 ; JSAMPARRAY output_buf
michael@0 88 %define output_col(b) (b)+20 ; JDIMENSION output_col
michael@0 89
michael@0 90 %define original_ebp ebp+0
michael@0 91 %define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM]
michael@0 92 %define WK_NUM 2
michael@0 93 %define workspace wk(0)-DCTSIZE2*SIZEOF_JCOEF
michael@0 94 ; JCOEF workspace[DCTSIZE2]
michael@0 95
michael@0 96 align 16
michael@0 97 global EXTN(jsimd_idct_ifast_mmx)
michael@0 98
michael@0 99 EXTN(jsimd_idct_ifast_mmx):
michael@0 100 push ebp
michael@0 101 mov eax,esp ; eax = original ebp
michael@0 102 sub esp, byte 4
michael@0 103 and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits
michael@0 104 mov [esp],eax
michael@0 105 mov ebp,esp ; ebp = aligned ebp
michael@0 106 lea esp, [workspace]
michael@0 107 push ebx
michael@0 108 ; push ecx ; need not be preserved
michael@0 109 ; push edx ; need not be preserved
michael@0 110 push esi
michael@0 111 push edi
michael@0 112
michael@0 113 get_GOT ebx ; get GOT address
michael@0 114
michael@0 115 ; ---- Pass 1: process columns from input, store into work array.
michael@0 116
michael@0 117 ; mov eax, [original_ebp]
michael@0 118 mov edx, POINTER [dct_table(eax)] ; quantptr
michael@0 119 mov esi, JCOEFPTR [coef_block(eax)] ; inptr
michael@0 120 lea edi, [workspace] ; JCOEF * wsptr
michael@0 121 mov ecx, DCTSIZE/4 ; ctr
michael@0 122 alignx 16,7
michael@0 123 .columnloop:
michael@0 124 %ifndef NO_ZERO_COLUMN_TEST_IFAST_MMX
michael@0 125 mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
michael@0 126 or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
michael@0 127 jnz short .columnDCT
michael@0 128
michael@0 129 movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
michael@0 130 movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
michael@0 131 por mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
michael@0 132 por mm1, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
michael@0 133 por mm0, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
michael@0 134 por mm1, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
michael@0 135 por mm0, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
michael@0 136 por mm1,mm0
michael@0 137 packsswb mm1,mm1
michael@0 138 movd eax,mm1
michael@0 139 test eax,eax
michael@0 140 jnz short .columnDCT
michael@0 141
michael@0 142 ; -- AC terms all zero
michael@0 143
michael@0 144 movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
michael@0 145 pmullw mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_IFAST_MULT_TYPE)]
michael@0 146
michael@0 147 movq mm2,mm0 ; mm0=in0=(00 01 02 03)
michael@0 148 punpcklwd mm0,mm0 ; mm0=(00 00 01 01)
michael@0 149 punpckhwd mm2,mm2 ; mm2=(02 02 03 03)
michael@0 150
michael@0 151 movq mm1,mm0
michael@0 152 punpckldq mm0,mm0 ; mm0=(00 00 00 00)
michael@0 153 punpckhdq mm1,mm1 ; mm1=(01 01 01 01)
michael@0 154 movq mm3,mm2
michael@0 155 punpckldq mm2,mm2 ; mm2=(02 02 02 02)
michael@0 156 punpckhdq mm3,mm3 ; mm3=(03 03 03 03)
michael@0 157
michael@0 158 movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0
michael@0 159 movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm0
michael@0 160 movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1
michael@0 161 movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm1
michael@0 162 movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2
michael@0 163 movq MMWORD [MMBLOCK(2,1,edi,SIZEOF_JCOEF)], mm2
michael@0 164 movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3
michael@0 165 movq MMWORD [MMBLOCK(3,1,edi,SIZEOF_JCOEF)], mm3
michael@0 166 jmp near .nextcolumn
michael@0 167 alignx 16,7
michael@0 168 %endif
michael@0 169 .columnDCT:
michael@0 170
michael@0 171 ; -- Even part
michael@0 172
michael@0 173 movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
michael@0 174 movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
michael@0 175 pmullw mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_IFAST_MULT_TYPE)]
michael@0 176 pmullw mm1, MMWORD [MMBLOCK(2,0,edx,SIZEOF_IFAST_MULT_TYPE)]
michael@0 177 movq mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
michael@0 178 movq mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
michael@0 179 pmullw mm2, MMWORD [MMBLOCK(4,0,edx,SIZEOF_IFAST_MULT_TYPE)]
michael@0 180 pmullw mm3, MMWORD [MMBLOCK(6,0,edx,SIZEOF_IFAST_MULT_TYPE)]
michael@0 181
michael@0 182 movq mm4,mm0
michael@0 183 movq mm5,mm1
michael@0 184 psubw mm0,mm2 ; mm0=tmp11
michael@0 185 psubw mm1,mm3
michael@0 186 paddw mm4,mm2 ; mm4=tmp10
michael@0 187 paddw mm5,mm3 ; mm5=tmp13
michael@0 188
michael@0 189 psllw mm1,PRE_MULTIPLY_SCALE_BITS
michael@0 190 pmulhw mm1,[GOTOFF(ebx,PW_F1414)]
michael@0 191 psubw mm1,mm5 ; mm1=tmp12
michael@0 192
michael@0 193 movq mm6,mm4
michael@0 194 movq mm7,mm0
michael@0 195 psubw mm4,mm5 ; mm4=tmp3
michael@0 196 psubw mm0,mm1 ; mm0=tmp2
michael@0 197 paddw mm6,mm5 ; mm6=tmp0
michael@0 198 paddw mm7,mm1 ; mm7=tmp1
michael@0 199
michael@0 200 movq MMWORD [wk(1)], mm4 ; wk(1)=tmp3
michael@0 201 movq MMWORD [wk(0)], mm0 ; wk(0)=tmp2
michael@0 202
michael@0 203 ; -- Odd part
michael@0 204
michael@0 205 movq mm2, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
michael@0 206 movq mm3, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
michael@0 207 pmullw mm2, MMWORD [MMBLOCK(1,0,edx,SIZEOF_IFAST_MULT_TYPE)]
michael@0 208 pmullw mm3, MMWORD [MMBLOCK(3,0,edx,SIZEOF_IFAST_MULT_TYPE)]
michael@0 209 movq mm5, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
michael@0 210 movq mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
michael@0 211 pmullw mm5, MMWORD [MMBLOCK(5,0,edx,SIZEOF_IFAST_MULT_TYPE)]
michael@0 212 pmullw mm1, MMWORD [MMBLOCK(7,0,edx,SIZEOF_IFAST_MULT_TYPE)]
michael@0 213
michael@0 214 movq mm4,mm2
michael@0 215 movq mm0,mm5
michael@0 216 psubw mm2,mm1 ; mm2=z12
michael@0 217 psubw mm5,mm3 ; mm5=z10
michael@0 218 paddw mm4,mm1 ; mm4=z11
michael@0 219 paddw mm0,mm3 ; mm0=z13
michael@0 220
michael@0 221 movq mm1,mm5 ; mm1=z10(unscaled)
michael@0 222 psllw mm2,PRE_MULTIPLY_SCALE_BITS
michael@0 223 psllw mm5,PRE_MULTIPLY_SCALE_BITS
michael@0 224
michael@0 225 movq mm3,mm4
michael@0 226 psubw mm4,mm0
michael@0 227 paddw mm3,mm0 ; mm3=tmp7
michael@0 228
michael@0 229 psllw mm4,PRE_MULTIPLY_SCALE_BITS
michael@0 230 pmulhw mm4,[GOTOFF(ebx,PW_F1414)] ; mm4=tmp11
michael@0 231
michael@0 232 ; To avoid overflow...
michael@0 233 ;
michael@0 234 ; (Original)
michael@0 235 ; tmp12 = -2.613125930 * z10 + z5;
michael@0 236 ;
michael@0 237 ; (This implementation)
michael@0 238 ; tmp12 = (-1.613125930 - 1) * z10 + z5;
michael@0 239 ; = -1.613125930 * z10 - z10 + z5;
michael@0 240
michael@0 241 movq mm0,mm5
michael@0 242 paddw mm5,mm2
michael@0 243 pmulhw mm5,[GOTOFF(ebx,PW_F1847)] ; mm5=z5
michael@0 244 pmulhw mm0,[GOTOFF(ebx,PW_MF1613)]
michael@0 245 pmulhw mm2,[GOTOFF(ebx,PW_F1082)]
michael@0 246 psubw mm0,mm1
michael@0 247 psubw mm2,mm5 ; mm2=tmp10
michael@0 248 paddw mm0,mm5 ; mm0=tmp12
michael@0 249
michael@0 250 ; -- Final output stage
michael@0 251
michael@0 252 psubw mm0,mm3 ; mm0=tmp6
michael@0 253 movq mm1,mm6
michael@0 254 movq mm5,mm7
michael@0 255 paddw mm6,mm3 ; mm6=data0=(00 01 02 03)
michael@0 256 paddw mm7,mm0 ; mm7=data1=(10 11 12 13)
michael@0 257 psubw mm1,mm3 ; mm1=data7=(70 71 72 73)
michael@0 258 psubw mm5,mm0 ; mm5=data6=(60 61 62 63)
michael@0 259 psubw mm4,mm0 ; mm4=tmp5
michael@0 260
michael@0 261 movq mm3,mm6 ; transpose coefficients(phase 1)
michael@0 262 punpcklwd mm6,mm7 ; mm6=(00 10 01 11)
michael@0 263 punpckhwd mm3,mm7 ; mm3=(02 12 03 13)
michael@0 264 movq mm0,mm5 ; transpose coefficients(phase 1)
michael@0 265 punpcklwd mm5,mm1 ; mm5=(60 70 61 71)
michael@0 266 punpckhwd mm0,mm1 ; mm0=(62 72 63 73)
michael@0 267
michael@0 268 movq mm7, MMWORD [wk(0)] ; mm7=tmp2
michael@0 269 movq mm1, MMWORD [wk(1)] ; mm1=tmp3
michael@0 270
michael@0 271 movq MMWORD [wk(0)], mm5 ; wk(0)=(60 70 61 71)
michael@0 272 movq MMWORD [wk(1)], mm0 ; wk(1)=(62 72 63 73)
michael@0 273
michael@0 274 paddw mm2,mm4 ; mm2=tmp4
michael@0 275 movq mm5,mm7
michael@0 276 movq mm0,mm1
michael@0 277 paddw mm7,mm4 ; mm7=data2=(20 21 22 23)
michael@0 278 paddw mm1,mm2 ; mm1=data4=(40 41 42 43)
michael@0 279 psubw mm5,mm4 ; mm5=data5=(50 51 52 53)
michael@0 280 psubw mm0,mm2 ; mm0=data3=(30 31 32 33)
michael@0 281
michael@0 282 movq mm4,mm7 ; transpose coefficients(phase 1)
michael@0 283 punpcklwd mm7,mm0 ; mm7=(20 30 21 31)
michael@0 284 punpckhwd mm4,mm0 ; mm4=(22 32 23 33)
michael@0 285 movq mm2,mm1 ; transpose coefficients(phase 1)
michael@0 286 punpcklwd mm1,mm5 ; mm1=(40 50 41 51)
michael@0 287 punpckhwd mm2,mm5 ; mm2=(42 52 43 53)
michael@0 288
michael@0 289 movq mm0,mm6 ; transpose coefficients(phase 2)
michael@0 290 punpckldq mm6,mm7 ; mm6=(00 10 20 30)
michael@0 291 punpckhdq mm0,mm7 ; mm0=(01 11 21 31)
michael@0 292 movq mm5,mm3 ; transpose coefficients(phase 2)
michael@0 293 punpckldq mm3,mm4 ; mm3=(02 12 22 32)
michael@0 294 punpckhdq mm5,mm4 ; mm5=(03 13 23 33)
michael@0 295
michael@0 296 movq mm7, MMWORD [wk(0)] ; mm7=(60 70 61 71)
michael@0 297 movq mm4, MMWORD [wk(1)] ; mm4=(62 72 63 73)
michael@0 298
michael@0 299 movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm6
michael@0 300 movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm0
michael@0 301 movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm3
michael@0 302 movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm5
michael@0 303
michael@0 304 movq mm6,mm1 ; transpose coefficients(phase 2)
michael@0 305 punpckldq mm1,mm7 ; mm1=(40 50 60 70)
michael@0 306 punpckhdq mm6,mm7 ; mm6=(41 51 61 71)
michael@0 307 movq mm0,mm2 ; transpose coefficients(phase 2)
michael@0 308 punpckldq mm2,mm4 ; mm2=(42 52 62 72)
michael@0 309 punpckhdq mm0,mm4 ; mm0=(43 53 63 73)
michael@0 310
michael@0 311 movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm1
michael@0 312 movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm6
michael@0 313 movq MMWORD [MMBLOCK(2,1,edi,SIZEOF_JCOEF)], mm2
michael@0 314 movq MMWORD [MMBLOCK(3,1,edi,SIZEOF_JCOEF)], mm0
michael@0 315
michael@0 316 .nextcolumn:
michael@0 317 add esi, byte 4*SIZEOF_JCOEF ; coef_block
michael@0 318 add edx, byte 4*SIZEOF_IFAST_MULT_TYPE ; quantptr
michael@0 319 add edi, byte 4*DCTSIZE*SIZEOF_JCOEF ; wsptr
michael@0 320 dec ecx ; ctr
michael@0 321 jnz near .columnloop
michael@0 322
michael@0 323 ; ---- Pass 2: process rows from work array, store into output array.
michael@0 324
michael@0 325 mov eax, [original_ebp]
michael@0 326 lea esi, [workspace] ; JCOEF * wsptr
michael@0 327 mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *)
michael@0 328 mov eax, JDIMENSION [output_col(eax)]
michael@0 329 mov ecx, DCTSIZE/4 ; ctr
michael@0 330 alignx 16,7
michael@0 331 .rowloop:
michael@0 332
michael@0 333 ; -- Even part
michael@0 334
michael@0 335 movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
michael@0 336 movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
michael@0 337 movq mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
michael@0 338 movq mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
michael@0 339
michael@0 340 movq mm4,mm0
michael@0 341 movq mm5,mm1
michael@0 342 psubw mm0,mm2 ; mm0=tmp11
michael@0 343 psubw mm1,mm3
michael@0 344 paddw mm4,mm2 ; mm4=tmp10
michael@0 345 paddw mm5,mm3 ; mm5=tmp13
michael@0 346
michael@0 347 psllw mm1,PRE_MULTIPLY_SCALE_BITS
michael@0 348 pmulhw mm1,[GOTOFF(ebx,PW_F1414)]
michael@0 349 psubw mm1,mm5 ; mm1=tmp12
michael@0 350
michael@0 351 movq mm6,mm4
michael@0 352 movq mm7,mm0
michael@0 353 psubw mm4,mm5 ; mm4=tmp3
michael@0 354 psubw mm0,mm1 ; mm0=tmp2
michael@0 355 paddw mm6,mm5 ; mm6=tmp0
michael@0 356 paddw mm7,mm1 ; mm7=tmp1
michael@0 357
michael@0 358 movq MMWORD [wk(1)], mm4 ; wk(1)=tmp3
michael@0 359 movq MMWORD [wk(0)], mm0 ; wk(0)=tmp2
michael@0 360
michael@0 361 ; -- Odd part
michael@0 362
michael@0 363 movq mm2, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
michael@0 364 movq mm3, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
michael@0 365 movq mm5, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
michael@0 366 movq mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
michael@0 367
michael@0 368 movq mm4,mm2
michael@0 369 movq mm0,mm5
michael@0 370 psubw mm2,mm1 ; mm2=z12
michael@0 371 psubw mm5,mm3 ; mm5=z10
michael@0 372 paddw mm4,mm1 ; mm4=z11
michael@0 373 paddw mm0,mm3 ; mm0=z13
michael@0 374
michael@0 375 movq mm1,mm5 ; mm1=z10(unscaled)
michael@0 376 psllw mm2,PRE_MULTIPLY_SCALE_BITS
michael@0 377 psllw mm5,PRE_MULTIPLY_SCALE_BITS
michael@0 378
michael@0 379 movq mm3,mm4
michael@0 380 psubw mm4,mm0
michael@0 381 paddw mm3,mm0 ; mm3=tmp7
michael@0 382
michael@0 383 psllw mm4,PRE_MULTIPLY_SCALE_BITS
michael@0 384 pmulhw mm4,[GOTOFF(ebx,PW_F1414)] ; mm4=tmp11
michael@0 385
michael@0 386 ; To avoid overflow...
michael@0 387 ;
michael@0 388 ; (Original)
michael@0 389 ; tmp12 = -2.613125930 * z10 + z5;
michael@0 390 ;
michael@0 391 ; (This implementation)
michael@0 392 ; tmp12 = (-1.613125930 - 1) * z10 + z5;
michael@0 393 ; = -1.613125930 * z10 - z10 + z5;
michael@0 394
michael@0 395 movq mm0,mm5
michael@0 396 paddw mm5,mm2
michael@0 397 pmulhw mm5,[GOTOFF(ebx,PW_F1847)] ; mm5=z5
michael@0 398 pmulhw mm0,[GOTOFF(ebx,PW_MF1613)]
michael@0 399 pmulhw mm2,[GOTOFF(ebx,PW_F1082)]
michael@0 400 psubw mm0,mm1
michael@0 401 psubw mm2,mm5 ; mm2=tmp10
michael@0 402 paddw mm0,mm5 ; mm0=tmp12
michael@0 403
michael@0 404 ; -- Final output stage
michael@0 405
michael@0 406 psubw mm0,mm3 ; mm0=tmp6
michael@0 407 movq mm1,mm6
michael@0 408 movq mm5,mm7
michael@0 409 paddw mm6,mm3 ; mm6=data0=(00 10 20 30)
michael@0 410 paddw mm7,mm0 ; mm7=data1=(01 11 21 31)
michael@0 411 psraw mm6,(PASS1_BITS+3) ; descale
michael@0 412 psraw mm7,(PASS1_BITS+3) ; descale
michael@0 413 psubw mm1,mm3 ; mm1=data7=(07 17 27 37)
michael@0 414 psubw mm5,mm0 ; mm5=data6=(06 16 26 36)
michael@0 415 psraw mm1,(PASS1_BITS+3) ; descale
michael@0 416 psraw mm5,(PASS1_BITS+3) ; descale
michael@0 417 psubw mm4,mm0 ; mm4=tmp5
michael@0 418
michael@0 419 packsswb mm6,mm5 ; mm6=(00 10 20 30 06 16 26 36)
michael@0 420 packsswb mm7,mm1 ; mm7=(01 11 21 31 07 17 27 37)
michael@0 421
michael@0 422 movq mm3, MMWORD [wk(0)] ; mm3=tmp2
michael@0 423 movq mm0, MMWORD [wk(1)] ; mm0=tmp3
michael@0 424
michael@0 425 paddw mm2,mm4 ; mm2=tmp4
michael@0 426 movq mm5,mm3
michael@0 427 movq mm1,mm0
michael@0 428 paddw mm3,mm4 ; mm3=data2=(02 12 22 32)
michael@0 429 paddw mm0,mm2 ; mm0=data4=(04 14 24 34)
michael@0 430 psraw mm3,(PASS1_BITS+3) ; descale
michael@0 431 psraw mm0,(PASS1_BITS+3) ; descale
michael@0 432 psubw mm5,mm4 ; mm5=data5=(05 15 25 35)
michael@0 433 psubw mm1,mm2 ; mm1=data3=(03 13 23 33)
michael@0 434 psraw mm5,(PASS1_BITS+3) ; descale
michael@0 435 psraw mm1,(PASS1_BITS+3) ; descale
michael@0 436
michael@0 437 movq mm4,[GOTOFF(ebx,PB_CENTERJSAMP)] ; mm4=[PB_CENTERJSAMP]
michael@0 438
michael@0 439 packsswb mm3,mm0 ; mm3=(02 12 22 32 04 14 24 34)
michael@0 440 packsswb mm1,mm5 ; mm1=(03 13 23 33 05 15 25 35)
michael@0 441
michael@0 442 paddb mm6,mm4
michael@0 443 paddb mm7,mm4
michael@0 444 paddb mm3,mm4
michael@0 445 paddb mm1,mm4
michael@0 446
michael@0 447 movq mm2,mm6 ; transpose coefficients(phase 1)
michael@0 448 punpcklbw mm6,mm7 ; mm6=(00 01 10 11 20 21 30 31)
michael@0 449 punpckhbw mm2,mm7 ; mm2=(06 07 16 17 26 27 36 37)
michael@0 450 movq mm0,mm3 ; transpose coefficients(phase 1)
michael@0 451 punpcklbw mm3,mm1 ; mm3=(02 03 12 13 22 23 32 33)
michael@0 452 punpckhbw mm0,mm1 ; mm0=(04 05 14 15 24 25 34 35)
michael@0 453
michael@0 454 movq mm5,mm6 ; transpose coefficients(phase 2)
michael@0 455 punpcklwd mm6,mm3 ; mm6=(00 01 02 03 10 11 12 13)
michael@0 456 punpckhwd mm5,mm3 ; mm5=(20 21 22 23 30 31 32 33)
michael@0 457 movq mm4,mm0 ; transpose coefficients(phase 2)
michael@0 458 punpcklwd mm0,mm2 ; mm0=(04 05 06 07 14 15 16 17)
michael@0 459 punpckhwd mm4,mm2 ; mm4=(24 25 26 27 34 35 36 37)
michael@0 460
michael@0 461 movq mm7,mm6 ; transpose coefficients(phase 3)
michael@0 462 punpckldq mm6,mm0 ; mm6=(00 01 02 03 04 05 06 07)
michael@0 463 punpckhdq mm7,mm0 ; mm7=(10 11 12 13 14 15 16 17)
michael@0 464 movq mm1,mm5 ; transpose coefficients(phase 3)
michael@0 465 punpckldq mm5,mm4 ; mm5=(20 21 22 23 24 25 26 27)
michael@0 466 punpckhdq mm1,mm4 ; mm1=(30 31 32 33 34 35 36 37)
michael@0 467
michael@0 468 pushpic ebx ; save GOT address
michael@0 469
michael@0 470 mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
michael@0 471 mov ebx, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
michael@0 472 movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm6
michael@0 473 movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm7
michael@0 474 mov edx, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
michael@0 475 mov ebx, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
michael@0 476 movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm5
michael@0 477 movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm1
michael@0 478
michael@0 479 poppic ebx ; restore GOT address
michael@0 480
michael@0 481 add esi, byte 4*SIZEOF_JCOEF ; wsptr
michael@0 482 add edi, byte 4*SIZEOF_JSAMPROW
michael@0 483 dec ecx ; ctr
michael@0 484 jnz near .rowloop
michael@0 485
michael@0 486 emms ; empty MMX state
michael@0 487
michael@0 488 pop edi
michael@0 489 pop esi
michael@0 490 ; pop edx ; need not be preserved
michael@0 491 ; pop ecx ; need not be preserved
michael@0 492 pop ebx
michael@0 493 mov esp,ebp ; esp <- aligned ebp
michael@0 494 pop esp ; esp <- original ebp
michael@0 495 pop ebp
michael@0 496 ret
michael@0 497
michael@0 498 ; For some reason, the OS X linker does not honor the request to align the
michael@0 499 ; segment unless we do this.
michael@0 500 align 16

mercurial