diff mbox series

[FFmpeg-devel,2/2] avfilter/vf_v360: add SIMD for lagrange interpolation

Message ID 20200331135106.32490-2-onemda@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avfilter/vf_v360: add lagrange interpolation
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Paul B Mahol March 31, 2020, 1:51 p.m. UTC
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavfilter/x86/vf_v360.asm    | 46 ++++++++++++++++++++++++++++++++++
 libavfilter/x86/vf_v360_init.c |  6 +++++
 2 files changed, 52 insertions(+)

Comments

James Almer March 31, 2020, 3:38 p.m. UTC | #1
On 3/31/2020 10:51 AM, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavfilter/x86/vf_v360.asm    | 46 ++++++++++++++++++++++++++++++++++
>  libavfilter/x86/vf_v360_init.c |  6 +++++
>  2 files changed, 52 insertions(+)
> 
> diff --git a/libavfilter/x86/vf_v360.asm b/libavfilter/x86/vf_v360.asm
> index 5b241220d8..e1908e5e71 100644
> --- a/libavfilter/x86/vf_v360.asm
> +++ b/libavfilter/x86/vf_v360.asm
> @@ -165,6 +165,52 @@ DEFINE_ARGS dst, width, src, x, u, v, ker
>  
>  %if ARCH_X86_64
>  
> +INIT_YMM avx2
> +cglobal remap3_8bit_line, 7, 11, 8, dst, width, src, in_linesize, u, v, ker, x, y, tmp, z
> +    movsxdifnidn widthq, widthd
> +    xor             zq, zq
> +    xor             yq, yq
> +    xor             xq, xq
> +    movd           xm0, in_linesized
> +    pcmpeqw         m7, m7
> +    vpbroadcastd    m0, xm0
> +    vpbroadcastd    m6, [pd_255]
> +
> +    .loop:
> +        pmovsxwd   m1, [kerq + yq]
> +        pmovsxwd   m2, [vq + yq]
> +        pmovsxwd   m3, [uq + yq]
> +
> +        pmulld          m4, m2, m0
> +        paddd           m4, m3
> +        mova            m3, m7
> +        vpgatherdd      m2, [srcq + m4], m3
> +        pand            m2, m6
> +        pmulld          m2, m1

> +        phaddd          m2, m2
> +        phaddd          m1, m2, m2
> +        vextracti128   xm2, m1, 1
> +        paddd           m2, m1

This is very slow. Use the HADDD macro instead.

> +        movzx         tmpq, word [vq + yq + 16]
> +        imul          tmpq, in_linesizeq
> +        movzx           zq, word [uq + yq + 16]
> +        add           tmpq, zq
> +        movzx           zq, byte [srcq + tmpq]
> +        movzx         tmpq, word [kerq + yq + 16]
> +        imul            zq, tmpq
> +        movd           xm1, zd
> +        paddd           m2, m1
> +        psrld           m2, m2, 0xe
> +
> +        packuswb        m2, m2
> +        pextrb   [dstq+xq], xm2, 0
> +
> +        add   xq, 1
> +        add   yq, 18
> +        cmp   xq, widthq
> +        jl .loop
> +    RET
> +
>  INIT_YMM avx2
>  cglobal remap4_8bit_line, 7, 9, 11, dst, width, src, in_linesize, u, v, ker, x, y
>      movsxdifnidn widthq, widthd
> diff --git a/libavfilter/x86/vf_v360_init.c b/libavfilter/x86/vf_v360_init.c
> index babc6c426a..83f58bb96a 100644
> --- a/libavfilter/x86/vf_v360_init.c
> +++ b/libavfilter/x86/vf_v360_init.c
> @@ -29,6 +29,9 @@ void ff_remap1_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdi
>  void ff_remap2_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
>                                const int16_t *const u, const int16_t *const v, const int16_t *const ker);
>  
> +void ff_remap3_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
> +                              const int16_t *const u, const int16_t *const v, const int16_t *const ker);
> +
>  void ff_remap4_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
>                                const int16_t *const u, const int16_t *const v, const int16_t *const ker);
>  
> @@ -48,6 +51,9 @@ av_cold void ff_v360_init_x86(V360Context *s, int depth)
>      if (EXTERNAL_AVX2_FAST(cpu_flags) && s->interp == BILINEAR && depth <= 8)
>          s->remap_line = ff_remap2_8bit_line_avx2;
>  
> +    if (EXTERNAL_AVX2_FAST(cpu_flags) && s->interp == LAGRANGE && depth <= 8)
> +        s->remap_line = ff_remap3_8bit_line_avx2;
> +
>      if (EXTERNAL_AVX2_FAST(cpu_flags) && s->interp == NEAREST && depth > 8)
>          s->remap_line = ff_remap1_16bit_line_avx2;
>  
>
Michael Niedermayer March 31, 2020, 7:05 p.m. UTC | #2
On Tue, Mar 31, 2020 at 03:51:06PM +0200, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavfilter/x86/vf_v360.asm    | 46 ++++++++++++++++++++++++++++++++++
>  libavfilter/x86/vf_v360_init.c |  6 +++++
>  2 files changed, 52 insertions(+)

this fails to build on x86-32

libavfilter/libavfilter.a(vf_v360_init.o): In function `ff_v360_init_x86':
ffmpeg/linux32/src/libavfilter/x86/vf_v360_init.c:55: undefined reference to `ff_remap3_8bit_line_avx2'
collect2: error: ld returned 1 exit status
Makefile:114: recipe for target 'ffprobe_g' failed
make: *** [ffprobe_g] Error 1
make: *** Waiting for unfinished jobs....
libavfilter/libavfilter.a(vf_v360_init.o): In function `ff_v360_init_x86':
ffmpeg/linux32/src/libavfilter/x86/vf_v360_init.c:55: undefined reference to `ff_remap3_8bit_line_avx2'
collect2: error: ld returned 1 exit status
Makefile:114: recipe for target 'ffmpeg_g' failed
make: *** [ffmpeg_g] Error 1

[...]
diff mbox series

Patch

diff --git a/libavfilter/x86/vf_v360.asm b/libavfilter/x86/vf_v360.asm
index 5b241220d8..e1908e5e71 100644
--- a/libavfilter/x86/vf_v360.asm
+++ b/libavfilter/x86/vf_v360.asm
@@ -165,6 +165,52 @@  DEFINE_ARGS dst, width, src, x, u, v, ker
 
 %if ARCH_X86_64
 
+INIT_YMM avx2
+cglobal remap3_8bit_line, 7, 11, 8, dst, width, src, in_linesize, u, v, ker, x, y, tmp, z
+    movsxdifnidn widthq, widthd
+    xor             zq, zq
+    xor             yq, yq
+    xor             xq, xq
+    movd           xm0, in_linesized
+    pcmpeqw         m7, m7
+    vpbroadcastd    m0, xm0
+    vpbroadcastd    m6, [pd_255]
+
+    .loop:
+        pmovsxwd   m1, [kerq + yq]
+        pmovsxwd   m2, [vq + yq]
+        pmovsxwd   m3, [uq + yq]
+
+        pmulld          m4, m2, m0
+        paddd           m4, m3
+        mova            m3, m7
+        vpgatherdd      m2, [srcq + m4], m3
+        pand            m2, m6
+        pmulld          m2, m1
+        phaddd          m2, m2
+        phaddd          m1, m2, m2
+        vextracti128   xm2, m1, 1
+        paddd           m2, m1
+        movzx         tmpq, word [vq + yq + 16]
+        imul          tmpq, in_linesizeq
+        movzx           zq, word [uq + yq + 16]
+        add           tmpq, zq
+        movzx           zq, byte [srcq + tmpq]
+        movzx         tmpq, word [kerq + yq + 16]
+        imul            zq, tmpq
+        movd           xm1, zd
+        paddd           m2, m1
+        psrld           m2, m2, 0xe
+
+        packuswb        m2, m2
+        pextrb   [dstq+xq], xm2, 0
+
+        add   xq, 1
+        add   yq, 18
+        cmp   xq, widthq
+        jl .loop
+    RET
+
 INIT_YMM avx2
 cglobal remap4_8bit_line, 7, 9, 11, dst, width, src, in_linesize, u, v, ker, x, y
     movsxdifnidn widthq, widthd
diff --git a/libavfilter/x86/vf_v360_init.c b/libavfilter/x86/vf_v360_init.c
index babc6c426a..83f58bb96a 100644
--- a/libavfilter/x86/vf_v360_init.c
+++ b/libavfilter/x86/vf_v360_init.c
@@ -29,6 +29,9 @@  void ff_remap1_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdi
 void ff_remap2_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
                               const int16_t *const u, const int16_t *const v, const int16_t *const ker);
 
+void ff_remap3_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
+                              const int16_t *const u, const int16_t *const v, const int16_t *const ker);
+
 void ff_remap4_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
                               const int16_t *const u, const int16_t *const v, const int16_t *const ker);
 
@@ -48,6 +51,9 @@  av_cold void ff_v360_init_x86(V360Context *s, int depth)
     if (EXTERNAL_AVX2_FAST(cpu_flags) && s->interp == BILINEAR && depth <= 8)
         s->remap_line = ff_remap2_8bit_line_avx2;
 
+    if (EXTERNAL_AVX2_FAST(cpu_flags) && s->interp == LAGRANGE && depth <= 8)
+        s->remap_line = ff_remap3_8bit_line_avx2;
+
     if (EXTERNAL_AVX2_FAST(cpu_flags) && s->interp == NEAREST && depth > 8)
         s->remap_line = ff_remap1_16bit_line_avx2;