aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/x86/me_cmp.asm
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2014-09-16 21:41:47 -0300
committerMichael Niedermayer <michaelni@gmx.at>2014-09-17 11:12:50 +0200
commit0456d169c469a79e305813d14c873fe698c8c572 (patch)
tree42982e394a09a6ebb90bf1aa57a2554476afe5fe /libavcodec/x86/me_cmp.asm
parentf1a8943ddd15223483cd342a322d02d97e2116c2 (diff)
downloadffmpeg-0456d169c469a79e305813d14c873fe698c8c572.tar.gz
x86/me_cmp: port mmxext and sse2 sad functions to yasm
Also add a missing c->pix_abs[0][0] initialization, and sse2 versions of sad16_x2, sad16_y2 and sad16_xy2 (%15 to %20 faster than mmxext). Since the _xy2 versions are not bitexact, they are accordingly marked as approximate. Signed-off-by: James Almer <jamrial@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/x86/me_cmp.asm')
-rw-r--r--libavcodec/x86/me_cmp.asm330
1 files changed, 330 insertions, 0 deletions
diff --git a/libavcodec/x86/me_cmp.asm b/libavcodec/x86/me_cmp.asm
index b0741f398b..27176f47ec 100644
--- a/libavcodec/x86/me_cmp.asm
+++ b/libavcodec/x86/me_cmp.asm
@@ -23,6 +23,10 @@
%include "libavutil/x86/x86util.asm"
+SECTION_RODATA
+
+cextern pb_1
+
SECTION .text
%macro DIFF_PIXELS_1 4
@@ -465,3 +469,329 @@ cglobal hf_noise%1, 3,3,0, pix1, lsize, h
INIT_MMX mmx
HF_NOISE 8
HF_NOISE 16
+
+;---------------------------------------------------------------------------------------
+;int ff_sad_<opt>(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, int stride, int h);
+;---------------------------------------------------------------------------------------
+INIT_MMX mmxext
+cglobal sad8, 4, 4, 0, v, pix1, pix2, stride
+ movu m2, [pix2q]
+ movu m1, [pix2q+strideq]
+ psadbw m2, [pix1q]
+ psadbw m1, [pix1q+strideq]
+ paddw m2, m1
+
+%rep 3
+ lea pix1q, [pix1q+strideq*2]
+ lea pix2q, [pix2q+strideq*2]
+ movu m0, [pix2q]
+ movu m1, [pix2q+strideq]
+ psadbw m0, [pix1q]
+ psadbw m1, [pix1q+strideq]
+ paddw m2, m0
+ paddw m2, m1
+%endrep
+ movd eax, m2
+ RET
+
+%macro SAD16 0
+cglobal sad16, 5, 5, 3, v, pix1, pix2, stride, h
+ pxor m2, m2
+
+align 16
+.loop
+ movu m0, [pix2q]
+ movu m1, [pix2q+strideq]
+ psadbw m0, [pix1q]
+ psadbw m1, [pix1q+strideq]
+ paddw m2, m0
+ paddw m2, m1
+%if mmsize == 8
+ movu m0, [pix2q+8]
+ movu m1, [pix2q+strideq+8]
+ psadbw m0, [pix1q+8]
+ psadbw m1, [pix1q+strideq+8]
+ paddw m2, m0
+ paddw m2, m1
+%endif
+ lea pix1q, [pix1q+strideq*2]
+ lea pix2q, [pix2q+strideq*2]
+ sub hd, 2
+ jg .loop
+%if mmsize == 16
+ movhlps m0, m2
+ paddw m2, m0
+%endif
+ movd eax, m2
+ RET
+%endmacro
+
+INIT_MMX mmxext
+SAD16
+INIT_XMM sse2
+SAD16
+
+;------------------------------------------------------------------------------------------
+;int ff_sad_x2_<opt>(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, int stride, int h);
+;------------------------------------------------------------------------------------------
+INIT_MMX mmxext
+cglobal sad8_x2, 4, 4, 0, v, pix1, pix2, stride
+ movu m0, [pix2q]
+ movu m2, [pix2q+strideq]
+ pavgb m0, [pix2q+1]
+ pavgb m2, [pix2q+strideq+1]
+ psadbw m0, [pix1q]
+ psadbw m2, [pix1q+strideq]
+ paddw m0, m2
+
+%rep 3
+ lea pix1q, [pix1q+2*strideq]
+ lea pix2q, [pix2q+2*strideq]
+ movu m1, [pix2q]
+ movu m2, [pix2q+strideq]
+ pavgb m1, [pix2q+1]
+ pavgb m2, [pix2q+strideq+1]
+ psadbw m1, [pix1q]
+ psadbw m2, [pix1q+strideq]
+ paddw m0, m1
+ paddw m0, m2
+%endrep
+ movd eax, m0
+ RET
+
+%macro SAD16_X2 0
+cglobal sad16_x2, 5, 5, 5, v, pix1, pix2, stride, h
+ pxor m0, m0
+
+align 16
+.loop:
+ movu m1, [pix2q]
+ movu m2, [pix2q+strideq]
+%if mmsize == 16
+ movu m3, [pix2q+1]
+ movu m4, [pix2q+strideq+1]
+ pavgb m1, m3
+ pavgb m2, m4
+%else
+ pavgb m1, [pix2q+1]
+ pavgb m2, [pix2q+strideq+1]
+%endif
+ psadbw m1, [pix1q]
+ psadbw m2, [pix1q+strideq]
+ paddw m0, m1
+ paddw m0, m2
+%if mmsize == 8
+ movu m1, [pix2q+8]
+ movu m2, [pix2q+strideq+8]
+ pavgb m1, [pix2q+9]
+ pavgb m2, [pix2q+strideq+9]
+ psadbw m1, [pix1q+8]
+ psadbw m2, [pix1q+strideq+8]
+ paddw m0, m1
+ paddw m0, m2
+%endif
+ lea pix1q, [pix1q+2*strideq]
+ lea pix2q, [pix2q+2*strideq]
+ sub hd, 2
+ jg .loop
+%if mmsize == 16
+ movhlps m1, m0
+ paddw m0, m1
+%endif
+ movd eax, m0
+ RET
+%endmacro
+
+INIT_MMX mmxext
+SAD16_X2
+INIT_XMM sse2
+SAD16_X2
+
+;------------------------------------------------------------------------------------------
+;int ff_sad_y2_<opt>(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, int stride, int h);
+;------------------------------------------------------------------------------------------
+INIT_MMX mmxext
+cglobal sad8_y2, 4, 4, 0, v, pix1, pix2, stride
+ movu m1, [pix2q]
+ movu m0, [pix2q+strideq]
+ movu m3, [pix2q+2*strideq]
+ pavgb m1, m0
+ pavgb m0, m3
+ add pix2q, strideq
+ psadbw m1, [pix1q]
+ psadbw m0, [pix1q+strideq]
+ paddw m0, m1
+ mova m1, m3
+
+%rep 3
+ lea pix1q, [pix1q+2*strideq]
+ lea pix2q, [pix2q+2*strideq]
+ movu m2, [pix2q]
+ movu m3, [pix2q+strideq]
+ pavgb m1, m2
+ pavgb m2, m3
+ psadbw m1, [pix1q]
+ psadbw m2, [pix1q+strideq]
+ paddw m0, m1
+ paddw m0, m2
+ mova m1, m3
+%endrep
+ movd eax, m0
+ RET
+
+%macro SAD16_Y2 0
+cglobal sad16_y2, 5, 5, 4, v, pix1, pix2, stride, h
+ movu m1, [pix2q]
+%if mmsize == 8
+ movu m4, [pix2q+8]
+%endif
+ pxor m0, m0
+ add pix2q, strideq
+
+align 16
+.loop:
+ movu m2, [pix2q]
+ movu m3, [pix2q+strideq]
+ pavgb m1, m2
+ pavgb m2, m3
+ psadbw m1, [pix1q]
+ psadbw m2, [pix1q+strideq]
+ paddw m0, m1
+ paddw m0, m2
+ mova m1, m3
+%if mmsize == 8
+ movu m5, [pix2q+8]
+ movu m6, [pix2q+strideq+8]
+ pavgb m4, m5
+ pavgb m5, m6
+ psadbw m4, [pix1q+8]
+ psadbw m5, [pix1q+strideq+8]
+ paddw m0, m4
+ paddw m0, m5
+ mova m4, m6
+%endif
+ lea pix1q, [pix1q+2*strideq]
+ lea pix2q, [pix2q+2*strideq]
+ sub hd, 2
+ jg .loop
+%if mmsize == 16
+ movhlps m1, m0
+ paddw m0, m1
+%endif
+ movd eax, m0
+ RET
+%endmacro
+
+INIT_MMX mmxext
+SAD16_Y2
+INIT_XMM sse2
+SAD16_Y2
+
+;-------------------------------------------------------------------------------------------
+;int ff_sad_approx_xy2_<opt>(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, int stride, int h);
+;-------------------------------------------------------------------------------------------
+INIT_MMX mmxext
+cglobal sad8_approx_xy2, 4, 4, 0, v, pix1, pix2, stride
+ pxor m0, m0
+ mova m4, [pb_1]
+ movu m1, [pix2q]
+ movu m0, [pix2q+strideq]
+ movu m3, [pix2q+2*strideq]
+ pavgb m1, [pix2q+1]
+ pavgb m0, [pix2q+strideq+1]
+ pavgb m3, [pix2q+2*strideq+1]
+ psubusb m0, m4
+ pavgb m1, m0
+ pavgb m0, m3
+ add pix2q, strideq
+ psadbw m1, [pix1q]
+ psadbw m0, [pix1q+strideq]
+ paddw m0, m1
+ mova m1, m3
+
+%rep 3
+ lea pix1q, [pix1q+2*strideq]
+ lea pix2q, [pix2q+2*strideq]
+ movu m2, [pix2q]
+ movu m3, [pix2q+strideq]
+ pavgb m2, [pix2q+1]
+ pavgb m3, [pix2q+strideq+1]
+ psubusb m2, m4
+ pavgb m1, m2
+ pavgb m2, m3
+ psadbw m1, [pix1q]
+ psadbw m2, [pix1q+strideq]
+ paddw m0, m1
+ paddw m0, m2
+ mova m1, m3
+%endrep
+ movd eax, m0
+ RET
+
+%macro SAD16_APPROX_XY2 0
+cglobal sad16_approx_xy2, 5, 5, 7, v, pix1, pix2, stride, h
+ pxor m0, m0
+ mova m4, [pb_1]
+
+ movu m1, [pix2q]
+%if mmsize == 16
+ movu m2, [pix2q+1]
+ pavgb m1, m2
+%else
+ movu m5, [pix2q+8]
+ pavgb m1, [pix2q+1]
+ pavgb m5, [pix2q+8+1]
+%endif
+ add pix2q, strideq
+
+align 16
+.loop:
+ movu m2, [pix2q]
+ movu m3, [pix2q+strideq]
+%if mmsize == 16
+ movu m5, [pix2q+1]
+ movu m6, [pix2q+strideq+1]
+ pavgb m2, m5
+ pavgb m3, m6
+%else
+ pavgb m2, [pix2q+1]
+ pavgb m3, [pix2q+strideq+1]
+%endif
+ psubusb m2, m4
+ pavgb m1, m2
+ pavgb m2, m3
+ psadbw m1, [pix1q]
+ psadbw m2, [pix1q+strideq]
+ paddw m0, m1
+ paddw m0, m2
+ mova m1, m3
+%if mmsize == 8
+ movu m6, [pix2q+8]
+ movu m7, [pix2q+strideq+8]
+ pavgb m6, [pix2q+8+1]
+ pavgb m7, [pix2q+strideq+8+1]
+ psubusb m6, m4
+ pavgb m5, m6
+ pavgb m6, m7
+ psadbw m5, [pix1q+8]
+ psadbw m6, [pix1q+strideq+8]
+ paddw m0, m5
+ paddw m0, m6
+ mova m5, m7
+%endif
+ lea pix1q, [pix1q+2*strideq]
+ lea pix2q, [pix2q+2*strideq]
+ sub hd, 2
+ jg .loop
+%if mmsize == 16
+ movhlps m1, m0
+ paddw m0, m1
+%endif
+ movd eax, m0
+ RET
+%endmacro
+
+INIT_MMX mmxext
+SAD16_APPROX_XY2
+INIT_XMM sse2
+SAD16_APPROX_XY2