[FFmpeg-devel] [PATCH] avfilter/vf_w3fdif: add x86 SIMD

Paul B Mahol onemda at gmail.com
Fri Oct 9 09:58:55 CEST 2015


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavfilter/vf_w3fdif.c          | 127 +++++++++++++-----
 libavfilter/w3fdif.h             |  47 +++++++
 libavfilter/x86/Makefile         |   2 +
 libavfilter/x86/vf_w3fdif.asm    | 270 +++++++++++++++++++++++++++++++++++++++
 libavfilter/x86/vf_w3fdif_init.c |  65 ++++++++++
 5 files changed, 478 insertions(+), 33 deletions(-)
 create mode 100644 libavfilter/w3fdif.h
 create mode 100644 libavfilter/x86/vf_w3fdif.asm
 create mode 100644 libavfilter/x86/vf_w3fdif_init.c

diff --git a/libavfilter/vf_w3fdif.c b/libavfilter/vf_w3fdif.c
index f7703cc..e7463cb 100644
--- a/libavfilter/vf_w3fdif.c
+++ b/libavfilter/vf_w3fdif.c
@@ -29,6 +29,7 @@
 #include "formats.h"
 #include "internal.h"
 #include "video.h"
+#include "w3fdif.h"
 
 typedef struct W3FDIFContext {
     const AVClass *class;
@@ -42,6 +43,8 @@ typedef struct W3FDIFContext {
     AVFrame *prev, *cur, *next;  ///< previous, current, next frames
     int32_t **work_line;  ///< lines we are calculating
     int nb_threads;
+
+    W3FDIFDSPContext dsp;
 } W3FDIFContext;
 
 #define OFFSET(x) offsetof(W3FDIFContext, x)
@@ -81,6 +84,78 @@ static int query_formats(AVFilterContext *ctx)
     return ff_set_common_formats(ctx, fmts_list);
 }
 
+static void filter_simple_low(int32_t *work_line,
+                              uint8_t *in_lines_cur[2],
+                              const int16_t *coef, int linesize)
+{
+    int i;
+
+    for (i = 0; i < linesize; i++) {
+        *work_line   += *in_lines_cur[0]++ * coef[0];
+        *work_line++ += *in_lines_cur[1]++ * coef[1];
+    }
+}
+
+static void filter_complex_low(int32_t *work_line,
+                               uint8_t *in_lines_cur[4],
+                               const int16_t *coef, int linesize)
+{
+    int i;
+
+    for (i = 0; i < linesize; i++) {
+        *work_line   += *in_lines_cur[0]++ * coef[0];
+        *work_line   += *in_lines_cur[1]++ * coef[1];
+        *work_line   += *in_lines_cur[2]++ * coef[2];
+        *work_line++ += *in_lines_cur[3]++ * coef[3];
+    }
+}
+
+static void filter_simple_high(int32_t *work_line,
+                               uint8_t *in_lines_cur[3],
+                               uint8_t *in_lines_adj[3],
+                               const int16_t *coef, int linesize)
+{
+    int i;
+
+    for (i = 0; i < linesize; i++) {
+        *work_line   += *in_lines_cur[0]++ * coef[0];
+        *work_line   += *in_lines_adj[0]++ * coef[0];
+        *work_line   += *in_lines_cur[1]++ * coef[1];
+        *work_line   += *in_lines_adj[1]++ * coef[1];
+        *work_line   += *in_lines_cur[2]++ * coef[2];
+        *work_line++ += *in_lines_adj[2]++ * coef[2];
+    }
+}
+
+static void filter_complex_high(int32_t *work_line,
+                                uint8_t *in_lines_cur[5],
+                                uint8_t *in_lines_adj[5],
+                                const int16_t *coef, int linesize)
+{
+    int i;
+
+    for (i = 0; i < linesize; i++) {
+        *work_line   += *in_lines_cur[0]++ * coef[0];
+        *work_line   += *in_lines_adj[0]++ * coef[0];
+        *work_line   += *in_lines_cur[1]++ * coef[1];
+        *work_line   += *in_lines_adj[1]++ * coef[1];
+        *work_line   += *in_lines_cur[2]++ * coef[2];
+        *work_line   += *in_lines_adj[2]++ * coef[2];
+        *work_line   += *in_lines_cur[3]++ * coef[3];
+        *work_line   += *in_lines_adj[3]++ * coef[3];
+        *work_line   += *in_lines_cur[4]++ * coef[4];
+        *work_line++ += *in_lines_adj[4]++ * coef[4];
+    }
+}
+
+static void filter_scale(uint8_t *out_pixel, const int32_t *work_pixel, int linesize)
+{
+    int j;
+
+    for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
+        *out_pixel = av_clip(*work_pixel, 0, 255 * 256 * 128) >> 15;
+}
+
 static int config_input(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
@@ -106,6 +181,15 @@ static int config_input(AVFilterLink *inlink)
             return AVERROR(ENOMEM);
     }
 
+    s->dsp.filter_simple_low   = filter_simple_low;
+    s->dsp.filter_complex_low  = filter_complex_low;
+    s->dsp.filter_simple_high  = filter_simple_high;
+    s->dsp.filter_complex_high = filter_complex_high;
+    s->dsp.filter_scale        = filter_scale;
+
+    if (ARCH_X86)
+        ff_w3fdif_init_x86(&s->dsp);
+
     return 0;
 }
 
@@ -163,7 +247,7 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_
     const int dst_line_stride = out->linesize[plane];
     const int start = (height * jobnr) / nb_jobs;
     const int end = (height * (jobnr+1)) / nb_jobs;
-    int i, j, y_in, y_out;
+    int j, y_in, y_out;
 
     /* copy unchanged the lines of the field */
     y_out = start + (s->field == cur->top_field_first) - (start & 1);
@@ -202,18 +286,12 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_
         work_line = s->work_line[jobnr];
         switch (n_coef_lf[filter]) {
         case 2:
-            for (i = 0; i < linesize; i++) {
-                *work_line   += *in_lines_cur[0]++ * coef_lf[filter][0];
-                *work_line++ += *in_lines_cur[1]++ * coef_lf[filter][1];
-            }
+            s->dsp.filter_simple_low(work_line, in_lines_cur,
+                                     coef_lf[filter], linesize);
             break;
         case 4:
-            for (i = 0; i < linesize; i++) {
-                *work_line   += *in_lines_cur[0]++ * coef_lf[filter][0];
-                *work_line   += *in_lines_cur[1]++ * coef_lf[filter][1];
-                *work_line   += *in_lines_cur[2]++ * coef_lf[filter][2];
-                *work_line++ += *in_lines_cur[3]++ * coef_lf[filter][3];
-            }
+            s->dsp.filter_complex_low(work_line, in_lines_cur,
+                                      coef_lf[filter], linesize);
         }
 
         /* get high vertical frequencies from adjacent fields */
@@ -232,36 +310,19 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_
         work_line = s->work_line[jobnr];
         switch (n_coef_hf[filter]) {
         case 3:
-            for (i = 0; i < linesize; i++) {
-                *work_line   += *in_lines_cur[0]++ * coef_hf[filter][0];
-                *work_line   += *in_lines_adj[0]++ * coef_hf[filter][0];
-                *work_line   += *in_lines_cur[1]++ * coef_hf[filter][1];
-                *work_line   += *in_lines_adj[1]++ * coef_hf[filter][1];
-                *work_line   += *in_lines_cur[2]++ * coef_hf[filter][2];
-                *work_line++ += *in_lines_adj[2]++ * coef_hf[filter][2];
-            }
+            s->dsp.filter_simple_high(work_line, in_lines_cur, in_lines_adj,
+                                      coef_hf[filter], linesize);
             break;
         case 5:
-            for (i = 0; i < linesize; i++) {
-                *work_line   += *in_lines_cur[0]++ * coef_hf[filter][0];
-                *work_line   += *in_lines_adj[0]++ * coef_hf[filter][0];
-                *work_line   += *in_lines_cur[1]++ * coef_hf[filter][1];
-                *work_line   += *in_lines_adj[1]++ * coef_hf[filter][1];
-                *work_line   += *in_lines_cur[2]++ * coef_hf[filter][2];
-                *work_line   += *in_lines_adj[2]++ * coef_hf[filter][2];
-                *work_line   += *in_lines_cur[3]++ * coef_hf[filter][3];
-                *work_line   += *in_lines_adj[3]++ * coef_hf[filter][3];
-                *work_line   += *in_lines_cur[4]++ * coef_hf[filter][4];
-                *work_line++ += *in_lines_adj[4]++ * coef_hf[filter][4];
-            }
+            s->dsp.filter_complex_high(work_line, in_lines_cur, in_lines_adj,
+                                       coef_hf[filter], linesize);
         }
 
         /* save scaled result to the output frame, scaling down by 256 * 128 */
         work_pixel = s->work_line[jobnr];
         out_pixel = out_line;
 
