1; 2; jidctred.asm - reduced-size IDCT (MMX) 3; 4; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB 5; Copyright (C) 2016, D. R. Commander. 6; 7; Based on the x86 SIMD extension for IJG JPEG library 8; Copyright (C) 1999-2006, MIYASAKA Masaru. 9; For conditions of distribution and use, see copyright notice in jsimdext.inc 10; 11; This file should be assembled with NASM (Netwide Assembler), 12; can *not* be assembled with Microsoft's MASM or any compatible 13; assembler (including Borland's Turbo Assembler). 14; NASM is available from http://nasm.sourceforge.net/ or 15; http://sourceforge.net/project/showfiles.php?group_id=6208 16; 17; This file contains inverse-DCT routines that produce reduced-size 18; output: either 4x4 or 2x2 pixels from an 8x8 DCT block. 19; The following code is based directly on the IJG's original jidctred.c; 20; see the jidctred.c for more details. 21; 22; [TAB8] 23 24%include "jsimdext.inc" 25%include "jdct.inc" 26 27; -------------------------------------------------------------------------- 28 29%define CONST_BITS 13 30%define PASS1_BITS 2 31 32%define DESCALE_P1_4 (CONST_BITS - PASS1_BITS + 1) 33%define DESCALE_P2_4 (CONST_BITS + PASS1_BITS + 3 + 1) 34%define DESCALE_P1_2 (CONST_BITS - PASS1_BITS + 2) 35%define DESCALE_P2_2 (CONST_BITS + PASS1_BITS + 3 + 2) 36 37%if CONST_BITS == 13 38F_0_211 equ 1730 ; FIX(0.211164243) 39F_0_509 equ 4176 ; FIX(0.509795579) 40F_0_601 equ 4926 ; FIX(0.601344887) 41F_0_720 equ 5906 ; FIX(0.720959822) 42F_0_765 equ 6270 ; FIX(0.765366865) 43F_0_850 equ 6967 ; FIX(0.850430095) 44F_0_899 equ 7373 ; FIX(0.899976223) 45F_1_061 equ 8697 ; FIX(1.061594337) 46F_1_272 equ 10426 ; FIX(1.272758580) 47F_1_451 equ 11893 ; FIX(1.451774981) 48F_1_847 equ 15137 ; FIX(1.847759065) 49F_2_172 equ 17799 ; FIX(2.172734803) 50F_2_562 equ 20995 ; FIX(2.562915447) 51F_3_624 equ 29692 ; FIX(3.624509785) 52%else 53; NASM cannot do compile-time arithmetic on floating-point constants. 54%define DESCALE(x, n) (((x) + (1 << ((n) - 1))) >> (n)) 55F_0_211 equ DESCALE( 226735879, 30 - CONST_BITS) ; FIX(0.211164243) 56F_0_509 equ DESCALE( 547388834, 30 - CONST_BITS) ; FIX(0.509795579) 57F_0_601 equ DESCALE( 645689155, 30 - CONST_BITS) ; FIX(0.601344887) 58F_0_720 equ DESCALE( 774124714, 30 - CONST_BITS) ; FIX(0.720959822) 59F_0_765 equ DESCALE( 821806413, 30 - CONST_BITS) ; FIX(0.765366865) 60F_0_850 equ DESCALE( 913142361, 30 - CONST_BITS) ; FIX(0.850430095) 61F_0_899 equ DESCALE( 966342111, 30 - CONST_BITS) ; FIX(0.899976223) 62F_1_061 equ DESCALE(1139878239, 30 - CONST_BITS) ; FIX(1.061594337) 63F_1_272 equ DESCALE(1366614119, 30 - CONST_BITS) ; FIX(1.272758580) 64F_1_451 equ DESCALE(1558831516, 30 - CONST_BITS) ; FIX(1.451774981) 65F_1_847 equ DESCALE(1984016188, 30 - CONST_BITS) ; FIX(1.847759065) 66F_2_172 equ DESCALE(2332956230, 30 - CONST_BITS) ; FIX(2.172734803) 67F_2_562 equ DESCALE(2751909506, 30 - CONST_BITS) ; FIX(2.562915447) 68F_3_624 equ DESCALE(3891787747, 30 - CONST_BITS) ; FIX(3.624509785) 69%endif 70 71; -------------------------------------------------------------------------- 72 SECTION SEG_CONST 73 74 alignz 32 75 GLOBAL_DATA(jconst_idct_red_mmx) 76 77EXTN(jconst_idct_red_mmx): 78 79PW_F184_MF076 times 2 dw F_1_847, -F_0_765 80PW_F256_F089 times 2 dw F_2_562, F_0_899 81PW_F106_MF217 times 2 dw F_1_061, -F_2_172 82PW_MF060_MF050 times 2 dw -F_0_601, -F_0_509 83PW_F145_MF021 times 2 dw F_1_451, -F_0_211 84PW_F362_MF127 times 2 dw F_3_624, -F_1_272 85PW_F085_MF072 times 2 dw F_0_850, -F_0_720 86PD_DESCALE_P1_4 times 2 dd 1 << (DESCALE_P1_4 - 1) 87PD_DESCALE_P2_4 times 2 dd 1 << (DESCALE_P2_4 - 1) 88PD_DESCALE_P1_2 times 2 dd 1 << (DESCALE_P1_2 - 1) 89PD_DESCALE_P2_2 times 2 dd 1 << (DESCALE_P2_2 - 1) 90PB_CENTERJSAMP times 8 db CENTERJSAMPLE 91 92 alignz 32 93 94; -------------------------------------------------------------------------- 95 SECTION SEG_TEXT 96 BITS 32 97; 98; Perform dequantization and inverse DCT on one block of coefficients, 99; producing a reduced-size 4x4 output block. 100; 101; GLOBAL(void) 102; jsimd_idct_4x4_mmx(void *dct_table, JCOEFPTR coef_block, 103; JSAMPARRAY output_buf, JDIMENSION output_col) 104; 105 106%define dct_table(b) (b) + 8 ; void *dct_table 107%define coef_block(b) (b) + 12 ; JCOEFPTR coef_block 108%define output_buf(b) (b) + 16 ; JSAMPARRAY output_buf 109%define output_col(b) (b) + 20 ; JDIMENSION output_col 110 111%define original_ebp ebp + 0 112%define wk(i) ebp - (WK_NUM - (i)) * SIZEOF_MMWORD 113 ; mmword wk[WK_NUM] 114%define WK_NUM 2 115%define workspace wk(0) - DCTSIZE2 * SIZEOF_JCOEF 116 ; JCOEF workspace[DCTSIZE2] 117 118 align 32 119 GLOBAL_FUNCTION(jsimd_idct_4x4_mmx) 120 121EXTN(jsimd_idct_4x4_mmx): 122 push ebp 123 mov eax, esp ; eax = original ebp 124 sub esp, byte 4 125 and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits 126 mov [esp], eax 127 mov ebp, esp ; ebp = aligned ebp 128 lea esp, [workspace] 129 pushpic ebx 130; push ecx ; need not be preserved 131; push edx ; need not be preserved 132 push esi 133 push edi 134 135 get_GOT ebx ; get GOT address 136 137 ; ---- Pass 1: process columns from input, store into work array. 138 139; mov eax, [original_ebp] 140 mov edx, POINTER [dct_table(eax)] ; quantptr 141 mov esi, JCOEFPTR [coef_block(eax)] ; inptr 142 lea edi, [workspace] ; JCOEF *wsptr 143 mov ecx, DCTSIZE/4 ; ctr 144 alignx 16, 7 145.columnloop: 146%ifndef NO_ZERO_COLUMN_TEST_4X4_MMX 147 mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] 148 or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] 149 jnz short .columnDCT 150 151 movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] 152 movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] 153 por mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] 154 por mm1, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] 155 por mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] 156 por mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] 157 por mm0, mm1 158 packsswb mm0, mm0 159 movd eax, mm0 160 test eax, eax 161 jnz short .columnDCT 162 163 ; -- AC terms all zero 164 165 movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] 166 pmullw mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 167 168 psllw mm0, PASS1_BITS 169 170 movq mm2, mm0 ; mm0=in0=(00 01 02 03) 171 punpcklwd mm0, mm0 ; mm0=(00 00 01 01) 172 punpckhwd mm2, mm2 ; mm2=(02 02 03 03) 173 174 movq mm1, mm0 175 punpckldq mm0, mm0 ; mm0=(00 00 00 00) 176 punpckhdq mm1, mm1 ; mm1=(01 01 01 01) 177 movq mm3, mm2 178 punpckldq mm2, mm2 ; mm2=(02 02 02 02) 179 punpckhdq mm3, mm3 ; mm3=(03 03 03 03) 180 181 movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0 182 movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1 183 movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2 184 movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3 185 jmp near .nextcolumn 186 alignx 16, 7 187%endif 188.columnDCT: 189 190 ; -- Odd part 191 192 movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] 193 movq mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] 194 pmullw mm0, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 195 pmullw mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 196 movq mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] 197 movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] 198 pmullw mm2, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 199 pmullw mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 200 201 movq mm4, mm0 202 movq mm5, mm0 203 punpcklwd mm4, mm1 204 punpckhwd mm5, mm1 205 movq mm0, mm4 206 movq mm1, mm5 207 pmaddwd mm4, [GOTOFF(ebx,PW_F256_F089)] ; mm4=(tmp2L) 208 pmaddwd mm5, [GOTOFF(ebx,PW_F256_F089)] ; mm5=(tmp2H) 209 pmaddwd mm0, [GOTOFF(ebx,PW_F106_MF217)] ; mm0=(tmp0L) 210 pmaddwd mm1, [GOTOFF(ebx,PW_F106_MF217)] ; mm1=(tmp0H) 211 212 movq mm6, mm2 213 movq mm7, mm2 214 punpcklwd mm6, mm3 215 punpckhwd mm7, mm3 216 movq mm2, mm6 217 movq mm3, mm7 218 pmaddwd mm6, [GOTOFF(ebx,PW_MF060_MF050)] ; mm6=(tmp2L) 219 pmaddwd mm7, [GOTOFF(ebx,PW_MF060_MF050)] ; mm7=(tmp2H) 220 pmaddwd mm2, [GOTOFF(ebx,PW_F145_MF021)] ; mm2=(tmp0L) 221 pmaddwd mm3, [GOTOFF(ebx,PW_F145_MF021)] ; mm3=(tmp0H) 222 223 paddd mm6, mm4 ; mm6=tmp2L 224 paddd mm7, mm5 ; mm7=tmp2H 225 paddd mm2, mm0 ; mm2=tmp0L 226 paddd mm3, mm1 ; mm3=tmp0H 227 228 movq MMWORD [wk(0)], mm2 ; wk(0)=tmp0L 229 movq MMWORD [wk(1)], mm3 ; wk(1)=tmp0H 230 231 ; -- Even part 232 233 movq mm4, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] 234 movq mm5, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] 235 movq mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] 236 pmullw mm4, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 237 pmullw mm5, MMWORD [MMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 238 pmullw mm0, MMWORD [MMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 239 240 pxor mm1, mm1 241 pxor mm2, mm2 242 punpcklwd mm1, mm4 ; mm1=tmp0L 243 punpckhwd mm2, mm4 ; mm2=tmp0H 244 psrad mm1, (16-CONST_BITS-1) ; psrad mm1,16 & pslld mm1,CONST_BITS+1 245 psrad mm2, (16-CONST_BITS-1) ; psrad mm2,16 & pslld mm2,CONST_BITS+1 246 247 movq mm3, mm5 ; mm5=in2=z2 248 punpcklwd mm5, mm0 ; mm0=in6=z3 249 punpckhwd mm3, mm0 250 pmaddwd mm5, [GOTOFF(ebx,PW_F184_MF076)] ; mm5=tmp2L 251 pmaddwd mm3, [GOTOFF(ebx,PW_F184_MF076)] ; mm3=tmp2H 252 253 movq mm4, mm1 254 movq mm0, mm2 255 paddd mm1, mm5 ; mm1=tmp10L 256 paddd mm2, mm3 ; mm2=tmp10H 257 psubd mm4, mm5 ; mm4=tmp12L 258 psubd mm0, mm3 ; mm0=tmp12H 259 260 ; -- Final output stage 261 262 movq mm5, mm1 263 movq mm3, mm2 264 paddd mm1, mm6 ; mm1=data0L 265 paddd mm2, mm7 ; mm2=data0H 266 psubd mm5, mm6 ; mm5=data3L 267 psubd mm3, mm7 ; mm3=data3H 268 269 movq mm6, [GOTOFF(ebx,PD_DESCALE_P1_4)] ; mm6=[PD_DESCALE_P1_4] 270 271 paddd mm1, mm6 272 paddd mm2, mm6 273 psrad mm1, DESCALE_P1_4 274 psrad mm2, DESCALE_P1_4 275 paddd mm5, mm6 276 paddd mm3, mm6 277 psrad mm5, DESCALE_P1_4 278 psrad mm3, DESCALE_P1_4 279 280 packssdw mm1, mm2 ; mm1=data0=(00 01 02 03) 281 packssdw mm5, mm3 ; mm5=data3=(30 31 32 33) 282 283 movq mm7, MMWORD [wk(0)] ; mm7=tmp0L 284 movq mm6, MMWORD [wk(1)] ; mm6=tmp0H 285 286 movq mm2, mm4 287 movq mm3, mm0 288 paddd mm4, mm7 ; mm4=data1L 289 paddd mm0, mm6 ; mm0=data1H 290 psubd mm2, mm7 ; mm2=data2L 291 psubd mm3, mm6 ; mm3=data2H 292 293 movq mm7, [GOTOFF(ebx,PD_DESCALE_P1_4)] ; mm7=[PD_DESCALE_P1_4] 294 295 paddd mm4, mm7 296 paddd mm0, mm7 297 psrad mm4, DESCALE_P1_4 298 psrad mm0, DESCALE_P1_4 299 paddd mm2, mm7 300 paddd mm3, mm7 301 psrad mm2, DESCALE_P1_4 302 psrad mm3, DESCALE_P1_4 303 304 packssdw mm4, mm0 ; mm4=data1=(10 11 12 13) 305 packssdw mm2, mm3 ; mm2=data2=(20 21 22 23) 306 307 movq mm6, mm1 ; transpose coefficients(phase 1) 308 punpcklwd mm1, mm4 ; mm1=(00 10 01 11) 309 punpckhwd mm6, mm4 ; mm6=(02 12 03 13) 310 movq mm7, mm2 ; transpose coefficients(phase 1) 311 punpcklwd mm2, mm5 ; mm2=(20 30 21 31) 312 punpckhwd mm7, mm5 ; mm7=(22 32 23 33) 313 314 movq mm0, mm1 ; transpose coefficients(phase 2) 315 punpckldq mm1, mm2 ; mm1=(00 10 20 30) 316 punpckhdq mm0, mm2 ; mm0=(01 11 21 31) 317 movq mm3, mm6 ; transpose coefficients(phase 2) 318 punpckldq mm6, mm7 ; mm6=(02 12 22 32) 319 punpckhdq mm3, mm7 ; mm3=(03 13 23 33) 320 321 movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm1 322 movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm0 323 movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm6 324 movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3 325 326.nextcolumn: 327 add esi, byte 4*SIZEOF_JCOEF ; coef_block 328 add edx, byte 4*SIZEOF_ISLOW_MULT_TYPE ; quantptr 329 add edi, byte 4*DCTSIZE*SIZEOF_JCOEF ; wsptr 330 dec ecx ; ctr 331 jnz near .columnloop 332 333 ; ---- Pass 2: process rows from work array, store into output array. 334 335 mov eax, [original_ebp] 336 lea esi, [workspace] ; JCOEF *wsptr 337 mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *) 338 mov eax, JDIMENSION [output_col(eax)] 339 340 ; -- Odd part 341 342 movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] 343 movq mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] 344 movq mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] 345 movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] 346 347 movq mm4, mm0 348 movq mm5, mm0 349 punpcklwd mm4, mm1 350 punpckhwd mm5, mm1 351 movq mm0, mm4 352 movq mm1, mm5 353 pmaddwd mm4, [GOTOFF(ebx,PW_F256_F089)] ; mm4=(tmp2L) 354 pmaddwd mm5, [GOTOFF(ebx,PW_F256_F089)] ; mm5=(tmp2H) 355 pmaddwd mm0, [GOTOFF(ebx,PW_F106_MF217)] ; mm0=(tmp0L) 356 pmaddwd mm1, [GOTOFF(ebx,PW_F106_MF217)] ; mm1=(tmp0H) 357 358 movq mm6, mm2 359 movq mm7, mm2 360 punpcklwd mm6, mm3 361 punpckhwd mm7, mm3 362 movq mm2, mm6 363 movq mm3, mm7 364 pmaddwd mm6, [GOTOFF(ebx,PW_MF060_MF050)] ; mm6=(tmp2L) 365 pmaddwd mm7, [GOTOFF(ebx,PW_MF060_MF050)] ; mm7=(tmp2H) 366 pmaddwd mm2, [GOTOFF(ebx,PW_F145_MF021)] ; mm2=(tmp0L) 367 pmaddwd mm3, [GOTOFF(ebx,PW_F145_MF021)] ; mm3=(tmp0H) 368 369 paddd mm6, mm4 ; mm6=tmp2L 370 paddd mm7, mm5 ; mm7=tmp2H 371 paddd mm2, mm0 ; mm2=tmp0L 372 paddd mm3, mm1 ; mm3=tmp0H 373 374 movq MMWORD [wk(0)], mm2 ; wk(0)=tmp0L 375 movq MMWORD [wk(1)], mm3 ; wk(1)=tmp0H 376 377 ; -- Even part 378 379 movq mm4, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] 380 movq mm5, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] 381 movq mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] 382 383 pxor mm1, mm1 384 pxor mm2, mm2 385 punpcklwd mm1, mm4 ; mm1=tmp0L 386 punpckhwd mm2, mm4 ; mm2=tmp0H 387 psrad mm1, (16-CONST_BITS-1) ; psrad mm1,16 & pslld mm1,CONST_BITS+1 388 psrad mm2, (16-CONST_BITS-1) ; psrad mm2,16 & pslld mm2,CONST_BITS+1 389 390 movq mm3, mm5 ; mm5=in2=z2 391 punpcklwd mm5, mm0 ; mm0=in6=z3 392 punpckhwd mm3, mm0 393 pmaddwd mm5, [GOTOFF(ebx,PW_F184_MF076)] ; mm5=tmp2L 394 pmaddwd mm3, [GOTOFF(ebx,PW_F184_MF076)] ; mm3=tmp2H 395 396 movq mm4, mm1 397 movq mm0, mm2 398 paddd mm1, mm5 ; mm1=tmp10L 399 paddd mm2, mm3 ; mm2=tmp10H 400 psubd mm4, mm5 ; mm4=tmp12L 401 psubd mm0, mm3 ; mm0=tmp12H 402 403 ; -- Final output stage 404 405 movq mm5, mm1 406 movq mm3, mm2 407 paddd mm1, mm6 ; mm1=data0L 408 paddd mm2, mm7 ; mm2=data0H 409 psubd mm5, mm6 ; mm5=data3L 410 psubd mm3, mm7 ; mm3=data3H 411 412 movq mm6, [GOTOFF(ebx,PD_DESCALE_P2_4)] ; mm6=[PD_DESCALE_P2_4] 413 414 paddd mm1, mm6 415 paddd mm2, mm6 416 psrad mm1, DESCALE_P2_4 417 psrad mm2, DESCALE_P2_4 418 paddd mm5, mm6 419 paddd mm3, mm6 420 psrad mm5, DESCALE_P2_4 421 psrad mm3, DESCALE_P2_4 422 423 packssdw mm1, mm2 ; mm1=data0=(00 10 20 30) 424 packssdw mm5, mm3 ; mm5=data3=(03 13 23 33) 425 426 movq mm7, MMWORD [wk(0)] ; mm7=tmp0L 427 movq mm6, MMWORD [wk(1)] ; mm6=tmp0H 428 429 movq mm2, mm4 430 movq mm3, mm0 431 paddd mm4, mm7 ; mm4=data1L 432 paddd mm0, mm6 ; mm0=data1H 433 psubd mm2, mm7 ; mm2=data2L 434 psubd mm3, mm6 ; mm3=data2H 435 436 movq mm7, [GOTOFF(ebx,PD_DESCALE_P2_4)] ; mm7=[PD_DESCALE_P2_4] 437 438 paddd mm4, mm7 439 paddd mm0, mm7 440 psrad mm4, DESCALE_P2_4 441 psrad mm0, DESCALE_P2_4 442 paddd mm2, mm7 443 paddd mm3, mm7 444 psrad mm2, DESCALE_P2_4 445 psrad mm3, DESCALE_P2_4 446 447 packssdw mm4, mm0 ; mm4=data1=(01 11 21 31) 448 packssdw mm2, mm3 ; mm2=data2=(02 12 22 32) 449 450 movq mm6, [GOTOFF(ebx,PB_CENTERJSAMP)] ; mm6=[PB_CENTERJSAMP] 451 452 packsswb mm1, mm2 ; mm1=(00 10 20 30 02 12 22 32) 453 packsswb mm4, mm5 ; mm4=(01 11 21 31 03 13 23 33) 454 paddb mm1, mm6 455 paddb mm4, mm6 456 457 movq mm7, mm1 ; transpose coefficients(phase 1) 458 punpcklbw mm1, mm4 ; mm1=(00 01 10 11 20 21 30 31) 459 punpckhbw mm7, mm4 ; mm7=(02 03 12 13 22 23 32 33) 460 461 movq mm0, mm1 ; transpose coefficients(phase 2) 462 punpcklwd mm1, mm7 ; mm1=(00 01 02 03 10 11 12 13) 463 punpckhwd mm0, mm7 ; mm0=(20 21 22 23 30 31 32 33) 464 465 mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] 466 mov esi, JSAMPROW [edi+2*SIZEOF_JSAMPROW] 467 movd DWORD [edx+eax*SIZEOF_JSAMPLE], mm1 468 movd DWORD [esi+eax*SIZEOF_JSAMPLE], mm0 469 470 psrlq mm1, 4*BYTE_BIT 471 psrlq mm0, 4*BYTE_BIT 472 473 mov edx, JSAMPROW [edi+1*SIZEOF_JSAMPROW] 474 mov esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW] 475 movd DWORD [edx+eax*SIZEOF_JSAMPLE], mm1 476 movd DWORD [esi+eax*SIZEOF_JSAMPLE], mm0 477 478 emms ; empty MMX state 479 480 pop edi 481 pop esi 482; pop edx ; need not be preserved 483; pop ecx ; need not be preserved 484 poppic ebx 485 mov esp, ebp ; esp <- aligned ebp 486 pop esp ; esp <- original ebp 487 pop ebp 488 ret 489 490; -------------------------------------------------------------------------- 491; 492; Perform dequantization and inverse DCT on one block of coefficients, 493; producing a reduced-size 2x2 output block. 494; 495; GLOBAL(void) 496; jsimd_idct_2x2_mmx(void *dct_table, JCOEFPTR coef_block, 497; JSAMPARRAY output_buf, JDIMENSION output_col) 498; 499 500%define dct_table(b) (b) + 8 ; void *dct_table 501%define coef_block(b) (b) + 12 ; JCOEFPTR coef_block 502%define output_buf(b) (b) + 16 ; JSAMPARRAY output_buf 503%define output_col(b) (b) + 20 ; JDIMENSION output_col 504 505 align 32 506 GLOBAL_FUNCTION(jsimd_idct_2x2_mmx) 507 508EXTN(jsimd_idct_2x2_mmx): 509 push ebp 510 mov ebp, esp 511 push ebx 512; push ecx ; need not be preserved 513; push edx ; need not be preserved 514 push esi 515 push edi 516 517 get_GOT ebx ; get GOT address 518 519 ; ---- Pass 1: process columns from input. 520 521 mov edx, POINTER [dct_table(ebp)] ; quantptr 522 mov esi, JCOEFPTR [coef_block(ebp)] ; inptr 523 524 ; | input: | result: | 525 ; | 00 01 ** 03 ** 05 ** 07 | | 526 ; | 10 11 ** 13 ** 15 ** 17 | | 527 ; | ** ** ** ** ** ** ** ** | | 528 ; | 30 31 ** 33 ** 35 ** 37 | A0 A1 A3 A5 A7 | 529 ; | ** ** ** ** ** ** ** ** | B0 B1 B3 B5 B7 | 530 ; | 50 51 ** 53 ** 55 ** 57 | | 531 ; | ** ** ** ** ** ** ** ** | | 532 ; | 70 71 ** 73 ** 75 ** 77 | | 533 534 ; -- Odd part 535 536 movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] 537 movq mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] 538 pmullw mm0, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 539 pmullw mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 540 movq mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] 541 movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] 542 pmullw mm2, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 543 pmullw mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 544 545 ; mm0=(10 11 ** 13), mm1=(30 31 ** 33) 546 ; mm2=(50 51 ** 53), mm3=(70 71 ** 73) 547 548 pcmpeqd mm7, mm7 549 pslld mm7, WORD_BIT ; mm7={0x0000 0xFFFF 0x0000 0xFFFF} 550 551 movq mm4, mm0 ; mm4=(10 11 ** 13) 552 movq mm5, mm2 ; mm5=(50 51 ** 53) 553 punpcklwd mm4, mm1 ; mm4=(10 30 11 31) 554 punpcklwd mm5, mm3 ; mm5=(50 70 51 71) 555 pmaddwd mm4, [GOTOFF(ebx,PW_F362_MF127)] 556 pmaddwd mm5, [GOTOFF(ebx,PW_F085_MF072)] 557 558 psrld mm0, WORD_BIT ; mm0=(11 -- 13 --) 559 pand mm1, mm7 ; mm1=(-- 31 -- 33) 560 psrld mm2, WORD_BIT ; mm2=(51 -- 53 --) 561 pand mm3, mm7 ; mm3=(-- 71 -- 73) 562 por mm0, mm1 ; mm0=(11 31 13 33) 563 por mm2, mm3 ; mm2=(51 71 53 73) 564 pmaddwd mm0, [GOTOFF(ebx,PW_F362_MF127)] 565 pmaddwd mm2, [GOTOFF(ebx,PW_F085_MF072)] 566 567 paddd mm4, mm5 ; mm4=tmp0[col0 col1] 568 569 movq mm6, MMWORD [MMBLOCK(1,1,esi,SIZEOF_JCOEF)] 570 movq mm1, MMWORD [MMBLOCK(3,1,esi,SIZEOF_JCOEF)] 571 pmullw mm6, MMWORD [MMBLOCK(1,1,edx,SIZEOF_ISLOW_MULT_TYPE)] 572 pmullw mm1, MMWORD [MMBLOCK(3,1,edx,SIZEOF_ISLOW_MULT_TYPE)] 573 movq mm3, MMWORD [MMBLOCK(5,1,esi,SIZEOF_JCOEF)] 574 movq mm5, MMWORD [MMBLOCK(7,1,esi,SIZEOF_JCOEF)] 575 pmullw mm3, MMWORD [MMBLOCK(5,1,edx,SIZEOF_ISLOW_MULT_TYPE)] 576 pmullw mm5, MMWORD [MMBLOCK(7,1,edx,SIZEOF_ISLOW_MULT_TYPE)] 577 578 ; mm6=(** 15 ** 17), mm1=(** 35 ** 37) 579 ; mm3=(** 55 ** 57), mm5=(** 75 ** 77) 580 581 psrld mm6, WORD_BIT ; mm6=(15 -- 17 --) 582 pand mm1, mm7 ; mm1=(-- 35 -- 37) 583 psrld mm3, WORD_BIT ; mm3=(55 -- 57 --) 584 pand mm5, mm7 ; mm5=(-- 75 -- 77) 585 por mm6, mm1 ; mm6=(15 35 17 37) 586 por mm3, mm5 ; mm3=(55 75 57 77) 587 pmaddwd mm6, [GOTOFF(ebx,PW_F362_MF127)] 588 pmaddwd mm3, [GOTOFF(ebx,PW_F085_MF072)] 589 590 paddd mm0, mm2 ; mm0=tmp0[col1 col3] 591 paddd mm6, mm3 ; mm6=tmp0[col5 col7] 592 593 ; -- Even part 594 595 movq mm1, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] 596 movq mm5, MMWORD [MMBLOCK(0,1,esi,SIZEOF_JCOEF)] 597 pmullw mm1, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 598 pmullw mm5, MMWORD [MMBLOCK(0,1,edx,SIZEOF_ISLOW_MULT_TYPE)] 599 600 ; mm1=(00 01 ** 03), mm5=(** 05 ** 07) 601 602 movq mm2, mm1 ; mm2=(00 01 ** 03) 603 pslld mm1, WORD_BIT ; mm1=(-- 00 -- **) 604 psrad mm1, (WORD_BIT-CONST_BITS-2) ; mm1=tmp10[col0 ****] 605 606 pand mm2, mm7 ; mm2=(-- 01 -- 03) 607 pand mm5, mm7 ; mm5=(-- 05 -- 07) 608 psrad mm2, (WORD_BIT-CONST_BITS-2) ; mm2=tmp10[col1 col3] 609 psrad mm5, (WORD_BIT-CONST_BITS-2) ; mm5=tmp10[col5 col7] 610 611 ; -- Final output stage 612 613 movq mm3, mm1 614 paddd mm1, mm4 ; mm1=data0[col0 ****]=(A0 **) 615 psubd mm3, mm4 ; mm3=data1[col0 ****]=(B0 **) 616 punpckldq mm1, mm3 ; mm1=(A0 B0) 617 618 movq mm7, [GOTOFF(ebx,PD_DESCALE_P1_2)] ; mm7=[PD_DESCALE_P1_2] 619 620 movq mm4, mm2 621 movq mm3, mm5 622 paddd mm2, mm0 ; mm2=data0[col1 col3]=(A1 A3) 623 paddd mm5, mm6 ; mm5=data0[col5 col7]=(A5 A7) 624 psubd mm4, mm0 ; mm4=data1[col1 col3]=(B1 B3) 625 psubd mm3, mm6 ; mm3=data1[col5 col7]=(B5 B7) 626 627 paddd mm1, mm7 628 psrad mm1, DESCALE_P1_2 629 630 paddd mm2, mm7 631 paddd mm5, mm7 632 psrad mm2, DESCALE_P1_2 633 psrad mm5, DESCALE_P1_2 634 paddd mm4, mm7 635 paddd mm3, mm7 636 psrad mm4, DESCALE_P1_2 637 psrad mm3, DESCALE_P1_2 638 639 ; ---- Pass 2: process rows, store into output array. 640 641 mov edi, JSAMPARRAY [output_buf(ebp)] ; (JSAMPROW *) 642 mov eax, JDIMENSION [output_col(ebp)] 643 644 ; | input:| result:| 645 ; | A0 B0 | | 646 ; | A1 B1 | C0 C1 | 647 ; | A3 B3 | D0 D1 | 648 ; | A5 B5 | | 649 ; | A7 B7 | | 650 651 ; -- Odd part 652 653 packssdw mm2, mm4 ; mm2=(A1 A3 B1 B3) 654 packssdw mm5, mm3 ; mm5=(A5 A7 B5 B7) 655 pmaddwd mm2, [GOTOFF(ebx,PW_F362_MF127)] 656 pmaddwd mm5, [GOTOFF(ebx,PW_F085_MF072)] 657 658 paddd mm2, mm5 ; mm2=tmp0[row0 row1] 659 660 ; -- Even part 661 662 pslld mm1, (CONST_BITS+2) ; mm1=tmp10[row0 row1] 663 664 ; -- Final output stage 665 666 movq mm0, [GOTOFF(ebx,PD_DESCALE_P2_2)] ; mm0=[PD_DESCALE_P2_2] 667 668 movq mm6, mm1 669 paddd mm1, mm2 ; mm1=data0[row0 row1]=(C0 C1) 670 psubd mm6, mm2 ; mm6=data1[row0 row1]=(D0 D1) 671 672 paddd mm1, mm0 673 paddd mm6, mm0 674 psrad mm1, DESCALE_P2_2 675 psrad mm6, DESCALE_P2_2 676 677 movq mm7, mm1 ; transpose coefficients 678 punpckldq mm1, mm6 ; mm1=(C0 D0) 679 punpckhdq mm7, mm6 ; mm7=(C1 D1) 680 681 packssdw mm1, mm7 ; mm1=(C0 D0 C1 D1) 682 packsswb mm1, mm1 ; mm1=(C0 D0 C1 D1 C0 D0 C1 D1) 683 paddb mm1, [GOTOFF(ebx,PB_CENTERJSAMP)] 684 685 movd ecx, mm1 686 movd ebx, mm1 ; ebx=(C0 D0 C1 D1) 687 shr ecx, 2*BYTE_BIT ; ecx=(C1 D1 -- --) 688 689 mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] 690 mov esi, JSAMPROW [edi+1*SIZEOF_JSAMPROW] 691 mov WORD [edx+eax*SIZEOF_JSAMPLE], bx 692 mov WORD [esi+eax*SIZEOF_JSAMPLE], cx 693 694 emms ; empty MMX state 695 696 pop edi 697 pop esi 698; pop edx ; need not be preserved 699; pop ecx ; need not be preserved 700 pop ebx 701 pop ebp 702 ret 703 704; For some reason, the OS X linker does not honor the request to align the 705; segment unless we do this. 706 align 32 707