1 |
;/************************************************************************** |
;/**************************************************************************** |
2 |
; * |
; * |
3 |
; * XVID MPEG-4 VIDEO CODEC |
; * XVID MPEG-4 VIDEO CODEC |
4 |
; * mmx 8bit<->16bit transfers |
; * - 8<->16 bit transfer functions - |
5 |
; * |
; * |
6 |
; * This file is part of XviD, a free MPEG-4 video encoder/decoder |
; * Copyright (C) 2001 Peter Ross <pross@xvid.org> |
7 |
|
; * 2001 Michael Militzer <isibaar@xvid.org> |
8 |
|
; * 2002 Pascal Massimino <skal@planet-d.net> |
9 |
; * |
; * |
10 |
; * XviD is free software; you can redistribute it and/or modify it |
; * This program is free software ; you can redistribute it and/or modify |
11 |
; * under the terms of the GNU General Public License as published by |
; * it under the terms of the GNU General Public License as published by |
12 |
; * the Free Software Foundation; either version 2 of the License, or |
; * the Free Software Foundation; either version 2 of the License, or |
13 |
; * (at your option) any later version. |
; * (at your option) any later version. |
14 |
; * |
; * |
21 |
; * along with this program; if not, write to the Free Software |
; * along with this program; if not, write to the Free Software |
22 |
; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
; * |
; * |
|
; * Under section 8 of the GNU General Public License, the copyright |
|
|
; * holders of XVID explicitly forbid distribution in the following |
|
|
; * countries: |
|
|
; * |
|
|
; * - Japan |
|
|
; * - United States of America |
|
|
; * |
|
|
; * Linking XviD statically or dynamically with other modules is making a |
|
|
; * combined work based on XviD. Thus, the terms and conditions of the |
|
|
; * GNU General Public License cover the whole combination. |
|
|
; * |
|
|
; * As a special exception, the copyright holders of XviD give you |
|
|
; * permission to link XviD with independent modules that communicate with |
|
|
; * XviD solely through the VFW1.1 and DShow interfaces, regardless of the |
|
|
; * license terms of these independent modules, and to copy and distribute |
|
|
; * the resulting combined work under terms of your choice, provided that |
|
|
; * every copy of the combined work is accompanied by a complete copy of |
|
|
; * the source code of XviD (the version of XviD used to produce the |
|
|
; * combined work), being distributed under the terms of the GNU General |
|
|
; * Public License plus this exception. An independent module is a module |
|
|
; * which is not derived from or based on XviD. |
|
|
; * |
|
|
; * Note that people who make modified versions of XviD are not obligated |
|
|
; * to grant this special exception for their modified versions; it is |
|
|
; * their choice whether to do so. The GNU General Public License gives |
|
|
; * permission to release a modified version without this exception; this |
|
|
; * exception also makes it possible to release a modified version which |
|
|
; * carries forward this exception. |
|
|
; * |
|
24 |
; * $Id$ |
; * $Id$ |
25 |
; * |
; * |
26 |
; *************************************************************************/ |
; ***************************************************************************/ |
|
|
|
|
;/************************************************************************** |
|
|
; * |
|
|
; * History: |
|
|
; * |
|
|
; * 04.06.2002 speed enhancement (unroll+overlap). -Skal- |
|
|
; * + added transfer_8to16sub2_mmx/xmm |
|
|
; * 07.01.2002 merge functions from compensate_mmx; rename functions |
|
|
; * 07.11.2001 initial version; (c)2001 peter ross <pross@xvid.org> |
|
|
; * |
|
|
; *************************************************************************/ |
|
27 |
|
|
28 |
|
BITS 32 |
|
bits 32 |
|
29 |
|
|
30 |
%macro cglobal 1 |
%macro cglobal 1 |
31 |
%ifdef PREFIX |
%ifdef PREFIX |
36 |
%endif |
%endif |
37 |
%endmacro |
%endmacro |
38 |
|
|
39 |
|
;============================================================================= |
40 |
|
; Read only data |
41 |
|
;============================================================================= |
42 |
|
|
43 |
|
%ifdef FORMAT_COFF |
44 |
|
SECTION .rodata data |
45 |
|
%else |
46 |
|
SECTION .rodata data align=16 |
47 |
|
%endif |
48 |
|
|
49 |
|
ALIGN 16 |
50 |
|
mmx_one: |
51 |
|
dw 1, 1, 1, 1 |
52 |
|
|
53 |
|
;============================================================================= |
54 |
|
; Code |
55 |
|
;============================================================================= |
56 |
|
|
57 |
section .text |
SECTION .text |
58 |
|
|
59 |
cglobal transfer_8to16copy_mmx |
cglobal transfer_8to16copy_mmx |
60 |
cglobal transfer_16to8copy_mmx |
cglobal transfer_16to8copy_mmx |
61 |
cglobal transfer_8to16sub_mmx |
cglobal transfer_8to16sub_mmx |
62 |
|
cglobal transfer_8to16subro_mmx |
63 |
cglobal transfer_8to16sub2_mmx |
cglobal transfer_8to16sub2_mmx |
64 |
cglobal transfer_8to16sub2_xmm |
cglobal transfer_8to16sub2_xmm |
65 |
cglobal transfer_16to8add_mmx |
cglobal transfer_16to8add_mmx |
66 |
cglobal transfer8x8_copy_mmx |
cglobal transfer8x8_copy_mmx |
67 |
|
|
68 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
69 |
; |
; |
70 |
; void transfer_8to16copy_mmx(int16_t * const dst, |
; void transfer_8to16copy_mmx(int16_t * const dst, |
71 |
; const uint8_t * const src, |
; const uint8_t * const src, |
72 |
; uint32_t stride); |
; uint32_t stride); |
73 |
; |
; |
74 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
75 |
|
|
76 |
%macro COPY_8_TO_16 1 |
%macro COPY_8_TO_16 1 |
77 |
movq mm0, [eax] |
movq mm0, [eax] |
89 |
movq [ecx+%1*32+24], mm3 |
movq [ecx+%1*32+24], mm3 |
90 |
%endmacro |
%endmacro |
91 |
|
|
92 |
align 16 |
ALIGN 16 |
93 |
transfer_8to16copy_mmx: |
transfer_8to16copy_mmx: |
94 |
|
|
95 |
mov ecx, [esp+ 4] ; Dst |
mov ecx, [esp+ 4] ; Dst |
103 |
COPY_8_TO_16 3 |
COPY_8_TO_16 3 |
104 |
ret |
ret |
105 |
|
|
106 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
107 |
; |
; |
108 |
; void transfer_16to8copy_mmx(uint8_t * const dst, |
; void transfer_16to8copy_mmx(uint8_t * const dst, |
109 |
; const int16_t * const src, |
; const int16_t * const src, |
110 |
; uint32_t stride); |
; uint32_t stride); |
111 |
; |
; |
112 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
113 |
|
|
114 |
%macro COPY_16_TO_8 1 |
%macro COPY_16_TO_8 1 |
115 |
movq mm0, [eax+%1*32] |
movq mm0, [eax+%1*32] |
122 |
movq [ecx+edx], mm2 |
movq [ecx+edx], mm2 |
123 |
%endmacro |
%endmacro |
124 |
|
|
125 |
align 16 |
ALIGN 16 |
126 |
transfer_16to8copy_mmx: |
transfer_16to8copy_mmx: |
127 |
|
|
128 |
mov ecx, [esp+ 4] ; Dst |
mov ecx, [esp+ 4] ; Dst |
138 |
COPY_16_TO_8 3 |
COPY_16_TO_8 3 |
139 |
ret |
ret |
140 |
|
|
141 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
142 |
; |
; |
143 |
; void transfer_8to16sub_mmx(int16_t * const dct, |
; void transfer_8to16sub_mmx(int16_t * const dct, |
144 |
; uint8_t * const cur, |
; uint8_t * const cur, |
145 |
; const uint8_t * const ref, |
; const uint8_t * const ref, |
146 |
; const uint32_t stride); |
; const uint32_t stride); |
147 |
; |
; |
148 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
;/************************************************************************** |
|
|
; * |
|
|
; * History: |
|
|
; * |
|
|
; * 27.12.2001 renamed from 'compensate' to 'transfer_8to16sub' |
|
|
; * 02.12.2001 loop unrolled, code runs 10% faster now (Isibaar) |
|
|
; * 30.11.2001 16 pixels are processed per iteration (Isibaar) |
|
|
; * 30.11.2001 .text missing |
|
|
; * 06.11.2001 inital version; (c)2001 peter ross <pross@xvid.org> |
|
|
; * |
|
|
; *************************************************************************/ |
|
149 |
|
|
150 |
%macro COPY_8_TO_16_SUB 1 |
; when second argument == 1, reference (ebx) block is to current (eax) |
151 |
|
%macro COPY_8_TO_16_SUB 2 |
152 |
movq mm0, [eax] ; cur |
movq mm0, [eax] ; cur |
153 |
movq mm2, [eax+edx] |
movq mm2, [eax+edx] |
154 |
movq mm1, mm0 |
movq mm1, mm0 |
162 |
movq mm5, [ebx+edx] ; ref |
movq mm5, [ebx+edx] ; ref |
163 |
|
|
164 |
movq mm6, mm4 |
movq mm6, mm4 |
165 |
|
%if %2 == 1 |
166 |
movq [eax], mm4 |
movq [eax], mm4 |
167 |
movq [eax+edx], mm5 |
movq [eax+edx], mm5 |
168 |
|
%endif |
169 |
punpcklbw mm4, mm7 |
punpcklbw mm4, mm7 |
170 |
punpckhbw mm6, mm7 |
punpckhbw mm6, mm7 |
171 |
psubsw mm0, mm4 |
psubsw mm0, mm4 |
184 |
movq [ecx+%1*32+24], mm3 |
movq [ecx+%1*32+24], mm3 |
185 |
%endmacro |
%endmacro |
186 |
|
|
187 |
align 16 |
ALIGN 16 |
188 |
transfer_8to16sub_mmx: |
transfer_8to16sub_mmx: |
189 |
mov ecx, [esp + 4] ; Dst |
mov ecx, [esp + 4] ; Dst |
190 |
mov eax, [esp + 8] ; Cur |
mov eax, [esp + 8] ; Cur |
193 |
mov edx, [esp+4+16] ; Stride |
mov edx, [esp+4+16] ; Stride |
194 |
pxor mm7, mm7 |
pxor mm7, mm7 |
195 |
|
|
196 |
COPY_8_TO_16_SUB 0 |
COPY_8_TO_16_SUB 0, 1 |
197 |
COPY_8_TO_16_SUB 1 |
COPY_8_TO_16_SUB 1, 1 |
198 |
COPY_8_TO_16_SUB 2 |
COPY_8_TO_16_SUB 2, 1 |
199 |
COPY_8_TO_16_SUB 3 |
COPY_8_TO_16_SUB 3, 1 |
200 |
|
|
201 |
pop ebx |
pop ebx |
202 |
ret |
ret |
203 |
|
|
204 |
;=========================================================================== |
|
205 |
|
ALIGN 16 |
206 |
|
transfer_8to16subro_mmx: |
207 |
|
mov ecx, [esp + 4] ; Dst |
208 |
|
mov eax, [esp + 8] ; Cur |
209 |
|
push ebx |
210 |
|
mov ebx, [esp+4+12] ; Ref |
211 |
|
mov edx, [esp+4+16] ; Stride |
212 |
|
pxor mm7, mm7 |
213 |
|
|
214 |
|
COPY_8_TO_16_SUB 0, 0 |
215 |
|
COPY_8_TO_16_SUB 1, 0 |
216 |
|
COPY_8_TO_16_SUB 2, 0 |
217 |
|
COPY_8_TO_16_SUB 3, 0 |
218 |
|
|
219 |
|
pop ebx |
220 |
|
ret |
221 |
|
|
222 |
|
|
223 |
|
;----------------------------------------------------------------------------- |
224 |
; |
; |
225 |
; void transfer_8to16sub2_mmx(int16_t * const dct, |
; void transfer_8to16sub2_mmx(int16_t * const dct, |
226 |
; uint8_t * const cur, |
; uint8_t * const cur, |
228 |
; const uint8_t * ref2, |
; const uint8_t * ref2, |
229 |
; const uint32_t stride) |
; const uint32_t stride) |
230 |
; |
; |
231 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
232 |
|
|
233 |
%macro COPY_8_TO_16_SUB2_MMX 1 |
%macro COPY_8_TO_16_SUB2_MMX 1 |
234 |
movq mm0, [eax] ; cur |
movq mm0, [eax] ; cur |
245 |
punpckhbw mm3, mm7 |
punpckhbw mm3, mm7 |
246 |
paddusw mm4, mm1 |
paddusw mm4, mm1 |
247 |
paddusw mm6, mm3 |
paddusw mm6, mm3 |
248 |
|
paddusw mm4, [mmx_one] |
249 |
|
paddusw mm6, [mmx_one] |
250 |
psrlw mm4,1 |
psrlw mm4,1 |
251 |
psrlw mm6,1 |
psrlw mm6,1 |
252 |
packuswb mm4, mm6 |
packuswb mm4, mm6 |
253 |
|
movq [eax], mm4 |
254 |
|
|
255 |
; mm5 <- (ref1+ref2+1) / 2 |
; mm5 <- (ref1+ref2+1) / 2 |
256 |
movq mm5, [ebx+edx] ; ref1 |
movq mm5, [ebx+edx] ; ref1 |
263 |
punpckhbw mm3, mm7 |
punpckhbw mm3, mm7 |
264 |
paddusw mm5, mm1 |
paddusw mm5, mm1 |
265 |
paddusw mm6, mm3 |
paddusw mm6, mm3 |
266 |
|
paddusw mm5, [mmx_one] |
267 |
|
paddusw mm6, [mmx_one] |
268 |
lea esi,[esi+2*edx] |
lea esi,[esi+2*edx] |
269 |
psrlw mm5,1 |
psrlw mm5,1 |
270 |
psrlw mm6,1 |
psrlw mm6,1 |
271 |
packuswb mm5, mm6 |
packuswb mm5, mm6 |
272 |
|
movq [eax+edx], mm5 |
273 |
|
|
274 |
movq mm1, mm0 |
movq mm1, mm0 |
275 |
movq mm3, mm2 |
movq mm3, mm2 |
297 |
movq [ecx+%1*32+24], mm3 |
movq [ecx+%1*32+24], mm3 |
298 |
%endmacro |
%endmacro |
299 |
|
|
300 |
align 16 |
ALIGN 16 |
301 |
transfer_8to16sub2_mmx: |
transfer_8to16sub2_mmx: |
302 |
mov ecx, [esp + 4] ; Dst |
mov ecx, [esp + 4] ; Dst |
303 |
mov eax, [esp + 8] ; Cur |
mov eax, [esp + 8] ; Cur |
317 |
pop ebx |
pop ebx |
318 |
ret |
ret |
319 |
|
|
320 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
321 |
; |
; |
322 |
; void transfer_8to16sub2_xmm(int16_t * const dct, |
; void transfer_8to16sub2_xmm(int16_t * const dct, |
323 |
; uint8_t * const cur, |
; uint8_t * const cur, |
325 |
; const uint8_t * ref2, |
; const uint8_t * ref2, |
326 |
; const uint32_t stride) |
; const uint32_t stride) |
327 |
; |
; |
328 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
329 |
|
|
330 |
%macro COPY_8_TO_16_SUB2_SSE 1 |
%macro COPY_8_TO_16_SUB2_SSE 1 |
331 |
movq mm0, [eax] ; cur |
movq mm0, [eax] ; cur |
337 |
punpcklbw mm2, mm7 |
punpcklbw mm2, mm7 |
338 |
movq mm4, [ebx] ; ref1 |
movq mm4, [ebx] ; ref1 |
339 |
pavgb mm4, [esi] ; ref2 |
pavgb mm4, [esi] ; ref2 |
340 |
|
movq [eax], mm4 |
341 |
punpckhbw mm1, mm7 |
punpckhbw mm1, mm7 |
342 |
punpckhbw mm3, mm7 |
punpckhbw mm3, mm7 |
343 |
movq mm5, [ebx+edx] ; ref |
movq mm5, [ebx+edx] ; ref |
344 |
pavgb mm5, [esi+edx] ; ref2 |
pavgb mm5, [esi+edx] ; ref2 |
345 |
|
movq [eax+edx], mm5 |
346 |
|
|
347 |
movq mm6, mm4 |
movq mm6, mm4 |
348 |
punpcklbw mm4, mm7 |
punpcklbw mm4, mm7 |
364 |
movq [ecx+%1*32+24], mm3 |
movq [ecx+%1*32+24], mm3 |
365 |
%endmacro |
%endmacro |
366 |
|
|
367 |
align 16 |
ALIGN 16 |
368 |
transfer_8to16sub2_xmm: |
transfer_8to16sub2_xmm: |
369 |
mov ecx, [esp + 4] ; Dst |
mov ecx, [esp + 4] ; Dst |
370 |
mov eax, [esp + 8] ; Cur |
mov eax, [esp + 8] ; Cur |
384 |
pop ebx |
pop ebx |
385 |
ret |
ret |
386 |
|
|
387 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
388 |
; |
; |
389 |
; void transfer_16to8add_mmx(uint8_t * const dst, |
; void transfer_16to8add_mmx(uint8_t * const dst, |
390 |
; const int16_t * const src, |
; const int16_t * const src, |
391 |
; uint32_t stride); |
; uint32_t stride); |
392 |
; |
; |
393 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
394 |
|
|
395 |
%macro COPY_16_TO_8_ADD 1 |
%macro COPY_16_TO_8_ADD 1 |
396 |
movq mm0, [ecx] |
movq mm0, [ecx] |
412 |
%endmacro |
%endmacro |
413 |
|
|
414 |
|
|
415 |
align 16 |
ALIGN 16 |
416 |
transfer_16to8add_mmx: |
transfer_16to8add_mmx: |
417 |
mov ecx, [esp+ 4] ; Dst |
mov ecx, [esp+ 4] ; Dst |
418 |
mov eax, [esp+ 8] ; Src |
mov eax, [esp+ 8] ; Src |
428 |
COPY_16_TO_8_ADD 3 |
COPY_16_TO_8_ADD 3 |
429 |
ret |
ret |
430 |
|
|
431 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
432 |
; |
; |
433 |
; void transfer8x8_copy_mmx(uint8_t * const dst, |
; void transfer8x8_copy_mmx(uint8_t * const dst, |
434 |
; const uint8_t * const src, |
; const uint8_t * const src, |
435 |
; const uint32_t stride); |
; const uint32_t stride); |
436 |
; |
; |
437 |
; |
; |
438 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
439 |
|
|
440 |
%macro COPY_8_TO_8 0 |
%macro COPY_8_TO_8 0 |
441 |
movq mm0, [eax] |
movq mm0, [eax] |
445 |
movq [ecx+edx], mm1 |
movq [ecx+edx], mm1 |
446 |
%endmacro |
%endmacro |
447 |
|
|
448 |
align 16 |
ALIGN 16 |
449 |
transfer8x8_copy_mmx: |
transfer8x8_copy_mmx: |
450 |
mov ecx, [esp+ 4] ; Dst |
mov ecx, [esp+ 4] ; Dst |
451 |
mov eax, [esp+ 8] ; Src |
mov eax, [esp+ 8] ; Src |