summaryrefslogtreecommitdiff
path: root/libavfilter/x86
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2015-10-02 17:22:42 +0200
committerPaul B Mahol <onemda@gmail.com>2015-10-03 21:26:17 +0200
commit9762554dd0e9116d28169f602380e7ccd2949ac5 (patch)
treec5f53a415850a401820097985d7f95522137d669 /libavfilter/x86
parent061b67fb50e2d5aab790d193ef93342e0312ddb2 (diff)
avfilter/vf_blend: add x86 SIMD for some modes
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/x86')
-rw-r--r--libavfilter/x86/Makefile4
-rw-r--r--libavfilter/x86/vf_blend.asm367
-rw-r--r--libavfilter/x86/vf_blend_init.c122
3 files changed, 493 insertions, 0 deletions
diff --git a/libavfilter/x86/Makefile b/libavfilter/x86/Makefile
index db072cd433..57b413fd57 100644
--- a/libavfilter/x86/Makefile
+++ b/libavfilter/x86/Makefile
@@ -1,3 +1,4 @@
+OBJS-$(CONFIG_BLEND_FILTER) += x86/vf_blend_init.o
OBJS-$(CONFIG_EQ_FILTER) += x86/vf_eq.o
OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp_init.o
OBJS-$(CONFIG_GRADFUN_FILTER) += x86/vf_gradfun_init.o
@@ -12,10 +13,12 @@ OBJS-$(CONFIG_PULLUP_FILTER) += x86/vf_pullup_init.o
OBJS-$(CONFIG_REMOVEGRAIN_FILTER) += x86/vf_removegrain_init.o
OBJS-$(CONFIG_SPP_FILTER) += x86/vf_spp.o
OBJS-$(CONFIG_SSIM_FILTER) += x86/vf_ssim_init.o
+OBJS-$(CONFIG_TBLEND_FILTER) += x86/vf_blend_init.o
OBJS-$(CONFIG_TINTERLACE_FILTER) += x86/vf_tinterlace_init.o
OBJS-$(CONFIG_VOLUME_FILTER) += x86/af_volume_init.o
OBJS-$(CONFIG_YADIF_FILTER) += x86/vf_yadif_init.o
+YASM-OBJS-$(CONFIG_BLEND_FILTER) += x86/vf_blend.o
YASM-OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp.o
YASM-OBJS-$(CONFIG_GRADFUN_FILTER) += x86/vf_gradfun.o
YASM-OBJS-$(CONFIG_HQDN3D_FILTER) += x86/vf_hqdn3d.o
@@ -29,6 +32,7 @@ ifdef CONFIG_GPL
YASM-OBJS-$(CONFIG_REMOVEGRAIN_FILTER) += x86/vf_removegrain.o
endif
YASM-OBJS-$(CONFIG_SSIM_FILTER) += x86/vf_ssim.o
+YASM-OBJS-$(CONFIG_TBLEND_FILTER) += x86/vf_blend.o
YASM-OBJS-$(CONFIG_TINTERLACE_FILTER) += x86/vf_interlace.o
YASM-OBJS-$(CONFIG_VOLUME_FILTER) += x86/af_volume.o
YASM-OBJS-$(CONFIG_YADIF_FILTER) += x86/vf_yadif.o x86/yadif-16.o x86/yadif-10.o
diff --git a/libavfilter/x86/vf_blend.asm b/libavfilter/x86/vf_blend.asm
new file mode 100644
index 0000000000..167e72b22d
--- /dev/null
+++ b/libavfilter/x86/vf_blend.asm
@@ -0,0 +1,367 @@
+;*****************************************************************************
+;* x86-optimized functions for blend filter
+;*
+;* Copyright (C) 2015 Paul B Mahol
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg is free software; you can redistribute it and/or
+;* modify it under the terms of the GNU Lesser General Public
+;* License as published by the Free Software Foundation; either
+;* version 2.1 of the License, or (at your option) any later version.
+;*
+;* FFmpeg is distributed in the hope that it will be useful,
+;* but WITHOUT ANY WARRANTY; without even the implied warranty of
+;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;* Lesser General Public License for more details.
+;*
+;* You should have received a copy of the GNU Lesser General Public
+;* License along with FFmpeg; if not, write to the Free Software
+;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;******************************************************************************
+
+%include "libavutil/x86/x86util.asm"
+
+%if ARCH_X86_64
+SECTION_RODATA
+
+pw_128: times 8 dw 128
+pw_255: times 8 dw 255
+
+SECTION .text
+
+INIT_XMM sse2
+cglobal blend_xor, 9, 10, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
+ add topq, widthq
+ add bottomq, widthq
+ add dstq, widthq
+ sub endq, startq
+ neg widthq
+.nextrow:
+ mov r10q, widthq
+ %define x r10q
+
+ .loop:
+ movu m0, [topq + x]
+ movu m1, [bottomq + x]
+ pxor m0, m1
+ mova [dstq + x], m0
+ add r10q, mmsize
+ jl .loop
+
+ add topq, top_linesizeq
+ add bottomq, bottom_linesizeq
+ add dstq, dst_linesizeq
+ sub endd, 1
+ jg .nextrow
+REP_RET
+
+cglobal blend_or, 9, 10, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
+ add topq, widthq
+ add bottomq, widthq
+ add dstq, widthq
+ sub endq, startq
+ neg widthq
+.nextrow:
+ mov r10q, widthq
+ %define x r10q
+
+ .loop:
+ movu m0, [topq + x]
+ movu m1, [bottomq + x]
+ por m0, m1
+ mova [dstq + x], m0
+ add r10q, mmsize
+ jl .loop
+
+ add topq, top_linesizeq
+ add bottomq, bottom_linesizeq
+ add dstq, dst_linesizeq
+ sub endd, 1
+ jg .nextrow
+REP_RET
+
+cglobal blend_and, 9, 10, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
+ add topq, widthq
+ add bottomq, widthq
+ add dstq, widthq
+ sub endq, startq
+ neg widthq
+.nextrow:
+ mov r10q, widthq
+ %define x r10q
+
+ .loop:
+ movu m0, [topq + x]
+ movu m1, [bottomq + x]
+ pand m0, m1
+ mova [dstq + x], m0
+ add r10q, mmsize
+ jl .loop
+
+ add topq, top_linesizeq
+ add bottomq, bottom_linesizeq
+ add dstq, dst_linesizeq
+ sub endd, 1
+ jg .nextrow
+REP_RET
+
+cglobal blend_addition, 9, 10, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
+ add topq, widthq
+ add bottomq, widthq
+ add dstq, widthq
+ sub endq, startq
+ neg widthq
+.nextrow:
+ mov r10q, widthq
+ %define x r10q
+
+ .loop:
+ movu m0, [topq + x]
+ movu m1, [bottomq + x]
+ paddusb m0, m1
+ mova [dstq + x], m0
+ add r10q, mmsize
+ jl .loop
+
+ add topq, top_linesizeq
+ add bottomq, bottom_linesizeq
+ add dstq, dst_linesizeq
+ sub endd, 1
+ jg .nextrow
+REP_RET
+
+cglobal blend_subtract, 9, 10, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
+ add topq, widthq
+ add bottomq, widthq
+ add dstq, widthq
+ sub endq, startq
+ neg widthq
+.nextrow:
+ mov r10q, widthq
+ %define x r10q
+
+ .loop:
+ movu m0, [topq + x]
+ movu m1, [bottomq + x]
+ psubusb m0, m1
+ mova [dstq + x], m0
+ add r10q, mmsize
+ jl .loop
+
+ add topq, top_linesizeq
+ add bottomq, bottom_linesizeq
+ add dstq, dst_linesizeq
+ sub endd, 1
+ jg .nextrow
+REP_RET
+
+cglobal blend_difference128, 9, 10, 4, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
+ add topq, widthq
+ add bottomq, widthq
+ add dstq, widthq
+ sub endq, startq
+ pxor m2, m2
+ mova m3, [pw_128]
+ neg widthq
+.nextrow:
+ mov r10q, widthq
+ %define x r10q
+
+ .loop:
+ movh m0, [topq + x]
+ movh m1, [bottomq + x]
+ punpcklbw m0, m2
+ punpcklbw m1, m2
+ paddw m0, m3
+ psubw m0, m1
+ packuswb m0, m0
+ movh [dstq + x], m0
+ add r10q, mmsize / 2
+ jl .loop
+
+ add topq, top_linesizeq
+ add bottomq, bottom_linesizeq
+ add dstq, dst_linesizeq
+ sub endd, 1
+ jg .nextrow
+REP_RET
+
+cglobal blend_average, 9, 10, 3, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
+ add topq, widthq
+ add bottomq, widthq
+ add dstq, widthq
+ sub endq, startq
+ pxor m2, m2
+ neg widthq
+.nextrow:
+ mov r10q, widthq
+ %define x r10q
+
+ .loop:
+ movh m0, [topq + x]
+ movh m1, [bottomq + x]
+ punpcklbw m0, m2
+ punpcklbw m1, m2
+ paddw m0, m1
+ psrlw m0, 1
+ packuswb m0, m0
+ movh [dstq + x], m0
+ add r10q, mmsize / 2
+ jl .loop
+
+ add topq, top_linesizeq
+ add bottomq, bottom_linesizeq
+ add dstq, dst_linesizeq
+ sub endd, 1
+ jg .nextrow
+REP_RET
+
+cglobal blend_addition128, 9, 10, 4, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
+ add topq, widthq
+ add bottomq, widthq
+ add dstq, widthq
+ sub endq, startq
+ pxor m2, m2
+ mova m3, [pw_128]
+ neg widthq
+.nextrow:
+ mov r10q, widthq
+ %define x r10q
+
+ .loop:
+ movh m0, [topq + x]
+ movh m1, [bottomq + x]
+ punpcklbw m0, m2
+ punpcklbw m1, m2
+ paddw m0, m1
+ psubw m0, m3
+ packuswb m0, m0
+ movh [dstq + x], m0
+ add r10q, mmsize / 2
+ jl .loop
+
+ add topq, top_linesizeq
+ add bottomq, bottom_linesizeq
+ add dstq, dst_linesizeq
+ sub endd, 1
+ jg .nextrow
+REP_RET
+
+cglobal blend_darken, 9, 10, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
+ add topq, widthq
+ add bottomq, widthq
+ add dstq, widthq
+ sub endq, startq
+ neg widthq
+.nextrow:
+ mov r10q, widthq
+ %define x r10q
+
+ .loop:
+ movu m0, [topq + x]
+ movu m1, [bottomq + x]
+ pminub m0, m1
+ mova [dstq + x], m0
+ add r10q, mmsize
+ jl .loop
+
+ add topq, top_linesizeq
+ add bottomq, bottom_linesizeq
+ add dstq, dst_linesizeq
+ sub endd, 1
+ jg .nextrow
+REP_RET
+
+cglobal blend_lighten, 9, 10, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
+ add topq, widthq
+ add bottomq, widthq
+ add dstq, widthq
+ sub endq, startq
+ neg widthq
+.nextrow:
+ mov r10q, widthq
+ %define x r10q
+
+ .loop:
+ movu m0, [topq + x]
+ movu m1, [bottomq + x]
+ pmaxub m0, m1
+ mova [dstq + x], m0
+ add r10q, mmsize
+ jl .loop
+
+ add topq, top_linesizeq
+ add bottomq, bottom_linesizeq
+ add dstq, dst_linesizeq
+ sub endd, 1
+ jg .nextrow
+REP_RET
+
+INIT_XMM ssse3
+cglobal blend_difference, 9, 10, 3, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
+ add topq, widthq
+ add bottomq, widthq
+ add dstq, widthq
+ sub endq, startq
+ pxor m2, m2
+ neg widthq
+.nextrow:
+ mov r10q, widthq
+ %define x r10q
+
+ .loop:
+ movh m0, [topq + x]
+ movh m1, [bottomq + x]
+ punpcklbw m0, m2
+ punpcklbw m1, m2
+ psubw m0, m1
+ pabsw m0, m0
+ packuswb m0, m0
+ movh [dstq + x], m0
+ add r10q, mmsize / 2
+ jl .loop
+
+ add topq, top_linesizeq
+ add bottomq, bottom_linesizeq
+ add dstq, dst_linesizeq
+ sub endd, 1
+ jg .nextrow
+REP_RET
+
+cglobal blend_negation, 9, 10, 5, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
+ add topq, widthq
+ add bottomq, widthq
+ add dstq, widthq
+ sub endq, startq
+ pxor m2, m2
+ mova m4, [pw_255]
+ neg widthq
+.nextrow:
+ mov r10q, widthq
+ %define x r10q
+
+ .loop:
+ movh m0, [topq + x]
+ movh m1, [bottomq + x]
+ punpcklbw m0, m2
+ punpcklbw m1, m2
+ mova m3, m4
+ psubw m3, m0
+ psubw m3, m1
+ pabsw m3, m3
+ mova m0, m4
+ psubw m0, m3
+ packuswb m0, m0
+ movh [dstq + x], m0
+ add r10q, mmsize / 2
+ jl .loop
+
+ add topq, top_linesizeq
+ add bottomq, bottom_linesizeq
+ add dstq, dst_linesizeq
+ sub endd, 1
+ jg .nextrow
+REP_RET
+
+%endif
diff --git a/libavfilter/x86/vf_blend_init.c b/libavfilter/x86/vf_blend_init.c
new file mode 100644
index 0000000000..243606389d
--- /dev/null
+++ b/libavfilter/x86/vf_blend_init.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2015 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libavutil/x86/cpu.h"
+#include "libavfilter/blend.h"
+
+void ff_blend_addition_sse2(const uint8_t *top, ptrdiff_t top_linesize,
+ const uint8_t *bottom, ptrdiff_t bottom_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int width, int start, int end,
+ struct FilterParams *param, double *values);
+
+void ff_blend_addition128_sse2(const uint8_t *top, ptrdiff_t top_linesize,
+ const uint8_t *bottom, ptrdiff_t bottom_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int width, int start, int end,
+ struct FilterParams *param, double *values);
+
+void ff_blend_average_sse2(const uint8_t *top, ptrdiff_t top_linesize,
+ const uint8_t *bottom, ptrdiff_t bottom_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int width, int start, int end,
+ struct FilterParams *param, double *values);
+
+void ff_blend_and_sse2(const uint8_t *top, ptrdiff_t top_linesize,
+ const uint8_t *bottom, ptrdiff_t bottom_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int width, int start, int end,
+ struct FilterParams *param, double *values);
+
+void ff_blend_darken_sse2(const uint8_t *top, ptrdiff_t top_linesize,
+ const uint8_t *bottom, ptrdiff_t bottom_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int width, int start, int end,
+ struct FilterParams *param, double *values);
+
+void ff_blend_difference128_sse2(const uint8_t *top, ptrdiff_t top_linesize,
+ const uint8_t *bottom, ptrdiff_t bottom_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int width, int start, int end,
+ struct FilterParams *param, double *values);
+
+void ff_blend_lighten_sse2(const uint8_t *top, ptrdiff_t top_linesize,
+ const uint8_t *bottom, ptrdiff_t bottom_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int width, int start, int end,
+ struct FilterParams *param, double *values);
+
+void ff_blend_or_sse2(const uint8_t *top, ptrdiff_t top_linesize,
+ const uint8_t *bottom, ptrdiff_t bottom_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int width, int start, int end,
+ struct FilterParams *param, double *values);
+
+void ff_blend_subtract_sse2(const uint8_t *top, ptrdiff_t top_linesize,
+ const uint8_t *bottom, ptrdiff_t bottom_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int width, int start, int end,
+ struct FilterParams *param, double *values);
+
+void ff_blend_xor_sse2(const uint8_t *top, ptrdiff_t top_linesize,
+ const uint8_t *bottom, ptrdiff_t bottom_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int width, int start, int end,
+ struct FilterParams *param, double *values);
+
+void ff_blend_difference_ssse3(const uint8_t *top, ptrdiff_t top_linesize,
+ const uint8_t *bottom, ptrdiff_t bottom_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int width, int start, int end,
+ struct FilterParams *param, double *values);
+
+void ff_blend_negation_ssse3(const uint8_t *top, ptrdiff_t top_linesize,
+ const uint8_t *bottom, ptrdiff_t bottom_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int width, int start, int end,
+ struct FilterParams *param, double *values);
+
+av_cold void ff_blend_init_x86(FilterParams *param, int is_16bit)
+{
+ int cpu_flags = av_get_cpu_flags();
+
+ if (ARCH_X86_64 && EXTERNAL_SSE2(cpu_flags) && param->opacity == 1 && !is_16bit) {
+ switch (param->mode) {
+ case BLEND_ADDITION: param->blend = ff_blend_addition_sse2; break;
+ case BLEND_ADDITION128: param->blend = ff_blend_addition128_sse2; break;
+ case BLEND_AND: param->blend = ff_blend_and_sse2; break;
+ case BLEND_AVERAGE: param->blend = ff_blend_average_sse2; break;
+ case BLEND_DARKEN: param->blend = ff_blend_darken_sse2; break;
+ case BLEND_DIFFERENCE128: param->blend = ff_blend_difference128_sse2; break;
+ case BLEND_LIGHTEN: param->blend = ff_blend_lighten_sse2; break;
+ case BLEND_OR: param->blend = ff_blend_or_sse2; break;
+ case BLEND_SUBTRACT: param->blend = ff_blend_subtract_sse2; break;
+ case BLEND_XOR: param->blend = ff_blend_xor_sse2; break;
+ }
+ }
+ if (ARCH_X86_64 && EXTERNAL_SSSE3(cpu_flags) && param->opacity == 1 && !is_16bit) {
+ switch (param->mode) {
+ case BLEND_DIFFERENCE: param->blend = ff_blend_difference_ssse3; break;
+ case BLEND_NEGATION: param->blend = ff_blend_negation_ssse3; break;
+ }
+ }
+}