blob: 9142ad8816e1e3bfd3cbaf7baeb0319cb7c6d4d1 [file] [log] [blame]
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +00001;
DRC72130be2014-05-09 20:14:26 +00002; jfdctint.asm - accurate integer FDCT (MMX)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +00003;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +00004; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5;
Alex Naidis6eb7d372016-10-16 23:10:08 +02006; Based on the x86 SIMD extension for IJG JPEG library
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +00007; Copyright (C) 1999-2006, MIYASAKA Masaru.
8; For conditions of distribution and use, see copyright notice in jsimdext.inc
9;
10; This file should be assembled with NASM (Netwide Assembler),
11; can *not* be assembled with Microsoft's MASM or any compatible
12; assembler (including Borland's Turbo Assembler).
13; NASM is available from http://nasm.sourceforge.net/ or
14; http://sourceforge.net/project/showfiles.php?group_id=6208
15;
16; This file contains a slow-but-accurate integer implementation of the
17; forward DCT (Discrete Cosine Transform). The following code is based
18; directly on the IJG's original jfdctint.c; see the jfdctint.c for
19; more details.
20;
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000021; [TAB8]
22
Pierre Ossman3a65ef42009-03-16 13:34:18 +000023%include "jsimdext.inc"
24%include "jdct.inc"
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000025
26; --------------------------------------------------------------------------
27
DRCe5eaf372014-05-09 18:00:32 +000028%define CONST_BITS 13
29%define PASS1_BITS 2
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000030
DRCe5eaf372014-05-09 18:00:32 +000031%define DESCALE_P1 (CONST_BITS-PASS1_BITS)
32%define DESCALE_P2 (CONST_BITS+PASS1_BITS)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000033
34%if CONST_BITS == 13
DRCe5eaf372014-05-09 18:00:32 +000035F_0_298 equ 2446 ; FIX(0.298631336)
36F_0_390 equ 3196 ; FIX(0.390180644)
37F_0_541 equ 4433 ; FIX(0.541196100)
38F_0_765 equ 6270 ; FIX(0.765366865)
39F_0_899 equ 7373 ; FIX(0.899976223)
40F_1_175 equ 9633 ; FIX(1.175875602)
41F_1_501 equ 12299 ; FIX(1.501321110)
42F_1_847 equ 15137 ; FIX(1.847759065)
43F_1_961 equ 16069 ; FIX(1.961570560)
44F_2_053 equ 16819 ; FIX(2.053119869)
45F_2_562 equ 20995 ; FIX(2.562915447)
46F_3_072 equ 25172 ; FIX(3.072711026)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000047%else
48; NASM cannot do compile-time arithmetic on floating-point constants.
49%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n))
DRCe5eaf372014-05-09 18:00:32 +000050F_0_298 equ DESCALE( 320652955,30-CONST_BITS) ; FIX(0.298631336)
51F_0_390 equ DESCALE( 418953276,30-CONST_BITS) ; FIX(0.390180644)
52F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100)
53F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865)
54F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223)
55F_1_175 equ DESCALE(1262586813,30-CONST_BITS) ; FIX(1.175875602)
56F_1_501 equ DESCALE(1612031267,30-CONST_BITS) ; FIX(1.501321110)
57F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065)
58F_1_961 equ DESCALE(2106220350,30-CONST_BITS) ; FIX(1.961570560)
59F_2_053 equ DESCALE(2204520673,30-CONST_BITS) ; FIX(2.053119869)
60F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447)
61F_3_072 equ DESCALE(3299298341,30-CONST_BITS) ; FIX(3.072711026)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000062%endif
63
64; --------------------------------------------------------------------------
DRCe5eaf372014-05-09 18:00:32 +000065 SECTION SEG_CONST
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000066
DRCe5eaf372014-05-09 18:00:32 +000067 alignz 16
68 global EXTN(jconst_fdct_islow_mmx)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000069
70EXTN(jconst_fdct_islow_mmx):
71
DRCe5eaf372014-05-09 18:00:32 +000072PW_F130_F054 times 2 dw (F_0_541+F_0_765), F_0_541
73PW_F054_MF130 times 2 dw F_0_541, (F_0_541-F_1_847)
74PW_MF078_F117 times 2 dw (F_1_175-F_1_961), F_1_175
75PW_F117_F078 times 2 dw F_1_175, (F_1_175-F_0_390)
76PW_MF060_MF089 times 2 dw (F_0_298-F_0_899),-F_0_899
77PW_MF089_F060 times 2 dw -F_0_899, (F_1_501-F_0_899)
78PW_MF050_MF256 times 2 dw (F_2_053-F_2_562),-F_2_562
79PW_MF256_F050 times 2 dw -F_2_562, (F_3_072-F_2_562)
80PD_DESCALE_P1 times 2 dd 1 << (DESCALE_P1-1)
81PD_DESCALE_P2 times 2 dd 1 << (DESCALE_P2-1)
82PW_DESCALE_P2X times 4 dw 1 << (PASS1_BITS-1)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000083
DRCe5eaf372014-05-09 18:00:32 +000084 alignz 16
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000085
86; --------------------------------------------------------------------------
DRCe5eaf372014-05-09 18:00:32 +000087 SECTION SEG_TEXT
88 BITS 32
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000089;
90; Perform the forward DCT on one block of samples.
91;
92; GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +020093; jsimd_fdct_islow_mmx (DCTELEM *data)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000094;
95
Alex Naidis6eb7d372016-10-16 23:10:08 +020096%define data(b) (b)+8 ; DCTELEM *data
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +000097
DRCe5eaf372014-05-09 18:00:32 +000098%define original_ebp ebp+0
99%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM]
100%define WK_NUM 2
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000101
DRCe5eaf372014-05-09 18:00:32 +0000102 align 16
103 global EXTN(jsimd_fdct_islow_mmx)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000104
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000105EXTN(jsimd_fdct_islow_mmx):
DRCe5eaf372014-05-09 18:00:32 +0000106 push ebp
107 mov eax,esp ; eax = original ebp
108 sub esp, byte 4
109 and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits
110 mov [esp],eax
111 mov ebp,esp ; ebp = aligned ebp
112 lea esp, [wk(0)]
113 pushpic ebx
114; push ecx ; need not be preserved
115; push edx ; need not be preserved
116; push esi ; unused
117; push edi ; unused
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000118
DRCe5eaf372014-05-09 18:00:32 +0000119 get_GOT ebx ; get GOT address
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000120
DRCe5eaf372014-05-09 18:00:32 +0000121 ; ---- Pass 1: process rows.
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000122
DRCe5eaf372014-05-09 18:00:32 +0000123 mov edx, POINTER [data(eax)] ; (DCTELEM *)
124 mov ecx, DCTSIZE/4
125 alignx 16,7
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000126.rowloop:
127
DRCe5eaf372014-05-09 18:00:32 +0000128 movq mm0, MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)]
129 movq mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)]
130 movq mm2, MMWORD [MMBLOCK(2,1,edx,SIZEOF_DCTELEM)]
131 movq mm3, MMWORD [MMBLOCK(3,1,edx,SIZEOF_DCTELEM)]
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000132
DRCe5eaf372014-05-09 18:00:32 +0000133 ; mm0=(20 21 22 23), mm2=(24 25 26 27)
134 ; mm1=(30 31 32 33), mm3=(34 35 36 37)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000135
DRCe5eaf372014-05-09 18:00:32 +0000136 movq mm4,mm0 ; transpose coefficients(phase 1)
137 punpcklwd mm0,mm1 ; mm0=(20 30 21 31)
138 punpckhwd mm4,mm1 ; mm4=(22 32 23 33)
139 movq mm5,mm2 ; transpose coefficients(phase 1)
140 punpcklwd mm2,mm3 ; mm2=(24 34 25 35)
141 punpckhwd mm5,mm3 ; mm5=(26 36 27 37)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000142
DRCe5eaf372014-05-09 18:00:32 +0000143 movq mm6, MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)]
144 movq mm7, MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)]
145 movq mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_DCTELEM)]
146 movq mm3, MMWORD [MMBLOCK(1,1,edx,SIZEOF_DCTELEM)]
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000147
DRCe5eaf372014-05-09 18:00:32 +0000148 ; mm6=(00 01 02 03), mm1=(04 05 06 07)
149 ; mm7=(10 11 12 13), mm3=(14 15 16 17)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000150
DRCe5eaf372014-05-09 18:00:32 +0000151 movq MMWORD [wk(0)], mm4 ; wk(0)=(22 32 23 33)
152 movq MMWORD [wk(1)], mm2 ; wk(1)=(24 34 25 35)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000153
DRCe5eaf372014-05-09 18:00:32 +0000154 movq mm4,mm6 ; transpose coefficients(phase 1)
155 punpcklwd mm6,mm7 ; mm6=(00 10 01 11)
156 punpckhwd mm4,mm7 ; mm4=(02 12 03 13)
157 movq mm2,mm1 ; transpose coefficients(phase 1)
158 punpcklwd mm1,mm3 ; mm1=(04 14 05 15)
159 punpckhwd mm2,mm3 ; mm2=(06 16 07 17)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000160
DRCe5eaf372014-05-09 18:00:32 +0000161 movq mm7,mm6 ; transpose coefficients(phase 2)
162 punpckldq mm6,mm0 ; mm6=(00 10 20 30)=data0
163 punpckhdq mm7,mm0 ; mm7=(01 11 21 31)=data1
164 movq mm3,mm2 ; transpose coefficients(phase 2)
165 punpckldq mm2,mm5 ; mm2=(06 16 26 36)=data6
166 punpckhdq mm3,mm5 ; mm3=(07 17 27 37)=data7
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000167
DRCe5eaf372014-05-09 18:00:32 +0000168 movq mm0,mm7
169 movq mm5,mm6
170 psubw mm7,mm2 ; mm7=data1-data6=tmp6
171 psubw mm6,mm3 ; mm6=data0-data7=tmp7
172 paddw mm0,mm2 ; mm0=data1+data6=tmp1
173 paddw mm5,mm3 ; mm5=data0+data7=tmp0
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000174
DRCe5eaf372014-05-09 18:00:32 +0000175 movq mm2, MMWORD [wk(0)] ; mm2=(22 32 23 33)
176 movq mm3, MMWORD [wk(1)] ; mm3=(24 34 25 35)
177 movq MMWORD [wk(0)], mm7 ; wk(0)=tmp6
178 movq MMWORD [wk(1)], mm6 ; wk(1)=tmp7
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000179
DRCe5eaf372014-05-09 18:00:32 +0000180 movq mm7,mm4 ; transpose coefficients(phase 2)
181 punpckldq mm4,mm2 ; mm4=(02 12 22 32)=data2
182 punpckhdq mm7,mm2 ; mm7=(03 13 23 33)=data3
183 movq mm6,mm1 ; transpose coefficients(phase 2)
184 punpckldq mm1,mm3 ; mm1=(04 14 24 34)=data4
185 punpckhdq mm6,mm3 ; mm6=(05 15 25 35)=data5
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000186
DRCe5eaf372014-05-09 18:00:32 +0000187 movq mm2,mm7
188 movq mm3,mm4
189 paddw mm7,mm1 ; mm7=data3+data4=tmp3
190 paddw mm4,mm6 ; mm4=data2+data5=tmp2
191 psubw mm2,mm1 ; mm2=data3-data4=tmp4
192 psubw mm3,mm6 ; mm3=data2-data5=tmp5
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000193
DRCe5eaf372014-05-09 18:00:32 +0000194 ; -- Even part
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000195
DRCe5eaf372014-05-09 18:00:32 +0000196 movq mm1,mm5
197 movq mm6,mm0
198 paddw mm5,mm7 ; mm5=tmp10
199 paddw mm0,mm4 ; mm0=tmp11
200 psubw mm1,mm7 ; mm1=tmp13
201 psubw mm6,mm4 ; mm6=tmp12
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000202
DRCe5eaf372014-05-09 18:00:32 +0000203 movq mm7,mm5
204 paddw mm5,mm0 ; mm5=tmp10+tmp11
205 psubw mm7,mm0 ; mm7=tmp10-tmp11
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000206
DRCe5eaf372014-05-09 18:00:32 +0000207 psllw mm5,PASS1_BITS ; mm5=data0
208 psllw mm7,PASS1_BITS ; mm7=data4
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000209
DRCe5eaf372014-05-09 18:00:32 +0000210 movq MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)], mm5
211 movq MMWORD [MMBLOCK(0,1,edx,SIZEOF_DCTELEM)], mm7
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000212
DRCe5eaf372014-05-09 18:00:32 +0000213 ; (Original)
214 ; z1 = (tmp12 + tmp13) * 0.541196100;
215 ; data2 = z1 + tmp13 * 0.765366865;
216 ; data6 = z1 + tmp12 * -1.847759065;
217 ;
218 ; (This implementation)
219 ; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100;
220 ; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065);
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000221
DRCe5eaf372014-05-09 18:00:32 +0000222 movq mm4,mm1 ; mm1=tmp13
223 movq mm0,mm1
224 punpcklwd mm4,mm6 ; mm6=tmp12
225 punpckhwd mm0,mm6
226 movq mm1,mm4
227 movq mm6,mm0
228 pmaddwd mm4,[GOTOFF(ebx,PW_F130_F054)] ; mm4=data2L
229 pmaddwd mm0,[GOTOFF(ebx,PW_F130_F054)] ; mm0=data2H
230 pmaddwd mm1,[GOTOFF(ebx,PW_F054_MF130)] ; mm1=data6L
231 pmaddwd mm6,[GOTOFF(ebx,PW_F054_MF130)] ; mm6=data6H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000232
DRCe5eaf372014-05-09 18:00:32 +0000233 paddd mm4,[GOTOFF(ebx,PD_DESCALE_P1)]
234 paddd mm0,[GOTOFF(ebx,PD_DESCALE_P1)]
235 psrad mm4,DESCALE_P1
236 psrad mm0,DESCALE_P1
237 paddd mm1,[GOTOFF(ebx,PD_DESCALE_P1)]
238 paddd mm6,[GOTOFF(ebx,PD_DESCALE_P1)]
239 psrad mm1,DESCALE_P1
240 psrad mm6,DESCALE_P1
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000241
DRCe5eaf372014-05-09 18:00:32 +0000242 packssdw mm4,mm0 ; mm4=data2
243 packssdw mm1,mm6 ; mm1=data6
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000244
DRCe5eaf372014-05-09 18:00:32 +0000245 movq MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)], mm4
246 movq MMWORD [MMBLOCK(2,1,edx,SIZEOF_DCTELEM)], mm1
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000247
DRCe5eaf372014-05-09 18:00:32 +0000248 ; -- Odd part
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000249
DRCe5eaf372014-05-09 18:00:32 +0000250 movq mm5, MMWORD [wk(0)] ; mm5=tmp6
251 movq mm7, MMWORD [wk(1)] ; mm7=tmp7
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000252
DRCe5eaf372014-05-09 18:00:32 +0000253 movq mm0,mm2 ; mm2=tmp4
254 movq mm6,mm3 ; mm3=tmp5
255 paddw mm0,mm5 ; mm0=z3
256 paddw mm6,mm7 ; mm6=z4
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000257
DRCe5eaf372014-05-09 18:00:32 +0000258 ; (Original)
259 ; z5 = (z3 + z4) * 1.175875602;
260 ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644;
261 ; z3 += z5; z4 += z5;
262 ;
263 ; (This implementation)
264 ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
265 ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000266
DRCe5eaf372014-05-09 18:00:32 +0000267 movq mm4,mm0
268 movq mm1,mm0
269 punpcklwd mm4,mm6
270 punpckhwd mm1,mm6
271 movq mm0,mm4
272 movq mm6,mm1
273 pmaddwd mm4,[GOTOFF(ebx,PW_MF078_F117)] ; mm4=z3L
274 pmaddwd mm1,[GOTOFF(ebx,PW_MF078_F117)] ; mm1=z3H
275 pmaddwd mm0,[GOTOFF(ebx,PW_F117_F078)] ; mm0=z4L
276 pmaddwd mm6,[GOTOFF(ebx,PW_F117_F078)] ; mm6=z4H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000277
DRCe5eaf372014-05-09 18:00:32 +0000278 movq MMWORD [wk(0)], mm4 ; wk(0)=z3L
279 movq MMWORD [wk(1)], mm1 ; wk(1)=z3H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000280
DRCe5eaf372014-05-09 18:00:32 +0000281 ; (Original)
282 ; z1 = tmp4 + tmp7; z2 = tmp5 + tmp6;
283 ; tmp4 = tmp4 * 0.298631336; tmp5 = tmp5 * 2.053119869;
284 ; tmp6 = tmp6 * 3.072711026; tmp7 = tmp7 * 1.501321110;
285 ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447;
286 ; data7 = tmp4 + z1 + z3; data5 = tmp5 + z2 + z4;
287 ; data3 = tmp6 + z2 + z3; data1 = tmp7 + z1 + z4;
288 ;
289 ; (This implementation)
290 ; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223;
291 ; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447;
292 ; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447);
293 ; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223);
294 ; data7 = tmp4 + z3; data5 = tmp5 + z4;
295 ; data3 = tmp6 + z3; data1 = tmp7 + z4;
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000296
DRCe5eaf372014-05-09 18:00:32 +0000297 movq mm4,mm2
298 movq mm1,mm2
299 punpcklwd mm4,mm7
300 punpckhwd mm1,mm7
301 movq mm2,mm4
302 movq mm7,mm1
303 pmaddwd mm4,[GOTOFF(ebx,PW_MF060_MF089)] ; mm4=tmp4L
304 pmaddwd mm1,[GOTOFF(ebx,PW_MF060_MF089)] ; mm1=tmp4H
305 pmaddwd mm2,[GOTOFF(ebx,PW_MF089_F060)] ; mm2=tmp7L
306 pmaddwd mm7,[GOTOFF(ebx,PW_MF089_F060)] ; mm7=tmp7H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000307
DRCe5eaf372014-05-09 18:00:32 +0000308 paddd mm4, MMWORD [wk(0)] ; mm4=data7L
309 paddd mm1, MMWORD [wk(1)] ; mm1=data7H
310 paddd mm2,mm0 ; mm2=data1L
311 paddd mm7,mm6 ; mm7=data1H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000312
DRCe5eaf372014-05-09 18:00:32 +0000313 paddd mm4,[GOTOFF(ebx,PD_DESCALE_P1)]
314 paddd mm1,[GOTOFF(ebx,PD_DESCALE_P1)]
315 psrad mm4,DESCALE_P1
316 psrad mm1,DESCALE_P1
317 paddd mm2,[GOTOFF(ebx,PD_DESCALE_P1)]
318 paddd mm7,[GOTOFF(ebx,PD_DESCALE_P1)]
319 psrad mm2,DESCALE_P1
320 psrad mm7,DESCALE_P1
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000321
DRCe5eaf372014-05-09 18:00:32 +0000322 packssdw mm4,mm1 ; mm4=data7
323 packssdw mm2,mm7 ; mm2=data1
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000324
DRCe5eaf372014-05-09 18:00:32 +0000325 movq MMWORD [MMBLOCK(3,1,edx,SIZEOF_DCTELEM)], mm4
326 movq MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)], mm2
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000327
DRCe5eaf372014-05-09 18:00:32 +0000328 movq mm1,mm3
329 movq mm7,mm3
330 punpcklwd mm1,mm5
331 punpckhwd mm7,mm5
332 movq mm3,mm1
333 movq mm5,mm7
334 pmaddwd mm1,[GOTOFF(ebx,PW_MF050_MF256)] ; mm1=tmp5L
335 pmaddwd mm7,[GOTOFF(ebx,PW_MF050_MF256)] ; mm7=tmp5H
336 pmaddwd mm3,[GOTOFF(ebx,PW_MF256_F050)] ; mm3=tmp6L
337 pmaddwd mm5,[GOTOFF(ebx,PW_MF256_F050)] ; mm5=tmp6H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000338
DRCe5eaf372014-05-09 18:00:32 +0000339 paddd mm1,mm0 ; mm1=data5L
340 paddd mm7,mm6 ; mm7=data5H
341 paddd mm3, MMWORD [wk(0)] ; mm3=data3L
342 paddd mm5, MMWORD [wk(1)] ; mm5=data3H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000343
DRCe5eaf372014-05-09 18:00:32 +0000344 paddd mm1,[GOTOFF(ebx,PD_DESCALE_P1)]
345 paddd mm7,[GOTOFF(ebx,PD_DESCALE_P1)]
346 psrad mm1,DESCALE_P1
347 psrad mm7,DESCALE_P1
348 paddd mm3,[GOTOFF(ebx,PD_DESCALE_P1)]
349 paddd mm5,[GOTOFF(ebx,PD_DESCALE_P1)]
350 psrad mm3,DESCALE_P1
351 psrad mm5,DESCALE_P1
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000352
DRCe5eaf372014-05-09 18:00:32 +0000353 packssdw mm1,mm7 ; mm1=data5
354 packssdw mm3,mm5 ; mm3=data3
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000355
DRCe5eaf372014-05-09 18:00:32 +0000356 movq MMWORD [MMBLOCK(1,1,edx,SIZEOF_DCTELEM)], mm1
357 movq MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)], mm3
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000358
DRCe5eaf372014-05-09 18:00:32 +0000359 add edx, byte 4*DCTSIZE*SIZEOF_DCTELEM
360 dec ecx
361 jnz near .rowloop
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000362
DRCe5eaf372014-05-09 18:00:32 +0000363 ; ---- Pass 2: process columns.
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000364
DRCe5eaf372014-05-09 18:00:32 +0000365 mov edx, POINTER [data(eax)] ; (DCTELEM *)
366 mov ecx, DCTSIZE/4
367 alignx 16,7
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000368.columnloop:
369
DRCe5eaf372014-05-09 18:00:32 +0000370 movq mm0, MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)]
371 movq mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)]
372 movq mm2, MMWORD [MMBLOCK(6,0,edx,SIZEOF_DCTELEM)]
373 movq mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_DCTELEM)]
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000374
DRCe5eaf372014-05-09 18:00:32 +0000375 ; mm0=(02 12 22 32), mm2=(42 52 62 72)
376 ; mm1=(03 13 23 33), mm3=(43 53 63 73)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000377
DRCe5eaf372014-05-09 18:00:32 +0000378 movq mm4,mm0 ; transpose coefficients(phase 1)
379 punpcklwd mm0,mm1 ; mm0=(02 03 12 13)
380 punpckhwd mm4,mm1 ; mm4=(22 23 32 33)
381 movq mm5,mm2 ; transpose coefficients(phase 1)
382 punpcklwd mm2,mm3 ; mm2=(42 43 52 53)
383 punpckhwd mm5,mm3 ; mm5=(62 63 72 73)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000384
DRCe5eaf372014-05-09 18:00:32 +0000385 movq mm6, MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)]
386 movq mm7, MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)]
387 movq mm1, MMWORD [MMBLOCK(4,0,edx,SIZEOF_DCTELEM)]
388 movq mm3, MMWORD [MMBLOCK(5,0,edx,SIZEOF_DCTELEM)]
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000389
DRCe5eaf372014-05-09 18:00:32 +0000390 ; mm6=(00 10 20 30), mm1=(40 50 60 70)
391 ; mm7=(01 11 21 31), mm3=(41 51 61 71)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000392
DRCe5eaf372014-05-09 18:00:32 +0000393 movq MMWORD [wk(0)], mm4 ; wk(0)=(22 23 32 33)
394 movq MMWORD [wk(1)], mm2 ; wk(1)=(42 43 52 53)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000395
DRCe5eaf372014-05-09 18:00:32 +0000396 movq mm4,mm6 ; transpose coefficients(phase 1)
397 punpcklwd mm6,mm7 ; mm6=(00 01 10 11)
398 punpckhwd mm4,mm7 ; mm4=(20 21 30 31)
399 movq mm2,mm1 ; transpose coefficients(phase 1)
400 punpcklwd mm1,mm3 ; mm1=(40 41 50 51)
401 punpckhwd mm2,mm3 ; mm2=(60 61 70 71)
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000402
DRCe5eaf372014-05-09 18:00:32 +0000403 movq mm7,mm6 ; transpose coefficients(phase 2)
404 punpckldq mm6,mm0 ; mm6=(00 01 02 03)=data0
405 punpckhdq mm7,mm0 ; mm7=(10 11 12 13)=data1
406 movq mm3,mm2 ; transpose coefficients(phase 2)
407 punpckldq mm2,mm5 ; mm2=(60 61 62 63)=data6
408 punpckhdq mm3,mm5 ; mm3=(70 71 72 73)=data7
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000409
DRCe5eaf372014-05-09 18:00:32 +0000410 movq mm0,mm7
411 movq mm5,mm6
412 psubw mm7,mm2 ; mm7=data1-data6=tmp6
413 psubw mm6,mm3 ; mm6=data0-data7=tmp7
414 paddw mm0,mm2 ; mm0=data1+data6=tmp1
415 paddw mm5,mm3 ; mm5=data0+data7=tmp0
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000416
DRCe5eaf372014-05-09 18:00:32 +0000417 movq mm2, MMWORD [wk(0)] ; mm2=(22 23 32 33)
418 movq mm3, MMWORD [wk(1)] ; mm3=(42 43 52 53)
419 movq MMWORD [wk(0)], mm7 ; wk(0)=tmp6
420 movq MMWORD [wk(1)], mm6 ; wk(1)=tmp7
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000421
DRCe5eaf372014-05-09 18:00:32 +0000422 movq mm7,mm4 ; transpose coefficients(phase 2)
423 punpckldq mm4,mm2 ; mm4=(20 21 22 23)=data2
424 punpckhdq mm7,mm2 ; mm7=(30 31 32 33)=data3
425 movq mm6,mm1 ; transpose coefficients(phase 2)
426 punpckldq mm1,mm3 ; mm1=(40 41 42 43)=data4
427 punpckhdq mm6,mm3 ; mm6=(50 51 52 53)=data5
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000428
DRCe5eaf372014-05-09 18:00:32 +0000429 movq mm2,mm7
430 movq mm3,mm4
431 paddw mm7,mm1 ; mm7=data3+data4=tmp3
432 paddw mm4,mm6 ; mm4=data2+data5=tmp2
433 psubw mm2,mm1 ; mm2=data3-data4=tmp4
434 psubw mm3,mm6 ; mm3=data2-data5=tmp5
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000435
DRCe5eaf372014-05-09 18:00:32 +0000436 ; -- Even part
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000437
DRCe5eaf372014-05-09 18:00:32 +0000438 movq mm1,mm5
439 movq mm6,mm0
440 paddw mm5,mm7 ; mm5=tmp10
441 paddw mm0,mm4 ; mm0=tmp11
442 psubw mm1,mm7 ; mm1=tmp13
443 psubw mm6,mm4 ; mm6=tmp12
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000444
DRCe5eaf372014-05-09 18:00:32 +0000445 movq mm7,mm5
446 paddw mm5,mm0 ; mm5=tmp10+tmp11
447 psubw mm7,mm0 ; mm7=tmp10-tmp11
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000448
DRCe5eaf372014-05-09 18:00:32 +0000449 paddw mm5,[GOTOFF(ebx,PW_DESCALE_P2X)]
450 paddw mm7,[GOTOFF(ebx,PW_DESCALE_P2X)]
451 psraw mm5,PASS1_BITS ; mm5=data0
452 psraw mm7,PASS1_BITS ; mm7=data4
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000453
DRCe5eaf372014-05-09 18:00:32 +0000454 movq MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)], mm5
455 movq MMWORD [MMBLOCK(4,0,edx,SIZEOF_DCTELEM)], mm7
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000456
DRCe5eaf372014-05-09 18:00:32 +0000457 ; (Original)
458 ; z1 = (tmp12 + tmp13) * 0.541196100;
459 ; data2 = z1 + tmp13 * 0.765366865;
460 ; data6 = z1 + tmp12 * -1.847759065;
461 ;
462 ; (This implementation)
463 ; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100;
464 ; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065);
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000465
DRCe5eaf372014-05-09 18:00:32 +0000466 movq mm4,mm1 ; mm1=tmp13
467 movq mm0,mm1
468 punpcklwd mm4,mm6 ; mm6=tmp12
469 punpckhwd mm0,mm6
470 movq mm1,mm4
471 movq mm6,mm0
472 pmaddwd mm4,[GOTOFF(ebx,PW_F130_F054)] ; mm4=data2L
473 pmaddwd mm0,[GOTOFF(ebx,PW_F130_F054)] ; mm0=data2H
474 pmaddwd mm1,[GOTOFF(ebx,PW_F054_MF130)] ; mm1=data6L
475 pmaddwd mm6,[GOTOFF(ebx,PW_F054_MF130)] ; mm6=data6H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000476
DRCe5eaf372014-05-09 18:00:32 +0000477 paddd mm4,[GOTOFF(ebx,PD_DESCALE_P2)]
478 paddd mm0,[GOTOFF(ebx,PD_DESCALE_P2)]
479 psrad mm4,DESCALE_P2
480 psrad mm0,DESCALE_P2
481 paddd mm1,[GOTOFF(ebx,PD_DESCALE_P2)]
482 paddd mm6,[GOTOFF(ebx,PD_DESCALE_P2)]
483 psrad mm1,DESCALE_P2
484 psrad mm6,DESCALE_P2
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000485
DRCe5eaf372014-05-09 18:00:32 +0000486 packssdw mm4,mm0 ; mm4=data2
487 packssdw mm1,mm6 ; mm1=data6
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000488
DRCe5eaf372014-05-09 18:00:32 +0000489 movq MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)], mm4
490 movq MMWORD [MMBLOCK(6,0,edx,SIZEOF_DCTELEM)], mm1
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000491
DRCe5eaf372014-05-09 18:00:32 +0000492 ; -- Odd part
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000493
DRCe5eaf372014-05-09 18:00:32 +0000494 movq mm5, MMWORD [wk(0)] ; mm5=tmp6
495 movq mm7, MMWORD [wk(1)] ; mm7=tmp7
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000496
DRCe5eaf372014-05-09 18:00:32 +0000497 movq mm0,mm2 ; mm2=tmp4
498 movq mm6,mm3 ; mm3=tmp5
499 paddw mm0,mm5 ; mm0=z3
500 paddw mm6,mm7 ; mm6=z4
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000501
DRCe5eaf372014-05-09 18:00:32 +0000502 ; (Original)
503 ; z5 = (z3 + z4) * 1.175875602;
504 ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644;
505 ; z3 += z5; z4 += z5;
506 ;
507 ; (This implementation)
508 ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
509 ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000510
DRCe5eaf372014-05-09 18:00:32 +0000511 movq mm4,mm0
512 movq mm1,mm0
513 punpcklwd mm4,mm6
514 punpckhwd mm1,mm6
515 movq mm0,mm4
516 movq mm6,mm1
517 pmaddwd mm4,[GOTOFF(ebx,PW_MF078_F117)] ; mm4=z3L
518 pmaddwd mm1,[GOTOFF(ebx,PW_MF078_F117)] ; mm1=z3H
519 pmaddwd mm0,[GOTOFF(ebx,PW_F117_F078)] ; mm0=z4L
520 pmaddwd mm6,[GOTOFF(ebx,PW_F117_F078)] ; mm6=z4H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000521
DRCe5eaf372014-05-09 18:00:32 +0000522 movq MMWORD [wk(0)], mm4 ; wk(0)=z3L
523 movq MMWORD [wk(1)], mm1 ; wk(1)=z3H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000524
DRCe5eaf372014-05-09 18:00:32 +0000525 ; (Original)
526 ; z1 = tmp4 + tmp7; z2 = tmp5 + tmp6;
527 ; tmp4 = tmp4 * 0.298631336; tmp5 = tmp5 * 2.053119869;
528 ; tmp6 = tmp6 * 3.072711026; tmp7 = tmp7 * 1.501321110;
529 ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447;
530 ; data7 = tmp4 + z1 + z3; data5 = tmp5 + z2 + z4;
531 ; data3 = tmp6 + z2 + z3; data1 = tmp7 + z1 + z4;
532 ;
533 ; (This implementation)
534 ; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223;
535 ; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447;
536 ; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447);
537 ; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223);
538 ; data7 = tmp4 + z3; data5 = tmp5 + z4;
539 ; data3 = tmp6 + z3; data1 = tmp7 + z4;
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000540
DRCe5eaf372014-05-09 18:00:32 +0000541 movq mm4,mm2
542 movq mm1,mm2
543 punpcklwd mm4,mm7
544 punpckhwd mm1,mm7
545 movq mm2,mm4
546 movq mm7,mm1
547 pmaddwd mm4,[GOTOFF(ebx,PW_MF060_MF089)] ; mm4=tmp4L
548 pmaddwd mm1,[GOTOFF(ebx,PW_MF060_MF089)] ; mm1=tmp4H
549 pmaddwd mm2,[GOTOFF(ebx,PW_MF089_F060)] ; mm2=tmp7L
550 pmaddwd mm7,[GOTOFF(ebx,PW_MF089_F060)] ; mm7=tmp7H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000551
DRCe5eaf372014-05-09 18:00:32 +0000552 paddd mm4, MMWORD [wk(0)] ; mm4=data7L
553 paddd mm1, MMWORD [wk(1)] ; mm1=data7H
554 paddd mm2,mm0 ; mm2=data1L
555 paddd mm7,mm6 ; mm7=data1H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000556
DRCe5eaf372014-05-09 18:00:32 +0000557 paddd mm4,[GOTOFF(ebx,PD_DESCALE_P2)]
558 paddd mm1,[GOTOFF(ebx,PD_DESCALE_P2)]
559 psrad mm4,DESCALE_P2
560 psrad mm1,DESCALE_P2
561 paddd mm2,[GOTOFF(ebx,PD_DESCALE_P2)]
562 paddd mm7,[GOTOFF(ebx,PD_DESCALE_P2)]
563 psrad mm2,DESCALE_P2
564 psrad mm7,DESCALE_P2
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000565
DRCe5eaf372014-05-09 18:00:32 +0000566 packssdw mm4,mm1 ; mm4=data7
567 packssdw mm2,mm7 ; mm2=data1
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000568
DRCe5eaf372014-05-09 18:00:32 +0000569 movq MMWORD [MMBLOCK(7,0,edx,SIZEOF_DCTELEM)], mm4
570 movq MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)], mm2
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000571
DRCe5eaf372014-05-09 18:00:32 +0000572 movq mm1,mm3
573 movq mm7,mm3
574 punpcklwd mm1,mm5
575 punpckhwd mm7,mm5
576 movq mm3,mm1
577 movq mm5,mm7
578 pmaddwd mm1,[GOTOFF(ebx,PW_MF050_MF256)] ; mm1=tmp5L
579 pmaddwd mm7,[GOTOFF(ebx,PW_MF050_MF256)] ; mm7=tmp5H
580 pmaddwd mm3,[GOTOFF(ebx,PW_MF256_F050)] ; mm3=tmp6L
581 pmaddwd mm5,[GOTOFF(ebx,PW_MF256_F050)] ; mm5=tmp6H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000582
DRCe5eaf372014-05-09 18:00:32 +0000583 paddd mm1,mm0 ; mm1=data5L
584 paddd mm7,mm6 ; mm7=data5H
585 paddd mm3, MMWORD [wk(0)] ; mm3=data3L
586 paddd mm5, MMWORD [wk(1)] ; mm5=data3H
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000587
DRCe5eaf372014-05-09 18:00:32 +0000588 paddd mm1,[GOTOFF(ebx,PD_DESCALE_P2)]
589 paddd mm7,[GOTOFF(ebx,PD_DESCALE_P2)]
590 psrad mm1,DESCALE_P2
591 psrad mm7,DESCALE_P2
592 paddd mm3,[GOTOFF(ebx,PD_DESCALE_P2)]
593 paddd mm5,[GOTOFF(ebx,PD_DESCALE_P2)]
594 psrad mm3,DESCALE_P2
595 psrad mm5,DESCALE_P2
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000596
DRCe5eaf372014-05-09 18:00:32 +0000597 packssdw mm1,mm7 ; mm1=data5
598 packssdw mm3,mm5 ; mm3=data3
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000599
DRCe5eaf372014-05-09 18:00:32 +0000600 movq MMWORD [MMBLOCK(5,0,edx,SIZEOF_DCTELEM)], mm1
601 movq MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)], mm3
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000602
DRCe5eaf372014-05-09 18:00:32 +0000603 add edx, byte 4*SIZEOF_DCTELEM
604 dec ecx
605 jnz near .columnloop
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000606
DRCe5eaf372014-05-09 18:00:32 +0000607 emms ; empty MMX state
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000608
DRCe5eaf372014-05-09 18:00:32 +0000609; pop edi ; unused
610; pop esi ; unused
611; pop edx ; need not be preserved
612; pop ecx ; need not be preserved
613 poppic ebx
614 mov esp,ebp ; esp <- aligned ebp
615 pop esp ; esp <- original ebp
616 pop ebp
617 ret
MIYASAKA Masarua2e6a9d2006-02-04 00:00:00 +0000618
DRC132b5fd2009-10-08 09:04:56 +0000619; For some reason, the OS X linker does not honor the request to align the
620; segment unless we do this.
DRCe5eaf372014-05-09 18:00:32 +0000621 align 16