Parent Directory | Revision Log
Revision 1.5 - (view) (download)
1 : | edgomez | 1.2 | ;/**************************************************************************** |
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 : | ; * $Id$ | ||
23 : | ; * | ||
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 : | BITS 32 | ||
46 : | |||
47 : | ;============================================================================= | ||
48 : | ; Macros and other preprocessor constants | ||
49 : | ;============================================================================= | ||
50 : | |||
51 : | %macro cglobal 1 | ||
52 : | %ifdef PREFIX | ||
53 : | edgomez | 1.4 | %ifdef MARK_FUNCS |
54 : | edgomez | 1.5 | global _%1:function %1.endfunc-%1 |
55 : | %define %1 _%1:function %1.endfunc-%1 | ||
56 : | edgomez | 1.4 | %else |
57 : | global _%1 | ||
58 : | %define %1 _%1 | ||
59 : | %endif | ||
60 : | edgomez | 1.2 | %else |
61 : | edgomez | 1.4 | %ifdef MARK_FUNCS |
62 : | edgomez | 1.5 | global %1:function %1.endfunc-%1 |
63 : | edgomez | 1.4 | %else |
64 : | global %1 | ||
65 : | %endif | ||
66 : | edgomez | 1.2 | %endif |
67 : | %endmacro | ||
68 : | |||
69 : | ;;; Define this if you want an unrolled version of the code | ||
70 : | %define UNROLLED_LOOP | ||
71 : | |||
72 : | %define BITS_FRW_ACC 3 | ||
73 : | %define SHIFT_FRW_COL BITS_FRW_ACC | ||
74 : | %define SHIFT_FRW_ROW (BITS_FRW_ACC + 17) | ||
75 : | %define RND_FRW_ROW (1 << (SHIFT_FRW_ROW-1)) | ||
76 : | %define RND_FRW_COL (1 << (SHIFT_FRW_COL-1)) | ||
77 : | |||
78 : | ;============================================================================= | ||
79 : | ; Local Data (Read Only) | ||
80 : | ;============================================================================= | ||
81 : | |||
82 : | %ifdef FORMAT_COFF | ||
83 : | edgomez | 1.3 | SECTION .rodata |
84 : | edgomez | 1.2 | %else |
85 : | edgomez | 1.3 | SECTION .rodata align=16 |
86 : | edgomez | 1.2 | %endif |
87 : | |||
88 : | ALIGN 8 | ||
89 : | tab_frw_01234567: | ||
90 : | dw 16384, 16384, -8867, -21407 | ||
91 : | dw 16384, 16384, 21407, 8867 | ||
92 : | dw 16384, -16384, 21407, -8867 | ||
93 : | dw -16384, 16384, 8867, -21407 | ||
94 : | dw 22725, 19266, -22725, -12873 | ||
95 : | dw 12873, 4520, 19266, -4520 | ||
96 : | dw 12873, -22725, 19266, -22725 | ||
97 : | dw 4520, 19266, 4520, -12873 | ||
98 : | |||
99 : | dw 22725, 22725, -12299, -29692 | ||
100 : | dw 22725, 22725, 29692, 12299 | ||
101 : | dw 22725, -22725, 29692, -12299 | ||
102 : | dw -22725, 22725, 12299, -29692 | ||
103 : | dw 31521, 26722, -31521, -17855 | ||
104 : | dw 17855, 6270, 26722, -6270 | ||
105 : | dw 17855, -31521, 26722, -31521 | ||
106 : | dw 6270, 26722, 6270, -17855 | ||
107 : | |||
108 : | dw 21407, 21407, -11585, -27969 | ||
109 : | dw 21407, 21407, 27969, 11585 | ||
110 : | dw 21407, -21407, 27969, -11585 | ||
111 : | dw -21407, 21407, 11585, -27969 | ||
112 : | dw 29692, 25172, -29692, -16819 | ||
113 : | dw 16819, 5906, 25172, -5906 | ||
114 : | dw 16819, -29692, 25172, -29692 | ||
115 : | dw 5906, 25172, 5906, -16819 | ||
116 : | |||
117 : | dw 19266, 19266, -10426, -25172 | ||
118 : | dw 19266, 19266, 25172, 10426 | ||
119 : | dw 19266, -19266, 25172, -10426 | ||
120 : | dw -19266, 19266, 10426, -25172 | ||
121 : | dw 26722, 22654, -26722, -15137 | ||
122 : | dw 15137, 5315, 22654, -5315 | ||
123 : | dw 15137, -26722, 22654, -26722 | ||
124 : | dw 5315, 22654, 5315, -15137 | ||
125 : | |||
126 : | dw 16384, 16384, -8867, -21407 | ||
127 : | dw 16384, 16384, 21407, 8867 | ||
128 : | dw 16384, -16384, 21407, -8867 | ||
129 : | dw -16384, 16384, 8867, -21407 | ||
130 : | dw 22725, 19266, -22725, -12873 | ||
131 : | dw 12873, 4520, 19266, -4520 | ||
132 : | dw 12873, -22725, 19266, -22725 | ||
133 : | dw 4520, 19266, 4520, -12873 | ||
134 : | |||
135 : | dw 19266, 19266, -10426, -25172 | ||
136 : | dw 19266, 19266, 25172, 10426 | ||
137 : | dw 19266, -19266, 25172, -10426 | ||
138 : | dw -19266, 19266, 10426, -25172 | ||
139 : | dw 26722, 22654, -26722, -15137 | ||
140 : | dw 15137, 5315, 22654, -5315 | ||
141 : | dw 15137, -26722, 22654, -26722 | ||
142 : | dw 5315, 22654, 5315, -15137 | ||
143 : | |||
144 : | dw 21407, 21407, -11585, -27969 | ||
145 : | dw 21407, 21407, 27969, 11585 | ||
146 : | dw 21407, -21407, 27969, -11585 | ||
147 : | dw -21407, 21407, 11585, -27969 | ||
148 : | dw 29692, 25172, -29692, -16819 | ||
149 : | dw 16819, 5906, 25172, -5906 | ||
150 : | dw 16819, -29692, 25172, -29692 | ||
151 : | dw 5906, 25172, 5906, -16819, | ||
152 : | |||
153 : | dw 22725, 22725, -12299, -29692 | ||
154 : | dw 22725, 22725, 29692, 12299 | ||
155 : | dw 22725, -22725, 29692, -12299 | ||
156 : | dw -22725, 22725, 12299, -29692 | ||
157 : | dw 31521, 26722, -31521, -17855 | ||
158 : | dw 17855, 6270, 26722, -6270 | ||
159 : | dw 17855, -31521, 26722, -31521 | ||
160 : | dw 6270, 26722, 6270, -17855 | ||
161 : | |||
162 : | ALIGN 8 | ||
163 : | fdct_one_corr: | ||
164 : | dw 1, 1, 1, 1 | ||
165 : | |||
166 : | ALIGN 8 | ||
167 : | fdct_tg_all_16: | ||
168 : | dw 13036, 13036, 13036, 13036 | ||
169 : | dw 27146, 27146, 27146, 27146 | ||
170 : | dw -21746, -21746, -21746, -21746 | ||
171 : | |||
172 : | ALIGN 8 | ||
173 : | cos_4_16: | ||
174 : | dw -19195, -19195, -19195, -19195 | ||
175 : | |||
176 : | ALIGN 8 | ||
177 : | ocos_4_16: | ||
178 : | dw 23170, 23170, 23170, 23170 | ||
179 : | |||
180 : | ALIGN 8 | ||
181 : | fdct_r_row: | ||
182 : | dd RND_FRW_ROW, RND_FRW_ROW | ||
183 : | |||
184 : | ;============================================================================= | ||
185 : | ; Factorized parts of the code turned into macros for better understanding | ||
186 : | ;============================================================================= | ||
187 : | |||
188 : | ;; Macro for column DCT | ||
189 : | ;; FDCT_COLUMN_MMX(int16_t *out, const int16_t *in, int offset); | ||
190 : | ;; - out, register name holding the out address | ||
191 : | ;; - in, register name holding the in address | ||
192 : | ;; - column number to process | ||
193 : | %macro FDCT_COLUMN_COMMON 3 | ||
194 : | movq mm0, [%2 + %3*2 + 1*16] | ||
195 : | movq mm1, [%2 + %3*2 + 6*16] | ||
196 : | movq mm2, mm0 | ||
197 : | movq mm3, [%2 + %3*2 + 2*16] | ||
198 : | paddsw mm0, mm1 | ||
199 : | movq mm4, [%2 + %3*2 + 5*16] | ||
200 : | psllw mm0, SHIFT_FRW_COL | ||
201 : | movq mm5, [%2 + %3*2 + 0*16] | ||
202 : | paddsw mm4, mm3 | ||
203 : | paddsw mm5, [%2 + %3*2 + 7*16] | ||
204 : | psllw mm4, SHIFT_FRW_COL | ||
205 : | movq mm6, mm0 | ||
206 : | psubsw mm2, mm1 | ||
207 : | movq mm1, [fdct_tg_all_16 + 4*2] | ||
208 : | psubsw mm0, mm4 | ||
209 : | movq mm7, [%2 + %3*2 + 3*16] | ||
210 : | pmulhw mm1, mm0 | ||
211 : | paddsw mm7, [%2 + %3*2 + 4*16] | ||
212 : | psllw mm5, SHIFT_FRW_COL | ||
213 : | paddsw mm6, mm4 | ||
214 : | psllw mm7, SHIFT_FRW_COL | ||
215 : | movq mm4, mm5 | ||
216 : | psubsw mm5, mm7 | ||
217 : | paddsw mm1, mm5 | ||
218 : | paddsw mm4, mm7 | ||
219 : | por mm1, [fdct_one_corr] | ||
220 : | psllw mm2, SHIFT_FRW_COL + 1 | ||
221 : | pmulhw mm5, [fdct_tg_all_16 + 4*2] | ||
222 : | movq mm7, mm4 | ||
223 : | psubsw mm3, [%2 + %3*2 + 5*16] | ||
224 : | psubsw mm4, mm6 | ||
225 : | movq [%1 + %3*2 + 2*16], mm1 | ||
226 : | paddsw mm7, mm6 | ||
227 : | movq mm1, [%2 + %3*2 + 3*16] | ||
228 : | psllw mm3, SHIFT_FRW_COL + 1 | ||
229 : | psubsw mm1, [%2 + %3*2 + 4*16] | ||
230 : | movq mm6, mm2 | ||
231 : | movq [%1 + %3*2 + 4*16], mm4 | ||
232 : | paddsw mm2, mm3 | ||
233 : | pmulhw mm2, [ocos_4_16] | ||
234 : | psubsw mm6, mm3 | ||
235 : | pmulhw mm6, [ocos_4_16] | ||
236 : | psubsw mm5, mm0 | ||
237 : | por mm5, [fdct_one_corr] | ||
238 : | psllw mm1, SHIFT_FRW_COL | ||
239 : | por mm2, [fdct_one_corr] | ||
240 : | movq mm4, mm1 | ||
241 : | movq mm3, [%2 + %3*2 + 0*16] | ||
242 : | paddsw mm1, mm6 | ||
243 : | psubsw mm3, [%2 + %3*2 + 7*16] | ||
244 : | psubsw mm4, mm6 | ||
245 : | movq mm0, [fdct_tg_all_16 + 0*2] | ||
246 : | psllw mm3, SHIFT_FRW_COL | ||
247 : | movq mm6, [fdct_tg_all_16 + 8*2] | ||
248 : | pmulhw mm0, mm1 | ||
249 : | movq [%1 + %3*2 + 0*16], mm7 | ||
250 : | pmulhw mm6, mm4 | ||
251 : | movq [%1 + %3*2 + 6*16], mm5 | ||
252 : | movq mm7, mm3 | ||
253 : | movq mm5, [fdct_tg_all_16 + 8*2] | ||
254 : | psubsw mm7, mm2 | ||
255 : | paddsw mm3, mm2 | ||
256 : | pmulhw mm5, mm7 | ||
257 : | paddsw mm0, mm3 | ||
258 : | paddsw mm6, mm4 | ||
259 : | pmulhw mm3, [fdct_tg_all_16 + 0*2] | ||
260 : | por mm0, [fdct_one_corr] | ||
261 : | paddsw mm5, mm7 | ||
262 : | psubsw mm7, mm6 | ||
263 : | movq [%1 + %3*2 + 1*16], mm0 | ||
264 : | paddsw mm5, mm4 | ||
265 : | movq [%1 + %3*2 + 3*16], mm7 | ||
266 : | psubsw mm3, mm1 | ||
267 : | movq [%1 + %3*2 + 5*16], mm5 | ||
268 : | movq [%1 + %3*2 + 7*16], mm3 | ||
269 : | %endmacro | ||
270 : | |||
271 : | ;; Macro for row DCT using MMX punpcklw instructions | ||
272 : | ;; FDCT_ROW_MMX(int16_t *out, const int16_t *in, const int16_t *table); | ||
273 : | ;; - out, register name holding the out address | ||
274 : | ;; - in, register name holding the in address | ||
275 : | ;; - table coefficients address (register or absolute) | ||
276 : | %macro FDCT_ROW_MMX 3 | ||
277 : | movd mm1, [%2 + 6*2] | ||
278 : | punpcklwd mm1, [%2 + 4*2] | ||
279 : | movq mm2, mm1 | ||
280 : | psrlq mm1, 0x20 | ||
281 : | movq mm0, [%2 + 0*2] | ||
282 : | punpcklwd mm1, mm2 | ||
283 : | movq mm5, mm0 | ||
284 : | paddsw mm0, mm1 | ||
285 : | psubsw mm5, mm1 | ||
286 : | movq mm1, mm0 | ||
287 : | movq mm6, mm5 | ||
288 : | punpckldq mm3, mm5 | ||
289 : | punpckhdq mm6, mm3 | ||
290 : | movq mm3, [%3 + 0*2] | ||
291 : | movq mm4, [%3 + 4*2] | ||
292 : | punpckldq mm2, mm0 | ||
293 : | pmaddwd mm3, mm0 | ||
294 : | punpckhdq mm1, mm2 | ||
295 : | movq mm2, [%3 + 16*2] | ||
296 : | pmaddwd mm4, mm1 | ||
297 : | pmaddwd mm0, [%3 + 8*2] | ||
298 : | movq mm7, [%3 + 20*2] | ||
299 : | pmaddwd mm2, mm5 | ||
300 : | paddd mm3, [fdct_r_row] | ||
301 : | pmaddwd mm7, mm6 | ||
302 : | pmaddwd mm1, [%3 + 12*2] | ||
303 : | paddd mm3, mm4 | ||
304 : | pmaddwd mm5, [%3 + 24*2] | ||
305 : | pmaddwd mm6, [%3 + 28*2] | ||
306 : | paddd mm2, mm7 | ||
307 : | paddd mm0, [fdct_r_row] | ||
308 : | psrad mm3, SHIFT_FRW_ROW | ||
309 : | paddd mm2, [fdct_r_row] | ||
310 : | paddd mm0, mm1 | ||
311 : | paddd mm5, [fdct_r_row] | ||
312 : | psrad mm2, SHIFT_FRW_ROW | ||
313 : | paddd mm5, mm6 | ||
314 : | psrad mm0, SHIFT_FRW_ROW | ||
315 : | psrad mm5, SHIFT_FRW_ROW | ||
316 : | packssdw mm3, mm0 | ||
317 : | packssdw mm2, mm5 | ||
318 : | movq mm6, mm3 | ||
319 : | punpcklwd mm3, mm2 | ||
320 : | punpckhwd mm6, mm2 | ||
321 : | movq [%1 + 0*2], mm3 | ||
322 : | movq [%1 + 4*2], mm6 | ||
323 : | %endmacro | ||
324 : | |||
325 : | ;; Macro for column DCT using XMM instuction pshufw | ||
326 : | ;; FDCT_ROW_XMM(int16_t *out, const int16_t *in, const int16_t *table); | ||
327 : | ;; - out, register name holding the out address | ||
328 : | ;; - in, register name holding the in address | ||
329 : | ;; - table coefficient address | ||
330 : | %macro FDCT_ROW_XMM 3 | ||
331 : | ;; fdct_row_mmx2(const int16_t *in, int16_t *out, const int16_t *table) | ||
332 : | pshufw mm5, [%2 + 4*2], 0x1B | ||
333 : | movq mm0, [%2 + 0*2] | ||
334 : | movq mm1, mm0 | ||
335 : | paddsw mm0, mm5 | ||
336 : | psubsw mm1, mm5 | ||
337 : | pshufw mm2, mm0, 0x4E | ||
338 : | pshufw mm3, mm1, 0x4E | ||
339 : | movq mm4, [%3 + 0*2] | ||
340 : | movq mm6, [%3 + 4*2] | ||
341 : | movq mm5, [%3 + 16*2] | ||
342 : | movq mm7, [%3 + 20*2] | ||
343 : | pmaddwd mm4, mm0 | ||
344 : | pmaddwd mm5, mm1 | ||
345 : | pmaddwd mm6, mm2 | ||
346 : | pmaddwd mm7, mm3 | ||
347 : | pmaddwd mm0, [%3 + 8*2] | ||
348 : | pmaddwd mm2, [%3 + 12*2] | ||
349 : | pmaddwd mm1, [%3 + 24*2] | ||
350 : | pmaddwd mm3, [%3 + 28*2] | ||
351 : | paddd mm4, mm6 | ||
352 : | paddd mm5, mm7 | ||
353 : | paddd mm0, mm2 | ||
354 : | paddd mm1, mm3 | ||
355 : | movq mm7, [fdct_r_row] | ||
356 : | paddd mm4, mm7 | ||
357 : | paddd mm5, mm7 | ||
358 : | paddd mm0, mm7 | ||
359 : | paddd mm1, mm7 | ||
360 : | psrad mm4, SHIFT_FRW_ROW | ||
361 : | psrad mm5, SHIFT_FRW_ROW | ||
362 : | psrad mm0, SHIFT_FRW_ROW | ||
363 : | psrad mm1, SHIFT_FRW_ROW | ||
364 : | packssdw mm4, mm0 | ||
365 : | packssdw mm5, mm1 | ||
366 : | movq mm2, mm4 | ||
367 : | punpcklwd mm4, mm5 | ||
368 : | punpckhwd mm2, mm5 | ||
369 : | movq [%1 + 0*2], mm4 | ||
370 : | movq [%1 + 4*2], mm2 | ||
371 : | %endmacro | ||
372 : | |||
373 : | %macro MAKE_FDCT_FUNC 2 | ||
374 : | ALIGN 16 | ||
375 : | cglobal %1 | ||
376 : | %1: | ||
377 : | ;; Move the destination/source address to the eax register | ||
378 : | mov eax, [esp + 4] | ||
379 : | |||
380 : | ;; Process the columns (4 at a time) | ||
381 : | FDCT_COLUMN_COMMON eax, eax, 0 ; columns 0..3 | ||
382 : | FDCT_COLUMN_COMMON eax, eax, 4 ; columns 4..7 | ||
383 : | |||
384 : | %ifdef UNROLLED_LOOP | ||
385 : | ; Unrolled loop version | ||
386 : | %assign i 0 | ||
387 : | %rep 8 | ||
388 : | ;; Process the 'i'th row | ||
389 : | %2 eax+2*i*8, eax+2*i*8, tab_frw_01234567+2*32*i | ||
390 : | %assign i i+1 | ||
391 : | %endrep | ||
392 : | %else | ||
393 : | mov ecx, 8 | ||
394 : | mov edx, tab_frw_01234567 | ||
395 : | ALIGN 8 | ||
396 : | .loop | ||
397 : | %2 eax, eax, edx | ||
398 : | add eax, 2*8 | ||
399 : | add edx, 2*32 | ||
400 : | dec ecx | ||
401 : | jne .loop | ||
402 : | %endif | ||
403 : | |||
404 : | ret | ||
405 : | edgomez | 1.5 | .endfunc |
406 : | edgomez | 1.2 | %endmacro |
407 : | |||
408 : | ;============================================================================= | ||
409 : | ; Code | ||
410 : | ;============================================================================= | ||
411 : | |||
412 : | SECTION .text | ||
413 : | |||
414 : | ;----------------------------------------------------------------------------- | ||
415 : | ; void fdct_mmx_ffmpeg(int16_t block[64]); | ||
416 : | ;----------------------------------------------------------------------------- | ||
417 : | |||
418 : | MAKE_FDCT_FUNC fdct_mmx_ffmpeg, FDCT_ROW_MMX | ||
419 : | |||
420 : | ;----------------------------------------------------------------------------- | ||
421 : | ; void fdct_xmm_ffmpeg(int16_t block[64]); | ||
422 : | ;----------------------------------------------------------------------------- | ||
423 : | |||
424 : | edgomez | 1.4 | MAKE_FDCT_FUNC fdct_xmm_ffmpeg, FDCT_ROW_XMM |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |