1 ; XVID MPEG-4 VIDEO CODEC
3 ; Conversion from gcc syntax to x264asm syntax with modifications
4 ; by Christophe Gisquet <christophe.gisquet@gmail.com>
6 ; =========== SSE2 inverse discrete cosine transform ===========
8 ; Copyright(C) 2003 Pascal Massimino <skal@planet-d.net>
10 ; Conversion to gcc syntax with modifications
11 ; by Alexander Strange <astrange@ithinksw.com>
13 ; Originally from dct/x86_asm/fdct_sse2_skal.asm in Xvid.
15 ; Vertical pass is an implementation of the scheme:
16 ; Loeffler C., Ligtenberg A., and Moschytz C.S.:
17 ; Practical Fast 1D DCT Algorithm with Eleven Multiplications,
18 ; Proc. ICASSP 1989, 988-991.
20 ; Horizontal pass is a double 4x4 vector/matrix multiplication,
21 ; (see also Intel's Application Note 922:
22 ; http://developer.intel.com/vtune/cbts/strmsimd/922down.htm
23 ; Copyright (C) 1999 Intel Corporation)
25 ; More details at http://skal.planet-d.net/coding/dct.html
27 ; ======= MMX and XMM forward discrete cosine transform =======
29 ; Copyright(C) 2001 Peter Ross <pross@xvid.org>
31 ; Originally provided by Intel at AP-922
32 ; http://developer.intel.com/vtune/cbts/strmsimd/922down.htm
33 ; (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm)
34 ; but in a limited edition.
35 ; New macro implements a column part for precise iDCT
36 ; The routine precision now satisfies IEEE standard 1180-1990.
38 ; Copyright(C) 2000-2001 Peter Gubanov <peter@elecard.net.ru>
39 ; Rounding trick Copyright(C) 2000 Michel Lespinasse <walken@zoy.org>
41 ; http://www.elecard.com/peter/idct.html
42 ; http://www.linuxvideo.org/mpeg2dec/
44 ; These examples contain code fragments for first stage iDCT 8x8
45 ; (for rows) and first stage DCT 8x8 (for columns)
47 ; conversion to gcc syntax by Michael Niedermayer
49 ; ======================================================================
51 ; This file is part of FFmpeg.
53 ; FFmpeg is free software; you can redistribute it and/or
54 ; modify it under the terms of the GNU Lesser General Public
55 ; License as published by the Free Software Foundation; either
56 ; version 2.1 of the License, or (at your option) any later version.
58 ; FFmpeg is distributed in the hope that it will be useful,
59 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
60 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
61 ; Lesser General Public License for more details.
63 ; You should have received a copy of the GNU Lesser General Public License
64 ; along with FFmpeg; if not, write to the Free Software Foundation,
65 ; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
67 %include "libavutil/x86/x86util.asm"
70 ; Similar to tg_1_16 in MMX code
71 tan1: times
8 dw 13036
72 tan2: times
8 dw 27146
73 tan3: times
8 dw 43790
74 sqrt2: times
8 dw 23170
77 iTab1: dw 0x4000, 0x539f, 0xc000, 0xac61, 0x4000, 0xdd5d, 0x4000, 0xdd5d
78 dw 0x4000, 0x22a3, 0x4000, 0x22a3, 0xc000, 0x539f, 0x4000, 0xac61
79 dw 0x3249, 0x11a8, 0x4b42, 0xee58, 0x11a8, 0x4b42, 0x11a8, 0xcdb7
80 dw 0x58c5, 0x4b42, 0xa73b, 0xcdb7, 0x3249, 0xa73b, 0x4b42, 0xa73b
81 iTab2: dw 0x58c5, 0x73fc, 0xa73b, 0x8c04, 0x58c5, 0xcff5, 0x58c5, 0xcff5
82 dw 0x58c5, 0x300b, 0x58c5, 0x300b, 0xa73b, 0x73fc, 0x58c5, 0x8c04
83 dw 0x45bf, 0x187e, 0x6862, 0xe782, 0x187e, 0x6862, 0x187e, 0xba41
84 dw 0x7b21, 0x6862, 0x84df, 0xba41, 0x45bf, 0x84df, 0x6862, 0x84df
85 iTab3: dw 0x539f, 0x6d41, 0xac61, 0x92bf, 0x539f, 0xd2bf, 0x539f, 0xd2bf
86 dw 0x539f, 0x2d41, 0x539f, 0x2d41, 0xac61, 0x6d41, 0x539f, 0x92bf
87 dw 0x41b3, 0x1712, 0x6254, 0xe8ee, 0x1712, 0x6254, 0x1712, 0xbe4d
88 dw 0x73fc, 0x6254, 0x8c04, 0xbe4d, 0x41b3, 0x8c04, 0x6254, 0x8c04
89 iTab4: dw 0x4b42, 0x6254, 0xb4be, 0x9dac, 0x4b42, 0xd746, 0x4b42, 0xd746
90 dw 0x4b42, 0x28ba, 0x4b42, 0x28ba, 0xb4be, 0x6254, 0x4b42, 0x9dac
91 dw 0x3b21, 0x14c3, 0x587e, 0xeb3d, 0x14c3, 0x587e, 0x14c3, 0xc4df
92 dw 0x6862, 0x587e, 0x979e, 0xc4df, 0x3b21, 0x979e, 0x587e, 0x979e
94 ; Similar to rounder_0 in MMX code
95 ; 4 first similar, then: 4*8->6*16 5*8->4*16 6/7*8->5*16
96 walkenIdctRounders: times
4 dd 65536
104 pb_127: times
8 db 127
108 ; Temporary storage before the column pass
118 pshufhw
%1, xmm2
, 0x1B
137 pshufhw xmm2
, xmm2
, 0x1B
156 %define ROW0
[BLOCK
+ 0*16]
158 %define ROW2
[BLOCK
+ 2*16]
160 %define ROW4
[BLOCK
+ 4*16]
162 %define ROW6
[BLOCK
+ 6*16]
180 %macro TEST_ONE_ROW
4 ; src, reg, clear, arg
188 ;row1, row2, reg1, reg2, clear1, arg1, clear2, arg2
189 %macro TEST_TWO_ROWS
8
203 %macro iMTX_MULT
4-5 ; src, table, put, arg, rounder
206 pshufd xmm1
, xmm3
, 0x11 ; 4602
207 punpcklqdq xmm0
, xmm0
; 0246
209 pmaddwd xmm1
, [%2+16]
210 pshufd xmm2
, xmm3
, 0xBB ; 5713
211 punpckhqdq xmm3
, xmm3
; 1357
212 pmaddwd xmm2
, [%2+32]
213 pmaddwd xmm3
, [%2+48]
217 paddd xmm0
, [walkenIdctRounders
+%5]
233 %macro FIRST_HALF
2 ; %1=dct %2=type(normal,add,put)
238 ; dct coeffs must still be written for AC prediction
240 movdqa
[%1+1*16], TAN3
241 movdqa
[%1+2*16], xmm3
242 movdqa
[%1+5*16], REG0
243 movdqa
[%1+6*16], xmm5
245 ; Must now load args as gprs are no longer used for masks
246 ; DEST is set to where address of dest was loaded
248 %if
%2 == 2 ; Not enough xmms, store
249 movdqa
[%1+1*16], TAN3
250 movdqa
[%1+2*16], xmm3
251 movdqa
[%1+5*16], REG0
252 movdqa
[%1+6*16], xmm5
254 %xdefine DEST r2q
; BLOCK is r0, stride r1
255 movifnidn DEST
, destm
256 movifnidn strideq
, stridem
264 movq
[DEST
+ strideq
], TAN3
265 movhps
[DEST
+ 2*strideq
], TAN3
266 ; REG0 and TAN3 are now available (and likely used in second half)
271 %macro SECOND_HALF
6 ; %1=dct %2=type(normal,add,put) 3-6: xmms
276 ; dct coeffs must still be written for AC prediction
285 ; address of dest may have been loaded
287 movhps
[DEST
+ r3q
], %3
288 lea DEST
, [DEST
+ 4*strideq
]
290 movhps
[DEST
+ r3q
], %6
291 ; and now write remainder of first half
292 movq
[DEST
+ 2*strideq
], xmm5
293 movhps
[DEST
+ strideq
], xmm5
297 ; free: m3 REG0=m4 m5
298 ; input: m1, m7, m2, m6
299 movq xmm3
, [DEST
+0*strideq
]
300 movq xmm4
, [DEST
+1*strideq
]
304 paddsw xmm4
, [%1 + 1*16]
305 movq
%3, [DEST
+2*strideq
]
306 movq xmm5
, [DEST
+ r3q
]
309 paddsw
%3, [%1 + 2*16]
313 movq
[DEST
+0*strideq
], xmm3
314 movhps
[DEST
+1*strideq
], xmm3
315 movq
[DEST
+2*strideq
], %3
316 movhps
[DEST
+ r3q
], %3
317 lea DEST
, [DEST
+4*strideq
]
318 movq xmm3
, [DEST
+0*strideq
]
319 movq xmm4
, [DEST
+1*strideq
]
320 movq
%3, [DEST
+2*strideq
]
321 movq xmm5
, [DEST
+ r3q
]
327 paddsw xmm4
, [%1 + 5*16]
328 paddsw
%3, [%1 + 6*16]
332 movq
[DEST
+0*strideq
], xmm3
333 movhps
[DEST
+1*strideq
], xmm3
334 movq
[DEST
+2*strideq
], %3
335 movhps
[DEST
+ r3q
], %3
337 ; l1:TAN3=m13 l2:m3 l5:REG0=m8 l6=m5
338 ; input: m1, m7/SREG2=m9, TAN1=m14, REG4=m10
339 movq xmm2
, [DEST
+0*strideq
]
340 movq xmm4
, [DEST
+1*strideq
]
341 movq xmm12
, [DEST
+2*strideq
]
342 movq xmm11
, [DEST
+ r3q
]
345 punpcklbw xmm12
, xmm0
346 punpcklbw xmm11
, xmm0
352 packuswb xmm12
, xmm11
353 movq
[DEST
+0*strideq
], xmm2
354 movhps
[DEST
+1*strideq
], xmm2
355 movq
[DEST
+2*strideq
], xmm12
356 movhps
[DEST
+ r3q
], xmm12
357 lea DEST
, [DEST
+4*strideq
]
358 movq xmm2
, [DEST
+0*strideq
]
359 movq xmm4
, [DEST
+1*strideq
]
360 movq xmm12
, [DEST
+2*strideq
]
361 movq xmm11
, [DEST
+ r3q
]
364 punpcklbw xmm12
, xmm0
365 punpcklbw xmm11
, xmm0
371 packuswb xmm12
, xmm11
372 movq
[DEST
+0*strideq
], xmm2
373 movhps
[DEST
+1*strideq
], xmm2
374 movq
[DEST
+2*strideq
], xmm12
375 movhps
[DEST
+ r3q
], xmm12
381 ; IDCT pass on columns.
382 %macro iLLM_PASS
2 ; %1=dct %2=type(normal,add,put)
446 SECOND_HALF
%1, %2, xmm1
, xmm7
, TAN1
, REG4
449 ; IDCT pass on columns, assuming rows 4-7 are zero
450 %macro iLLM_PASS_SPARSE
2 ; %1=dct %2=type(normal,put,add)
497 SECOND_HALF
%1, %2, xmm1
, SREG2
, TAN1
, xmm6
500 %macro IDCT_SSE2
1 ; 0=normal 1=put 2=add
501 %if
%1 == 0 || ARCH_X86_32
515 cglobal xvid_idct
, 1, NUM_GPRS
, 8+7*ARCH_X86_64
, block
516 %xdefine BLOCK blockq
519 cglobal xvid_idct_put
, 0, NUM_GPRS
, 8+7*ARCH_X86_64
, dest
, stride
, block
521 cglobal xvid_idct_add
, 0, NUM_GPRS
, 8+7*ARCH_X86_64
, dest
, stride
, block
524 %xdefine BLOCK blockq
531 iMTX_MULT BLOCK
+ 0*16, iTab1
, PUT_EVEN
, ROW0
, 0*16
532 iMTX_MULT BLOCK
+ 1*16, iTab2
, PUT_ODD
, ROW1
, 1*16
533 iMTX_MULT BLOCK
+ 2*16, iTab3
, PUT_EVEN
, ROW2
, 2*16
535 TEST_TWO_ROWS BLOCK
+ 3*16, BLOCK
+ 4*16, GPR0
, GPR1
, CLEAR_ODD
, ROW3
, CLEAR_EVEN
, ROW4
; a, c
537 iMTX_MULT BLOCK
+ 3*16, iTab4
, PUT_ODD
, ROW3
, 3*16
539 TEST_TWO_ROWS BLOCK
+ 5*16, BLOCK
+ 6*16, GPR0
, GPR2
, CLEAR_ODD
, ROW5
, CLEAR_EVEN
, ROW6
; a, d
540 TEST_ONE_ROW BLOCK
+ 7*16, GPR3
, CLEAR_ODD
, ROW7
; esi
547 iLLM_PASS_SPARSE BLOCK
, %1
550 iMTX_MULT BLOCK
+ 4*16, iTab1
, PUT_EVEN
, ROW4
552 iMTX_MULT BLOCK
+ 5*16, iTab4
, PUT_ODD
, ROW5
, 4*16
555 iMTX_MULT BLOCK
+ 6*16, iTab3
, PUT_EVEN
, ROW6
, 5*16
559 iMTX_MULT BLOCK
+ 7*16, iTab2
, PUT_ODD
, ROW7
, 5*16