History

avfilter/x86/vf_eq: Change inline assembly into nasm code

Ting Fu committed 7 years ago

Commit 6aff2041 parent 9691e2a4 files · +138 −97Browse files

Showing the changes to libavfilter (4 of 4 files). Show all

Unified · Split

4 files
  1. libavfilter/x86/Makefile +2 −1
  2. libavfilter/x86/vf_eq.asm +82 −0
  3. libavfilter/x86/vf_eq.c +0 −96
  4. libavfilter/x86/vf_eq_init.c +54 −0
libavfilter/x86/Makefile+2−1
@@ -6,7 +6,7 @@ OBJS-$(CONFIG_BLEND_FILTER) += x86/vf_blend_init.o · 5 unmodified lines
66 OBJS-$(CONFIG_BWDIF_FILTER) += x86/vf_bwdif_init.o
77 OBJS-$(CONFIG_COLORSPACE_FILTER) += x86/colorspacedsp_init.o
88 OBJS-$(CONFIG_CONVOLUTION_FILTER) += x86/vf_convolution_init.o
9−OBJS-$(CONFIG_EQ_FILTER) += x86/vf_eq.o
9+OBJS-$(CONFIG_EQ_FILTER) += x86/vf_eq_init.o
1010 OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp_init.o
1111 OBJS-$(CONFIG_GBLUR_FILTER) += x86/vf_gblur_init.o
1212 OBJS-$(CONFIG_GRADFUN_FILTER) += x86/vf_gradfun_init.o
@@ -43,6 +43,7 @@ X86ASM-OBJS-$(CONFIG_BLEND_FILTER) += x86/vf_blend.o · 30 unmodified lines
4343 X86ASM-OBJS-$(CONFIG_BWDIF_FILTER) += x86/vf_bwdif.o
4444 X86ASM-OBJS-$(CONFIG_COLORSPACE_FILTER) += x86/colorspacedsp.o
4545 X86ASM-OBJS-$(CONFIG_CONVOLUTION_FILTER) += x86/vf_convolution.o
46+X86ASM-OBJS-$(CONFIG_CONVOLUTION_FILTER) += x86/vf_eq.o
4647 X86ASM-OBJS-$(CONFIG_FRAMERATE_FILTER) += x86/vf_framerate.o
4748 X86ASM-OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp.o
4849 X86ASM-OBJS-$(CONFIG_GBLUR_FILTER) += x86/vf_gblur.o
libavfilter/x86/vf_eq.asm+82−0
@@ -0,0 +1,82 @@
1+;*****************************************************************************
2+;* x86-optimized functions for eq filter
3+;*
4+;* Original MPlayer filters by Richard Felker.
5+;*
6+;* This file is part of FFmpeg.
7+;*
8+;* FFmpeg is free software; you can redistribute it and/or modify
9+;* it under the terms of the GNU General Public License as published by
10+;* the Free Software Foundation; either version 2 of the License, or
11+;* (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
16+;* GNU General Public License for more details.
17+;*
18+;* You should have received a copy of the GNU General Public License along
19+;* with FFmpeg; if not, write to the Free Software Foundation, Inc.,
20+;* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21+;*****************************************************************************
22+
23+%include "libavutil/x86/x86util.asm"
24+
25+SECTION .text
26+
27+INIT_MMX mmxext
28+cglobal process_one_line, 5, 7, 5, src, dst, contrast, brightness, w
29+ movd m3, contrastd
30+ movd m4, brightnessd
31+ movsx r5d, contrastw
32+ movsx r6d, brightnessw
33+ SPLATW m3, m3, 0
34+ SPLATW m4, m4, 0
35+
36+ DEFINE_ARGS src, dst, tmp, scalar, w
37+ xor tmpd, tmpd
38+ pxor m0, m0
39+ pxor m1, m1
40+ mov scalard, wd
41+ and scalard, mmsize-1
42+ sar wd, 3
43+ cmp wd, 1
44+ jl .loop1
45+
46+ .loop0:
47+ movu m1, [srcq]
48+ mova m2, m1
49+ punpcklbw m1, m0
50+ punpckhbw m2, m0
51+ psllw m1, 4
52+ psllw m2, 4
53+ pmulhw m1, m3
54+ pmulhw m2, m3
55+ paddw m1, m4
56+ paddw m2, m4
57+ packuswb m1, m2
58+ movu [dstq], m1
59+ add srcq, mmsize
60+ add dstq, mmsize
61+ sub wd, 1
62+ cmp wd, 0
63+ jne .loop0
64+
65+ .loop1:
66+ cmp scalard, 0
67+ je .end
68+ movzx tmpd, byte [srcq]
69+ imul tmpd, r5d
70+ sar tmpd, 12
71+ add tmpd, r6d
72+ movd m1, tmpd
73+ packuswb m1, m0
74+ movd tmpd, m1
75+ mov [dstq], tmpb
76+ inc srcq
77+ inc dstq
78+ dec scalard
79+ jmp .loop1
80+
81+ .end:
82+ RET
libavfilter/x86/vf_eq.c+0−96
@@ -1,96 +0,0 @@
1−/*
2− *
3− * Original MPlayer filters by Richard Felker.
4− *
5− * This file is part of FFmpeg.
6− *
7− * FFmpeg is free software; you can redistribute it and/or modify
8− * it under the terms of the GNU General Public License as published by
9− * the Free Software Foundation; either version 2 of the License, or
10− * (at your option) any later version.
11− *
12− * FFmpeg is distributed in the hope that it will be useful,
13− * but WITHOUT ANY WARRANTY; without even the implied warranty of
14− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15− * GNU General Public License for more details.
16− *
17− * You should have received a copy of the GNU General Public License along
18− * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19− * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20− */
21−
22−#include "libavutil/attributes.h"
23−#include "libavutil/cpu.h"
24−#include "libavutil/mem.h"
25−#include "libavutil/x86/asm.h"
26−#include "libavfilter/vf_eq.h"
27−
28−#if HAVE_MMX_INLINE && HAVE_6REGS
29−static void process_MMX(EQParameters *param, uint8_t *dst, int dst_stride,
30− const uint8_t *src, int src_stride, int w, int h)
31−{
32− int i;
33− int pel;
34− int dstep = dst_stride - w;
35− int sstep = src_stride - w;
36− short brvec[4];
37− short contvec[4];
38− int contrast = (int) (param->contrast * 256 * 16);
39− int brightness = ((int) (100.0 * param->brightness + 100.0) * 511) / 200 - 128 - contrast / 32;
40−
41− brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness;
42− contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast;
43−
44− while (h--) {
45− __asm__ volatile (
46− "movq (%5), %%mm3 \n\t"
47− "movq (%6), %%mm4 \n\t"
48− "pxor %%mm0, %%mm0 \n\t"
49− "movl %4, %%eax \n\t"
50− ".p2align 4 \n\t"
51− "1: \n\t"
52− "movq (%0), %%mm1 \n\t"
53− "movq (%0), %%mm2 \n\t"
54− "punpcklbw %%mm0, %%mm1\n\t"
55− "punpckhbw %%mm0, %%mm2\n\t"
56− "psllw $4, %%mm1 \n\t"
57− "psllw $4, %%mm2 \n\t"
58− "pmulhw %%mm4, %%mm1 \n\t"
59− "pmulhw %%mm4, %%mm2 \n\t"
60− "paddw %%mm3, %%mm1 \n\t"
61− "paddw %%mm3, %%mm2 \n\t"
62− "packuswb %%mm2, %%mm1 \n\t"
63− "add $8, %0 \n\t"
64− "movq %%mm1, (%1) \n\t"
65− "add $8, %1 \n\t"
66− "decl %%eax \n\t"
67− "jnz 1b \n\t"
68− : "=r" (src), "=r" (dst)
69− : "0" (src), "1" (dst), "r" (w>>3), "r" (brvec), "r" (contvec)
70− : "%eax"
71− );
72−
73− for (i = w&7; i; i--) {
74− pel = ((*src++ * contrast) >> 12) + brightness;
75− if (pel & ~255)
76− pel = (-pel) >> 31;
77− *dst++ = pel;
78− }
79−
80− src += sstep;
81− dst += dstep;
82− }
83− __asm__ volatile ( "emms \n\t" ::: "memory" );
84−}
85−#endif
86−
87−av_cold void ff_eq_init_x86(EQContext *eq)
88−{
89−#if HAVE_MMX_INLINE && HAVE_6REGS
90− int cpu_flags = av_get_cpu_flags();
91−
92− if (cpu_flags & AV_CPU_FLAG_MMX) {
93− eq->process = process_MMX;
94− }
95−#endif
96−}
libavfilter/x86/vf_eq_init.c+54−0
@@ -0,0 +1,54 @@
1+/*
2+ *
3+ * Original MPlayer filters by Richard Felker.
4+ *
5+ * This file is part of FFmpeg.
6+ *
7+ * FFmpeg is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; either version 2 of the License, or
10+ * (at your option) any later version.
11+ *
12+ * FFmpeg is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License along
18+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20+ */
21+
22+#include "libavutil/attributes.h"
23+#include "libavutil/cpu.h"
24+#include "libavutil/mem.h"
25+#include "libavutil/x86/cpu.h"
26+#include "libavutil/x86/asm.h"
27+#include "libavfilter/vf_eq.h"
28+
29+extern void ff_process_one_line_mmxext(const uint8_t *src, uint8_t *dst, short contrast,
30+ short brightness, int w);
31+
32+static void process_mmxext(EQParameters *param, uint8_t *dst, int dst_stride,
33+ const uint8_t *src, int src_stride, int w, int h)
34+{
35+ short contrast = (short) (param->contrast * 256 * 16);
36+ short brightness = ((short) (100.0 * param->brightness + 100.0) * 511)
37+ / 200 - 128 - contrast / 32;
38+
39+ while (h--) {
40+ ff_process_one_line_mmxext(src, dst, contrast, brightness, w);
41+ src += src_stride;
42+ dst += dst_stride;
43+ }
44+ emms_c();
45+}
46+
47+av_cold void ff_eq_init_x86(EQContext *eq)
48+{
49+ int cpu_flags = av_get_cpu_flags();
50+
51+ if (cpu_flags & AV_CPU_FLAG_MMXEXT) {
52+ eq->process = process_mmxext;
53+ }
54+}

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