1 |
;/************************************************************************** |
;/**************************************************************************** |
2 |
; * |
; * |
3 |
; * XVID MPEG-4 VIDEO CODEC |
; * XVID MPEG-4 VIDEO CODEC |
4 |
; * xmm sum of absolute difference |
; * - K7 optimized SAD operators - |
5 |
; * |
; * |
6 |
; * This program is an implementation of a part of one or more MPEG-4 |
; * Copyright(C) 2001 Peter Ross <pross@xvid.org> |
7 |
; * Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
; * 2001 Michael Militzer <isibaar@xvid.org> |
8 |
; * to use this software module in hardware or software products are |
; * 2002 Pascal Massimino <skal@planet-d.net> |
|
; * advised that its use may infringe existing patents or copyrights, and |
|
|
; * any such use would be at such party's own risk. The original |
|
|
; * developer of this software module and his/her company, and subsequent |
|
|
; * editors and their companies, will have no liability for use of this |
|
|
; * software or modifications or derivatives thereof. |
|
9 |
; * |
; * |
10 |
; * This program is free software; you can redistribute it and/or modify |
; * This program is free software; you can redistribute it and/or modify it |
11 |
; * it under the terms of the GNU General Public License as published by |
; * 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 |
; * |
; * |
19 |
; * |
; * |
20 |
; * You should have received a copy of the GNU General Public License |
; * You should have received a copy of the GNU General Public License |
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., 675 Mass Ave, Cambridge, MA 02139, USA. |
; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
; * |
; * |
24 |
; *************************************************************************/ |
; * $Id$ |
|
|
|
|
;/************************************************************************** |
|
|
; * |
|
|
; * History: |
|
|
; * |
|
|
; * 23.07.2002 sad8bi_xmm; <pross@xvid.org> |
|
|
; * 04.06.2002 rewrote some funcs (XMM mainly) -Skal- |
|
|
; * 17.11.2001 bugfix and small improvement for dev16_xmm, |
|
|
; * removed terminate early in sad16_xmm (Isibaar) |
|
|
; * 12.11.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
|
25 |
; * |
; * |
26 |
; *************************************************************************/ |
; ***************************************************************************/ |
27 |
|
|
28 |
bits 32 |
BITS 32 |
29 |
|
|
30 |
%macro cglobal 1 |
%macro cglobal 1 |
31 |
%ifdef PREFIX |
%ifdef PREFIX |
32 |
|
%ifdef MARK_FUNCS |
33 |
|
global _%1:function |
34 |
|
%define %1 _%1:function |
35 |
|
%else |
36 |
global _%1 |
global _%1 |
37 |
%define %1 _%1 |
%define %1 _%1 |
38 |
|
%endif |
39 |
|
%else |
40 |
|
%ifdef MARK_FUNCS |
41 |
|
global %1:function |
42 |
%else |
%else |
43 |
global %1 |
global %1 |
44 |
%endif |
%endif |
45 |
|
%endif |
46 |
|
%endmacro |
47 |
|
|
48 |
|
;============================================================================= |
49 |
|
; Read only data |
50 |
|
;============================================================================= |
51 |
|
|
52 |
|
%ifdef FORMAT_COFF |
53 |
|
SECTION .rodata |
54 |
|
%else |
55 |
|
SECTION .rodata align=16 |
56 |
|
%endif |
57 |
|
|
58 |
|
ALIGN 16 |
59 |
|
mmx_one: times 4 dw 1 |
60 |
|
|
61 |
|
;============================================================================= |
62 |
|
; Helper macros |
63 |
|
;============================================================================= |
64 |
|
|
65 |
|
%macro SAD_16x16_SSE 0 |
66 |
|
movq mm0, [eax] |
67 |
|
psadbw mm0, [edx] |
68 |
|
movq mm1, [eax+8] |
69 |
|
add eax, ecx |
70 |
|
psadbw mm1, [edx+8] |
71 |
|
paddusw mm5, mm0 |
72 |
|
add edx, ecx |
73 |
|
paddusw mm6, mm1 |
74 |
|
%endmacro |
75 |
|
|
76 |
|
%macro SAD_8x8_SSE 0 |
77 |
|
movq mm0, [eax] |
78 |
|
movq mm1, [eax+ecx] |
79 |
|
psadbw mm0, [edx] |
80 |
|
psadbw mm1, [edx+ecx] |
81 |
|
add eax, ebx |
82 |
|
add edx, ebx |
83 |
|
paddusw mm5, mm0 |
84 |
|
paddusw mm6, mm1 |
85 |
|
%endmacro |
86 |
|
|
87 |
|
%macro SADBI_16x16_SSE 0 |
88 |
|
movq mm0, [eax] |
89 |
|
movq mm1, [eax+8] |
90 |
|
movq mm2, [edx] |
91 |
|
movq mm3, [edx+8] |
92 |
|
pavgb mm2, [ebx] |
93 |
|
add edx, ecx |
94 |
|
pavgb mm3, [ebx+8] |
95 |
|
add ebx, ecx |
96 |
|
psadbw mm0, mm2 |
97 |
|
add eax, ecx |
98 |
|
psadbw mm1, mm3 |
99 |
|
paddusw mm5, mm0 |
100 |
|
paddusw mm6, mm1 |
101 |
|
%endmacro |
102 |
|
|
103 |
|
%macro SADBI_8x8_XMM 0 |
104 |
|
movq mm0, [eax] |
105 |
|
movq mm1, [eax+ecx] |
106 |
|
movq mm2, [edx] |
107 |
|
movq mm3, [edx+ecx] |
108 |
|
pavgb mm2, [ebx] |
109 |
|
lea edx, [edx+2*ecx] |
110 |
|
pavgb mm3, [ebx+ecx] |
111 |
|
lea ebx, [ebx+2*ecx] |
112 |
|
psadbw mm0, mm2 |
113 |
|
lea eax, [eax+2*ecx] |
114 |
|
psadbw mm1, mm3 |
115 |
|
paddusw mm5, mm0 |
116 |
|
paddusw mm6, mm1 |
117 |
|
%endmacro |
118 |
|
|
119 |
|
%macro MEAN_16x16_SSE 0 |
120 |
|
movq mm0, [eax] |
121 |
|
movq mm1, [eax+8] |
122 |
|
psadbw mm0, mm7 |
123 |
|
psadbw mm1, mm7 |
124 |
|
add eax, ecx |
125 |
|
paddw mm5, mm0 |
126 |
|
paddw mm6, mm1 |
127 |
%endmacro |
%endmacro |
128 |
|
|
129 |
section .data |
%macro ABS_16x16_SSE 0 |
130 |
|
movq mm0, [eax] |
131 |
|
movq mm1, [eax+8] |
132 |
|
psadbw mm0, mm4 |
133 |
|
psadbw mm1, mm4 |
134 |
|
lea eax, [eax+ecx] |
135 |
|
paddw mm5, mm0 |
136 |
|
paddw mm6, mm1 |
137 |
|
%endmacro |
138 |
|
|
139 |
align 16 |
;============================================================================= |
140 |
mmx_one times 4 dw 1 |
; Code |
141 |
|
;============================================================================= |
142 |
|
|
143 |
section .text |
SECTION .text |
144 |
|
|
145 |
cglobal sad16_xmm |
cglobal sad16_xmm |
146 |
cglobal sad8_xmm |
cglobal sad8_xmm |
147 |
cglobal sad16bi_xmm |
cglobal sad16bi_xmm |
148 |
cglobal sad8bi_xmm |
cglobal sad8bi_xmm |
149 |
cglobal dev16_xmm |
cglobal dev16_xmm |
150 |
|
cglobal sad16v_xmm |
151 |
|
|
152 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
153 |
; |
; |
154 |
; uint32_t sad16_xmm(const uint8_t * const cur, |
; uint32_t sad16_xmm(const uint8_t * const cur, |
155 |
; const uint8_t * const ref, |
; const uint8_t * const ref, |
156 |
; const uint32_t stride, |
; const uint32_t stride, |
157 |
; const uint32_t best_sad); |
; const uint32_t best_sad); |
158 |
; |
; |
159 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
|
|
|
%macro SAD_16x16_SSE 0 |
|
|
movq mm0, [eax] |
|
|
psadbw mm0, [edx] |
|
|
movq mm1, [eax+8] |
|
|
add eax, ecx |
|
|
psadbw mm1, [edx+8] |
|
|
paddusw mm5,mm0 |
|
|
add edx, ecx |
|
|
paddusw mm6,mm1 |
|
|
%endmacro |
|
160 |
|
|
161 |
align 16 |
ALIGN 16 |
162 |
sad16_xmm: |
sad16_xmm: |
163 |
|
|
164 |
mov eax, [esp+ 4] ; Src1 |
mov eax, [esp+ 4] ; Src1 |
191 |
ret |
ret |
192 |
|
|
193 |
|
|
194 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
195 |
; |
; |
196 |
; uint32_t sad8_xmm(const uint8_t * const cur, |
; uint32_t sad8_xmm(const uint8_t * const cur, |
197 |
; const uint8_t * const ref, |
; const uint8_t * const ref, |
198 |
; const uint32_t stride); |
; const uint32_t stride); |
199 |
; |
; |
200 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
201 |
|
|
202 |
%macro SAD_8x8_SSE 0 |
ALIGN 16 |
|
movq mm0, [eax] |
|
|
movq mm1, [eax+ecx] |
|
|
|
|
|
psadbw mm0, [edx] |
|
|
psadbw mm1, [edx+ecx] |
|
|
add eax, ebx |
|
|
add edx, ebx |
|
|
|
|
|
paddusw mm5,mm0 |
|
|
paddusw mm6,mm1 |
|
|
%endmacro |
|
|
|
|
|
align 16 |
|
203 |
sad8_xmm: |
sad8_xmm: |
204 |
|
|
205 |
mov eax, [esp+ 4] ; Src1 |
mov eax, [esp+ 4] ; Src1 |
231 |
ret |
ret |
232 |
|
|
233 |
|
|
234 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
235 |
; |
; |
236 |
; uint32_t sad16bi_xmm(const uint8_t * const cur, |
; uint32_t sad16bi_xmm(const uint8_t * const cur, |
237 |
; const uint8_t * const ref1, |
; const uint8_t * const ref1, |
238 |
; const uint8_t * const ref2, |
; const uint8_t * const ref2, |
239 |
; const uint32_t stride); |
; const uint32_t stride); |
240 |
; |
; |
241 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
|
|
|
%macro SADBI_16x16_SSE 0 |
|
|
movq mm0, [eax] |
|
|
movq mm1, [eax+8] |
|
242 |
|
|
243 |
movq mm2, [edx] |
ALIGN 16 |
|
movq mm3, [edx+8] |
|
|
|
|
|
pavgb mm2, [ebx] |
|
|
add edx, ecx |
|
|
|
|
|
pavgb mm3, [ebx+8] |
|
|
add ebx, ecx |
|
|
|
|
|
psadbw mm0, mm2 |
|
|
add eax, ecx |
|
|
|
|
|
psadbw mm1, mm3 |
|
|
paddusw mm5,mm0 |
|
|
|
|
|
paddusw mm6,mm1 |
|
|
%endmacro |
|
|
|
|
|
align 16 |
|
244 |
sad16bi_xmm: |
sad16bi_xmm: |
245 |
push ebx |
push ebx |
246 |
mov eax, [esp+4+ 4] ; Src |
mov eax, [esp+4+ 4] ; Src |
274 |
pop ebx |
pop ebx |
275 |
ret |
ret |
276 |
|
|
277 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
278 |
; |
; |
279 |
; uint32_t sad8bi_xmm(const uint8_t * const cur, |
; uint32_t sad8bi_xmm(const uint8_t * const cur, |
280 |
; const uint8_t * const ref1, |
; const uint8_t * const ref1, |
281 |
; const uint8_t * const ref2, |
; const uint8_t * const ref2, |
282 |
; const uint32_t stride); |
; const uint32_t stride); |
283 |
; |
; |
284 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
|
|
|
%macro SADBI_8x8_XMM 0 |
|
|
movq mm0, [eax] |
|
|
movq mm1, [eax+ecx] |
|
|
|
|
|
movq mm2, [edx] |
|
|
movq mm3, [edx+ecx] |
|
|
|
|
|
pavgb mm2, [ebx] |
|
|
lea edx, [edx+2*ecx] |
|
|
|
|
|
pavgb mm3, [ebx+ecx] |
|
|
lea ebx, [ebx+2*ecx] |
|
|
|
|
|
psadbw mm0, mm2 |
|
|
lea eax, [eax+2*ecx] |
|
285 |
|
|
286 |
psadbw mm1, mm3 |
ALIGN 16 |
|
paddusw mm5,mm0 |
|
|
|
|
|
paddusw mm6,mm1 |
|
|
%endmacro |
|
|
|
|
|
align 16 |
|
287 |
sad8bi_xmm: |
sad8bi_xmm: |
288 |
push ebx |
push ebx |
289 |
mov eax, [esp+4+ 4] ; Src |
mov eax, [esp+4+ 4] ; Src |
305 |
ret |
ret |
306 |
|
|
307 |
|
|
308 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
309 |
; |
; |
310 |
; uint32_t dev16_xmm(const uint8_t * const cur, |
; uint32_t dev16_xmm(const uint8_t * const cur, |
311 |
; const uint32_t stride); |
; const uint32_t stride); |
312 |
; |
; |
313 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
|
|
|
%macro MEAN_16x16_SSE 0 |
|
|
movq mm0, [eax] |
|
|
movq mm1, [eax+8] |
|
|
psadbw mm0, mm7 |
|
|
psadbw mm1, mm7 |
|
|
add eax, ecx |
|
|
paddw mm5, mm0 |
|
|
paddw mm6, mm1 |
|
|
%endmacro |
|
314 |
|
|
315 |
%macro ABS_16x16_SSE 0 |
ALIGN 16 |
|
movq mm0, [eax] |
|
|
movq mm1, [eax+8] |
|
|
psadbw mm0, mm4 |
|
|
psadbw mm1, mm4 |
|
|
lea eax,[eax+ecx] |
|
|
paddw mm5, mm0 |
|
|
paddw mm6, mm1 |
|
|
%endmacro |
|
|
|
|
|
align 16 |
|
316 |
dev16_xmm: |
dev16_xmm: |
317 |
|
|
318 |
mov eax, [esp+ 4] ; Src |
mov eax, [esp+ 4] ; Src |
384 |
movd eax, mm6 |
movd eax, mm6 |
385 |
ret |
ret |
386 |
|
|
387 |
cglobal sad16v_xmm |
;----------------------------------------------------------------------------- |
|
|
|
|
;=========================================================================== |
|
388 |
;int sad16v_xmm(const uint8_t * const cur, |
;int sad16v_xmm(const uint8_t * const cur, |
389 |
; const uint8_t * const ref, |
; const uint8_t * const ref, |
390 |
; const uint32_t stride, |
; const uint32_t stride, |
391 |
; int* sad8); |
; int* sad8); |
392 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
393 |
align 16 |
|
394 |
|
ALIGN 16 |
395 |
sad16v_xmm: |
sad16v_xmm: |
396 |
push ebx |
push ebx |
397 |
mov eax, [esp+4+ 4] ; Src1 |
mov eax, [esp+4+ 4] ; Src1 |
402 |
pxor mm5, mm5 ; accum1 |
pxor mm5, mm5 ; accum1 |
403 |
pxor mm6, mm6 ; accum2 |
pxor mm6, mm6 ; accum2 |
404 |
pxor mm7, mm7 ; total |
pxor mm7, mm7 ; total |
405 |
|
|
406 |
SAD_16x16_SSE |
SAD_16x16_SSE |
407 |
SAD_16x16_SSE |
SAD_16x16_SSE |
408 |
SAD_16x16_SSE |
SAD_16x16_SSE |
411 |
SAD_16x16_SSE |
SAD_16x16_SSE |
412 |
SAD_16x16_SSE |
SAD_16x16_SSE |
413 |
SAD_16x16_SSE |
SAD_16x16_SSE |
414 |
|
|
415 |
paddusw mm7, mm5 |
paddusw mm7, mm5 |
416 |
paddusw mm7, mm6 |
paddusw mm7, mm6 |
417 |
movd [ebx], mm5 |
movd [ebx], mm5 |
419 |
|
|
420 |
pxor mm5, mm5 ; accum1 |
pxor mm5, mm5 ; accum1 |
421 |
pxor mm6, mm6 ; accum2 |
pxor mm6, mm6 ; accum2 |
422 |
|
|
423 |
SAD_16x16_SSE |
SAD_16x16_SSE |
424 |
SAD_16x16_SSE |
SAD_16x16_SSE |
425 |
SAD_16x16_SSE |
SAD_16x16_SSE |
428 |
SAD_16x16_SSE |
SAD_16x16_SSE |
429 |
SAD_16x16_SSE |
SAD_16x16_SSE |
430 |
SAD_16x16_SSE |
SAD_16x16_SSE |
431 |
|
|
432 |
paddusw mm7, mm5 |
paddusw mm7, mm5 |
433 |
paddusw mm7, mm6 |
paddusw mm7, mm6 |
434 |
movd [ebx+8], mm5 |
movd [ebx+8], mm5 |
437 |
movd eax, mm7 |
movd eax, mm7 |
438 |
pop ebx |
pop ebx |
439 |
ret |
ret |
|
;-------- |
|
|
|
|
|
|
|