[svn] / trunk / xvidcore / src / dct / x86_asm / fdct_sse2_skal.asm Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/src/dct/x86_asm/fdct_sse2_skal.asm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1540 - (view) (download)

1 : edgomez 1382 ;/****************************************************************************
2 :     ; *
3 :     ; * XVID MPEG-4 VIDEO CODEC
4 :     ; * - SSE2 forward discrete cosine transform -
5 :     ; *
6 :     ; * Copyright(C) 2003 Pascal Massimino <skal@planet-d.net>
7 :     ; *
8 :     ; * This program is free software; you can redistribute it and/or modify it
9 :     ; * under the terms of the GNU General Public License as published by
10 :     ; * the Free Software Foundation; either version 2 of the License, or
11 :     ; * (at your option) any later version.
12 :     ; *
13 :     ; * This program is distributed in the hope that it will be useful,
14 :     ; * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 :     ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 :     ; * GNU General Public License for more details.
17 :     ; *
18 :     ; * You should have received a copy of the GNU General Public License
19 :     ; * along with this program; if not, write to the Free Software
20 :     ; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 :     ; *
22 : edgomez 1540 ; * $Id: fdct_sse2_skal.asm,v 1.5 2004-08-29 10:02:38 edgomez Exp $
23 : edgomez 1382 ; *
24 :     ; ***************************************************************************/
25 :    
26 :     BITS 32
27 :    
28 :     %macro cglobal 1
29 : edgomez 1535 %ifdef PREFIX
30 :     %ifdef MARK_FUNCS
31 : edgomez 1540 global _%1:function %1.endfunc-%1
32 :     %define %1 _%1:function %1.endfunc-%1
33 : edgomez 1535 %else
34 :     global _%1
35 :     %define %1 _%1
36 :     %endif
37 :     %else
38 :     %ifdef MARK_FUNCS
39 : edgomez 1540 global %1:function %1.endfunc-%1
40 : edgomez 1535 %else
41 :     global %1
42 :     %endif
43 :     %endif
44 : edgomez 1382 %endmacro
45 :    
46 :     ;-----------------------------------------------------------------------------
47 :     ;
48 :     ; -=FDCT=-
49 :     ;
50 :     ; Vertical pass is an implementation of the scheme:
51 :     ; Loeffler C., Ligtenberg A., and Moschytz C.S.:
52 :     ; Practical Fast 1D DCT Algorithm with Eleven Multiplications,
53 :     ; Proc. ICASSP 1989, 988-991.
54 :     ;
55 :     ; Horizontal pass is a double 4x4 vector/matrix multiplication,
56 :     ; (see also Intel's Application Note 922:
57 :     ; http://developer.intel.com/vtune/cbts/strmsimd/922down.htm
58 :     ; Copyright (C) 1999 Intel Corporation)
59 :     ;
60 :     ; Notes:
61 :     ; * tan(3pi/16) is greater than 0.5, and would use the
62 :     ; sign bit when turned into 16b fixed-point precision. So,
63 :     ; we use the trick: x*tan3 = x*(tan3-1)+x
64 :     ;
65 :     ; * There's only one SSE-specific instruction (pshufw).
66 :     ;
67 :     ; * There's still 1 or 2 ticks to save in fLLM_PASS, but
68 :     ; I prefer having a readable code, instead of a tightly
69 :     ; scheduled one...
70 :     ;
71 :     ; * Quantization stage (as well as pre-transposition for the
72 :     ; idct way back) can be included in the fTab* constants
73 :     ; (with induced loss of precision, somehow)
74 :     ;
75 :     ; * Some more details at: http://skal.planet-d.net/coding/dct.html
76 :     ;
77 :     ;
78 :     ;//////////////////////////////////////////////////////////////////////
79 :     ;
80 :     ; == Mean square errors ==
81 :     ; 0.000 0.001 0.001 0.002 0.000 0.002 0.001 0.000 [0.001]
82 :     ; 0.035 0.029 0.032 0.032 0.031 0.032 0.034 0.035 [0.032]
83 :     ; 0.026 0.028 0.027 0.027 0.025 0.028 0.028 0.025 [0.027]
84 :     ; 0.037 0.032 0.031 0.030 0.028 0.029 0.026 0.031 [0.030]
85 :     ; 0.000 0.001 0.001 0.002 0.000 0.002 0.001 0.001 [0.001]
86 :     ; 0.025 0.024 0.022 0.022 0.022 0.022 0.023 0.023 [0.023]
87 :     ; 0.026 0.028 0.025 0.028 0.030 0.025 0.026 0.027 [0.027]
88 :     ; 0.021 0.020 0.020 0.022 0.020 0.022 0.017 0.019 [0.020]
89 :     ;
90 :     ; == Abs Mean errors ==
91 :     ; 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 [0.000]
92 :     ; 0.020 0.001 0.003 0.003 0.000 0.004 0.002 0.003 [0.002]
93 :     ; 0.000 0.001 0.001 0.001 0.001 0.004 0.000 0.000 [0.000]
94 :     ; 0.027 0.001 0.000 0.002 0.002 0.002 0.001 0.000 [0.003]
95 :     ; 0.000 0.000 0.000 0.000 0.000 0.001 0.000 0.001 [-0.000]
96 :     ; 0.001 0.003 0.001 0.001 0.002 0.001 0.000 0.000 [-0.000]
97 :     ; 0.000 0.002 0.002 0.001 0.001 0.002 0.001 0.000 [-0.000]
98 :     ; 0.000 0.002 0.001 0.002 0.001 0.002 0.001 0.001 [-0.000]
99 :     ;
100 :     ; =========================
101 :     ; Peak error: 1.0000
102 :     ; Peak MSE: 0.0365
103 :     ; Overall MSE: 0.0201
104 :     ; Peak ME: 0.0265
105 :     ; Overall ME: 0.0006
106 :     ;
107 :     ;-----------------------------------------------------------------------------
108 :     ;
109 :     ; -=IDCT=-
110 :     ;
111 :     ; A little slower than fdct, because the final stages (butterflies and
112 :     ; descaling) require some unpairable shifting and packing, all on
113 :     ; the same CPU unit.
114 :     ;
115 :     ; THIS IDCT IS NOT IEEE-COMPLIANT: IT WILL FAIL THE [-300,300]
116 :     ; INPUT RANGE TEST (because of overflow). But the [-256,255] one
117 :     ; is OK, and I'm fine with it (for now;)
118 :     ;
119 :     ; == Mean square errors ==
120 :     ; 0.007 0.006 0.005 0.007 0.006 0.007 0.005 0.007 [0.006]
121 :     ; 0.006 0.008 0.007 0.007 0.007 0.008 0.008 0.008 [0.007]
122 :     ; 0.008 0.008 0.008 0.008 0.007 0.009 0.010 0.007 [0.008]
123 :     ; 0.007 0.007 0.006 0.007 0.008 0.007 0.006 0.008 [0.007]
124 :     ; 0.007 0.006 0.006 0.006 0.006 0.005 0.006 0.006 [0.006]
125 :     ; 0.008 0.007 0.006 0.008 0.007 0.008 0.009 0.009 [0.008]
126 :     ; 0.008 0.006 0.010 0.008 0.008 0.008 0.007 0.007 [0.008]
127 :     ; 0.007 0.006 0.006 0.007 0.007 0.006 0.006 0.007 [0.006]
128 :     ;
129 :     ; == Abs Mean errors ==
130 :     ; 0.001 0.000 0.000 0.001 0.001 0.000 0.000 0.000 [0.000]
131 :     ; 0.000 0.002 0.002 0.000 0.001 0.001 0.000 0.002 [0.000]
132 :     ; 0.001 0.002 0.001 0.001 0.001 0.001 0.000 0.001 [-0.001]
133 :     ; 0.000 0.002 0.000 0.000 0.001 0.000 0.000 0.001 [-0.000]
134 :     ; 0.000 0.001 0.001 0.001 0.000 0.001 0.000 0.001 [0.000]
135 :     ; 0.000 0.001 0.001 0.001 0.001 0.000 0.001 0.000 [0.000]
136 :     ; 0.001 0.001 0.002 0.001 0.001 0.002 0.001 0.001 [0.001]
137 :     ; 0.000 0.000 0.001 0.000 0.000 0.000 0.000 0.000 [0.000]
138 :     ;
139 :     ; =========================
140 :     ;
141 :     ; Peak error: 1.0000
142 :     ; Peak MSE: 0.0096
143 :     ; Overall MSE: 0.0070
144 :     ; Peak ME: 0.0024
145 :     ; Overall ME: 0.0001
146 :     ;
147 :     ;-----------------------------------------------------------------------------
148 :    
149 :     ;=============================================================================
150 :     ; Read only data
151 :     ;=============================================================================
152 :    
153 :     %ifdef FORMAT_COFF
154 : edgomez 1519 SECTION .rodata
155 : edgomez 1382 %else
156 : edgomez 1519 SECTION .rodata align=16
157 : edgomez 1382 %endif
158 :    
159 :     ALIGN 16
160 :     tan1: times 8 dw 0x32ec ; tan( pi/16)
161 :     tan2: times 8 dw 0x6a0a ; tan(2pi/16) (=sqrt(2)-1)
162 :     tan3: times 8 dw 0xab0e ; tan(3pi/16)-1
163 :     sqrt2: times 8 dw 0x5a82 ; 0.5/sqrt(2)
164 :    
165 :     ;-----------------------------------------------------------------------------
166 :     ; Inverse DCT tables
167 :     ;-----------------------------------------------------------------------------
168 :    
169 :     ALIGN 16
170 :     iTab1:
171 :     dw 0x4000, 0x539f, 0x4000, 0x22a3
172 :     dw 0x4000, 0xdd5d, 0x4000, 0xac61
173 :     dw 0x4000, 0x22a3, 0xc000, 0xac61
174 :     dw 0xc000, 0x539f, 0x4000, 0xdd5d
175 :     dw 0x58c5, 0x4b42, 0x4b42, 0xee58
176 :     dw 0x3249, 0xa73b, 0x11a8, 0xcdb7
177 :     dw 0x3249, 0x11a8, 0xa73b, 0xcdb7
178 :     dw 0x11a8, 0x4b42, 0x4b42, 0xa73b
179 :    
180 :     iTab2:
181 :     dw 0x58c5, 0x73fc, 0x58c5, 0x300b
182 :     dw 0x58c5, 0xcff5, 0x58c5, 0x8c04
183 :     dw 0x58c5, 0x300b, 0xa73b, 0x8c04
184 :     dw 0xa73b, 0x73fc, 0x58c5, 0xcff5
185 :     dw 0x7b21, 0x6862, 0x6862, 0xe782
186 :     dw 0x45bf, 0x84df, 0x187e, 0xba41
187 :     dw 0x45bf, 0x187e, 0x84df, 0xba41
188 :     dw 0x187e, 0x6862, 0x6862, 0x84df
189 :    
190 :     iTab3:
191 :     dw 0x539f, 0x6d41, 0x539f, 0x2d41
192 :     dw 0x539f, 0xd2bf, 0x539f, 0x92bf
193 :     dw 0x539f, 0x2d41, 0xac61, 0x92bf
194 :     dw 0xac61, 0x6d41, 0x539f, 0xd2bf
195 :     dw 0x73fc, 0x6254, 0x6254, 0xe8ee
196 :     dw 0x41b3, 0x8c04, 0x1712, 0xbe4d
197 :     dw 0x41b3, 0x1712, 0x8c04, 0xbe4d
198 :     dw 0x1712, 0x6254, 0x6254, 0x8c04
199 :    
200 :     iTab4:
201 :     dw 0x4b42, 0x6254, 0x4b42, 0x28ba
202 :     dw 0x4b42, 0xd746, 0x4b42, 0x9dac
203 :     dw 0x4b42, 0x28ba, 0xb4be, 0x9dac
204 :     dw 0xb4be, 0x6254, 0x4b42, 0xd746
205 :     dw 0x6862, 0x587e, 0x587e, 0xeb3d
206 :     dw 0x3b21, 0x979e, 0x14c3, 0xc4df
207 :     dw 0x3b21, 0x14c3, 0x979e, 0xc4df
208 :     dw 0x14c3, 0x587e, 0x587e, 0x979e
209 :    
210 :     ; the original rounding trick is by
211 :     ; Michel Lespinasse (hi Walken!) <walken@zoy.org>
212 :    
213 :     ALIGN 16
214 :     Idct_Rnd0: dd 65535, 65535, 65535, 65535
215 :     Idct_Rnd1: dd 3612, 3612, 3612, 3612
216 :     Idct_Rnd2: dd 2271, 2271, 2271, 2271
217 :     Idct_Rnd3: dd 1203, 1203, 1203, 1203
218 :     Idct_Rnd4: dd 1023, 1023, 1023, 1023
219 :     Idct_Rnd5: dd 102, 102, 102, 102
220 :     Idct_Rnd6: dd 398, 398, 398, 398
221 :     Idct_Rnd7: dd 469, 469, 469, 469
222 :    
223 :     Idct_Sparse_Rnd0: times 4 dw (65535>>11)
224 :     Idct_Sparse_Rnd1: times 4 dw ( 3612>>11)
225 :     Idct_Sparse_Rnd2: times 4 dw ( 2271>>11)
226 :     ; other rounders are zero...
227 :    
228 :     ;-----------------------------------------------------------------------------
229 :     ; Forward DCT tables
230 :     ;-----------------------------------------------------------------------------
231 :    
232 :     ALIGN 16
233 :     fTab1:
234 :     dw 0x4000, 0x4000, 0x58c5, 0x4b42,
235 :     dw 0xdd5d, 0xac61, 0xa73b, 0xcdb7,
236 :     dw 0x4000, 0x4000, 0x3249, 0x11a8,
237 :     dw 0x539f, 0x22a3, 0x4b42, 0xee58,
238 :     dw 0x4000, 0xc000, 0x3249, 0xa73b,
239 :     dw 0x539f, 0xdd5d, 0x4b42, 0xa73b,
240 :     dw 0xc000, 0x4000, 0x11a8, 0x4b42,
241 :     dw 0x22a3, 0xac61, 0x11a8, 0xcdb7
242 :    
243 :     fTab2:
244 :     dw 0x58c5, 0x58c5, 0x7b21, 0x6862,
245 :     dw 0xcff5, 0x8c04, 0x84df, 0xba41,
246 :     dw 0x58c5, 0x58c5, 0x45bf, 0x187e,
247 :     dw 0x73fc, 0x300b, 0x6862, 0xe782,
248 :     dw 0x58c5, 0xa73b, 0x45bf, 0x84df,
249 :     dw 0x73fc, 0xcff5, 0x6862, 0x84df,
250 :     dw 0xa73b, 0x58c5, 0x187e, 0x6862,
251 :     dw 0x300b, 0x8c04, 0x187e, 0xba41
252 :    
253 :     fTab3:
254 :     dw 0x539f, 0x539f, 0x73fc, 0x6254,
255 :     dw 0xd2bf, 0x92bf, 0x8c04, 0xbe4d,
256 :     dw 0x539f, 0x539f, 0x41b3, 0x1712,
257 :     dw 0x6d41, 0x2d41, 0x6254, 0xe8ee,
258 :     dw 0x539f, 0xac61, 0x41b3, 0x8c04,
259 :     dw 0x6d41, 0xd2bf, 0x6254, 0x8c04,
260 :     dw 0xac61, 0x539f, 0x1712, 0x6254,
261 :     dw 0x2d41, 0x92bf, 0x1712, 0xbe4d
262 :    
263 :     fTab4:
264 :     dw 0x4b42, 0x4b42, 0x6862, 0x587e,
265 :     dw 0xd746, 0x9dac, 0x979e, 0xc4df,
266 :     dw 0x4b42, 0x4b42, 0x3b21, 0x14c3,
267 :     dw 0x6254, 0x28ba, 0x587e, 0xeb3d,
268 :     dw 0x4b42, 0xb4be, 0x3b21, 0x979e,
269 :     dw 0x6254, 0xd746, 0x587e, 0x979e,
270 :     dw 0xb4be, 0x4b42, 0x14c3, 0x587e,
271 :     dw 0x28ba, 0x9dac, 0x14c3, 0xc4df
272 :    
273 :    
274 :     ALIGN 16
275 :     Fdct_Rnd0: dw 6,8,8,8, 6,8,8,8
276 :     Fdct_Rnd1: dw 8,8,8,8, 8,8,8,8
277 :     Fdct_Rnd2: dw 10,8,8,8, 8,8,8,8
278 :     Rounder1: dw 1,1,1,1, 1,1,1,1
279 :    
280 :     ;=============================================================================
281 :     ; Code
282 :     ;=============================================================================
283 :    
284 :     SECTION .text
285 :    
286 :     cglobal idct_sse2_skal
287 :     cglobal idct_sse2_sparse_skal
288 :     cglobal fdct_sse2_skal
289 :    
290 :     ;-----------------------------------------------------------------------------
291 :     ; Helper macro iMTX_MULT
292 :     ;-----------------------------------------------------------------------------
293 :    
294 :     %macro iMTX_MULT 4 ; %1=src, %2 = Table to use, %3=rounder, %4=Shift
295 :    
296 :     movdqa xmm0, [ecx+%1*16] ; xmm0 = [01234567]
297 :    
298 :     pshuflw xmm0, xmm0, 11011000b ; [0213]
299 :     pshufhw xmm0, xmm0, 11011000b ; [02134657]
300 :     pshufd xmm4, xmm0, 00000000b ; [02020202]
301 :     pshufd xmm5, xmm0, 10101010b ; [46464646]
302 :     pshufd xmm6, xmm0, 01010101b ; [13131313]
303 :     pshufd xmm7, xmm0, 11111111b ; [57575757]
304 :    
305 :     pmaddwd xmm4, [%2+ 0] ; dot [M00,M01][M04,M05][M08,M09][M12,M13]
306 :     pmaddwd xmm5, [%2+16] ; dot [M02,M03][M06,M07][M10,M11][M14,M15]
307 :     pmaddwd xmm6, [%2+32] ; dot [M16,M17][M20,M21][M24,M25][M28,M29]
308 :     pmaddwd xmm7, [%2+48] ; dot [M18,M19][M22,M23][M26,M27][M30,M31]
309 :     paddd xmm4, [%3] ; Round
310 :    
311 :     paddd xmm6, xmm7 ; [b0|b1|b2|b3]
312 :     paddd xmm4, xmm5 ; [a0|a1|a2|a3]
313 :    
314 :     movdqa xmm7, xmm6
315 :     paddd xmm6, xmm4 ; mm6=a+b
316 :     psubd xmm4, xmm7 ; mm4=a-b
317 :     psrad xmm6, %4 ; => out [0123]
318 :     psrad xmm4, %4 ; => out [7654]
319 :    
320 :     packssdw xmm6, xmm4 ; [01237654]
321 :     pshufhw xmm6, xmm6, 00011011b ; [01234567]
322 :    
323 :     movdqa [ecx+%1*16], xmm6
324 :    
325 :     %endmacro
326 :    
327 :     ;-----------------------------------------------------------------------------
328 :     ; Helper macro iLLM_PASS
329 :     ;-----------------------------------------------------------------------------
330 :    
331 :     %macro iLLM_PASS 1 ; %1: src/dst
332 :    
333 :     movdqa xmm0, [tan3] ; t3-1
334 :     movdqa xmm3, [%1+16*3] ; x3
335 :     movdqa xmm1, xmm0 ; t3-1
336 :     movdqa xmm5, [%1+16*5] ; x5
337 :    
338 :     movdqa xmm4, [tan1] ; t1
339 :     movdqa xmm6, [%1+16*1] ; x1
340 :     movdqa xmm7, [%1+16*7] ; x7
341 :     movdqa xmm2, xmm4 ; t1
342 :    
343 :     pmulhw xmm0, xmm3 ; x3*(t3-1)
344 :     pmulhw xmm1, xmm5 ; x5*(t3-1)
345 :     paddsw xmm0, xmm3 ; x3*t3
346 :     paddsw xmm1, xmm5 ; x5*t3
347 :     psubsw xmm0, xmm5 ; x3*t3-x5 = tm35
348 :     paddsw xmm1, xmm3 ; x3+x5*t3 = tp35
349 :    
350 :     pmulhw xmm4, xmm7 ; x7*t1
351 :     pmulhw xmm2, xmm6 ; x1*t1
352 :     paddsw xmm4, xmm6 ; x1+t1*x7 = tp17
353 :     psubsw xmm2, xmm7 ; x1*t1-x7 = tm17
354 :    
355 :    
356 :     movdqa xmm3, [sqrt2]
357 :     movdqa xmm7, xmm4
358 :     movdqa xmm6, xmm2
359 :     psubsw xmm4, xmm1 ; tp17-tp35 = t1
360 :     psubsw xmm2, xmm0 ; tm17-tm35 = b3
361 :     paddsw xmm1, xmm7 ; tp17+tp35 = b0
362 :     paddsw xmm0, xmm6 ; tm17+tm35 = t2
363 :    
364 :     ; xmm1 = b0, xmm2 = b3. preserved
365 :    
366 :     movdqa xmm6, xmm4
367 :     psubsw xmm4, xmm0 ; t1-t2
368 :     paddsw xmm0, xmm6 ; t1+t2
369 :    
370 :     pmulhw xmm4, xmm3 ; (t1-t2)/(2.sqrt2)
371 :     pmulhw xmm0, xmm3 ; (t1+t2)/(2.sqrt2)
372 :    
373 :     paddsw xmm0, xmm0 ; 2.(t1+t2) = b1
374 :     paddsw xmm4, xmm4 ; 2.(t1-t2) = b2
375 :    
376 :     movdqa xmm7, [tan2] ; t2
377 :     movdqa xmm3, [%1+2*16] ; x2
378 :     movdqa xmm6, [%1+6*16] ; x6
379 :     movdqa xmm5, xmm7 ; t2
380 :    
381 :     pmulhw xmm7, xmm6 ; x6*t2
382 :     pmulhw xmm5, xmm3 ; x2*t2
383 :    
384 :     paddsw xmm7, xmm3 ; x2+x6*t2 = tp26
385 :     psubsw xmm5, xmm6 ; x2*t2-x6 = tm26
386 :    
387 :    
388 :     ; use:xmm3,xmm5,xmm6,xmm7 frozen: xmm0,xmm4,xmm1,xmm2
389 :    
390 :     movdqa xmm3, [%1+0*16] ; x0
391 :     movdqa xmm6, [%1+4*16] ; x4
392 :    
393 :     psubsw xmm3, xmm6 ; x0-x4 = tm04
394 :     paddsw xmm6, xmm6 ; 2.x4
395 :     paddsw xmm6, xmm3 ; x0+x4 = tp04
396 :    
397 :     psubsw xmm3, xmm5 ; tm04-tm26 = a2
398 :     psubsw xmm6, xmm7 ; tp04-tp26 = a3
399 :     paddsw xmm5, xmm5 ; 2.tm26
400 :     paddsw xmm7, xmm7 ; 2.tp26
401 :     paddsw xmm5, xmm3 ; tm04+tm26 = a1
402 :     paddsw xmm7, xmm6 ; tp04+tp26 = a0
403 :    
404 :     psubsw xmm5, xmm0 ; a1-b1
405 :     psubsw xmm3, xmm4 ; a2-b2
406 :     paddsw xmm0, xmm0 ; 2.b1
407 :     paddsw xmm4, xmm4 ; 2.b2
408 :     paddsw xmm0, xmm5 ; a1+b1
409 :     paddsw xmm4, xmm3 ; a2+b2
410 :    
411 :     psraw xmm5, 6 ; out6
412 :     psraw xmm3, 6 ; out5
413 :     psraw xmm0, 6 ; out1
414 :     psraw xmm4, 6 ; out2
415 :    
416 :     movdqa [%1+6*16], xmm5
417 :     movdqa [%1+5*16], xmm3
418 :     movdqa [%1+1*16], xmm0
419 :     movdqa [%1+2*16], xmm4
420 :    
421 :     ; reminder: xmm1=b0, xmm2=b3, xmm7=a0, xmm6=a3
422 :    
423 :     movdqa xmm0, xmm7
424 :     movdqa xmm4, xmm6
425 :     psubsw xmm7, xmm1 ; a0-b0
426 :     psubsw xmm6, xmm2 ; a3-b3
427 :     paddsw xmm1, xmm0 ; a0+b0
428 :     paddsw xmm2, xmm4 ; a3+b3
429 :    
430 :     psraw xmm1, 6 ; out0
431 :     psraw xmm7, 6 ; out7
432 :     psraw xmm2, 6 ; out3
433 :     psraw xmm6, 6 ; out4
434 :    
435 :     movdqa [%1+0*16], xmm1
436 :     movdqa [%1+3*16], xmm2
437 :     movdqa [%1+4*16], xmm6
438 :     movdqa [%1+7*16], xmm7
439 :     %endmacro
440 :    
441 :     ;-----------------------------------------------------------------------------
442 :     ; Function idct (the straight forward version)
443 :     ;-----------------------------------------------------------------------------
444 :    
445 :     ALIGN 16
446 :     idct_sse2_skal:
447 :     mov ecx, [esp+4]
448 :     iMTX_MULT 0, iTab1, Idct_Rnd0, 11
449 :     iMTX_MULT 1, iTab2, Idct_Rnd1, 11
450 :     iMTX_MULT 2, iTab3, Idct_Rnd2, 11
451 :     iMTX_MULT 3, iTab4, Idct_Rnd3, 11
452 :     iMTX_MULT 4, iTab1, Idct_Rnd4, 11
453 :     iMTX_MULT 5, iTab4, Idct_Rnd5, 11
454 :     iMTX_MULT 6, iTab3, Idct_Rnd6, 11
455 :     iMTX_MULT 7, iTab2, Idct_Rnd7, 11
456 :     iLLM_PASS ecx+0
457 :     ret
458 : edgomez 1540 .endfunc
459 : edgomez 1382
460 :     ;-----------------------------------------------------------------------------
461 :     ; Helper macro TEST_ROW (test a null row)
462 :     ;-----------------------------------------------------------------------------
463 :    
464 :     %macro TEST_ROW 2 ; %1:src, %2:label x8
465 :     mov eax, [%1 ]
466 :     mov edx, [%1+ 8]
467 :     or eax, [%1+ 4]
468 :     or edx, [%1+12]
469 :     or eax, edx
470 :     jz near %2
471 :     %endmacro
472 :    
473 :     ;-----------------------------------------------------------------------------
474 :     ; Function idct (this one skips null rows)
475 :     ;-----------------------------------------------------------------------------
476 :    
477 :     ALIGN 16
478 :     idct_sse2_sparse_skal:
479 :    
480 :     mov ecx, [esp+ 4] ; Src
481 :    
482 :     TEST_ROW ecx, .Row0_Round
483 :     iMTX_MULT 0, iTab1, Idct_Rnd0, 11
484 :     jmp .Row1
485 :     .Row0_Round
486 :     movq mm0, [Idct_Sparse_Rnd0]
487 :     movq [ecx ], mm0
488 :     movq [ecx+8], mm0
489 :    
490 :     .Row1
491 :     TEST_ROW ecx+16, .Row1_Round
492 :     iMTX_MULT 1, iTab2, Idct_Rnd1, 11
493 :     jmp .Row2
494 :     .Row1_Round
495 :     movq mm0, [Idct_Sparse_Rnd1]
496 :     movq [ecx+16 ], mm0
497 :     movq [ecx+16+8], mm0
498 :    
499 :     .Row2
500 :     TEST_ROW ecx+32, .Row2_Round
501 :     iMTX_MULT 2, iTab3, Idct_Rnd2, 11
502 :     jmp .Row3
503 :     .Row2_Round
504 :     movq mm0, [Idct_Sparse_Rnd2]
505 :     movq [ecx+32 ], mm0
506 :     movq [ecx+32+8], mm0
507 :    
508 :     .Row3
509 :     TEST_ROW ecx+48, .Row4
510 :     iMTX_MULT 3, iTab4, Idct_Rnd3, 11
511 :     jmp .Row4
512 :    
513 :     .Row4
514 :     TEST_ROW ecx+64, .Row5
515 :     iMTX_MULT 4, iTab1, Idct_Rnd4, 11
516 :     jmp .Row5
517 :    
518 :     .Row5
519 :     TEST_ROW ecx+80, .Row6
520 :     iMTX_MULT 5, iTab4, Idct_Rnd5, 11
521 :    
522 :     .Row6
523 :     TEST_ROW ecx+96, .Row7
524 :     iMTX_MULT 6, iTab3, Idct_Rnd6, 11
525 :    
526 :     .Row7
527 :     TEST_ROW ecx+112, .End
528 :     iMTX_MULT 7, iTab2, Idct_Rnd7, 11
529 :     .End
530 :    
531 :     iLLM_PASS ecx+0
532 :     ret
533 : edgomez 1540 .endfunc
534 : edgomez 1382
535 :     ;-----------------------------------------------------------------------------
536 :     ; Helper macro fLLM_PASS
537 :     ;-----------------------------------------------------------------------------
538 :    
539 :     %macro fLLM_PASS 2 ; %1: src/dst, %2:Shift
540 :    
541 :     movdqa xmm0, [%1+0*16] ; In0
542 :     movdqa xmm2, [%1+2*16] ; In2
543 :     movdqa xmm3, xmm0
544 :     movdqa xmm4, xmm2
545 :     movdqa xmm7, [%1+7*16] ; In7
546 :     movdqa xmm5, [%1+5*16] ; In5
547 :    
548 :     psubsw xmm0, xmm7 ; t7 = In0-In7
549 :     paddsw xmm7, xmm3 ; t0 = In0+In7
550 :     psubsw xmm2, xmm5 ; t5 = In2-In5
551 :     paddsw xmm5, xmm4 ; t2 = In2+In5
552 :    
553 :     movdqa xmm3, [%1+3*16] ; In3
554 :     movdqa xmm4, [%1+4*16] ; In4
555 :     movdqa xmm1, xmm3
556 :     psubsw xmm3, xmm4 ; t4 = In3-In4
557 :     paddsw xmm4, xmm1 ; t3 = In3+In4
558 :     movdqa xmm6, [%1+6*16] ; In6
559 :     movdqa xmm1, [%1+1*16] ; In1
560 :     psubsw xmm1, xmm6 ; t6 = In1-In6
561 :     paddsw xmm6, [%1+1*16] ; t1 = In1+In6
562 :    
563 :     psubsw xmm7, xmm4 ; tm03 = t0-t3
564 :     psubsw xmm6, xmm5 ; tm12 = t1-t2
565 :     paddsw xmm4, xmm4 ; 2.t3
566 :     paddsw xmm5, xmm5 ; 2.t2
567 :     paddsw xmm4, xmm7 ; tp03 = t0+t3
568 :     paddsw xmm5, xmm6 ; tp12 = t1+t2
569 :    
570 :     psllw xmm2, %2+1 ; shift t5 (shift +1 to..
571 :     psllw xmm1, %2+1 ; shift t6 ..compensate cos4/2)
572 :     psllw xmm4, %2 ; shift t3
573 :     psllw xmm5, %2 ; shift t2
574 :     psllw xmm7, %2 ; shift t0
575 :     psllw xmm6, %2 ; shift t1
576 :     psllw xmm3, %2 ; shift t4
577 :     psllw xmm0, %2 ; shift t7
578 :    
579 :     psubsw xmm4, xmm5 ; out4 = tp03-tp12
580 :     psubsw xmm1, xmm2 ; xmm1: t6-t5
581 :     paddsw xmm5, xmm5
582 :     paddsw xmm2, xmm2
583 :     paddsw xmm5, xmm4 ; out0 = tp03+tp12
584 :     movdqa [%1+4*16], xmm4 ; => out4
585 :     paddsw xmm2, xmm1 ; xmm2: t6+t5
586 :     movdqa [%1+0*16], xmm5 ; => out0
587 :    
588 :     movdqa xmm4, [tan2] ; xmm4 <= tan2
589 :     pmulhw xmm4, xmm7 ; tm03*tan2
590 :     movdqa xmm5, [tan2] ; xmm5 <= tan2
591 :     psubsw xmm4, xmm6 ; out6 = tm03*tan2 - tm12
592 :     pmulhw xmm5, xmm6 ; tm12*tan2
593 :     paddsw xmm5, xmm7 ; out2 = tm12*tan2 + tm03
594 :    
595 :     movdqa xmm6, [sqrt2]
596 :     movdqa xmm7, [Rounder1]
597 :    
598 :     pmulhw xmm2, xmm6 ; xmm2: tp65 = (t6 + t5)*cos4
599 :     por xmm5, xmm7 ; correct out2
600 :     por xmm4, xmm7 ; correct out6
601 :     pmulhw xmm1, xmm6 ; xmm1: tm65 = (t6 - t5)*cos4
602 :     por xmm2, xmm7 ; correct tp65
603 :    
604 :     movdqa [%1+2*16], xmm5 ; => out2
605 :     movdqa xmm5, xmm3 ; save t4
606 :     movdqa [%1+6*16], xmm4 ; => out6
607 :     movdqa xmm4, xmm0 ; save t7
608 :    
609 :     psubsw xmm3, xmm1 ; xmm3: tm465 = t4 - tm65
610 :     psubsw xmm0, xmm2 ; xmm0: tm765 = t7 - tp65
611 :     paddsw xmm2, xmm4 ; xmm2: tp765 = t7 + tp65
612 :     paddsw xmm1, xmm5 ; xmm1: tp465 = t4 + tm65
613 :    
614 :     movdqa xmm4, [tan3] ; tan3 - 1
615 :     movdqa xmm5, [tan1] ; tan1
616 :    
617 :     movdqa xmm7, xmm3 ; save tm465
618 :     pmulhw xmm3, xmm4 ; tm465*(tan3-1)
619 :     movdqa xmm6, xmm1 ; save tp465
620 :     pmulhw xmm1, xmm5 ; tp465*tan1
621 :    
622 :     paddsw xmm3, xmm7 ; tm465*tan3
623 :     pmulhw xmm4, xmm0 ; tm765*(tan3-1)
624 :     paddsw xmm4, xmm0 ; tm765*tan3
625 :     pmulhw xmm5, xmm2 ; tp765*tan1
626 :    
627 :     paddsw xmm1, xmm2 ; out1 = tp765 + tp465*tan1
628 :     psubsw xmm0, xmm3 ; out3 = tm765 - tm465*tan3
629 :     paddsw xmm7, xmm4 ; out5 = tm465 + tm765*tan3
630 :     psubsw xmm5, xmm6 ; out7 =-tp465 + tp765*tan1
631 :    
632 :     movdqa [%1+1*16], xmm1 ; => out1
633 :     movdqa [%1+3*16], xmm0 ; => out3
634 :     movdqa [%1+5*16], xmm7 ; => out5
635 :     movdqa [%1+7*16], xmm5 ; => out7
636 :    
637 :     %endmacro
638 :    
639 :     ;-----------------------------------------------------------------------------
640 :     ;Helper macro fMTX_MULT
641 :     ;-----------------------------------------------------------------------------
642 :    
643 :     %macro fMTX_MULT 3 ; %1=src, %2 = Coeffs, %3=rounders
644 :    
645 :     movdqa xmm0, [ecx+%1*16+0] ; xmm0 = [0123][4567]
646 :     pshufhw xmm1, xmm0, 00011011b ; xmm1 = [----][7654]
647 :     pshufd xmm0, xmm0, 01000100b
648 :     pshufd xmm1, xmm1, 11101110b
649 :    
650 :     movdqa xmm2, xmm0
651 :     paddsw xmm0, xmm1 ; xmm0 = [a0 a1 a2 a3]
652 :     psubsw xmm2, xmm1 ; xmm2 = [b0 b1 b2 b3]
653 :    
654 :     punpckldq xmm0, xmm2 ; xmm0 = [a0 a1 b0 b1][a2 a3 b2 b3]
655 :     pshufd xmm2, xmm0, 01001110b ; xmm2 = [a2 a3 b2 b3][a0 a1 b0 b1]
656 :    
657 :     ; [M00 M01 M16 M17] [M06 M07 M22 M23] x mm0 = [0 /1 /2'/3']
658 :     ; [M02 M03 M18 M19] [M04 M05 M20 M21] x mm2 = [0'/1'/2 /3 ]
659 :     ; [M08 M09 M24 M25] [M14 M15 M30 M31] x mm0 = [4 /5 /6'/7']
660 :     ; [M10 M11 M26 M27] [M12 M13 M28 M29] x mm2 = [4'/5'/6 /7 ]
661 :    
662 :     movdqa xmm1, [%2+16]
663 :     movdqa xmm3, [%2+32]
664 :     pmaddwd xmm1, xmm2
665 :     pmaddwd xmm3, xmm0
666 :     pmaddwd xmm2, [%2+48]
667 :     pmaddwd xmm0, [%2+ 0]
668 :    
669 :     paddd xmm0, xmm1 ; [ out0 | out1 ][ out2 | out3 ]
670 :     paddd xmm2, xmm3 ; [ out4 | out5 ][ out6 | out7 ]
671 :     psrad xmm0, 16
672 :     psrad xmm2, 16
673 :    
674 :     packssdw xmm0, xmm2 ; [ out0 .. out7 ]
675 :     paddsw xmm0, [%3] ; Round
676 :    
677 :     psraw xmm0, 4 ; => [-2048, 2047]
678 :    
679 :     movdqa [ecx+%1*16+0], xmm0
680 :     %endmacro
681 :    
682 :     ;-----------------------------------------------------------------------------
683 :     ; Function Forward DCT
684 :     ;-----------------------------------------------------------------------------
685 :    
686 :     ALIGN 16
687 :     fdct_sse2_skal:
688 :     mov ecx, [esp+4]
689 :     fLLM_PASS ecx+0, 3
690 :     fMTX_MULT 0, fTab1, Fdct_Rnd0
691 :     fMTX_MULT 1, fTab2, Fdct_Rnd2
692 :     fMTX_MULT 2, fTab3, Fdct_Rnd1
693 :     fMTX_MULT 3, fTab4, Fdct_Rnd1
694 :     fMTX_MULT 4, fTab1, Fdct_Rnd0
695 :     fMTX_MULT 5, fTab4, Fdct_Rnd1
696 :     fMTX_MULT 6, fTab3, Fdct_Rnd1
697 :     fMTX_MULT 7, fTab2, Fdct_Rnd1
698 :     ret
699 : edgomez 1540 .endfunc
700 :    

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4