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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1877 - (view) (download)

1 : edgomez 1382 ;/****************************************************************************
2 :     ; *
3 :     ; * XVID MPEG-4 VIDEO CODEC
4 :     ; * - MMX and XMM forward discrete cosine transform -
5 :     ; *
6 :     ; * Copyright(C) 2003 Edouard Gomez <ed.gomez@free.fr>
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 : Isibaar 1877 ; * $Id: fdct_mmx_ffmpeg.asm,v 1.10 2009-09-16 17:07:58 Isibaar Exp $
23 : edgomez 1382 ; *
24 :     ; ***************************************************************************/
25 :    
26 :     ;/****************************************************************************
27 :     ; *
28 :     ; * Initial, but incomplete version provided by Intel at AppNote AP-922
29 :     ; * http://developer.intel.com/vtune/cbts/strmsimd/922down.htm
30 :     ; * Copyright (C) 1999 Intel Corporation
31 :     ; *
32 :     ; * Completed and corrected in fdctmm32.c/fdctmm32.doc
33 :     ; * http://members.tripod.com/~liaor/
34 :     ; * Copyright (C) 2000 - Royce Shih-Wea Liao <liaor@iname.com>
35 :     ; *
36 :     ; * Minimizing coefficients reordering changing the tables constants order
37 :     ; * http://ffmpeg.sourceforge.net/
38 :     ; * Copyright (C) 2001 Fabrice Bellard.
39 :     ; *
40 :     ; * The version coded here is just a port to NASM syntax from the FFMPEG's
41 :     ; * version. So all credits go to the previous authors for all their
42 :     ; * respective work in order to have a nice/fast mmx fDCT.
43 :     ; ***************************************************************************/
44 :    
45 :     ;=============================================================================
46 :     ; Macros and other preprocessor constants
47 :     ;=============================================================================
48 :    
49 : Isibaar 1795 %include "nasm.inc"
50 : edgomez 1382
51 :     ;;; Define this if you want an unrolled version of the code
52 :     %define UNROLLED_LOOP
53 :    
54 :     %define BITS_FRW_ACC 3
55 :     %define SHIFT_FRW_COL BITS_FRW_ACC
56 :     %define SHIFT_FRW_ROW (BITS_FRW_ACC + 17)
57 :     %define RND_FRW_ROW (1 << (SHIFT_FRW_ROW-1))
58 :     %define RND_FRW_COL (1 << (SHIFT_FRW_COL-1))
59 :    
60 :     ;=============================================================================
61 :     ; Local Data (Read Only)
62 :     ;=============================================================================
63 :    
64 : Isibaar 1795 DATA
65 : edgomez 1382
66 : Isibaar 1795 ALIGN SECTION_ALIGN
67 : edgomez 1382 tab_frw_01234567:
68 :     dw 16384, 16384, -8867, -21407
69 :     dw 16384, 16384, 21407, 8867
70 :     dw 16384, -16384, 21407, -8867
71 :     dw -16384, 16384, 8867, -21407
72 :     dw 22725, 19266, -22725, -12873
73 :     dw 12873, 4520, 19266, -4520
74 :     dw 12873, -22725, 19266, -22725
75 :     dw 4520, 19266, 4520, -12873
76 :    
77 :     dw 22725, 22725, -12299, -29692
78 :     dw 22725, 22725, 29692, 12299
79 :     dw 22725, -22725, 29692, -12299
80 :     dw -22725, 22725, 12299, -29692
81 :     dw 31521, 26722, -31521, -17855
82 :     dw 17855, 6270, 26722, -6270
83 :     dw 17855, -31521, 26722, -31521
84 :     dw 6270, 26722, 6270, -17855
85 :    
86 :     dw 21407, 21407, -11585, -27969
87 :     dw 21407, 21407, 27969, 11585
88 :     dw 21407, -21407, 27969, -11585
89 :     dw -21407, 21407, 11585, -27969
90 :     dw 29692, 25172, -29692, -16819
91 :     dw 16819, 5906, 25172, -5906
92 :     dw 16819, -29692, 25172, -29692
93 :     dw 5906, 25172, 5906, -16819
94 :    
95 :     dw 19266, 19266, -10426, -25172
96 :     dw 19266, 19266, 25172, 10426
97 :     dw 19266, -19266, 25172, -10426
98 :     dw -19266, 19266, 10426, -25172
99 :     dw 26722, 22654, -26722, -15137
100 :     dw 15137, 5315, 22654, -5315
101 :     dw 15137, -26722, 22654, -26722
102 :     dw 5315, 22654, 5315, -15137
103 :    
104 :     dw 16384, 16384, -8867, -21407
105 :     dw 16384, 16384, 21407, 8867
106 :     dw 16384, -16384, 21407, -8867
107 :     dw -16384, 16384, 8867, -21407
108 :     dw 22725, 19266, -22725, -12873
109 :     dw 12873, 4520, 19266, -4520
110 :     dw 12873, -22725, 19266, -22725
111 :     dw 4520, 19266, 4520, -12873
112 :    
113 :     dw 19266, 19266, -10426, -25172
114 :     dw 19266, 19266, 25172, 10426
115 :     dw 19266, -19266, 25172, -10426
116 :     dw -19266, 19266, 10426, -25172
117 :     dw 26722, 22654, -26722, -15137
118 :     dw 15137, 5315, 22654, -5315
119 :     dw 15137, -26722, 22654, -26722
120 :     dw 5315, 22654, 5315, -15137
121 :    
122 :     dw 21407, 21407, -11585, -27969
123 :     dw 21407, 21407, 27969, 11585
124 :     dw 21407, -21407, 27969, -11585
125 :     dw -21407, 21407, 11585, -27969
126 :     dw 29692, 25172, -29692, -16819
127 :     dw 16819, 5906, 25172, -5906
128 :     dw 16819, -29692, 25172, -29692
129 :     dw 5906, 25172, 5906, -16819,
130 :    
131 :     dw 22725, 22725, -12299, -29692
132 :     dw 22725, 22725, 29692, 12299
133 :     dw 22725, -22725, 29692, -12299
134 :     dw -22725, 22725, 12299, -29692
135 :     dw 31521, 26722, -31521, -17855
136 :     dw 17855, 6270, 26722, -6270
137 :     dw 17855, -31521, 26722, -31521
138 :     dw 6270, 26722, 6270, -17855
139 :    
140 : Isibaar 1795 ALIGN SECTION_ALIGN
141 : edgomez 1382 fdct_one_corr:
142 :     dw 1, 1, 1, 1
143 :    
144 : Isibaar 1795 ALIGN SECTION_ALIGN
145 : edgomez 1382 fdct_tg_all_16:
146 :     dw 13036, 13036, 13036, 13036
147 :     dw 27146, 27146, 27146, 27146
148 :     dw -21746, -21746, -21746, -21746
149 :    
150 : Isibaar 1795 ALIGN SECTION_ALIGN
151 : edgomez 1382 cos_4_16:
152 :     dw -19195, -19195, -19195, -19195
153 :    
154 : Isibaar 1795 ALIGN SECTION_ALIGN
155 : edgomez 1382 ocos_4_16:
156 :     dw 23170, 23170, 23170, 23170
157 :    
158 : Isibaar 1795 ALIGN SECTION_ALIGN
159 : edgomez 1382 fdct_r_row:
160 :     dd RND_FRW_ROW, RND_FRW_ROW
161 :    
162 :     ;=============================================================================
163 :     ; Factorized parts of the code turned into macros for better understanding
164 :     ;=============================================================================
165 :    
166 :     ;; Macro for column DCT
167 :     ;; FDCT_COLUMN_MMX(int16_t *out, const int16_t *in, int offset);
168 :     ;; - out, register name holding the out address
169 :     ;; - in, register name holding the in address
170 :     ;; - column number to process
171 :     %macro FDCT_COLUMN_COMMON 3
172 :     movq mm0, [%2 + %3*2 + 1*16]
173 :     movq mm1, [%2 + %3*2 + 6*16]
174 :     movq mm2, mm0
175 :     movq mm3, [%2 + %3*2 + 2*16]
176 :     paddsw mm0, mm1
177 :     movq mm4, [%2 + %3*2 + 5*16]
178 :     psllw mm0, SHIFT_FRW_COL
179 :     movq mm5, [%2 + %3*2 + 0*16]
180 :     paddsw mm4, mm3
181 :     paddsw mm5, [%2 + %3*2 + 7*16]
182 :     psllw mm4, SHIFT_FRW_COL
183 :     movq mm6, mm0
184 :     psubsw mm2, mm1
185 :     movq mm1, [fdct_tg_all_16 + 4*2]
186 :     psubsw mm0, mm4
187 :     movq mm7, [%2 + %3*2 + 3*16]
188 :     pmulhw mm1, mm0
189 :     paddsw mm7, [%2 + %3*2 + 4*16]
190 :     psllw mm5, SHIFT_FRW_COL
191 :     paddsw mm6, mm4
192 :     psllw mm7, SHIFT_FRW_COL
193 :     movq mm4, mm5
194 :     psubsw mm5, mm7
195 :     paddsw mm1, mm5
196 :     paddsw mm4, mm7
197 :     por mm1, [fdct_one_corr]
198 :     psllw mm2, SHIFT_FRW_COL + 1
199 :     pmulhw mm5, [fdct_tg_all_16 + 4*2]
200 :     movq mm7, mm4
201 :     psubsw mm3, [%2 + %3*2 + 5*16]
202 :     psubsw mm4, mm6
203 :     movq [%1 + %3*2 + 2*16], mm1
204 :     paddsw mm7, mm6
205 :     movq mm1, [%2 + %3*2 + 3*16]
206 :     psllw mm3, SHIFT_FRW_COL + 1
207 :     psubsw mm1, [%2 + %3*2 + 4*16]
208 :     movq mm6, mm2
209 :     movq [%1 + %3*2 + 4*16], mm4
210 :     paddsw mm2, mm3
211 :     pmulhw mm2, [ocos_4_16]
212 :     psubsw mm6, mm3
213 :     pmulhw mm6, [ocos_4_16]
214 :     psubsw mm5, mm0
215 :     por mm5, [fdct_one_corr]
216 :     psllw mm1, SHIFT_FRW_COL
217 :     por mm2, [fdct_one_corr]
218 :     movq mm4, mm1
219 :     movq mm3, [%2 + %3*2 + 0*16]
220 :     paddsw mm1, mm6
221 :     psubsw mm3, [%2 + %3*2 + 7*16]
222 :     psubsw mm4, mm6
223 :     movq mm0, [fdct_tg_all_16 + 0*2]
224 :     psllw mm3, SHIFT_FRW_COL
225 :     movq mm6, [fdct_tg_all_16 + 8*2]
226 :     pmulhw mm0, mm1
227 :     movq [%1 + %3*2 + 0*16], mm7
228 :     pmulhw mm6, mm4
229 :     movq [%1 + %3*2 + 6*16], mm5
230 :     movq mm7, mm3
231 :     movq mm5, [fdct_tg_all_16 + 8*2]
232 :     psubsw mm7, mm2
233 :     paddsw mm3, mm2
234 :     pmulhw mm5, mm7
235 :     paddsw mm0, mm3
236 :     paddsw mm6, mm4
237 :     pmulhw mm3, [fdct_tg_all_16 + 0*2]
238 :     por mm0, [fdct_one_corr]
239 :     paddsw mm5, mm7
240 :     psubsw mm7, mm6
241 :     movq [%1 + %3*2 + 1*16], mm0
242 :     paddsw mm5, mm4
243 :     movq [%1 + %3*2 + 3*16], mm7
244 :     psubsw mm3, mm1
245 :     movq [%1 + %3*2 + 5*16], mm5
246 :     movq [%1 + %3*2 + 7*16], mm3
247 :     %endmacro
248 :    
249 :     ;; Macro for row DCT using MMX punpcklw instructions
250 :     ;; FDCT_ROW_MMX(int16_t *out, const int16_t *in, const int16_t *table);
251 :     ;; - out, register name holding the out address
252 :     ;; - in, register name holding the in address
253 :     ;; - table coefficients address (register or absolute)
254 :     %macro FDCT_ROW_MMX 3
255 :     movd mm1, [%2 + 6*2]
256 :     punpcklwd mm1, [%2 + 4*2]
257 :     movq mm2, mm1
258 :     psrlq mm1, 0x20
259 :     movq mm0, [%2 + 0*2]
260 :     punpcklwd mm1, mm2
261 :     movq mm5, mm0
262 :     paddsw mm0, mm1
263 :     psubsw mm5, mm1
264 :     movq mm1, mm0
265 :     movq mm6, mm5
266 :     punpckldq mm3, mm5
267 :     punpckhdq mm6, mm3
268 :     movq mm3, [%3 + 0*2]
269 :     movq mm4, [%3 + 4*2]
270 :     punpckldq mm2, mm0
271 :     pmaddwd mm3, mm0
272 :     punpckhdq mm1, mm2
273 :     movq mm2, [%3 + 16*2]
274 :     pmaddwd mm4, mm1
275 :     pmaddwd mm0, [%3 + 8*2]
276 :     movq mm7, [%3 + 20*2]
277 :     pmaddwd mm2, mm5
278 :     paddd mm3, [fdct_r_row]
279 :     pmaddwd mm7, mm6
280 :     pmaddwd mm1, [%3 + 12*2]
281 :     paddd mm3, mm4
282 :     pmaddwd mm5, [%3 + 24*2]
283 :     pmaddwd mm6, [%3 + 28*2]
284 :     paddd mm2, mm7
285 :     paddd mm0, [fdct_r_row]
286 :     psrad mm3, SHIFT_FRW_ROW
287 :     paddd mm2, [fdct_r_row]
288 :     paddd mm0, mm1
289 :     paddd mm5, [fdct_r_row]
290 :     psrad mm2, SHIFT_FRW_ROW
291 :     paddd mm5, mm6
292 :     psrad mm0, SHIFT_FRW_ROW
293 :     psrad mm5, SHIFT_FRW_ROW
294 :     packssdw mm3, mm0
295 :     packssdw mm2, mm5
296 :     movq mm6, mm3
297 :     punpcklwd mm3, mm2
298 :     punpckhwd mm6, mm2
299 :     movq [%1 + 0*2], mm3
300 :     movq [%1 + 4*2], mm6
301 :     %endmacro
302 :    
303 :     ;; Macro for column DCT using XMM instuction pshufw
304 :     ;; FDCT_ROW_XMM(int16_t *out, const int16_t *in, const int16_t *table);
305 :     ;; - out, register name holding the out address
306 :     ;; - in, register name holding the in address
307 :     ;; - table coefficient address
308 :     %macro FDCT_ROW_XMM 3
309 :     ;; fdct_row_mmx2(const int16_t *in, int16_t *out, const int16_t *table)
310 :     pshufw mm5, [%2 + 4*2], 0x1B
311 :     movq mm0, [%2 + 0*2]
312 :     movq mm1, mm0
313 :     paddsw mm0, mm5
314 :     psubsw mm1, mm5
315 :     pshufw mm2, mm0, 0x4E
316 :     pshufw mm3, mm1, 0x4E
317 :     movq mm4, [%3 + 0*2]
318 :     movq mm6, [%3 + 4*2]
319 :     movq mm5, [%3 + 16*2]
320 :     movq mm7, [%3 + 20*2]
321 :     pmaddwd mm4, mm0
322 :     pmaddwd mm5, mm1
323 :     pmaddwd mm6, mm2
324 :     pmaddwd mm7, mm3
325 :     pmaddwd mm0, [%3 + 8*2]
326 :     pmaddwd mm2, [%3 + 12*2]
327 :     pmaddwd mm1, [%3 + 24*2]
328 :     pmaddwd mm3, [%3 + 28*2]
329 :     paddd mm4, mm6
330 :     paddd mm5, mm7
331 :     paddd mm0, mm2
332 :     paddd mm1, mm3
333 :     movq mm7, [fdct_r_row]
334 :     paddd mm4, mm7
335 :     paddd mm5, mm7
336 :     paddd mm0, mm7
337 :     paddd mm1, mm7
338 :     psrad mm4, SHIFT_FRW_ROW
339 :     psrad mm5, SHIFT_FRW_ROW
340 :     psrad mm0, SHIFT_FRW_ROW
341 :     psrad mm1, SHIFT_FRW_ROW
342 :     packssdw mm4, mm0
343 :     packssdw mm5, mm1
344 :     movq mm2, mm4
345 :     punpcklwd mm4, mm5
346 :     punpckhwd mm2, mm5
347 :     movq [%1 + 0*2], mm4
348 :     movq [%1 + 4*2], mm2
349 :     %endmacro
350 :    
351 :     %macro MAKE_FDCT_FUNC 2
352 : Isibaar 1795 ALIGN SECTION_ALIGN
353 : edgomez 1382 cglobal %1
354 :     %1:
355 :     ;; Move the destination/source address to the eax register
356 : Isibaar 1795 mov _EAX, prm1
357 : edgomez 1382
358 :     ;; Process the columns (4 at a time)
359 : Isibaar 1795 FDCT_COLUMN_COMMON _EAX, _EAX, 0 ; columns 0..3
360 :     FDCT_COLUMN_COMMON _EAX, _EAX, 4 ; columns 4..7
361 : edgomez 1382
362 :     %ifdef UNROLLED_LOOP
363 :     ; Unrolled loop version
364 :     %assign i 0
365 :     %rep 8
366 :     ;; Process the 'i'th row
367 : Isibaar 1795 %2 _EAX+2*i*8, _EAX+2*i*8, tab_frw_01234567+2*32*i
368 : edgomez 1382 %assign i i+1
369 :     %endrep
370 :     %else
371 : Isibaar 1795 mov _ECX, 8
372 :     mov _EDX, tab_frw_01234567
373 :     ALIGN SECTION_ALIGN
374 : edgomez 1382 .loop
375 : Isibaar 1795 %2 _EAX, _EAX,_EDX
376 :     add _EAX, 2*8
377 :     add _EDX, 2*32
378 :     dec _ECX
379 : edgomez 1382 jne .loop
380 :     %endif
381 :    
382 :     ret
383 : Isibaar 1793 ENDFUNC
384 : edgomez 1382 %endmacro
385 :    
386 :     ;=============================================================================
387 :     ; Code
388 :     ;=============================================================================
389 :    
390 : Isibaar 1844 TEXT
391 : edgomez 1382
392 :     ;-----------------------------------------------------------------------------
393 :     ; void fdct_mmx_ffmpeg(int16_t block[64]);
394 :     ;-----------------------------------------------------------------------------
395 :    
396 :     MAKE_FDCT_FUNC fdct_mmx_ffmpeg, FDCT_ROW_MMX
397 :    
398 :     ;-----------------------------------------------------------------------------
399 :     ; void fdct_xmm_ffmpeg(int16_t block[64]);
400 :     ;-----------------------------------------------------------------------------
401 :    
402 : edgomez 1535 MAKE_FDCT_FUNC fdct_xmm_ffmpeg, FDCT_ROW_XMM
403 : Isibaar 1790
404 : Isibaar 1877 NON_EXEC_STACK

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