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 |
; * Copyright(C) 2002 Peter Ross <pross@xvid.org> |
; * Copyright(C) 2001 Peter Ross <pross@xvid.org> |
7 |
|
; * 2002 Pascal Massimino <skal@planet-d.net> |
8 |
; * |
; * |
9 |
; * This program is an implementation of a part of one or more MPEG-4 |
; * This program is free software; you can redistribute it and/or modify it |
10 |
; * Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
; * under the terms of the GNU General Public License as published by |
|
; * to use this software module in hardware or software products are |
|
|
; * 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. |
|
|
; * |
|
|
; * This program is free software; you can redistribute it and/or modify |
|
|
; * it 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 |
; * |
; * |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 |
; * |
; * |
23 |
, ****************************************************************************/ |
; * $Id: sad_mmx.asm,v 1.11.2.1 2003-10-28 22:23:03 edgomez Exp $ |
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 sad8_mmx |
times 4 dw 1 |
47 |
cglobal sad16bi_mmx |
|
48 |
cglobal sad8bi_mmx |
;============================================================================= |
49 |
cglobal dev16_mmx |
; Helper macros |
50 |
|
;============================================================================= |
|
;=========================================================================== |
|
|
; |
|
|
; 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 |
|
|
|
align 16 |
|
|
sad16_mmx: |
|
|
|
|
|
mov eax, [esp+ 4] ; Src1 |
|
|
mov edx, [esp+ 8] ; Src2 |
|
|
mov ecx, [esp+12] ; Stride |
|
|
|
|
|
pxor mm6, mm6 ; accum |
|
|
pxor mm7, mm7 ; zero |
|
|
|
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
|
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
SAD_16x16_MMX |
|
|
|
|
|
pmaddwd mm6, [mmx_one] ; collapse |
|
|
movq mm7, mm6 |
|
|
psrlq mm7, 32 |
|
|
paddd mm6, mm7 |
|
|
|
|
|
movd eax, mm6 |
|
|
|
|
|
ret |
|
|
|
|
|
|
|
|
;=========================================================================== |
|
|
; |
|
|
; uint32_t sad8_mmx(const uint8_t * const cur, |
|
|
; const uint8_t * const ref, |
|
|
; const uint32_t stride); |
|
|
; |
|
|
;=========================================================================== |
|
|
|
|
85 |
%macro SAD_8x8_MMX 0 |
%macro SAD_8x8_MMX 0 |
86 |
movq mm0, [eax] |
movq mm0, [eax] |
87 |
movq mm1, [edx] |
movq mm1, [edx] |
116 |
paddusw mm6,mm2 |
paddusw mm6,mm2 |
117 |
%endmacro |
%endmacro |
118 |
|
|
119 |
align 16 |
%macro SADV_16x16_MMX 0 |
120 |
sad8_mmx: |
movq mm0, [eax] |
121 |
|
movq mm1, [edx] |
|
mov eax, [esp+ 4] ; Src1 |
|
|
mov edx, [esp+ 8] ; Src2 |
|
|
mov ecx, [esp+12] ; Stride |
|
122 |
|
|
123 |
pxor mm6, mm6 ; accum |
movq mm2, [eax+8] |
124 |
pxor mm7, mm7 ; zero |
movq mm3, [edx+8] |
125 |
|
|
126 |
SAD_8x8_MMX |
movq mm4, mm0 |
127 |
SAD_8x8_MMX |
psubusb mm0, mm1 |
|
SAD_8x8_MMX |
|
|
SAD_8x8_MMX |
|
128 |
|
|
129 |
pmaddwd mm6, [mmx_one] ; collapse |
psubusb mm1, mm4 |
130 |
movq mm7, mm6 |
por mm0, mm1 |
131 |
psrlq mm7, 32 |
lea eax,[eax+ecx] |
|
paddd mm6, mm7 |
|
132 |
|
|
133 |
movd eax, mm6 |
movq mm4, mm2 |
134 |
|
psubusb mm2, mm3 |
135 |
|
|
136 |
ret |
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 |
|
|
|
;=========================================================================== |
|
|
; |
|
|
; uint32_t sad16bi_mmx(const uint8_t * const cur, |
|
|
; const uint8_t * const ref1, |
|
|
; const uint8_t * const ref2, |
|
|
; const uint32_t stride); |
|
|
; |
|
|
;=========================================================================== |
|
155 |
%macro SADBI_16x16_MMX 2 ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr ); |
%macro SADBI_16x16_MMX 2 ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr ); |
156 |
|
|
157 |
movq mm0, [edx+%1] |
movq mm0, [edx+%1] |
202 |
|
|
203 |
%endmacro |
%endmacro |
204 |
|
|
205 |
align 16 |
%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: |
282 |
|
|
283 |
|
mov eax, [esp+ 4] ; Src1 |
284 |
|
mov edx, [esp+ 8] ; Src2 |
285 |
|
mov ecx, [esp+12] ; Stride |
286 |
|
|
287 |
|
pxor mm6, mm6 ; accum |
288 |
|
pxor mm7, mm7 ; zero |
289 |
|
|
290 |
|
SAD_16x16_MMX |
291 |
|
SAD_16x16_MMX |
292 |
|
SAD_16x16_MMX |
293 |
|
SAD_16x16_MMX |
294 |
|
SAD_16x16_MMX |
295 |
|
SAD_16x16_MMX |
296 |
|
SAD_16x16_MMX |
297 |
|
SAD_16x16_MMX |
298 |
|
|
299 |
|
SAD_16x16_MMX |
300 |
|
SAD_16x16_MMX |
301 |
|
SAD_16x16_MMX |
302 |
|
SAD_16x16_MMX |
303 |
|
SAD_16x16_MMX |
304 |
|
SAD_16x16_MMX |
305 |
|
SAD_16x16_MMX |
306 |
|
SAD_16x16_MMX |
307 |
|
|
308 |
|
pmaddwd mm6, [mmx_one] ; collapse |
309 |
|
movq mm7, mm6 |
310 |
|
psrlq mm7, 32 |
311 |
|
paddd mm6, mm7 |
312 |
|
|
313 |
|
movd eax, mm6 |
314 |
|
|
315 |
|
ret |
316 |
|
|
317 |
|
;----------------------------------------------------------------------------- |
318 |
|
; |
319 |
|
; uint32_t sad8_mmx(const uint8_t * const cur, |
320 |
|
; const uint8_t * const ref, |
321 |
|
; const uint32_t stride); |
322 |
|
; |
323 |
|
;----------------------------------------------------------------------------- |
324 |
|
|
325 |
|
ALIGN 16 |
326 |
|
sad8_mmx: |
327 |
|
|
328 |
|
mov eax, [esp+ 4] ; Src1 |
329 |
|
mov edx, [esp+ 8] ; Src2 |
330 |
|
mov ecx, [esp+12] ; Stride |
331 |
|
|
332 |
|
pxor mm6, mm6 ; accum |
333 |
|
pxor mm7, mm7 ; zero |
334 |
|
|
335 |
|
SAD_8x8_MMX |
336 |
|
SAD_8x8_MMX |
337 |
|
SAD_8x8_MMX |
338 |
|
SAD_8x8_MMX |
339 |
|
|
340 |
|
pmaddwd mm6, [mmx_one] ; collapse |
341 |
|
movq mm7, mm6 |
342 |
|
psrlq mm7, 32 |
343 |
|
paddd mm6, mm7 |
344 |
|
|
345 |
|
movd eax, mm6 |
346 |
|
|
347 |
|
ret |
348 |
|
|
349 |
|
;----------------------------------------------------------------------------- |
350 |
|
; |
351 |
|
; uint32_t sad16v_mmx(const uint8_t * const cur, |
352 |
|
; const uint8_t * const ref, |
353 |
|
; const uint32_t stride, |
354 |
|
; int32_t *sad); |
355 |
|
; |
356 |
|
;----------------------------------------------------------------------------- |
357 |
|
|
358 |
|
ALIGN 16 |
359 |
|
sad16v_mmx: |
360 |
|
|
361 |
|
push ebx |
362 |
|
push edi |
363 |
|
|
364 |
|
mov eax, [esp + 8 + 4] ; Src1 |
365 |
|
mov edx, [esp + 8 + 8] ; Src2 |
366 |
|
mov ecx, [esp + 8 + 12] ; Stride |
367 |
|
mov ebx, [esp + 8 + 16] ; sad ptr |
368 |
|
|
369 |
|
pxor mm5, mm5 ; accum |
370 |
|
pxor mm6, mm6 ; accum |
371 |
|
pxor mm7, mm7 ; zero |
372 |
|
|
373 |
|
SADV_16x16_MMX |
374 |
|
SADV_16x16_MMX |
375 |
|
SADV_16x16_MMX |
376 |
|
SADV_16x16_MMX |
377 |
|
SADV_16x16_MMX |
378 |
|
SADV_16x16_MMX |
379 |
|
SADV_16x16_MMX |
380 |
|
SADV_16x16_MMX |
381 |
|
|
382 |
|
pmaddwd mm5, [mmx_one] ; collapse |
383 |
|
pmaddwd mm6, [mmx_one] ; collapse |
384 |
|
|
385 |
|
movq mm2, mm5 |
386 |
|
movq mm3, mm6 |
387 |
|
|
388 |
|
psrlq mm2, 32 |
389 |
|
psrlq mm3, 32 |
390 |
|
|
391 |
|
paddd mm5, mm2 |
392 |
|
paddd mm6, mm3 |
393 |
|
|
394 |
|
movd [ebx], mm5 |
395 |
|
movd [ebx + 4], mm6 |
396 |
|
|
397 |
|
paddd mm5, mm6 |
398 |
|
|
399 |
|
movd edi, mm5 |
400 |
|
|
401 |
|
pxor mm5, mm5 |
402 |
|
pxor mm6, mm6 |
403 |
|
|
404 |
|
SADV_16x16_MMX |
405 |
|
SADV_16x16_MMX |
406 |
|
SADV_16x16_MMX |
407 |
|
SADV_16x16_MMX |
408 |
|
SADV_16x16_MMX |
409 |
|
SADV_16x16_MMX |
410 |
|
SADV_16x16_MMX |
411 |
|
SADV_16x16_MMX |
412 |
|
|
413 |
|
pmaddwd mm5, [mmx_one] ; collapse |
414 |
|
pmaddwd mm6, [mmx_one] ; collapse |
415 |
|
|
416 |
|
movq mm2, mm5 |
417 |
|
movq mm3, mm6 |
418 |
|
|
419 |
|
psrlq mm2, 32 |
420 |
|
psrlq mm3, 32 |
421 |
|
|
422 |
|
paddd mm5, mm2 |
423 |
|
paddd mm6, mm3 |
424 |
|
|
425 |
|
movd [ebx + 8], mm5 |
426 |
|
movd [ebx + 12], mm6 |
427 |
|
|
428 |
|
paddd mm5, mm6 |
429 |
|
|
430 |
|
movd eax, mm5 |
431 |
|
|
432 |
|
add eax, edi |
433 |
|
|
434 |
|
pop edi |
435 |
|
pop ebx |
436 |
|
|
437 |
|
ret |
438 |
|
|
439 |
|
;----------------------------------------------------------------------------- |
440 |
|
; |
441 |
|
; uint32_t sad16bi_mmx(const uint8_t * const cur, |
442 |
|
; const uint8_t * const ref1, |
443 |
|
; const uint8_t * const ref2, |
444 |
|
; const uint32_t stride); |
445 |
|
; |
446 |
|
;----------------------------------------------------------------------------- |
447 |
|
|
448 |
|
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 |
|
|
|
|
|
%macro ABS_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 |
|
|
movq mm4, mm6 |
|
|
psubusw mm4, mm0 |
|
547 |
|
|
548 |
psubusw mm0, mm6 |
ALIGN 16 |
|
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 |
|
ret |
|
617 |
|
|
618 |
|
ret |