1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libjpeg/simd/jimmxred.asm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,706 @@ 1.4 +; 1.5 +; jimmxred.asm - reduced-size IDCT (MMX) 1.6 +; 1.7 +; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB 1.8 +; 1.9 +; Based on 1.10 +; x86 SIMD extension for IJG JPEG library 1.11 +; Copyright (C) 1999-2006, MIYASAKA Masaru. 1.12 +; For conditions of distribution and use, see copyright notice in jsimdext.inc 1.13 +; 1.14 +; This file should be assembled with NASM (Netwide Assembler), 1.15 +; can *not* be assembled with Microsoft's MASM or any compatible 1.16 +; assembler (including Borland's Turbo Assembler). 1.17 +; NASM is available from http://nasm.sourceforge.net/ or 1.18 +; http://sourceforge.net/project/showfiles.php?group_id=6208 1.19 +; 1.20 +; This file contains inverse-DCT routines that produce reduced-size 1.21 +; output: either 4x4 or 2x2 pixels from an 8x8 DCT block. 1.22 +; The following code is based directly on the IJG's original jidctred.c; 1.23 +; see the jidctred.c for more details. 1.24 +; 1.25 +; [TAB8] 1.26 + 1.27 +%include "jsimdext.inc" 1.28 +%include "jdct.inc" 1.29 + 1.30 +; -------------------------------------------------------------------------- 1.31 + 1.32 +%define CONST_BITS 13 1.33 +%define PASS1_BITS 2 1.34 + 1.35 +%define DESCALE_P1_4 (CONST_BITS-PASS1_BITS+1) 1.36 +%define DESCALE_P2_4 (CONST_BITS+PASS1_BITS+3+1) 1.37 +%define DESCALE_P1_2 (CONST_BITS-PASS1_BITS+2) 1.38 +%define DESCALE_P2_2 (CONST_BITS+PASS1_BITS+3+2) 1.39 + 1.40 +%if CONST_BITS == 13 1.41 +F_0_211 equ 1730 ; FIX(0.211164243) 1.42 +F_0_509 equ 4176 ; FIX(0.509795579) 1.43 +F_0_601 equ 4926 ; FIX(0.601344887) 1.44 +F_0_720 equ 5906 ; FIX(0.720959822) 1.45 +F_0_765 equ 6270 ; FIX(0.765366865) 1.46 +F_0_850 equ 6967 ; FIX(0.850430095) 1.47 +F_0_899 equ 7373 ; FIX(0.899976223) 1.48 +F_1_061 equ 8697 ; FIX(1.061594337) 1.49 +F_1_272 equ 10426 ; FIX(1.272758580) 1.50 +F_1_451 equ 11893 ; FIX(1.451774981) 1.51 +F_1_847 equ 15137 ; FIX(1.847759065) 1.52 +F_2_172 equ 17799 ; FIX(2.172734803) 1.53 +F_2_562 equ 20995 ; FIX(2.562915447) 1.54 +F_3_624 equ 29692 ; FIX(3.624509785) 1.55 +%else 1.56 +; NASM cannot do compile-time arithmetic on floating-point constants. 1.57 +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) 1.58 +F_0_211 equ DESCALE( 226735879,30-CONST_BITS) ; FIX(0.211164243) 1.59 +F_0_509 equ DESCALE( 547388834,30-CONST_BITS) ; FIX(0.509795579) 1.60 +F_0_601 equ DESCALE( 645689155,30-CONST_BITS) ; FIX(0.601344887) 1.61 +F_0_720 equ DESCALE( 774124714,30-CONST_BITS) ; FIX(0.720959822) 1.62 +F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865) 1.63 +F_0_850 equ DESCALE( 913142361,30-CONST_BITS) ; FIX(0.850430095) 1.64 +F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223) 1.65 +F_1_061 equ DESCALE(1139878239,30-CONST_BITS) ; FIX(1.061594337) 1.66 +F_1_272 equ DESCALE(1366614119,30-CONST_BITS) ; FIX(1.272758580) 1.67 +F_1_451 equ DESCALE(1558831516,30-CONST_BITS) ; FIX(1.451774981) 1.68 +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) 1.69 +F_2_172 equ DESCALE(2332956230,30-CONST_BITS) ; FIX(2.172734803) 1.70 +F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447) 1.71 +F_3_624 equ DESCALE(3891787747,30-CONST_BITS) ; FIX(3.624509785) 1.72 +%endif 1.73 + 1.74 +; -------------------------------------------------------------------------- 1.75 + SECTION SEG_CONST 1.76 + 1.77 + alignz 16 1.78 + global EXTN(jconst_idct_red_mmx) 1.79 + 1.80 +EXTN(jconst_idct_red_mmx): 1.81 + 1.82 +PW_F184_MF076 times 2 dw F_1_847,-F_0_765 1.83 +PW_F256_F089 times 2 dw F_2_562, F_0_899 1.84 +PW_F106_MF217 times 2 dw F_1_061,-F_2_172 1.85 +PW_MF060_MF050 times 2 dw -F_0_601,-F_0_509 1.86 +PW_F145_MF021 times 2 dw F_1_451,-F_0_211 1.87 +PW_F362_MF127 times 2 dw F_3_624,-F_1_272 1.88 +PW_F085_MF072 times 2 dw F_0_850,-F_0_720 1.89 +PD_DESCALE_P1_4 times 2 dd 1 << (DESCALE_P1_4-1) 1.90 +PD_DESCALE_P2_4 times 2 dd 1 << (DESCALE_P2_4-1) 1.91 +PD_DESCALE_P1_2 times 2 dd 1 << (DESCALE_P1_2-1) 1.92 +PD_DESCALE_P2_2 times 2 dd 1 << (DESCALE_P2_2-1) 1.93 +PB_CENTERJSAMP times 8 db CENTERJSAMPLE 1.94 + 1.95 + alignz 16 1.96 + 1.97 +; -------------------------------------------------------------------------- 1.98 + SECTION SEG_TEXT 1.99 + BITS 32 1.100 +; 1.101 +; Perform dequantization and inverse DCT on one block of coefficients, 1.102 +; producing a reduced-size 4x4 output block. 1.103 +; 1.104 +; GLOBAL(void) 1.105 +; jsimd_idct_4x4_mmx (void * dct_table, JCOEFPTR coef_block, 1.106 +; JSAMPARRAY output_buf, JDIMENSION output_col) 1.107 +; 1.108 + 1.109 +%define dct_table(b) (b)+8 ; void * dct_table 1.110 +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block 1.111 +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf 1.112 +%define output_col(b) (b)+20 ; JDIMENSION output_col 1.113 + 1.114 +%define original_ebp ebp+0 1.115 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] 1.116 +%define WK_NUM 2 1.117 +%define workspace wk(0)-DCTSIZE2*SIZEOF_JCOEF 1.118 + ; JCOEF workspace[DCTSIZE2] 1.119 + 1.120 + align 16 1.121 + global EXTN(jsimd_idct_4x4_mmx) 1.122 + 1.123 +EXTN(jsimd_idct_4x4_mmx): 1.124 + push ebp 1.125 + mov eax,esp ; eax = original ebp 1.126 + sub esp, byte 4 1.127 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits 1.128 + mov [esp],eax 1.129 + mov ebp,esp ; ebp = aligned ebp 1.130 + lea esp, [workspace] 1.131 + pushpic ebx 1.132 +; push ecx ; need not be preserved 1.133 +; push edx ; need not be preserved 1.134 + push esi 1.135 + push edi 1.136 + 1.137 + get_GOT ebx ; get GOT address 1.138 + 1.139 + ; ---- Pass 1: process columns from input, store into work array. 1.140 + 1.141 +; mov eax, [original_ebp] 1.142 + mov edx, POINTER [dct_table(eax)] ; quantptr 1.143 + mov esi, JCOEFPTR [coef_block(eax)] ; inptr 1.144 + lea edi, [workspace] ; JCOEF * wsptr 1.145 + mov ecx, DCTSIZE/4 ; ctr 1.146 + alignx 16,7 1.147 +.columnloop: 1.148 +%ifndef NO_ZERO_COLUMN_TEST_4X4_MMX 1.149 + mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] 1.150 + or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] 1.151 + jnz short .columnDCT 1.152 + 1.153 + movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] 1.154 + movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] 1.155 + por mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] 1.156 + por mm1, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] 1.157 + por mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] 1.158 + por mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] 1.159 + por mm0,mm1 1.160 + packsswb mm0,mm0 1.161 + movd eax,mm0 1.162 + test eax,eax 1.163 + jnz short .columnDCT 1.164 + 1.165 + ; -- AC terms all zero 1.166 + 1.167 + movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] 1.168 + pmullw mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.169 + 1.170 + psllw mm0,PASS1_BITS 1.171 + 1.172 + movq mm2,mm0 ; mm0=in0=(00 01 02 03) 1.173 + punpcklwd mm0,mm0 ; mm0=(00 00 01 01) 1.174 + punpckhwd mm2,mm2 ; mm2=(02 02 03 03) 1.175 + 1.176 + movq mm1,mm0 1.177 + punpckldq mm0,mm0 ; mm0=(00 00 00 00) 1.178 + punpckhdq mm1,mm1 ; mm1=(01 01 01 01) 1.179 + movq mm3,mm2 1.180 + punpckldq mm2,mm2 ; mm2=(02 02 02 02) 1.181 + punpckhdq mm3,mm3 ; mm3=(03 03 03 03) 1.182 + 1.183 + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0 1.184 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1 1.185 + movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2 1.186 + movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3 1.187 + jmp near .nextcolumn 1.188 + alignx 16,7 1.189 +%endif 1.190 +.columnDCT: 1.191 + 1.192 + ; -- Odd part 1.193 + 1.194 + movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] 1.195 + movq mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] 1.196 + pmullw mm0, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.197 + pmullw mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.198 + movq mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] 1.199 + movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] 1.200 + pmullw mm2, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.201 + pmullw mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.202 + 1.203 + movq mm4,mm0 1.204 + movq mm5,mm0 1.205 + punpcklwd mm4,mm1 1.206 + punpckhwd mm5,mm1 1.207 + movq mm0,mm4 1.208 + movq mm1,mm5 1.209 + pmaddwd mm4,[GOTOFF(ebx,PW_F256_F089)] ; mm4=(tmp2L) 1.210 + pmaddwd mm5,[GOTOFF(ebx,PW_F256_F089)] ; mm5=(tmp2H) 1.211 + pmaddwd mm0,[GOTOFF(ebx,PW_F106_MF217)] ; mm0=(tmp0L) 1.212 + pmaddwd mm1,[GOTOFF(ebx,PW_F106_MF217)] ; mm1=(tmp0H) 1.213 + 1.214 + movq mm6,mm2 1.215 + movq mm7,mm2 1.216 + punpcklwd mm6,mm3 1.217 + punpckhwd mm7,mm3 1.218 + movq mm2,mm6 1.219 + movq mm3,mm7 1.220 + pmaddwd mm6,[GOTOFF(ebx,PW_MF060_MF050)] ; mm6=(tmp2L) 1.221 + pmaddwd mm7,[GOTOFF(ebx,PW_MF060_MF050)] ; mm7=(tmp2H) 1.222 + pmaddwd mm2,[GOTOFF(ebx,PW_F145_MF021)] ; mm2=(tmp0L) 1.223 + pmaddwd mm3,[GOTOFF(ebx,PW_F145_MF021)] ; mm3=(tmp0H) 1.224 + 1.225 + paddd mm6,mm4 ; mm6=tmp2L 1.226 + paddd mm7,mm5 ; mm7=tmp2H 1.227 + paddd mm2,mm0 ; mm2=tmp0L 1.228 + paddd mm3,mm1 ; mm3=tmp0H 1.229 + 1.230 + movq MMWORD [wk(0)], mm2 ; wk(0)=tmp0L 1.231 + movq MMWORD [wk(1)], mm3 ; wk(1)=tmp0H 1.232 + 1.233 + ; -- Even part 1.234 + 1.235 + movq mm4, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] 1.236 + movq mm5, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] 1.237 + movq mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] 1.238 + pmullw mm4, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.239 + pmullw mm5, MMWORD [MMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.240 + pmullw mm0, MMWORD [MMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.241 + 1.242 + pxor mm1,mm1 1.243 + pxor mm2,mm2 1.244 + punpcklwd mm1,mm4 ; mm1=tmp0L 1.245 + punpckhwd mm2,mm4 ; mm2=tmp0H 1.246 + psrad mm1,(16-CONST_BITS-1) ; psrad mm1,16 & pslld mm1,CONST_BITS+1 1.247 + psrad mm2,(16-CONST_BITS-1) ; psrad mm2,16 & pslld mm2,CONST_BITS+1 1.248 + 1.249 + movq mm3,mm5 ; mm5=in2=z2 1.250 + punpcklwd mm5,mm0 ; mm0=in6=z3 1.251 + punpckhwd mm3,mm0 1.252 + pmaddwd mm5,[GOTOFF(ebx,PW_F184_MF076)] ; mm5=tmp2L 1.253 + pmaddwd mm3,[GOTOFF(ebx,PW_F184_MF076)] ; mm3=tmp2H 1.254 + 1.255 + movq mm4,mm1 1.256 + movq mm0,mm2 1.257 + paddd mm1,mm5 ; mm1=tmp10L 1.258 + paddd mm2,mm3 ; mm2=tmp10H 1.259 + psubd mm4,mm5 ; mm4=tmp12L 1.260 + psubd mm0,mm3 ; mm0=tmp12H 1.261 + 1.262 + ; -- Final output stage 1.263 + 1.264 + movq mm5,mm1 1.265 + movq mm3,mm2 1.266 + paddd mm1,mm6 ; mm1=data0L 1.267 + paddd mm2,mm7 ; mm2=data0H 1.268 + psubd mm5,mm6 ; mm5=data3L 1.269 + psubd mm3,mm7 ; mm3=data3H 1.270 + 1.271 + movq mm6,[GOTOFF(ebx,PD_DESCALE_P1_4)] ; mm6=[PD_DESCALE_P1_4] 1.272 + 1.273 + paddd mm1,mm6 1.274 + paddd mm2,mm6 1.275 + psrad mm1,DESCALE_P1_4 1.276 + psrad mm2,DESCALE_P1_4 1.277 + paddd mm5,mm6 1.278 + paddd mm3,mm6 1.279 + psrad mm5,DESCALE_P1_4 1.280 + psrad mm3,DESCALE_P1_4 1.281 + 1.282 + packssdw mm1,mm2 ; mm1=data0=(00 01 02 03) 1.283 + packssdw mm5,mm3 ; mm5=data3=(30 31 32 33) 1.284 + 1.285 + movq mm7, MMWORD [wk(0)] ; mm7=tmp0L 1.286 + movq mm6, MMWORD [wk(1)] ; mm6=tmp0H 1.287 + 1.288 + movq mm2,mm4 1.289 + movq mm3,mm0 1.290 + paddd mm4,mm7 ; mm4=data1L 1.291 + paddd mm0,mm6 ; mm0=data1H 1.292 + psubd mm2,mm7 ; mm2=data2L 1.293 + psubd mm3,mm6 ; mm3=data2H 1.294 + 1.295 + movq mm7,[GOTOFF(ebx,PD_DESCALE_P1_4)] ; mm7=[PD_DESCALE_P1_4] 1.296 + 1.297 + paddd mm4,mm7 1.298 + paddd mm0,mm7 1.299 + psrad mm4,DESCALE_P1_4 1.300 + psrad mm0,DESCALE_P1_4 1.301 + paddd mm2,mm7 1.302 + paddd mm3,mm7 1.303 + psrad mm2,DESCALE_P1_4 1.304 + psrad mm3,DESCALE_P1_4 1.305 + 1.306 + packssdw mm4,mm0 ; mm4=data1=(10 11 12 13) 1.307 + packssdw mm2,mm3 ; mm2=data2=(20 21 22 23) 1.308 + 1.309 + movq mm6,mm1 ; transpose coefficients(phase 1) 1.310 + punpcklwd mm1,mm4 ; mm1=(00 10 01 11) 1.311 + punpckhwd mm6,mm4 ; mm6=(02 12 03 13) 1.312 + movq mm7,mm2 ; transpose coefficients(phase 1) 1.313 + punpcklwd mm2,mm5 ; mm2=(20 30 21 31) 1.314 + punpckhwd mm7,mm5 ; mm7=(22 32 23 33) 1.315 + 1.316 + movq mm0,mm1 ; transpose coefficients(phase 2) 1.317 + punpckldq mm1,mm2 ; mm1=(00 10 20 30) 1.318 + punpckhdq mm0,mm2 ; mm0=(01 11 21 31) 1.319 + movq mm3,mm6 ; transpose coefficients(phase 2) 1.320 + punpckldq mm6,mm7 ; mm6=(02 12 22 32) 1.321 + punpckhdq mm3,mm7 ; mm3=(03 13 23 33) 1.322 + 1.323 + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm1 1.324 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm0 1.325 + movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm6 1.326 + movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3 1.327 + 1.328 +.nextcolumn: 1.329 + add esi, byte 4*SIZEOF_JCOEF ; coef_block 1.330 + add edx, byte 4*SIZEOF_ISLOW_MULT_TYPE ; quantptr 1.331 + add edi, byte 4*DCTSIZE*SIZEOF_JCOEF ; wsptr 1.332 + dec ecx ; ctr 1.333 + jnz near .columnloop 1.334 + 1.335 + ; ---- Pass 2: process rows from work array, store into output array. 1.336 + 1.337 + mov eax, [original_ebp] 1.338 + lea esi, [workspace] ; JCOEF * wsptr 1.339 + mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *) 1.340 + mov eax, JDIMENSION [output_col(eax)] 1.341 + 1.342 + ; -- Odd part 1.343 + 1.344 + movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] 1.345 + movq mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] 1.346 + movq mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] 1.347 + movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] 1.348 + 1.349 + movq mm4,mm0 1.350 + movq mm5,mm0 1.351 + punpcklwd mm4,mm1 1.352 + punpckhwd mm5,mm1 1.353 + movq mm0,mm4 1.354 + movq mm1,mm5 1.355 + pmaddwd mm4,[GOTOFF(ebx,PW_F256_F089)] ; mm4=(tmp2L) 1.356 + pmaddwd mm5,[GOTOFF(ebx,PW_F256_F089)] ; mm5=(tmp2H) 1.357 + pmaddwd mm0,[GOTOFF(ebx,PW_F106_MF217)] ; mm0=(tmp0L) 1.358 + pmaddwd mm1,[GOTOFF(ebx,PW_F106_MF217)] ; mm1=(tmp0H) 1.359 + 1.360 + movq mm6,mm2 1.361 + movq mm7,mm2 1.362 + punpcklwd mm6,mm3 1.363 + punpckhwd mm7,mm3 1.364 + movq mm2,mm6 1.365 + movq mm3,mm7 1.366 + pmaddwd mm6,[GOTOFF(ebx,PW_MF060_MF050)] ; mm6=(tmp2L) 1.367 + pmaddwd mm7,[GOTOFF(ebx,PW_MF060_MF050)] ; mm7=(tmp2H) 1.368 + pmaddwd mm2,[GOTOFF(ebx,PW_F145_MF021)] ; mm2=(tmp0L) 1.369 + pmaddwd mm3,[GOTOFF(ebx,PW_F145_MF021)] ; mm3=(tmp0H) 1.370 + 1.371 + paddd mm6,mm4 ; mm6=tmp2L 1.372 + paddd mm7,mm5 ; mm7=tmp2H 1.373 + paddd mm2,mm0 ; mm2=tmp0L 1.374 + paddd mm3,mm1 ; mm3=tmp0H 1.375 + 1.376 + movq MMWORD [wk(0)], mm2 ; wk(0)=tmp0L 1.377 + movq MMWORD [wk(1)], mm3 ; wk(1)=tmp0H 1.378 + 1.379 + ; -- Even part 1.380 + 1.381 + movq mm4, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] 1.382 + movq mm5, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] 1.383 + movq mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] 1.384 + 1.385 + pxor mm1,mm1 1.386 + pxor mm2,mm2 1.387 + punpcklwd mm1,mm4 ; mm1=tmp0L 1.388 + punpckhwd mm2,mm4 ; mm2=tmp0H 1.389 + psrad mm1,(16-CONST_BITS-1) ; psrad mm1,16 & pslld mm1,CONST_BITS+1 1.390 + psrad mm2,(16-CONST_BITS-1) ; psrad mm2,16 & pslld mm2,CONST_BITS+1 1.391 + 1.392 + movq mm3,mm5 ; mm5=in2=z2 1.393 + punpcklwd mm5,mm0 ; mm0=in6=z3 1.394 + punpckhwd mm3,mm0 1.395 + pmaddwd mm5,[GOTOFF(ebx,PW_F184_MF076)] ; mm5=tmp2L 1.396 + pmaddwd mm3,[GOTOFF(ebx,PW_F184_MF076)] ; mm3=tmp2H 1.397 + 1.398 + movq mm4,mm1 1.399 + movq mm0,mm2 1.400 + paddd mm1,mm5 ; mm1=tmp10L 1.401 + paddd mm2,mm3 ; mm2=tmp10H 1.402 + psubd mm4,mm5 ; mm4=tmp12L 1.403 + psubd mm0,mm3 ; mm0=tmp12H 1.404 + 1.405 + ; -- Final output stage 1.406 + 1.407 + movq mm5,mm1 1.408 + movq mm3,mm2 1.409 + paddd mm1,mm6 ; mm1=data0L 1.410 + paddd mm2,mm7 ; mm2=data0H 1.411 + psubd mm5,mm6 ; mm5=data3L 1.412 + psubd mm3,mm7 ; mm3=data3H 1.413 + 1.414 + movq mm6,[GOTOFF(ebx,PD_DESCALE_P2_4)] ; mm6=[PD_DESCALE_P2_4] 1.415 + 1.416 + paddd mm1,mm6 1.417 + paddd mm2,mm6 1.418 + psrad mm1,DESCALE_P2_4 1.419 + psrad mm2,DESCALE_P2_4 1.420 + paddd mm5,mm6 1.421 + paddd mm3,mm6 1.422 + psrad mm5,DESCALE_P2_4 1.423 + psrad mm3,DESCALE_P2_4 1.424 + 1.425 + packssdw mm1,mm2 ; mm1=data0=(00 10 20 30) 1.426 + packssdw mm5,mm3 ; mm5=data3=(03 13 23 33) 1.427 + 1.428 + movq mm7, MMWORD [wk(0)] ; mm7=tmp0L 1.429 + movq mm6, MMWORD [wk(1)] ; mm6=tmp0H 1.430 + 1.431 + movq mm2,mm4 1.432 + movq mm3,mm0 1.433 + paddd mm4,mm7 ; mm4=data1L 1.434 + paddd mm0,mm6 ; mm0=data1H 1.435 + psubd mm2,mm7 ; mm2=data2L 1.436 + psubd mm3,mm6 ; mm3=data2H 1.437 + 1.438 + movq mm7,[GOTOFF(ebx,PD_DESCALE_P2_4)] ; mm7=[PD_DESCALE_P2_4] 1.439 + 1.440 + paddd mm4,mm7 1.441 + paddd mm0,mm7 1.442 + psrad mm4,DESCALE_P2_4 1.443 + psrad mm0,DESCALE_P2_4 1.444 + paddd mm2,mm7 1.445 + paddd mm3,mm7 1.446 + psrad mm2,DESCALE_P2_4 1.447 + psrad mm3,DESCALE_P2_4 1.448 + 1.449 + packssdw mm4,mm0 ; mm4=data1=(01 11 21 31) 1.450 + packssdw mm2,mm3 ; mm2=data2=(02 12 22 32) 1.451 + 1.452 + movq mm6,[GOTOFF(ebx,PB_CENTERJSAMP)] ; mm6=[PB_CENTERJSAMP] 1.453 + 1.454 + packsswb mm1,mm2 ; mm1=(00 10 20 30 02 12 22 32) 1.455 + packsswb mm4,mm5 ; mm4=(01 11 21 31 03 13 23 33) 1.456 + paddb mm1,mm6 1.457 + paddb mm4,mm6 1.458 + 1.459 + movq mm7,mm1 ; transpose coefficients(phase 1) 1.460 + punpcklbw mm1,mm4 ; mm1=(00 01 10 11 20 21 30 31) 1.461 + punpckhbw mm7,mm4 ; mm7=(02 03 12 13 22 23 32 33) 1.462 + 1.463 + movq mm0,mm1 ; transpose coefficients(phase 2) 1.464 + punpcklwd mm1,mm7 ; mm1=(00 01 02 03 10 11 12 13) 1.465 + punpckhwd mm0,mm7 ; mm0=(20 21 22 23 30 31 32 33) 1.466 + 1.467 + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] 1.468 + mov esi, JSAMPROW [edi+2*SIZEOF_JSAMPROW] 1.469 + movd DWORD [edx+eax*SIZEOF_JSAMPLE], mm1 1.470 + movd DWORD [esi+eax*SIZEOF_JSAMPLE], mm0 1.471 + 1.472 + psrlq mm1,4*BYTE_BIT 1.473 + psrlq mm0,4*BYTE_BIT 1.474 + 1.475 + mov edx, JSAMPROW [edi+1*SIZEOF_JSAMPROW] 1.476 + mov esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW] 1.477 + movd DWORD [edx+eax*SIZEOF_JSAMPLE], mm1 1.478 + movd DWORD [esi+eax*SIZEOF_JSAMPLE], mm0 1.479 + 1.480 + emms ; empty MMX state 1.481 + 1.482 + pop edi 1.483 + pop esi 1.484 +; pop edx ; need not be preserved 1.485 +; pop ecx ; need not be preserved 1.486 + poppic ebx 1.487 + mov esp,ebp ; esp <- aligned ebp 1.488 + pop esp ; esp <- original ebp 1.489 + pop ebp 1.490 + ret 1.491 + 1.492 + 1.493 +; -------------------------------------------------------------------------- 1.494 +; 1.495 +; Perform dequantization and inverse DCT on one block of coefficients, 1.496 +; producing a reduced-size 2x2 output block. 1.497 +; 1.498 +; GLOBAL(void) 1.499 +; jsimd_idct_2x2_mmx (void * dct_table, JCOEFPTR coef_block, 1.500 +; JSAMPARRAY output_buf, JDIMENSION output_col) 1.501 +; 1.502 + 1.503 +%define dct_table(b) (b)+8 ; void * dct_table 1.504 +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block 1.505 +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf 1.506 +%define output_col(b) (b)+20 ; JDIMENSION output_col 1.507 + 1.508 + align 16 1.509 + global EXTN(jsimd_idct_2x2_mmx) 1.510 + 1.511 +EXTN(jsimd_idct_2x2_mmx): 1.512 + push ebp 1.513 + mov ebp,esp 1.514 + push ebx 1.515 +; push ecx ; need not be preserved 1.516 +; push edx ; need not be preserved 1.517 + push esi 1.518 + push edi 1.519 + 1.520 + get_GOT ebx ; get GOT address 1.521 + 1.522 + ; ---- Pass 1: process columns from input. 1.523 + 1.524 + mov edx, POINTER [dct_table(ebp)] ; quantptr 1.525 + mov esi, JCOEFPTR [coef_block(ebp)] ; inptr 1.526 + 1.527 + ; | input: | result: | 1.528 + ; | 00 01 ** 03 ** 05 ** 07 | | 1.529 + ; | 10 11 ** 13 ** 15 ** 17 | | 1.530 + ; | ** ** ** ** ** ** ** ** | | 1.531 + ; | 30 31 ** 33 ** 35 ** 37 | A0 A1 A3 A5 A7 | 1.532 + ; | ** ** ** ** ** ** ** ** | B0 B1 B3 B5 B7 | 1.533 + ; | 50 51 ** 53 ** 55 ** 57 | | 1.534 + ; | ** ** ** ** ** ** ** ** | | 1.535 + ; | 70 71 ** 73 ** 75 ** 77 | | 1.536 + 1.537 + ; -- Odd part 1.538 + 1.539 + movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] 1.540 + movq mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] 1.541 + pmullw mm0, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.542 + pmullw mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.543 + movq mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] 1.544 + movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] 1.545 + pmullw mm2, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.546 + pmullw mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.547 + 1.548 + ; mm0=(10 11 ** 13), mm1=(30 31 ** 33) 1.549 + ; mm2=(50 51 ** 53), mm3=(70 71 ** 73) 1.550 + 1.551 + pcmpeqd mm7,mm7 1.552 + pslld mm7,WORD_BIT ; mm7={0x0000 0xFFFF 0x0000 0xFFFF} 1.553 + 1.554 + movq mm4,mm0 ; mm4=(10 11 ** 13) 1.555 + movq mm5,mm2 ; mm5=(50 51 ** 53) 1.556 + punpcklwd mm4,mm1 ; mm4=(10 30 11 31) 1.557 + punpcklwd mm5,mm3 ; mm5=(50 70 51 71) 1.558 + pmaddwd mm4,[GOTOFF(ebx,PW_F362_MF127)] 1.559 + pmaddwd mm5,[GOTOFF(ebx,PW_F085_MF072)] 1.560 + 1.561 + psrld mm0,WORD_BIT ; mm0=(11 -- 13 --) 1.562 + pand mm1,mm7 ; mm1=(-- 31 -- 33) 1.563 + psrld mm2,WORD_BIT ; mm2=(51 -- 53 --) 1.564 + pand mm3,mm7 ; mm3=(-- 71 -- 73) 1.565 + por mm0,mm1 ; mm0=(11 31 13 33) 1.566 + por mm2,mm3 ; mm2=(51 71 53 73) 1.567 + pmaddwd mm0,[GOTOFF(ebx,PW_F362_MF127)] 1.568 + pmaddwd mm2,[GOTOFF(ebx,PW_F085_MF072)] 1.569 + 1.570 + paddd mm4,mm5 ; mm4=tmp0[col0 col1] 1.571 + 1.572 + movq mm6, MMWORD [MMBLOCK(1,1,esi,SIZEOF_JCOEF)] 1.573 + movq mm1, MMWORD [MMBLOCK(3,1,esi,SIZEOF_JCOEF)] 1.574 + pmullw mm6, MMWORD [MMBLOCK(1,1,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.575 + pmullw mm1, MMWORD [MMBLOCK(3,1,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.576 + movq mm3, MMWORD [MMBLOCK(5,1,esi,SIZEOF_JCOEF)] 1.577 + movq mm5, MMWORD [MMBLOCK(7,1,esi,SIZEOF_JCOEF)] 1.578 + pmullw mm3, MMWORD [MMBLOCK(5,1,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.579 + pmullw mm5, MMWORD [MMBLOCK(7,1,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.580 + 1.581 + ; mm6=(** 15 ** 17), mm1=(** 35 ** 37) 1.582 + ; mm3=(** 55 ** 57), mm5=(** 75 ** 77) 1.583 + 1.584 + psrld mm6,WORD_BIT ; mm6=(15 -- 17 --) 1.585 + pand mm1,mm7 ; mm1=(-- 35 -- 37) 1.586 + psrld mm3,WORD_BIT ; mm3=(55 -- 57 --) 1.587 + pand mm5,mm7 ; mm5=(-- 75 -- 77) 1.588 + por mm6,mm1 ; mm6=(15 35 17 37) 1.589 + por mm3,mm5 ; mm3=(55 75 57 77) 1.590 + pmaddwd mm6,[GOTOFF(ebx,PW_F362_MF127)] 1.591 + pmaddwd mm3,[GOTOFF(ebx,PW_F085_MF072)] 1.592 + 1.593 + paddd mm0,mm2 ; mm0=tmp0[col1 col3] 1.594 + paddd mm6,mm3 ; mm6=tmp0[col5 col7] 1.595 + 1.596 + ; -- Even part 1.597 + 1.598 + movq mm1, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] 1.599 + movq mm5, MMWORD [MMBLOCK(0,1,esi,SIZEOF_JCOEF)] 1.600 + pmullw mm1, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.601 + pmullw mm5, MMWORD [MMBLOCK(0,1,edx,SIZEOF_ISLOW_MULT_TYPE)] 1.602 + 1.603 + ; mm1=(00 01 ** 03), mm5=(** 05 ** 07) 1.604 + 1.605 + movq mm2,mm1 ; mm2=(00 01 ** 03) 1.606 + pslld mm1,WORD_BIT ; mm1=(-- 00 -- **) 1.607 + psrad mm1,(WORD_BIT-CONST_BITS-2) ; mm1=tmp10[col0 ****] 1.608 + 1.609 + pand mm2,mm7 ; mm2=(-- 01 -- 03) 1.610 + pand mm5,mm7 ; mm5=(-- 05 -- 07) 1.611 + psrad mm2,(WORD_BIT-CONST_BITS-2) ; mm2=tmp10[col1 col3] 1.612 + psrad mm5,(WORD_BIT-CONST_BITS-2) ; mm5=tmp10[col5 col7] 1.613 + 1.614 + ; -- Final output stage 1.615 + 1.616 + movq mm3,mm1 1.617 + paddd mm1,mm4 ; mm1=data0[col0 ****]=(A0 **) 1.618 + psubd mm3,mm4 ; mm3=data1[col0 ****]=(B0 **) 1.619 + punpckldq mm1,mm3 ; mm1=(A0 B0) 1.620 + 1.621 + movq mm7,[GOTOFF(ebx,PD_DESCALE_P1_2)] ; mm7=[PD_DESCALE_P1_2] 1.622 + 1.623 + movq mm4,mm2 1.624 + movq mm3,mm5 1.625 + paddd mm2,mm0 ; mm2=data0[col1 col3]=(A1 A3) 1.626 + paddd mm5,mm6 ; mm5=data0[col5 col7]=(A5 A7) 1.627 + psubd mm4,mm0 ; mm4=data1[col1 col3]=(B1 B3) 1.628 + psubd mm3,mm6 ; mm3=data1[col5 col7]=(B5 B7) 1.629 + 1.630 + paddd mm1,mm7 1.631 + psrad mm1,DESCALE_P1_2 1.632 + 1.633 + paddd mm2,mm7 1.634 + paddd mm5,mm7 1.635 + psrad mm2,DESCALE_P1_2 1.636 + psrad mm5,DESCALE_P1_2 1.637 + paddd mm4,mm7 1.638 + paddd mm3,mm7 1.639 + psrad mm4,DESCALE_P1_2 1.640 + psrad mm3,DESCALE_P1_2 1.641 + 1.642 + ; ---- Pass 2: process rows, store into output array. 1.643 + 1.644 + mov edi, JSAMPARRAY [output_buf(ebp)] ; (JSAMPROW *) 1.645 + mov eax, JDIMENSION [output_col(ebp)] 1.646 + 1.647 + ; | input:| result:| 1.648 + ; | A0 B0 | | 1.649 + ; | A1 B1 | C0 C1 | 1.650 + ; | A3 B3 | D0 D1 | 1.651 + ; | A5 B5 | | 1.652 + ; | A7 B7 | | 1.653 + 1.654 + ; -- Odd part 1.655 + 1.656 + packssdw mm2,mm4 ; mm2=(A1 A3 B1 B3) 1.657 + packssdw mm5,mm3 ; mm5=(A5 A7 B5 B7) 1.658 + pmaddwd mm2,[GOTOFF(ebx,PW_F362_MF127)] 1.659 + pmaddwd mm5,[GOTOFF(ebx,PW_F085_MF072)] 1.660 + 1.661 + paddd mm2,mm5 ; mm2=tmp0[row0 row1] 1.662 + 1.663 + ; -- Even part 1.664 + 1.665 + pslld mm1,(CONST_BITS+2) ; mm1=tmp10[row0 row1] 1.666 + 1.667 + ; -- Final output stage 1.668 + 1.669 + movq mm0,[GOTOFF(ebx,PD_DESCALE_P2_2)] ; mm0=[PD_DESCALE_P2_2] 1.670 + 1.671 + movq mm6,mm1 1.672 + paddd mm1,mm2 ; mm1=data0[row0 row1]=(C0 C1) 1.673 + psubd mm6,mm2 ; mm6=data1[row0 row1]=(D0 D1) 1.674 + 1.675 + paddd mm1,mm0 1.676 + paddd mm6,mm0 1.677 + psrad mm1,DESCALE_P2_2 1.678 + psrad mm6,DESCALE_P2_2 1.679 + 1.680 + movq mm7,mm1 ; transpose coefficients 1.681 + punpckldq mm1,mm6 ; mm1=(C0 D0) 1.682 + punpckhdq mm7,mm6 ; mm7=(C1 D1) 1.683 + 1.684 + packssdw mm1,mm7 ; mm1=(C0 D0 C1 D1) 1.685 + packsswb mm1,mm1 ; mm1=(C0 D0 C1 D1 C0 D0 C1 D1) 1.686 + paddb mm1,[GOTOFF(ebx,PB_CENTERJSAMP)] 1.687 + 1.688 + movd ecx,mm1 1.689 + movd ebx,mm1 ; ebx=(C0 D0 C1 D1) 1.690 + shr ecx,2*BYTE_BIT ; ecx=(C1 D1 -- --) 1.691 + 1.692 + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] 1.693 + mov esi, JSAMPROW [edi+1*SIZEOF_JSAMPROW] 1.694 + mov WORD [edx+eax*SIZEOF_JSAMPLE], bx 1.695 + mov WORD [esi+eax*SIZEOF_JSAMPLE], cx 1.696 + 1.697 + emms ; empty MMX state 1.698 + 1.699 + pop edi 1.700 + pop esi 1.701 +; pop edx ; need not be preserved 1.702 +; pop ecx ; need not be preserved 1.703 + pop ebx 1.704 + pop ebp 1.705 + ret 1.706 + 1.707 +; For some reason, the OS X linker does not honor the request to align the 1.708 +; segment unless we do this. 1.709 + align 16