-        for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
-             *out_pixel = av_clip(*work_pixel, 0, 255 * 256 * 128) >> 15;
+        s->dsp.filter_scale(out_pixel, work_pixel, linesize);
 
         /* move on to next line */
         y_out += 2;
diff --git a/libavfilter/w3fdif.h b/libavfilter/w3fdif.h
new file mode 100644
index 0000000..67bb874
--- /dev/null
+++ b/libavfilter/w3fdif.h
@@ -0,0 +1,47 @@
+/*
+ * 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
+ */
+
+#ifndef AVFILTER_W3FDIF_H
+#define AVFILTER_W3FDIF_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+typedef struct W3FDIFDSPContext {
+    void (*filter_simple_low)(int32_t *work_line,
+                              uint8_t *in_lines_cur[2],
+                              const int16_t *coef, int linesize);
+    void (*filter_complex_low)(int32_t *work_line,
+                               uint8_t *in_lines_cur[4],
+                               const int16_t *coef, int linesize);
+    void (*filter_simple_high)(int32_t *work_line,
+                               uint8_t *in_lines_cur[3],
+                               uint8_t *in_lines_adj[3],
+                               const int16_t *coef, int linesize);
+    void (*filter_complex_high)(int32_t *work_line,
+                                uint8_t *in_lines_cur[5],
+                                uint8_t *in_lines_adj[5],
+                                const int16_t *coef, int linesize);
+    void (*filter_scale)(uint8_t *out_pixel, const int32_t *work_pixel, int linesize);
+} W3FDIFDSPContext;
+
+void ff_w3fdif_init_x86(W3FDIFDSPContext *dsp);
+
+#endif /* AVFILTER_W3FDIF_H */
diff --git a/libavfilter/x86/Makefile b/libavfilter/x86/Makefile
index c024204..33de380 100644
--- a/libavfilter/x86/Makefile
+++ b/libavfilter/x86/Makefile
@@ -17,6 +17,7 @@ OBJS-$(CONFIG_STEREO3D_FILTER)               += x86/vf_stereo3d_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_W3FDIF_FILTER)                 += x86/vf_w3fdif_init.o
 OBJS-$(CONFIG_YADIF_FILTER)                  += x86/vf_yadif_init.o
 
 YASM-OBJS-$(CONFIG_BLEND_FILTER)             += x86/vf_blend.o
@@ -37,4 +38,5 @@ YASM-OBJS-$(CONFIG_STEREO3D_FILTER)          += x86/vf_stereo3d.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_W3FDIF_FILTER)            += x86/vf_w3fdif.o
 YASM-OBJS-$(CONFIG_YADIF_FILTER)             += x86/vf_yadif.o x86/yadif-16.o x86/yadif-10.o
