History

avfilter/vf_adadenoise: add x86 SIMD

Paul B Mahol committed 7 years ago

Commit 295d99b1 parent eb17bf65 files · +241 −7Browse files

Unified · Split

5 files
  1. libavfilter/atadenoise.h +36 −0
  2. libavfilter/vf_atadenoise.c +9 −7
  3. libavfilter/x86/Makefile +2 −0
  4. libavfilter/x86/vf_atadenoise.asm +154 −0
  5. libavfilter/x86/vf_atadenoise_init.c +40 −0
libavfilter/atadenoise.h+36−0
@@ -0,0 +1,36 @@
1+ /*
2+ * Copyright (c) 2019 Paul B Mahol
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#ifndef AVFILTER_ATADENOISE_H
22+#define AVFILTER_ATADENOISE_H
23+
24+#include <stddef.h>
25+#include <stdint.h>
26+
27+typedef struct ATADenoiseDSPContext {
28+ void (*filter_row)(const uint8_t *src, uint8_t *dst,
29+ const uint8_t **srcf,
30+ int w, int mid, int size,
31+ int thra, int thrb);
32+} ATADenoiseDSPContext;
33+
34+void ff_atadenoise_init_x86(ATADenoiseDSPContext *dsp, int depth);
35+
36+#endif /* AVFILTER_ATADENOISE_H */
libavfilter/vf_atadenoise.c+9−7
@@ -33,6 +33,7 @@ · 32 unmodified lines
3333 #define FF_BUFQUEUE_SIZE 129
3434 #include "bufferqueue.h"
3535
36+#include "atadenoise.h"
3637 #include "formats.h"
3738 #include "internal.h"
3839 #include "video.h"
@@ -57,10 +58,8 @@ typedef struct ATADenoiseContext { · 18 unmodified lines
5758 int available;
5859
5960 int (*filter_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
60− void (*filter_row)(const uint8_t *src, uint8_t *dst,
61− const uint8_t *srcf[SIZE],
62− int w, int mid, int size,
63− int thra, int thrb);
61+
62+ ATADenoiseDSPContext dsp;
6463 } ATADenoiseContext;
6564
6665 #define OFFSET(x) offsetof(ATADenoiseContext, x)
@@ -209,7 +208,7 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 142 unmodified lines
209208 srcf[i] = data[i] + slice_start * linesize[i];
210209
211210 for (y = slice_start; y < slice_end; y++) {
212− s->filter_row(src, dst, srcf, w, mid, size, thra, thrb);
211+ s->dsp.filter_row(src, dst, srcf, w, mid, size, thra, thrb);
213212
214213 dst += out->linesize[p];
215214 src += in->linesize[p];
@@ -239,9 +238,9 @@ static int config_input(AVFilterLink *inlink) · 23 unmodified lines
239238 depth = desc->comp[0].depth;
240239 s->filter_slice = filter_slice;
241240 if (depth == 8)
242− s->filter_row = filter_row8;
241+ s->dsp.filter_row = filter_row8;
243242 else
244− s->filter_row = filter_row16;
243+ s->dsp.filter_row = filter_row16;
245244
246245 s->thra[0] = s->fthra[0] * (1 << depth) - 1;
247246 s->thra[1] = s->fthra[1] * (1 << depth) - 1;
@@ -250,6 +249,9 @@ static int config_input(AVFilterLink *inlink) · 2 unmodified lines
250249 s->thrb[1] = s->fthrb[1] * (1 << depth) - 1;
251250 s->thrb[2] = s->fthrb[2] * (1 << depth) - 1;
252251
252+ if (ARCH_X86)
253+ ff_atadenoise_init_x86(&s->dsp, depth);
254+
253255 return 0;
254256 }
255257
libavfilter/x86/Makefile+2−0
@@ -2,6 +2,7 @@ OBJS-$(CONFIG_SCENE_SAD) += x86/scene_sad_init.o · 1 unmodified line
22
33 OBJS-$(CONFIG_AFIR_FILTER) += x86/af_afir_init.o
44 OBJS-$(CONFIG_ANLMDN_FILTER) += x86/af_anlmdn_init.o
5+OBJS-$(CONFIG_ATADENOISE_FILTER) += x86/vf_atadenoise_init.o
56 OBJS-$(CONFIG_BLEND_FILTER) += x86/vf_blend_init.o
67 OBJS-$(CONFIG_BWDIF_FILTER) += x86/vf_bwdif_init.o
78 OBJS-$(CONFIG_COLORSPACE_FILTER) += x86/colorspacedsp_init.o
@@ -39,6 +40,7 @@ X86ASM-OBJS-$(CONFIG_SCENE_SAD) += x86/scene_sad.o · 31 unmodified lines
3940
4041 X86ASM-OBJS-$(CONFIG_AFIR_FILTER) += x86/af_afir.o
4142 X86ASM-OBJS-$(CONFIG_ANLMDN_FILTER) += x86/af_anlmdn.o
43+X86ASM-OBJS-$(CONFIG_ATADENOISE_FILTER) += x86/vf_atadenoise.o
4244 X86ASM-OBJS-$(CONFIG_BLEND_FILTER) += x86/vf_blend.o
4345 X86ASM-OBJS-$(CONFIG_BWDIF_FILTER) += x86/vf_bwdif.o
4446 X86ASM-OBJS-$(CONFIG_COLORSPACE_FILTER) += x86/colorspacedsp.o
libavfilter/x86/vf_atadenoise.asm+154−0
@@ -0,0 +1,154 @@
1+;*****************************************************************************
2+;* x86-optimized functions for blend filter
3+;*
4+;* Copyright (C) 2019 Paul B Mahol
5+;*
6+;* This file is part of FFmpeg.
7+;*
8+;* FFmpeg is free software; you can redistribute it and/or
9+;* modify it under the terms of the GNU Lesser General Public
10+;* License as published by the Free Software Foundation; either
11+;* version 2.1 of the License, or (at your option) any later version.
12+;*
13+;* FFmpeg is distributed in the hope that it will be useful,
14+;* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+;* Lesser General Public License for more details.
17+;*
18+;* You should have received a copy of the GNU Lesser General Public
19+;* License along with FFmpeg; if not, write to the Free Software
20+;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+;******************************************************************************
22+
23+%if ARCH_X86_64
24+
25+%include "libavutil/x86/x86util.asm"
26+
27+SECTION_RODATA
28+pw_one: times 8 dw 1
29+pw_ones: times 8 dw 65535
30+
31+SECTION .text
32+
33+;------------------------------------------------------------------------------
34+; void ff_filter_row(const uint8_t *src, uint8_t *dst,
35+; const uint8_t **srcf,
36+; int w, int mid, int size,
37+; int thra, int thrb)
38+;------------------------------------------------------------------------------
39+
40+INIT_XMM sse4
41+cglobal atadenoise_filter_row8, 8,10,13, src, dst, srcf, w, mid, size, i, j, srcfx, x
42+ movsxdifnidn wq, wd
43+ movsxdifnidn midq, midd
44+ movsxdifnidn sizeq, sized
45+ add srcq, wq
46+ add dstq, wq
47+ mov xq, wq
48+ dec sizeq
49+ neg xq
50+ movd m4, r6m
51+ SPLATW m4, m4
52+ movd m5, r7m
53+ SPLATW m5, m5
54+ pxor m2, m2
55+ mova m10, [pw_ones]
56+
57+ .loop:
58+ mov iq, midq
59+ mov jq, midq
60+ pxor m3, m3
61+ pxor m11, m11
62+ movu m0, [srcq + xq]
63+ punpcklbw m0, m2
64+ mova m7, m0
65+ mova m8, [pw_one]
66+ mova m12, [pw_ones]
67+
68+ .loop0:
69+ inc iq
70+ dec jq
71+
72+ mov srcfxq, [srcfq + jq * 8]
73+ add srcfxq, wq
74+
75+ movu m1, [srcfxq + xq]
76+ punpcklbw m1, m2
77+ mova m9, m1
78+ psubw m1, m0
79+ pabsw m1, m1
80+ paddw m11, m1
81+ pcmpgtw m1, m4
82+ mova m6, m11
83+ pcmpgtw m6, m5
84+ por m6, m1
85+ pxor m6, m10
86+ pand m12, m6
87+ pand m9, m12
88+ paddw m7, m9
89+ mova m6, m12
90+ psrlw m6, 15
91+ paddw m8, m6
92+
93+ mov srcfxq, [srcfq + iq * 8]
94+ add srcfxq, wq
95+
96+ movu m1, [srcfxq + xq]
97+ punpcklbw m1, m2
98+ mova m9, m1
99+ psubw m1, m0
100+ pabsw m1, m1
101+ paddw m3, m1
102+ pcmpgtw m1, m4
103+ mova m6, m3
104+ pcmpgtw m6, m5
105+ por m6, m1
106+ pxor m6, m10
107+ pand m12, m6
108+ pand m9, m12
109+ paddw m7, m9
110+ mova m6, m12
111+ psrlw m6, 15
112+ paddw m8, m6
113+
114+ ptest m12, m12
115+ jz .finish
116+
117+ cmp iq, sizeq
118+ jl .loop0
119+
120+ .finish:
121+ mova m9, m8
122+ psrlw m9, 1
123+ paddw m7, m9
124+
125+ mova m1, m7
126+ mova m6, m8
127+
128+ punpcklwd m7, m2
129+ punpcklwd m8, m2
130+ cvtdq2ps m7, m7
131+ cvtdq2ps m8, m8
132+ divps m7, m8
133+ cvttps2dq m7, m7
134+ packssdw m7, m7
135+ packuswb m7, m7
136+
137+ movd [dstq + xq], m7
138+
139+ punpckhwd m1, m2
140+ punpckhwd m6, m2
141+ cvtdq2ps m1, m1
142+ cvtdq2ps m6, m6
143+ divps m1, m6
144+ cvttps2dq m1, m1
145+ packssdw m1, m1
146+ packuswb m1, m1
147+
148+ movd [dstq + xq + 4], m1
149+
150+ add xq, mmsize/2
151+ jl .loop
152+ RET
153+
154+%endif
libavfilter/x86/vf_atadenoise_init.c+40−0
@@ -0,0 +1,40 @@
1+/*
2+ * Copyright (C) 2019 Paul B Mahol
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#include "libavutil/attributes.h"
22+#include "libavutil/cpu.h"
23+#include "libavutil/mem.h"
24+#include "libavutil/x86/asm.h"
25+#include "libavutil/x86/cpu.h"
26+#include "libavfilter/atadenoise.h"
27+
28+void ff_atadenoise_filter_row8_sse4(const uint8_t *src, uint8_t *dst,
29+ const uint8_t **srcf,
30+ int w, int mid, int size,
31+ int thra, int thrb);
32+
33+av_cold void ff_atadenoise_init_x86(ATADenoiseDSPContext *dsp, int depth)
34+{
35+ int cpu_flags = av_get_cpu_flags();
36+
37+ if (ARCH_X86_64 && EXTERNAL_SSE4(cpu_flags) && depth <= 8) {
38+ dsp->filter_row = ff_atadenoise_filter_row8_sse4;
39+ }
40+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t