1 |
;/************************************************************************** |
;/**************************************************************************** |
2 |
; * |
; * |
3 |
; * XVID MPEG-4 VIDEO CODEC |
; * XVID MPEG-4 VIDEO CODEC |
4 |
; * mmx sum of absolute difference |
; * - K7 optimized SAD operators - |
5 |
; * |
; * |
6 |
; * This program is free software; you can redistribute it and/or modify |
; * Copyright(C) 2001 Peter Ross <pross@xvid.org> |
7 |
; * it under the terms of the GNU General Public License as published by |
; * 2002 Pascal Massimino <skal@planet-d.net> |
8 |
|
; * |
9 |
|
; * This program is free software; you can redistribute it and/or modify it |
10 |
|
; * under the terms of the GNU General Public License as published by |
11 |
; * the Free Software Foundation; either version 2 of the License, or |
; * the Free Software Foundation; either version 2 of the License, or |
12 |
; * (at your option) any later version. |
; * (at your option) any later version. |
13 |
; * |
; * |
18 |
; * |
; * |
19 |
; * You should have received a copy of the GNU General Public License |
; * You should have received a copy of the GNU General Public License |
20 |
; * along with this program; if not, write to the Free Software |
; * along with this program; if not, write to the Free Software |
21 |
; * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
; * |
|
|
; *************************************************************************/ |
|
|
|
|
|
;/************************************************************************** |
|
|
; * |
|
|
; * History: |
|
22 |
; * |
; * |
23 |
; * 23.07.2002 sad[16,8]bi_xmm; <pross@xvid.org> |
; * $Id: sad_mmx.asm,v 1.11.2.1 2003-10-28 22:23:03 edgomez Exp $ |
|
; * 04.06.2002 cleanup -Skal- |
|
|
; * 12.11.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
|
24 |
; * |
; * |
25 |
; *************************************************************************/ |
; ***************************************************************************/ |
26 |
|
|
27 |
bits 32 |
BITS 32 |
28 |
|
|
29 |
%macro cglobal 1 |
%macro cglobal 1 |
30 |
%ifdef PREFIX |
%ifdef PREFIX |
35 |
%endif |
%endif |
36 |
%endmacro |
%endmacro |
37 |
|
|
38 |
section .data |
;============================================================================= |
39 |
|
; Read only data |
40 |
align 16 |
;============================================================================= |
41 |
mmx_one times 4 dw 1 |
|
42 |
|
SECTION .rodata |
43 |
section .text |
|
44 |
|
ALIGN 16 |
45 |
cglobal sad16_mmx |
mmx_one: |
46 |
cglobal sad16v_mmx |
times 4 dw 1 |
47 |
cglobal sad8_mmx |
|
48 |
cglobal sad16bi_mmx |
;============================================================================= |
49 |
cglobal sad8bi_mmx |
; Helper macros |
50 |
cglobal dev16_mmx |
;============================================================================= |
|
|
|
|
;=========================================================================== |
|
|
; |
|
|
; uint32_t sad16_mmx(const uint8_t * const cur, |
|
|
; const uint8_t * const ref, |
|
|
; const uint32_t stride, |
|
|
; const uint32_t best_sad); |
|
|
; |
|
|
; (early termination ignore; slows this down) |
|
|
; |
|
|
;=========================================================================== |
|
51 |
|
|
52 |
%macro SAD_16x16_MMX 0 |
%macro SAD_16x16_MMX 0 |
53 |
movq mm0, [eax] |
movq mm0, [eax] |
82 |
paddusw mm6,mm2 |
paddusw mm6,mm2 |
83 |
%endmacro |
%endmacro |
84 |
|
|
85 |
align 16 |
%macro SAD_8x8_MMX 0 |
86 |
|
movq mm0, [eax] |
87 |
|
movq mm1, [edx] |
88 |
|
|
89 |
|
movq mm2, [eax+ecx] |
90 |
|
movq mm3, [edx+ecx] |
91 |
|
|
92 |
|
lea eax,[eax+2*ecx] |
93 |
|
lea edx,[edx+2*ecx] |
94 |
|
|
95 |
|
movq mm4, mm0 |
96 |
|
psubusb mm0, mm1 |
97 |
|
movq mm5, mm2 |
98 |
|
psubusb mm2, mm3 |
99 |
|
|
100 |
|
psubusb mm1, mm4 |
101 |
|
por mm0, mm1 |
102 |
|
psubusb mm3, mm5 |
103 |
|
por mm2, mm3 |
104 |
|
|
105 |
|
movq mm1,mm0 |
106 |
|
movq mm3,mm2 |
107 |
|
|
108 |
|
punpcklbw mm0,mm7 |
109 |
|
punpckhbw mm1,mm7 |
110 |
|
punpcklbw mm2,mm7 |
111 |
|
punpckhbw mm3,mm7 |
112 |
|
|
113 |
|
paddusw mm0,mm1 |
114 |
|
paddusw mm6,mm0 |
115 |
|
paddusw mm2,mm3 |
116 |
|
paddusw mm6,mm2 |
117 |
|
%endmacro |
118 |
|
|
119 |
|
%macro SADV_16x16_MMX 0 |
120 |
|
movq mm0, [eax] |
121 |
|
movq mm1, [edx] |
122 |
|
|
123 |
|
movq mm2, [eax+8] |
124 |
|
movq mm3, [edx+8] |
125 |
|
|
126 |
|
movq mm4, mm0 |
127 |
|
psubusb mm0, mm1 |
128 |
|
|
129 |
|
psubusb mm1, mm4 |
130 |
|
por mm0, mm1 |
131 |
|
lea eax,[eax+ecx] |
132 |
|
|
133 |
|
movq mm4, mm2 |
134 |
|
psubusb mm2, mm3 |
135 |
|
|
136 |
|
psubusb mm3, mm4 |
137 |
|
por mm2, mm3 |
138 |
|
lea edx,[edx+ecx] |
139 |
|
|
140 |
|
movq mm1,mm0 |
141 |
|
movq mm3,mm2 |
142 |
|
|
143 |
|
punpcklbw mm0,mm7 |
144 |
|
punpckhbw mm1,mm7 |
145 |
|
punpcklbw mm2,mm7 |
146 |
|
punpckhbw mm3,mm7 |
147 |
|
|
148 |
|
paddusw mm0,mm1 |
149 |
|
paddusw mm2,mm3 |
150 |
|
|
151 |
|
paddusw mm5, mm0 |
152 |
|
paddusw mm6, mm2 |
153 |
|
%endmacro |
154 |
|
|
155 |
|
%macro SADBI_16x16_MMX 2 ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr ); |
156 |
|
|
157 |
|
movq mm0, [edx+%1] |
158 |
|
movq mm2, [ebx+%1] |
159 |
|
movq mm1, mm0 |
160 |
|
movq mm3, mm2 |
161 |
|
|
162 |
|
%if %2 != 0 |
163 |
|
add edx, ecx |
164 |
|
%endif |
165 |
|
|
166 |
|
punpcklbw mm0, mm7 |
167 |
|
punpckhbw mm1, mm7 |
168 |
|
punpcklbw mm2, mm7 |
169 |
|
punpckhbw mm3, mm7 |
170 |
|
|
171 |
|
%if %2 != 0 |
172 |
|
add ebx, ecx |
173 |
|
%endif |
174 |
|
|
175 |
|
paddusw mm0, mm2 ; mm01 = ref1 + ref2 |
176 |
|
paddusw mm1, mm3 |
177 |
|
paddusw mm0, [mmx_one] ; mm01 += 1 |
178 |
|
paddusw mm1, [mmx_one] |
179 |
|
psrlw mm0, 1 ; mm01 >>= 1 |
180 |
|
psrlw mm1, 1 |
181 |
|
|
182 |
|
movq mm2, [eax+%1] |
183 |
|
movq mm3, mm2 |
184 |
|
punpcklbw mm2, mm7 ; mm23 = src |
185 |
|
punpckhbw mm3, mm7 |
186 |
|
|
187 |
|
%if %2 != 0 |
188 |
|
add eax, ecx |
189 |
|
%endif |
190 |
|
|
191 |
|
movq mm4, mm0 |
192 |
|
movq mm5, mm1 |
193 |
|
psubusw mm0, mm2 |
194 |
|
psubusw mm1, mm3 |
195 |
|
psubusw mm2, mm4 |
196 |
|
psubusw mm3, mm5 |
197 |
|
por mm0, mm2 ; mm01 = ABS(mm01 - mm23) |
198 |
|
por mm1, mm3 |
199 |
|
|
200 |
|
paddusw mm6, mm0 ; mm6 += mm01 |
201 |
|
paddusw mm6, mm1 |
202 |
|
|
203 |
|
%endmacro |
204 |
|
|
205 |
|
%macro MEAN_16x16_MMX 0 |
206 |
|
movq mm0, [eax] |
207 |
|
movq mm2, [eax+8] |
208 |
|
lea eax, [eax+ecx] |
209 |
|
movq mm1, mm0 |
210 |
|
movq mm3, mm2 |
211 |
|
punpcklbw mm0, mm7 |
212 |
|
punpcklbw mm2, mm7 |
213 |
|
punpckhbw mm1, mm7 |
214 |
|
punpckhbw mm3, mm7 |
215 |
|
paddw mm5, mm0 |
216 |
|
paddw mm6, mm1 |
217 |
|
paddw mm5, mm2 |
218 |
|
paddw mm6, mm3 |
219 |
|
%endmacro |
220 |
|
|
221 |
|
%macro ABS_16x16_MMX 0 |
222 |
|
movq mm0, [eax] |
223 |
|
movq mm2, [eax+8] |
224 |
|
lea eax, [eax+ecx] |
225 |
|
movq mm1, mm0 |
226 |
|
movq mm3, mm2 |
227 |
|
punpcklbw mm0, mm7 |
228 |
|
punpcklbw mm2, mm7 |
229 |
|
punpckhbw mm1, mm7 |
230 |
|
punpckhbw mm3, mm7 |
231 |
|
movq mm4, mm6 |
232 |
|
psubusw mm4, mm0 |
233 |
|
|
234 |
|
psubusw mm0, mm6 |
235 |
|
por mm0, mm4 |
236 |
|
movq mm4, mm6 |
237 |
|
psubusw mm4, mm1 |
238 |
|
psubusw mm1, mm6 |
239 |
|
por mm1, mm4 |
240 |
|
|
241 |
|
movq mm4, mm6 |
242 |
|
psubusw mm4, mm2 |
243 |
|
psubusw mm2, mm6 |
244 |
|
por mm2, mm4 |
245 |
|
movq mm4, mm6 |
246 |
|
psubusw mm4, mm3 |
247 |
|
psubusw mm3, mm6 |
248 |
|
por mm3, mm4 |
249 |
|
|
250 |
|
paddw mm0, mm1 |
251 |
|
paddw mm2, mm3 |
252 |
|
paddw mm5, mm0 |
253 |
|
paddw mm5, mm2 |
254 |
|
%endmacro |
255 |
|
|
256 |
|
;============================================================================= |
257 |
|
; Code |
258 |
|
;============================================================================= |
259 |
|
|
260 |
|
SECTION .text |
261 |
|
|
262 |
|
cglobal sad16_mmx |
263 |
|
cglobal sad16v_mmx |
264 |
|
cglobal sad8_mmx |
265 |
|
cglobal sad16bi_mmx |
266 |
|
cglobal sad8bi_mmx |
267 |
|
cglobal dev16_mmx |
268 |
|
|
269 |
|
;----------------------------------------------------------------------------- |
270 |
|
; |
271 |
|
; uint32_t sad16_mmx(const uint8_t * const cur, |
272 |
|
; const uint8_t * const ref, |
273 |
|
; const uint32_t stride, |
274 |
|
; const uint32_t best_sad); |
275 |
|
; |
276 |
|
; (early termination ignore; slows this down) |
277 |
|
; |
278 |
|
;----------------------------------------------------------------------------- |
279 |
|
|
280 |
|
ALIGN 16 |
281 |
sad16_mmx: |
sad16_mmx: |
282 |
|
|
283 |
mov eax, [esp+ 4] ; Src1 |
mov eax, [esp+ 4] ; Src1 |
314 |
|
|
315 |
ret |
ret |
316 |
|
|
317 |
|
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
318 |
; |
; |
319 |
; uint32_t sad8_mmx(const uint8_t * const cur, |
; uint32_t sad8_mmx(const uint8_t * const cur, |
320 |
; const uint8_t * const ref, |
; const uint8_t * const ref, |
321 |
; const uint32_t stride); |
; const uint32_t stride); |
322 |
; |
; |
323 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
|
|
|
%macro SAD_8x8_MMX 0 |
|
|
movq mm0, [eax] |
|
|
movq mm1, [edx] |
|
|
|
|
|
movq mm2, [eax+ecx] |
|
|
movq mm3, [edx+ecx] |
|
|
|
|
|
lea eax,[eax+2*ecx] |
|
|
lea edx,[edx+2*ecx] |
|
|
|
|
|
movq mm4, mm0 |
|
|
psubusb mm0, mm1 |
|
|
movq mm5, mm2 |
|
|
psubusb mm2, mm3 |
|
|
|
|
|
psubusb mm1, mm4 |
|
|
por mm0, mm1 |
|
|
psubusb mm3, mm5 |
|
|
por mm2, mm3 |
|
|
|
|
|
movq mm1,mm0 |
|
|
movq mm3,mm2 |
|
|
|
|
|
punpcklbw mm0,mm7 |
|
|
punpckhbw mm1,mm7 |
|
|
punpcklbw mm2,mm7 |
|
|
punpckhbw mm3,mm7 |
|
|
|
|
|
paddusw mm0,mm1 |
|
|
paddusw mm6,mm0 |
|
|
paddusw mm2,mm3 |
|
|
paddusw mm6,mm2 |
|
|
%endmacro |
|
324 |
|
|
325 |
align 16 |
ALIGN 16 |
326 |
sad8_mmx: |
sad8_mmx: |
327 |
|
|
328 |
mov eax, [esp+ 4] ; Src1 |
mov eax, [esp+ 4] ; Src1 |
346 |
|
|
347 |
ret |
ret |
348 |
|
|
349 |
|
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
350 |
; |
; |
351 |
; uint32_t sad16v_mmx(const uint8_t * const cur, |
; uint32_t sad16v_mmx(const uint8_t * const cur, |
352 |
; const uint8_t * const ref, |
; const uint8_t * const ref, |
353 |
; const uint32_t stride, |
; const uint32_t stride, |
354 |
; int32_t *sad); |
; int32_t *sad); |
355 |
; |
; |
356 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
357 |
|
|
358 |
%macro SADV_16x16_MMX 0 |
ALIGN 16 |
|
movq mm0, [eax] |
|
|
movq mm1, [edx] |
|
|
|
|
|
movq mm2, [eax+8] |
|
|
movq mm3, [edx+8] |
|
|
|
|
|
movq mm4, mm0 |
|
|
psubusb mm0, mm1 |
|
|
|
|
|
psubusb mm1, mm4 |
|
|
por mm0, mm1 |
|
|
lea eax,[eax+ecx] |
|
|
|
|
|
movq mm4, mm2 |
|
|
psubusb mm2, mm3 |
|
|
|
|
|
psubusb mm3, mm4 |
|
|
por mm2, mm3 |
|
|
lea edx,[edx+ecx] |
|
|
|
|
|
movq mm1,mm0 |
|
|
movq mm3,mm2 |
|
|
|
|
|
punpcklbw mm0,mm7 |
|
|
punpckhbw mm1,mm7 |
|
|
punpcklbw mm2,mm7 |
|
|
punpckhbw mm3,mm7 |
|
|
|
|
|
paddusw mm0,mm1 |
|
|
paddusw mm2,mm3 |
|
|
|
|
|
paddusw mm5, mm0 |
|
|
paddusw mm6, mm2 |
|
|
%endmacro |
|
|
|
|
|
align 16 |
|
359 |
sad16v_mmx: |
sad16v_mmx: |
360 |
|
|
361 |
push ebx |
push ebx |
433 |
|
|
434 |
pop edi |
pop edi |
435 |
pop ebx |
pop ebx |
|
ret |
|
|
|
|
436 |
|
|
437 |
|
ret |
438 |
|
|
439 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
440 |
; |
; |
441 |
; uint32_t sad16bi_mmx(const uint8_t * const cur, |
; uint32_t sad16bi_mmx(const uint8_t * const cur, |
442 |
; const uint8_t * const ref1, |
; const uint8_t * const ref1, |
443 |
; const uint8_t * const ref2, |
; const uint8_t * const ref2, |
444 |
; const uint32_t stride); |
; const uint32_t stride); |
445 |
; |
; |
446 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
%macro SADBI_16x16_MMX 2 ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr ); |
|
|
|
|
|
movq mm0, [edx+%1] |
|
|
movq mm2, [ebx+%1] |
|
|
movq mm1, mm0 |
|
|
movq mm3, mm2 |
|
|
|
|
|
%if %2 != 0 |
|
|
add edx, ecx |
|
|
%endif |
|
|
|
|
|
punpcklbw mm0, mm7 |
|
|
punpckhbw mm1, mm7 |
|
|
punpcklbw mm2, mm7 |
|
|
punpckhbw mm3, mm7 |
|
447 |
|
|
448 |
%if %2 != 0 |
ALIGN 16 |
|
add ebx, ecx |
|
|
%endif |
|
|
|
|
|
paddusw mm0, mm2 ; mm01 = ref1 + ref2 |
|
|
paddusw mm1, mm3 |
|
|
paddusw mm0, [mmx_one] ; mm01 += 1 |
|
|
paddusw mm1, [mmx_one] |
|
|
psrlw mm0, 1 ; mm01 >>= 1 |
|
|
psrlw mm1, 1 |
|
|
|
|
|
movq mm2, [eax+%1] |
|
|
movq mm3, mm2 |
|
|
punpcklbw mm2, mm7 ; mm23 = src |
|
|
punpckhbw mm3, mm7 |
|
|
|
|
|
%if %2 != 0 |
|
|
add eax, ecx |
|
|
%endif |
|
|
|
|
|
movq mm4, mm0 |
|
|
movq mm5, mm1 |
|
|
psubusw mm0, mm2 |
|
|
psubusw mm1, mm3 |
|
|
psubusw mm2, mm4 |
|
|
psubusw mm3, mm5 |
|
|
por mm0, mm2 ; mm01 = ABS(mm01 - mm23) |
|
|
por mm1, mm3 |
|
|
|
|
|
paddusw mm6,mm0 ; mm6 += mm01 |
|
|
paddusw mm6,mm1 |
|
|
|
|
|
%endmacro |
|
|
|
|
|
align 16 |
|
449 |
sad16bi_mmx: |
sad16bi_mmx: |
450 |
push ebx |
push ebx |
451 |
mov eax, [esp+4+ 4] ; Src |
mov eax, [esp+4+ 4] ; Src |
497 |
|
|
498 |
movd eax, mm6 |
movd eax, mm6 |
499 |
pop ebx |
pop ebx |
500 |
|
|
501 |
ret |
ret |
502 |
|
|
503 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
504 |
; |
; |
505 |
; uint32_t sad8bi_mmx(const uint8_t * const cur, |
; uint32_t sad8bi_mmx(const uint8_t * const cur, |
506 |
; const uint8_t * const ref1, |
; const uint8_t * const ref1, |
507 |
; const uint8_t * const ref2, |
; const uint8_t * const ref2, |
508 |
; const uint32_t stride); |
; const uint32_t stride); |
509 |
; |
; |
510 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
511 |
align 16 |
|
512 |
|
ALIGN 16 |
513 |
sad8bi_mmx: |
sad8bi_mmx: |
514 |
push ebx |
push ebx |
515 |
mov eax, [esp+4+ 4] ; Src |
mov eax, [esp+4+ 4] ; Src |
538 |
pop ebx |
pop ebx |
539 |
ret |
ret |
540 |
|
|
541 |
|
;----------------------------------------------------------------------------- |
|
|
|
|
|
|
|
;=========================================================================== |
|
542 |
; |
; |
543 |
; uint32_t dev16_mmx(const uint8_t * const cur, |
; uint32_t dev16_mmx(const uint8_t * const cur, |
544 |
; const uint32_t stride); |
; const uint32_t stride); |
545 |
; |
; |
546 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
|
|
|
%macro MEAN_16x16_MMX 0 |
|
|
movq mm0, [eax] |
|
|
movq mm2, [eax+8] |
|
|
lea eax,[eax+ecx] |
|
|
movq mm1, mm0 |
|
|
movq mm3, mm2 |
|
|
punpcklbw mm0,mm7 |
|
|
punpcklbw mm2,mm7 |
|
|
punpckhbw mm1,mm7 |
|
|
punpckhbw mm3,mm7 |
|
|
paddw mm5, mm0 |
|
|
paddw mm6, mm1 |
|
|
paddw mm5, mm2 |
|
|
paddw mm6, mm3 |
|
|
%endmacro |
|
547 |
|
|
548 |
%macro ABS_16x16_MMX 0 |
ALIGN 16 |
|
movq mm0, [eax] |
|
|
movq mm2, [eax+8] |
|
|
lea eax,[eax+ecx] |
|
|
movq mm1, mm0 |
|
|
movq mm3, mm2 |
|
|
punpcklbw mm0, mm7 |
|
|
punpcklbw mm2, mm7 |
|
|
punpckhbw mm1, mm7 |
|
|
punpckhbw mm3, mm7 |
|
|
movq mm4, mm6 |
|
|
psubusw mm4, mm0 |
|
|
|
|
|
psubusw mm0, mm6 |
|
|
por mm0, mm4 |
|
|
movq mm4, mm6 |
|
|
psubusw mm4, mm1 |
|
|
psubusw mm1, mm6 |
|
|
por mm1, mm4 |
|
|
|
|
|
movq mm4, mm6 |
|
|
psubusw mm4, mm2 |
|
|
psubusw mm2, mm6 |
|
|
por mm2, mm4 |
|
|
movq mm4, mm6 |
|
|
psubusw mm4, mm3 |
|
|
psubusw mm3, mm6 |
|
|
por mm3, mm4 |
|
|
|
|
|
paddw mm0, mm1 |
|
|
paddw mm2, mm3 |
|
|
paddw mm5, mm0 |
|
|
paddw mm5, mm2 |
|
|
%endmacro |
|
|
|
|
|
align 16 |
|
549 |
dev16_mmx: |
dev16_mmx: |
550 |
mov eax, [esp+ 4] ; Src |
mov eax, [esp+ 4] ; Src |
551 |
mov ecx, [esp+ 8] ; Stride |
mov ecx, [esp+ 8] ; Stride |
614 |
paddd mm6, mm5 |
paddd mm6, mm5 |
615 |
|
|
616 |
movd eax, mm6 |
movd eax, mm6 |
617 |
|
|
618 |
ret |
ret |