diff --git a/libavfilter/x86/vf_w3fdif.asm b/libavfilter/x86/vf_w3fdif.asm
new file mode 100644
index 0000000..e7eacb7
--- /dev/null
+++ b/libavfilter/x86/vf_w3fdif.asm
@@ -0,0 +1,270 @@
+;*****************************************************************************
+;* x86-optimized functions for w3fdif 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"
+
+SECTION_RODATA
+
+pd_2_23: times 4 dd 256*256*128
+
+SECTION .text
+
+INIT_XMM sse4
+cglobal w3fdif_scale, 3, 3, 3, 0, out_pixel, work_pixel, linesize
+    pxor                  m1, m1
+    mova                  m2, [pd_2_23]
+    shr            linesized, 2
+
+    .loop
+    mova                         m0, [work_pixelq]
+    pmaxsd                       m0, m1
+    pminsd                       m0, m2
+    psrld                        m0, 15
+    packusdw                     m0, m0
+    packuswb                     m0, m0
+    movd               [out_pixelq], m0
+    add                  out_pixelq, mmsize/4
+    add                 work_pixelq, mmsize
+    sub                   linesized, 1
+    jg .loop
+REP_RET
+
+INIT_XMM sse2
+cglobal w3fdif_simple_low, 4, 6, 5, 0, work_line, in_lines_cur0, coef, linesize
+    movd                  m1, [coefq+0]
+    SPLATW                m0, m1, 0
+    SPLATW                m1, m1, 1
+    mov                  r4q, 0
+    mov                  r5q, [in_lines_cur0q + gprsize]
+    mov       in_lines_cur0q, [in_lines_cur0q]
+    %define   in_lines_cur1q  r5q
+
+    .loop
+    movh                            m2, [in_lines_cur0q+r4q]
+    movh                            m3, [in_lines_cur1q+r4q]
+    pxor                            m4, m4
+    punpcklbw                       m2, m4
+    punpcklbw                       m3, m4
+    SBUTTERFLY                      wd, 2, 3, 4
+    pmaddwd                         m2, m0
+    pmaddwd                         m3, m1
+    mova            [work_lineq+r4q*4], m2
+    mova     [work_lineq+r4q*4+mmsize], m3
+    add                            r4q, 8
+    sub                      linesized, 8
+    jg .loop
+REP_RET
+
+%if ARCH_X86_64
+
+cglobal w3fdif_simple_high, 5, 10, 8, 0, work_line, in_lines_cur0, in_lines_adj0, coef, linesize
+    movq                  m2, [coefq+0]
+    SPLATW                m0, m2, 0
+    SPLATW                m1, m2, 1
+    SPLATW                m2, m2, 2
+    SBUTTERFLY            wd, 0, 1, 7
+    mov                  r5q, 0
+    mov                  r7q, [in_lines_cur0q+gprsize*2]
+    mov                  r6q, [in_lines_cur0q+gprsize]
+    mov       in_lines_cur0q, [in_lines_cur0q]
+    %define   in_lines_cur1q  r6q
+    %define   in_lines_cur2q  r7q
+    mov                  r9q, [in_lines_adj0q+gprsize*2]
+    mov                  r8q, [in_lines_adj0q+gprsize]
+    mov       in_lines_adj0q, [in_lines_adj0q]
+    %define   in_lines_adj1q  r8q
+    %define   in_lines_adj2q  r9q
+
+    .loop
+    movh                            m3, [in_lines_cur0q+r5q]
+    movh                            m4, [in_lines_cur1q+r5q]
+    pxor                            m7, m7
+    punpcklbw                       m3, m7
+    punpcklbw                       m4, m7
+    SBUTTERFLY                      wd, 3, 4, 7
+    pmaddwd                         m3, m0
+    pmaddwd                         m4, m1
+    movh                            m5, [in_lines_adj0q+r5q]
+    movh                            m6, [in_lines_adj1q+r5q]
+    pxor                            m7, m7
+    punpcklbw                       m5, m7
+    punpcklbw                       m6, m7
+    SBUTTERFLY                      wd, 5, 6, 7
+    pmaddwd                         m5, m0
+    pmaddwd                         m6, m1
+    paddd                           m3, m5
+    paddd                           m4, m6
+    movh                            m5, [in_lines_cur2q+r5q]
+    movh                            m6, [in_lines_adj2q+r5q]
+    pxor                            m7, m7
+    punpcklbw                       m5, m7
+    punpcklbw                       m6, m7
+    SBUTTERFLY                      wd, 5, 6, 7
+    pmaddwd                         m5, m2
+    pmaddwd                         m6, m2
+    paddd                           m3, m5
+    paddd                           m4, m6
+    movu                            m5, [work_lineq+r5q*4]
+    movu                            m6, [work_lineq+r5q*4+mmsize]
+    paddd                           m3, m5
+    paddd                           m4, m6
+    mova            [work_lineq+r5q*4], m3
+    mova     [work_lineq+r5q*4+mmsize], m4
+    add                            r5q, 8
+    sub                      linesized, 8
+    jg .loop
+REP_RET
+
+cglobal w3fdif_complex_low, 4, 8, 9, 0, work_line, in_lines_cur0, coef, linesize
+    movq                  m3, [coefq+0]
+    SPLATW                m0, m3, 0
+    SPLATW                m1, m3, 1
+    SPLATW                m2, m3, 2
+    SPLATW                m3, m3, 3
+    SBUTTERFLY            wd, 0, 1, 7
+    SBUTTERFLY            wd, 2, 3, 7
+    mov                  r4q, 0
+    mov                  r7q, [in_lines_cur0q+gprsize*3]
+    mov                  r6q, [in_lines_cur0q+gprsize*2]
+    mov                  r5q, [in_lines_cur0q+gprsize]
+    mov       in_lines_cur0q, [in_lines_cur0q]
+    %define   in_lines_cur1q  r5q
+    %define   in_lines_cur2q  r6q
+    %define   in_lines_cur3q  r7q
+
+    .loop
+    movh                            m4, [in_lines_cur0q+r4q]
+    movh                            m5, [in_lines_cur1q+r4q]
+    pxor                            m7, m7
+    punpcklbw                       m4, m7
+    punpcklbw                       m5, m7
+    SBUTTERFLY                      wd, 4, 5, 7
+    pmaddwd                         m4, m0
+    pmaddwd                         m5, m1
+    movh                            m6, [in_lines_cur2q+r4q]
+    movh                            m8, [in_lines_cur3q+r4q]
+    pxor                            m7, m7
+    punpcklbw                       m6, m7
+    punpcklbw                       m8, m7
+    SBUTTERFLY                      wd, 6, 8, 7
+    pmaddwd                         m6, m2
+    pmaddwd                         m8, m3
+    paddd                           m4, m6
+    paddd                           m5, m8
+    mova            [work_lineq+r4q*4], m4
+    mova     [work_lineq+r4q*4+mmsize], m5
+    add                            r4q, 8
+    sub                      linesized, 8
+    jg .loop
+REP_RET
+
+cglobal w3fdif_complex_high, 5, 14, 10, 0, work_line, in_lines_cur0, in_lines_adj0, coef, linesize
+    movq                  m3, [coefq+0]
+    movd                  m4, [coefq+8]
+    SPLATW                m0, m3, 0
+    SPLATW                m1, m3, 1
+    SPLATW                m2, m3, 2
+    SPLATW                m3, m3, 3
+    SPLATW                m4, m4
+    SBUTTERFLY            wd, 0, 1, 7
+    SBUTTERFLY            wd, 2, 3, 7
+    mov                  r5q, 0
+    mov                  r9q, [in_lines_cur0q+gprsize*4]
+    mov                  r8q, [in_lines_cur0q+gprsize*3]
+    mov                  r7q, [in_lines_cur0q+gprsize*2]
+    mov                  r6q, [in_lines_cur0q+gprsize]
+    mov       in_lines_cur0q, [in_lines_cur0q]
+    %define   in_lines_cur1q  r6q
+    %define   in_lines_cur2q  r7q
+    %define   in_lines_cur3q  r8q
+    %define   in_lines_cur4q  r9q
+    mov                 r13q, [in_lines_adj0q+gprsize*4]
+    mov                 r12q, [in_lines_adj0q+gprsize*3]
+    mov                 r11q, [in_lines_adj0q+gprsize*2]
+    mov                 r10q, [in_lines_adj0q+gprsize]
+    mov       in_lines_adj0q, [in_lines_adj0q]
+    %define   in_lines_adj1q  r10q
+    %define   in_lines_adj2q  r11q
+    %define   in_lines_adj3q  r12q
+    %define   in_lines_adj4q  r13q
+
+    .loop
+    movh                            m5, [in_lines_cur0q+r5q]
+    movh                            m6, [in_lines_cur1q+r5q]
+    pxor                            m7, m7
+    punpcklbw                       m5, m7
+    punpcklbw                       m6, m7
+    SBUTTERFLY                      wd, 5, 6, 7
+    pmaddwd                         m5, m0
+    pmaddwd                         m6, m1
+    movh                            m8, [in_lines_cur2q+r5q]
+    movh                            m9, [in_lines_cur3q+r5q]
+    pxor                            m7, m7
+    punpcklbw                       m8, m7
+    punpcklbw                       m9, m7
+    SBUTTERFLY                      wd, 8, 9, 7
+    pmaddwd                         m8, m2
+    pmaddwd                         m9, m3
+    paddd                           m5, m8
+    paddd                           m6, m9
+    movh                            m8, [in_lines_adj0q+r5q]
+    movh                            m9, [in_lines_adj1q+r5q]
+    pxor                            m7, m7
+    punpcklbw                       m8, m7
+    punpcklbw                       m9, m7
+    SBUTTERFLY                      wd, 8, 9, 7
+    pmaddwd                         m8, m0
+    pmaddwd                         m9, m1
+    paddd                           m5, m8
+    paddd                           m6, m9
+    movh                            m8, [in_lines_adj2q+r5q]
+    movh                            m9, [in_lines_adj3q+r5q]
+    pxor                            m7, m7
+    punpcklbw                       m8, m7
+    punpcklbw                       m9, m7
+    SBUTTERFLY                      wd, 8, 9, 7
+    pmaddwd                         m8, m2
+    pmaddwd                         m9, m3
+    paddd                           m5, m8
+    paddd                           m6, m9
+    movh                            m8, [in_lines_cur4q+r5q]
+    movh                            m9, [in_lines_adj4q+r5q]
+    pxor                            m7, m7
+    punpcklbw                       m8, m7
+    punpcklbw                       m9, m7
+    SBUTTERFLY                      wd, 8, 9, 7
+    pmaddwd                         m8, m4
+    pmaddwd                         m9, m4
+    paddd                           m5, m8
+    paddd                           m6, m9
+    movu                            m8, [work_lineq+r5q*4]
+    movu                            m9, [work_lineq+r5q*4+mmsize]
+    paddd                           m5, m8
+    paddd                           m6, m9
+    mova            [work_lineq+r5q*4], m5
+    mova     [work_lineq+r5q*4+mmsize], m6
+    add                            r5q, 8
+    sub                      linesized, 8
+    jg .loop
+REP_RET
+
+%endif
diff --git a/libavfilter/x86/vf_w3fdif_init.c b/libavfilter/x86/vf_w3fdif_init.c
new file mode 100644
index 0000000..957e9ae
--- /dev/null
+++ b/libavfilter/x86/vf_w3fdif_init.c
@@ -0,0 +1,65 @@
+/*
+ * 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/mem.h"
+#include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
+#include "libavfilter/w3fdif.h"
+
+void ff_w3fdif_simple_low_sse2(int32_t *work_line,
+                               uint8_t *in_lines_cur[2],
+                               const int16_t *coef, int linesize);
+
+void ff_w3fdif_simple_high_sse2(int32_t *work_line,
+                                uint8_t *in_lines_cur[3],
+                                uint8_t *in_lines_adj[3],
+                                const int16_t *coef, int linesize);
+
+void ff_w3fdif_complex_low_sse2(int32_t *work_line,
+                                uint8_t *in_lines_cur[4],
+                                const int16_t *coef, int linesize);
+
+void ff_w3fdif_complex_high_sse2(int32_t *work_line,
+                                 uint8_t *in_lines_cur[5],
+                                 uint8_t *in_lines_adj[5],
+                                 const int16_t *coef, int linesize);
+
+void ff_w3fdif_scale_sse4(uint8_t *out_pixel, const int32_t *work_pixel, int linesize);
+
+av_cold void ff_w3fdif_init_x86(W3FDIFDSPContext *dsp)
+{
+    int cpu_flags = av_get_cpu_flags();
+
+    if (EXTERNAL_SSE2(cpu_flags)) {
+        dsp->filter_simple_low   = ff_w3fdif_simple_low_sse2;
+        dsp->filter_simple_high  = ff_w3fdif_simple_high_sse2;
+    }
+
+    if (ARCH_X86_64 && EXTERNAL_SSE2(cpu_flags)) {
+        dsp->filter_complex_low  = ff_w3fdif_complex_low_sse2;
+        dsp->filter_complex_high = ff_w3fdif_complex_high_sse2;
+    }
+
+    if (EXTERNAL_SSE4(cpu_flags)) {
+        dsp->filter_scale        = ff_w3fdif_scale_sse4;
+    }
+}
-- 
1.9.1



More information about the ffmpeg-devel mailing list