PR #26038 opened by DROO AMOR (DROOdotFOO)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26038
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26038.patch

# Summary of changes

Adds NEON `filter_line` for yadif and a checkasm test. 
The test exposes two x86 bugs, fixed here: wrong 14-bit output and stores past 
the line end. 

_checkasm numbers are in the commit messages._

`ffmpeg -vf yadif`, 1080p, 1 thread, ms/frame, C -> NEON:

| | A55 | A76 | M1 |
|---|---|---|---|
| 8-bit | 78.3 -> 34.4 (2.28x) | 27.7 -> 4.6 (6.04x) | 10.3 -> 0.51 (20.3x) |
| 10-bit | 119.2 -> 72.2 (1.65x) | 29.6 -> 6.9 (4.28x) | 11.2 -> 1.77 (6.30x) |
| 16-bit | 118.8 -> 73.9 (1.61x) | 28.9 -> 8.5 (3.38x) | 11.6 -> 1.98 (5.84x) |

## Manual testing

- [x] checkasm vf_yadif: A55, A76, M1, Zen 4, Rocket Lake, x86_32
- [x] FATE filter-yadif*: aarch64; x86_64 default, `CPUFLAGS=sse2`, `THREADS=4`
- [x] Each commit builds on aarch64 and x86_64; aarch64 `--disable-asm`


>From e79d69ee638fba948ec258a4e97b734fe0c43045 Mon Sep 17 00:00:00 2001
From: DROOdotFOO <[email protected]>
Date: Fri, 13 Nov 2026 22:29:28 +0100
Subject: [PATCH 1/5] avfilter/x86/yadif-10: fix 14-bit score overflow

The spatial scores are the sum of three absolute differences and reach
3 * 16383 at 14-bit, which pcmpgtw and pminsw treat as negative. Add
14-bit versions that bias the scores by 0x8000 so the signed compares
order them as unsigned, and saturate the initial -1 to 0: with a strict
compare, a best score of 0 rejects every direction just as -1 does.
The 10-bit versions, still used up to 13-bit, are unchanged.

Test Name               Zen4-gcc-13   RocketLake-gcc-13
-------------------------------------------------------
yadif14_sse2        1424.7 ( 4.13x)     1673.2 ( 6.38x)
yadif14_ssse3       1349.2 ( 4.36x)     1641.2 ( 6.50x)

Signed-off-by: DROOdotFOO <[email protected]>
---
 libavfilter/x86/vf_yadif_init.c | 13 ++++++++++++-
 libavfilter/x86/yadif-10.asm    | 23 ++++++++++++++++++-----
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/libavfilter/x86/vf_yadif_init.c b/libavfilter/x86/vf_yadif_init.c
index 257c3f91995..40efd3fffa4 100644
--- a/libavfilter/x86/vf_yadif_init.c
+++ b/libavfilter/x86/vf_yadif_init.c
@@ -46,6 +46,12 @@ void ff_yadif_filter_line_10bit_sse2(void *dst, void *prev, 
void *cur,
 void ff_yadif_filter_line_10bit_ssse3(void *dst, void *prev, void *cur,
                                       void *next, int w, int prefs,
                                       int mrefs, int parity, int mode);
+void ff_yadif_filter_line_14bit_sse2(void *dst, void *prev, void *cur,
+                                     void *next, int w, int prefs,
+                                     int mrefs, int parity, int mode);
+void ff_yadif_filter_line_14bit_ssse3(void *dst, void *prev, void *cur,
+                                      void *next, int w, int prefs,
+                                      int mrefs, int parity, int mode);
 
 av_cold void ff_yadif_init_x86(YADIFContext *yadif)
 {
@@ -60,7 +66,12 @@ av_cold void ff_yadif_init_x86(YADIFContext *yadif)
             yadif->filter_line = ff_yadif_filter_line_16bit_ssse3;
         if (EXTERNAL_SSE4(cpu_flags))
             yadif->filter_line = ff_yadif_filter_line_16bit_sse4;
-    } else if ( bit_depth >= 9 && bit_depth <= 14) {
+    } else if (bit_depth == 14) {
+        if (EXTERNAL_SSE2(cpu_flags))
+            yadif->filter_line = ff_yadif_filter_line_14bit_sse2;
+        if (EXTERNAL_SSSE3(cpu_flags))
+            yadif->filter_line = ff_yadif_filter_line_14bit_ssse3;
+    } else if ( bit_depth >= 9 && bit_depth <= 13) {
         if (EXTERNAL_SSE2(cpu_flags))
             yadif->filter_line = ff_yadif_filter_line_10bit_sse2;
         if (EXTERNAL_SSSE3(cpu_flags))
diff --git a/libavfilter/x86/yadif-10.asm b/libavfilter/x86/yadif-10.asm
index 3a6b3ef7599..0f4d84e21f2 100644
--- a/libavfilter/x86/yadif-10.asm
+++ b/libavfilter/x86/yadif-10.asm
@@ -27,6 +27,7 @@
 SECTION_RODATA
 
 pw_1: times 8 dw 1
+pw_8000: times 8 dw 0x8000
 
 SECTION .text
 
@@ -59,6 +60,9 @@ SECTION .text
     psrldq    m4, 4
     paddw     m2, m3
     paddw     m2, m4
+%if BIAS_SCORES
+    pxor      m2, [pw_8000]
+%endif
 %endmacro
 
 %macro CHECK1 0
@@ -156,7 +160,13 @@ SECTION .text
     psrldq       m3, 4
     paddw        m0, m2
     paddw        m0, m3
+%if BIAS_SCORES
+    ; scores reach 3 * 16383 at 14-bit; bias them for the signed compares
+    psubusw      m0, [pw_1]
+    pxor         m0, [pw_8000]
+%else
     psubw        m0, [pw_1]
+%endif
 
     CHECK -2, 0
     CHECK1
@@ -215,12 +225,13 @@ SECTION .text
     jg .loop%1
 %endmacro
 
-%macro YADIF 0
+%macro YADIF 1
+%assign BIAS_SCORES %1 == 14
 %if ARCH_X86_32
-cglobal yadif_filter_line_10bit, 4, 6, 8, 80, dst, prev, cur, next, w, \
+cglobal yadif_filter_line_%{1}bit, 4, 6, 8, 80, dst, prev, cur, next, w, \
                                               prefs, mrefs, parity, mode
 %else
-cglobal yadif_filter_line_10bit, 4, 7, 8, 80, dst, prev, cur, next, w, \
+cglobal yadif_filter_line_%{1}bit, 4, 7, 8, 80, dst, prev, cur, next, w, \
                                               prefs, mrefs, parity, mode
 %endif
 %if ARCH_X86_32
@@ -246,6 +257,8 @@ cglobal yadif_filter_line_10bit, 4, 7, 8, 80, dst, prev, 
cur, next, w, \
 %endmacro
 
 INIT_XMM ssse3
-YADIF
+YADIF 10
+YADIF 14
 INIT_XMM sse2
-YADIF
+YADIF 10
+YADIF 14
-- 
2.54.0


>From ddb0e44b727833335b73417e3065e09c94ed7766 Mon Sep 17 00:00:00 2001
From: DROOdotFOO <[email protected]>
Date: Sat, 14 Nov 2026 00:45:55 +0100
Subject: [PATCH 2/5] avfilter/x86/yadif: don't write past the line end

The 10-bit version stores 8 pixels per iteration but advances by 6, so
its last store could write up to 4 pixels past the end of the line,
which is the start of the next line when the linesize is tight. Store
only the pixels that fit on the last iteration.

All versions also ran one iteration when w <= 0, writing past the end
of narrow lines. Return early instead.

Signed-off-by: DROOdotFOO <[email protected]>
---
 libavfilter/x86/vf_yadif.asm |  2 ++
 libavfilter/x86/yadif-10.asm | 17 +++++++++++++++++
 libavfilter/x86/yadif-16.asm |  2 ++
 3 files changed, 21 insertions(+)

diff --git a/libavfilter/x86/vf_yadif.asm b/libavfilter/x86/vf_yadif.asm
index 5a0ba50fa08..18d3f2fca93 100644
--- a/libavfilter/x86/vf_yadif.asm
+++ b/libavfilter/x86/vf_yadif.asm
@@ -217,6 +217,8 @@ cglobal yadif_filter_line, 4, 7, 8, 80, dst, prev, cur, 
next, w, prefs, \
     DECLARE_REG_TMP 5,6
 %endif
 
+    cmp DWORD wm, 0
+    jle .ret
     cmp DWORD paritym, 0
     je .parity0
     FILTER 1, prevq, curq
diff --git a/libavfilter/x86/yadif-10.asm b/libavfilter/x86/yadif-10.asm
index 0f4d84e21f2..72169331651 100644
--- a/libavfilter/x86/yadif-10.asm
+++ b/libavfilter/x86/yadif-10.asm
@@ -216,6 +216,8 @@ SECTION .text
     pmaxsw       m1, m2
     pminsw       m1, m3
 
+    cmp   DWORD r4m, mmsize/2-2
+    jl .tail%1
     movu     [dstq], m1
     add        dstq, mmsize-4
     add       prevq, mmsize-4
@@ -223,6 +225,19 @@ SECTION .text
     add       nextq, mmsize-4
     sub   DWORD r4m, mmsize/2-2
     jg .loop%1
+    jmp .ret
+
+.tail%1:
+    cmp   DWORD r4m, 2
+    jg .tail4%1
+    movd     [dstq], m1
+    jmp .ret
+.tail4%1:
+    movh     [dstq], m1
+    cmp   DWORD r4m, 4
+    jle .ret
+    psrldq       m1, 8
+    movd   [dstq+8], m1
 %endmacro
 
 %macro YADIF 1
@@ -244,6 +259,8 @@ cglobal yadif_filter_line_%{1}bit, 4, 7, 8, 80, dst, prev, 
cur, next, w, \
     DECLARE_REG_TMP 5,6
 %endif
 
+    cmp DWORD wm, 0
+    jle .ret
     cmp DWORD paritym, 0
     je .parity0
     FILTER 1, prevq, curq
diff --git a/libavfilter/x86/yadif-16.asm b/libavfilter/x86/yadif-16.asm
index a161164a0d3..cfc9f959328 100644
--- a/libavfilter/x86/yadif-16.asm
+++ b/libavfilter/x86/yadif-16.asm
@@ -269,6 +269,8 @@ cglobal yadif_filter_line_16bit, 4, 7, 8, 80, dst, prev, 
cur, next, w, \
     DECLARE_REG_TMP 5,6
 %endif
 
+    cmp DWORD wm, 0
+    jle .ret
     cmp DWORD paritym, 0
     je .parity0
     FILTER 1, prevq, curq
-- 
2.54.0


>From bd60f2572c66f720cc9c0ee1682e4eb94c4fc33e Mon Sep 17 00:00:00 2001
From: DROOdotFOO <[email protected]>
Date: Sat, 7 Nov 2026 01:33:12 +0100
Subject: [PATCH 3/5] avfilter/vf_yadif: move the C line functions to
 vf_yadif_init.h

Move filter_line and filter_edges into a header, and the init code
from config_output() into ff_yadif_init() there, so that checkasm can
test them. No functional change.

Signed-off-by: DROOdotFOO <[email protected]>
---
 libavfilter/vf_yadif.c      | 166 +----------------------------
 libavfilter/vf_yadif_init.h | 201 ++++++++++++++++++++++++++++++++++++
 2 files changed, 203 insertions(+), 164 deletions(-)
 create mode 100644 libavfilter/vf_yadif_init.h

diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c
index 7e6ac171f14..d34fb9e359a 100644
--- a/libavfilter/vf_yadif.c
+++ b/libavfilter/vf_yadif.c
@@ -23,6 +23,7 @@
 #include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "filters.h"
+#include "vf_yadif_init.h"
 #include "yadif.h"
 
 typedef struct ThreadData {
@@ -33,159 +34,6 @@ typedef struct ThreadData {
     int tff;
 } ThreadData;
 
-#define CHECK(j)\
-    {   int score = FFABS(cur[mrefs - 1 + (j)] - cur[prefs - 1 - (j)])\
-                  + FFABS(cur[mrefs  +(j)] - cur[prefs  -(j)])\
-                  + FFABS(cur[mrefs + 1 + (j)] - cur[prefs + 1 - (j)]);\
-        if (score < spatial_score) {\
-            spatial_score= score;\
-            spatial_pred= (cur[mrefs  +(j)] + cur[prefs  -(j)])>>1;\
-
-/* The is_not_edge argument here controls when the code will enter a branch
- * which reads up to and including x-3 and x+3. */
-
-#define FILTER(start, end, is_not_edge) \
-    for (x = start;  x < end; x++) { \
-        int c = cur[mrefs]; \
-        int d = (prev2[0] + next2[0])>>1; \
-        int e = cur[prefs]; \
-        int temporal_diff0 = FFABS(prev2[0] - next2[0]); \
-        int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) 
)>>1; \
-        int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) 
)>>1; \
-        int diff = FFMAX3(temporal_diff0 >> 1, temporal_diff1, 
temporal_diff2); \
-        int spatial_pred = (c+e) >> 1; \
- \
-        if (is_not_edge) {\
-            int spatial_score = FFABS(cur[mrefs - 1] - cur[prefs - 1]) + 
FFABS(c-e) \
-                              + FFABS(cur[mrefs + 1] - cur[prefs + 1]) - 1; \
-            CHECK(-1) CHECK(-2) }} }} \
-            CHECK( 1) CHECK( 2) }} }} \
-        }\
- \
-        if (!(mode&2)) { \
-            int b = (prev2[2 * mrefs] + next2[2 * mrefs])>>1; \
-            int f = (prev2[2 * prefs] + next2[2 * prefs])>>1; \
-            int max = FFMAX3(d - e, d - c, FFMIN(b - c, f - e)); \
-            int min = FFMIN3(d - e, d - c, FFMAX(b - c, f - e)); \
- \
-            diff = FFMAX3(diff, min, -max); \
-        } \
- \
-        if (spatial_pred > d + diff) \
-           spatial_pred = d + diff; \
-        else if (spatial_pred < d - diff) \
-           spatial_pred = d - diff; \
- \
-        dst[0] = spatial_pred; \
- \
-        dst++; \
-        cur++; \
-        prev++; \
-        next++; \
-        prev2++; \
-        next2++; \
-    }
-
-static void filter_line_c(void *dst1,
-                          void *prev1, void *cur1, void *next1,
-                          int w, int prefs, int mrefs, int parity, int mode)
-{
-    uint8_t *dst  = dst1;
-    uint8_t *prev = prev1;
-    uint8_t *cur  = cur1;
-    uint8_t *next = next1;
-    int x;
-    uint8_t *prev2 = parity ? prev : cur ;
-    uint8_t *next2 = parity ? cur  : next;
-
-    /* The function is called with the pointers already pointing to data[3] and
-     * with 6 subtracted from the width.  This allows the FILTER macro to be
-     * called so that it processes all the pixels normally.  A constant value 
of
-     * true for is_not_edge lets the compiler ignore the if statement. */
-    FILTER(0, w, 1)
-}
-
-#define MAX_ALIGN 8
-static void filter_edges(void *dst1, void *prev1, void *cur1, void *next1,
-                         int w, int prefs, int mrefs, int parity, int mode)
-{
-    uint8_t *dst  = dst1;
-    uint8_t *prev = prev1;
-    uint8_t *cur  = cur1;
-    uint8_t *next = next1;
-    int x;
-    uint8_t *prev2 = parity ? prev : cur ;
-    uint8_t *next2 = parity ? cur  : next;
-
-    const int edge = MAX_ALIGN - 1;
-    int offset = FFMAX(w - edge, 3);
-
-    /* Only edge pixels need to be processed here.  A constant value of false
-     * for is_not_edge should let the compiler ignore the whole branch. */
-    FILTER(0, FFMIN(3, w), 0)
-
-    dst  = (uint8_t*)dst1  + offset;
-    prev = (uint8_t*)prev1 + offset;
-    cur  = (uint8_t*)cur1  + offset;
-    next = (uint8_t*)next1 + offset;
-    prev2 = (uint8_t*)(parity ? prev : cur);
-    next2 = (uint8_t*)(parity ? cur  : next);
-
-    FILTER(offset, w - 3, 1)
-    offset = FFMAX(offset, w - 3);
-    FILTER(offset, w, 0)
-}
-
-
-static void filter_line_c_16bit(void *dst1,
-                                void *prev1, void *cur1, void *next1,
-                                int w, int prefs, int mrefs, int parity,
-                                int mode)
-{
-    uint16_t *dst  = dst1;
-    uint16_t *prev = prev1;
-    uint16_t *cur  = cur1;
-    uint16_t *next = next1;
-    int x;
-    uint16_t *prev2 = parity ? prev : cur ;
-    uint16_t *next2 = parity ? cur  : next;
-    mrefs /= 2;
-    prefs /= 2;
-
-    FILTER(0, w, 1)
-}
-
-static void filter_edges_16bit(void *dst1, void *prev1, void *cur1, void 
*next1,
-                               int w, int prefs, int mrefs, int parity, int 
mode)
-{
-    uint16_t *dst  = dst1;
-    uint16_t *prev = prev1;
-    uint16_t *cur  = cur1;
-    uint16_t *next = next1;
-    int x;
-    uint16_t *prev2 = parity ? prev : cur ;
-    uint16_t *next2 = parity ? cur  : next;
-
-    const int edge = MAX_ALIGN / 2 - 1;
-    int offset = FFMAX(w - edge, 3);
-
-    mrefs /= 2;
-    prefs /= 2;
-
-    FILTER(0,  FFMIN(3, w), 0)
-
-    dst   = (uint16_t*)dst1  + offset;
-    prev  = (uint16_t*)prev1 + offset;
-    cur   = (uint16_t*)cur1  + offset;
-    next  = (uint16_t*)next1 + offset;
-    prev2 = (uint16_t*)(parity ? prev : cur);
-    next2 = (uint16_t*)(parity ? cur  : next);
-
-    FILTER(offset, w - 3, 1)
-    offset = FFMAX(offset, w - 3);
-    FILTER(offset, w, 0)
-}
-
 static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
 {
     YADIFContext *s = ctx->priv;
@@ -283,17 +131,7 @@ static int config_output(AVFilterLink *outlink)
 
     s->csp = av_pix_fmt_desc_get(outlink->format);
     s->filter = filter;
-    if (s->csp->comp[0].depth > 8) {
-        s->filter_line  = filter_line_c_16bit;
-        s->filter_edges = filter_edges_16bit;
-    } else {
-        s->filter_line  = filter_line_c;
-        s->filter_edges = filter_edges;
-    }
-
-#if ARCH_X86 && HAVE_X86ASM
-    ff_yadif_init_x86(s);
-#endif
+    ff_yadif_init(s);
 
     return 0;
 }
diff --git a/libavfilter/vf_yadif_init.h b/libavfilter/vf_yadif_init.h
new file mode 100644
index 00000000000..7160e444ff6
--- /dev/null
+++ b/libavfilter/vf_yadif_init.h
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2006-2011 Michael Niedermayer <[email protected]>
+ *               2010      James Darnley <[email protected]>
+ *
+ * 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_YADIF_INIT_H
+#define AVFILTER_YADIF_INIT_H
+
+#include <stdint.h>
+
+#include "config.h"
+#include "libavutil/attributes.h"
+#include "libavutil/common.h"
+#include "libavutil/pixdesc.h"
+#include "yadif.h"
+
+#define CHECK(j)\
+    {   int score = FFABS(cur[mrefs - 1 + (j)] - cur[prefs - 1 - (j)])\
+                  + FFABS(cur[mrefs  +(j)] - cur[prefs  -(j)])\
+                  + FFABS(cur[mrefs + 1 + (j)] - cur[prefs + 1 - (j)]);\
+        if (score < spatial_score) {\
+            spatial_score= score;\
+            spatial_pred= (cur[mrefs  +(j)] + cur[prefs  -(j)])>>1;\
+
+/* The is_not_edge argument here controls when the code will enter a branch
+ * which reads up to and including x-3 and x+3. */
+
+#define FILTER(start, end, is_not_edge) \
+    for (x = start;  x < end; x++) { \
+        int c = cur[mrefs]; \
+        int d = (prev2[0] + next2[0])>>1; \
+        int e = cur[prefs]; \
+        int temporal_diff0 = FFABS(prev2[0] - next2[0]); \
+        int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) 
)>>1; \
+        int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) 
)>>1; \
+        int diff = FFMAX3(temporal_diff0 >> 1, temporal_diff1, 
temporal_diff2); \
+        int spatial_pred = (c+e) >> 1; \
+ \
+        if (is_not_edge) {\
+            int spatial_score = FFABS(cur[mrefs - 1] - cur[prefs - 1]) + 
FFABS(c-e) \
+                              + FFABS(cur[mrefs + 1] - cur[prefs + 1]) - 1; \
+            CHECK(-1) CHECK(-2) }} }} \
+            CHECK( 1) CHECK( 2) }} }} \
+        }\
+ \
+        if (!(mode&2)) { \
+            int b = (prev2[2 * mrefs] + next2[2 * mrefs])>>1; \
+            int f = (prev2[2 * prefs] + next2[2 * prefs])>>1; \
+            int max = FFMAX3(d - e, d - c, FFMIN(b - c, f - e)); \
+            int min = FFMIN3(d - e, d - c, FFMAX(b - c, f - e)); \
+ \
+            diff = FFMAX3(diff, min, -max); \
+        } \
+ \
+        if (spatial_pred > d + diff) \
+           spatial_pred = d + diff; \
+        else if (spatial_pred < d - diff) \
+           spatial_pred = d - diff; \
+ \
+        dst[0] = spatial_pred; \
+ \
+        dst++; \
+        cur++; \
+        prev++; \
+        next++; \
+        prev2++; \
+        next2++; \
+    }
+
+static void filter_line_c(void *dst1,
+                          void *prev1, void *cur1, void *next1,
+                          int w, int prefs, int mrefs, int parity, int mode)
+{
+    uint8_t *dst  = dst1;
+    uint8_t *prev = prev1;
+    uint8_t *cur  = cur1;
+    uint8_t *next = next1;
+    int x;
+    uint8_t *prev2 = parity ? prev : cur ;
+    uint8_t *next2 = parity ? cur  : next;
+
+    /* The function is called with the pointers already pointing to data[3] and
+     * with 6 subtracted from the width.  This allows the FILTER macro to be
+     * called so that it processes all the pixels normally.  A constant value 
of
+     * true for is_not_edge lets the compiler ignore the if statement. */
+    FILTER(0, w, 1)
+}
+
+#define MAX_ALIGN 8
+static void filter_edges(void *dst1, void *prev1, void *cur1, void *next1,
+                         int w, int prefs, int mrefs, int parity, int mode)
+{
+    uint8_t *dst  = dst1;
+    uint8_t *prev = prev1;
+    uint8_t *cur  = cur1;
+    uint8_t *next = next1;
+    int x;
+    uint8_t *prev2 = parity ? prev : cur ;
+    uint8_t *next2 = parity ? cur  : next;
+
+    const int edge = MAX_ALIGN - 1;
+    int offset = FFMAX(w - edge, 3);
+
+    /* Only edge pixels need to be processed here.  A constant value of false
+     * for is_not_edge should let the compiler ignore the whole branch. */
+    FILTER(0, FFMIN(3, w), 0)
+
+    dst  = (uint8_t*)dst1  + offset;
+    prev = (uint8_t*)prev1 + offset;
+    cur  = (uint8_t*)cur1  + offset;
+    next = (uint8_t*)next1 + offset;
+    prev2 = (uint8_t*)(parity ? prev : cur);
+    next2 = (uint8_t*)(parity ? cur  : next);
+
+    FILTER(offset, w - 3, 1)
+    offset = FFMAX(offset, w - 3);
+    FILTER(offset, w, 0)
+}
+
+
+static void filter_line_c_16bit(void *dst1,
+                                void *prev1, void *cur1, void *next1,
+                                int w, int prefs, int mrefs, int parity,
+                                int mode)
+{
+    uint16_t *dst  = dst1;
+    uint16_t *prev = prev1;
+    uint16_t *cur  = cur1;
+    uint16_t *next = next1;
+    int x;
+    uint16_t *prev2 = parity ? prev : cur ;
+    uint16_t *next2 = parity ? cur  : next;
+    mrefs /= 2;
+    prefs /= 2;
+
+    FILTER(0, w, 1)
+}
+
+static void filter_edges_16bit(void *dst1, void *prev1, void *cur1, void 
*next1,
+                               int w, int prefs, int mrefs, int parity, int 
mode)
+{
+    uint16_t *dst  = dst1;
+    uint16_t *prev = prev1;
+    uint16_t *cur  = cur1;
+    uint16_t *next = next1;
+    int x;
+    uint16_t *prev2 = parity ? prev : cur ;
+    uint16_t *next2 = parity ? cur  : next;
+
+    const int edge = MAX_ALIGN / 2 - 1;
+    int offset = FFMAX(w - edge, 3);
+
+    mrefs /= 2;
+    prefs /= 2;
+
+    FILTER(0,  FFMIN(3, w), 0)
+
+    dst   = (uint16_t*)dst1  + offset;
+    prev  = (uint16_t*)prev1 + offset;
+    cur   = (uint16_t*)cur1  + offset;
+    next  = (uint16_t*)next1 + offset;
+    prev2 = (uint16_t*)(parity ? prev : cur);
+    next2 = (uint16_t*)(parity ? cur  : next);
+
+    FILTER(offset, w - 3, 1)
+    offset = FFMAX(offset, w - 3);
+    FILTER(offset, w, 0)
+}
+
+av_unused static void ff_yadif_init(YADIFContext *s)
+{
+    if (s->csp->comp[0].depth > 8) {
+        s->filter_line  = filter_line_c_16bit;
+        s->filter_edges = filter_edges_16bit;
+    } else {
+        s->filter_line  = filter_line_c;
+        s->filter_edges = filter_edges;
+    }
+
+#if ARCH_X86 && HAVE_X86ASM
+    ff_yadif_init_x86(s);
+#endif
+}
+
+#endif /* AVFILTER_YADIF_INIT_H */
-- 
2.54.0


>From 13a9da0c1ddf95b3330fbe91a02f8eda0f7dd831 Mon Sep 17 00:00:00 2001
From: DROOdotFOO <[email protected]>
Date: Sat, 7 Nov 2026 01:34:24 +0100
Subject: [PATCH 4/5] tests/checkasm: add vf_yadif test

Covers 8, 9, 10, 12, 14 and 16-bit, interior, first and last rows,
negative linesizes, both parities and all modes, and checks that
nothing is written outside the line.

Signed-off-by: DROOdotFOO <[email protected]>
---
 tests/checkasm/Makefile   |   1 +
 tests/checkasm/checkasm.c |   3 +
 tests/checkasm/checkasm.h |   1 +
 tests/checkasm/vf_yadif.c | 157 ++++++++++++++++++++++++++++++++++++++
 tests/fate/checkasm.mak   |   1 +
 5 files changed, 163 insertions(+)
 create mode 100644 tests/checkasm/vf_yadif.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index ab1cc17b56c..abd14024572 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -86,6 +86,7 @@ AVFILTEROBJS-$(CONFIG_PP7_FILTER)        += vf_pp7.o
 AVFILTEROBJS-$(CONFIG_THRESHOLD_FILTER)  += vf_threshold.o
 AVFILTEROBJS-$(CONFIG_NLMEANS_FILTER)    += vf_nlmeans.o
 AVFILTEROBJS-$(CONFIG_SOBEL_FILTER)      += vf_convolution.o
+AVFILTEROBJS-$(CONFIG_YADIF_FILTER)      += vf_yadif.o
 
 CHECKASMOBJS-$(CONFIG_AVFILTER) += $(AVFILTEROBJS-yes)
 
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index e50d2885a3a..0e3c27ecb5c 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -300,6 +300,9 @@ static const CheckasmTest tests[] = {
     #if CONFIG_SOBEL_FILTER
         { "vf_sobel", checkasm_check_vf_sobel },
     #endif
+    #if CONFIG_YADIF_FILTER
+        { "vf_yadif", checkasm_check_vf_yadif },
+    #endif
 #endif
 #if CONFIG_SWSCALE
     { "sw_gbrp", checkasm_check_sw_gbrp },
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 0fc6823c4fb..50cc6cd159e 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -123,6 +123,7 @@ void checkasm_check_vf_limiter(void);
 void checkasm_check_vf_pp7(void);
 void checkasm_check_vf_threshold(void);
 void checkasm_check_vf_sobel(void);
+void checkasm_check_vf_yadif(void);
 void checkasm_check_vp3dsp(void);
 void checkasm_check_vp6dsp(void);
 void checkasm_check_vp8dsp(void);
diff --git a/tests/checkasm/vf_yadif.c b/tests/checkasm/vf_yadif.c
new file mode 100644
index 00000000000..e3aedefc896
--- /dev/null
+++ b/tests/checkasm/vf_yadif.c
@@ -0,0 +1,157 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 <string.h>
+#include "checkasm.h"
+#include "libavfilter/vf_yadif_init.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
+
+#define WIDTH  256
+#define STRIDE ((WIDTH + 32) * 2)
+#define ROWS   5
+
+enum {
+    PATTERN_RANDOM,
+    PATTERN_EXTREMES,   /* only 0 and the maximum value */
+    PATTERN_LOW,        /* many equal spatial scores */
+    NB_PATTERNS,
+};
+
+static void fill_planes(uint8_t *prev, uint8_t *cur, uint8_t *next,
+                        int depth, int pattern)
+{
+    const unsigned mask = (1U << depth) - 1;
+    uint8_t *planes[3]  = { prev, cur, next };
+
+    for (int p = 0; p < 3; p++) {
+        for (int i = 0; i < STRIDE * ROWS; i += depth > 8 ? 2 : 1) {
+            unsigned v = pattern == PATTERN_EXTREMES ? (rnd() & 1) * mask :
+                         pattern == PATTERN_LOW      ?  rnd() & 3         :
+                                                        rnd() & mask;
+            if (depth > 8)
+                AV_WN16A(planes[p] + i, v);
+            else
+                planes[p][i] = v;
+        }
+    }
+}
+
+static int untouched(const uint8_t *buf, int start, int end)
+{
+    for (int i = start; i < end; i++)
+        if (buf[i] != 0xba)
+            return 0;
+    return 1;
+}
+
+static void check_yadif(enum AVPixelFormat fmt)
+{
+    LOCAL_ALIGNED_16(uint8_t, prev, [STRIDE * ROWS]);
+    LOCAL_ALIGNED_16(uint8_t, cur,  [STRIDE * ROWS]);
+    LOCAL_ALIGNED_16(uint8_t, next, [STRIDE * ROWS]);
+    LOCAL_ALIGNED_16(uint8_t, dst0, [STRIDE]);
+    LOCAL_ALIGNED_16(uint8_t, dst1, [STRIDE]);
+    static const int widths[] = {
+        WIDTH, WIDTH - 5, 64, 33, 26, 22, 17, 12, 11, 10, 7, 6, 5, 4, 3
+    };
+    YADIFContext s = { .csp = av_pix_fmt_desc_get(fmt) };
+    const int depth = s.csp->comp[0].depth;
+    const int df    = (depth + 7) / 8;
+    const int edge  = 3 + MAX_ALIGN / df - 1;
+    const int pix_3 = 3 * df;
+    uint8_t *prevl  = prev + 2 * STRIDE;
+    uint8_t *curl   = cur  + 2 * STRIDE;
+    uint8_t *nextl  = next + 2 * STRIDE;
+
+    declare_func(void, void *dst, void *prev, void *cur, void *next,
+                 int w, int prefs, int mrefs, int parity, int mode);
+
+    ff_yadif_init(&s);
+
+    if (!check_func(s.filter_line, "yadif%d", depth))
+        return;
+
+    for (int pattern = 0; pattern < NB_PATTERNS; pattern++) {
+        fill_planes(prev, cur, next, depth, pattern);
+
+        for (int i = 0; i < FF_ARRAY_ELEMS(widths); i++) {
+            /* interior rows, first row, last row, negative linesize */
+            for (int refs = 0; refs < 4; refs++) {
+                const int prefs = refs & 2 ? -STRIDE : STRIDE;
+                const int mrefs = refs & 1 ?  STRIDE : -STRIDE;
+
+                for (int parity = 0; parity < 2; parity++) {
+                    for (int mode = 0; mode < 4; mode++) {
+                        const int w = widths[i];
+                        int left;
+
+                        memset(dst0, 0xba, STRIDE);
+                        memset(dst1, 0xba, STRIDE);
+
+                        call_ref(dst0 + pix_3, prevl + pix_3, curl + pix_3,
+                                 nextl + pix_3, w - edge, prefs, mrefs,
+                                 parity, mode);
+                        call_new(dst1 + pix_3, prevl + pix_3, curl + pix_3,
+                                 nextl + pix_3, w - edge, prefs, mrefs,
+                                 parity, mode);
+                        left = untouched(dst1, 0, pix_3);
+
+                        s.filter_edges(dst0, prevl, curl, nextl, w,
+                                       prefs, mrefs, parity, mode);
+                        s.filter_edges(dst1, prevl, curl, nextl, w,
+                                       prefs, mrefs, parity, mode);
+
+                        if (!left || memcmp(dst0, dst1, w * df) ||
+                            !untouched(dst1, w * df, STRIDE)) {
+                            fprintf(stderr, "yadif%d: w=%d prefs=%d mrefs=%d "
+                                    "parity=%d mode=%d pattern=%d\n", depth,
+                                    w, prefs, mrefs, parity, mode, pattern);
+                            fail();
+                            return;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    bench_new(dst1 + pix_3, prevl + pix_3, curl + pix_3, nextl + pix_3,
+              WIDTH - edge, STRIDE, -STRIDE, 0, 0);
+}
+
+void checkasm_check_vf_yadif(void)
+{
+    check_yadif(AV_PIX_FMT_YUV420P);
+    report("yadif8");
+
+    check_yadif(AV_PIX_FMT_YUV420P9);
+    report("yadif9");
+
+    check_yadif(AV_PIX_FMT_YUV420P10);
+    report("yadif10");
+
+    check_yadif(AV_PIX_FMT_YUV420P12);
+    report("yadif12");
+
+    check_yadif(AV_PIX_FMT_YUV420P14);
+    report("yadif14");
+
+    check_yadif(AV_PIX_FMT_YUV420P16);
+    report("yadif16");
+}
diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak
index 19bbe7e571a..82d2cc149c1 100644
--- a/tests/fate/checkasm.mak
+++ b/tests/fate/checkasm.mak
@@ -92,6 +92,7 @@ FATE_CHECKASM = fate-checkasm-aacencdsp                       
          \
                 fate-checkasm-vf_pp7                                    \
                 fate-checkasm-vf_threshold                              \
                 fate-checkasm-vf_sobel                                  \
+                fate-checkasm-vf_yadif                                  \
                 fate-checkasm-videodsp                                  \
                 fate-checkasm-vorbisdsp                                 \
                 fate-checkasm-vp3dsp                                    \
-- 
2.54.0


>From 1f715316167ce13c26c9173083e6afca6487ce77 Mon Sep 17 00:00:00 2001
From: DROOdotFOO <[email protected]>
Date: Sat, 7 Nov 2026 01:48:42 +0100
Subject: [PATCH 5/5] avfilter/aarch64: add NEON yadif filter_line

Test Name                A55-gcc-11          A76-gcc-11          M1-clang
-------------------------------------------------------------------------
yadif8_neon         3919.7 ( 4.64x)     1082.0 ( 7.66x)    127.8 (13.26x)
yadif9_neon         6616.6 ( 3.43x)     1546.1 ( 6.01x)    184.2 ( 9.38x)
yadif10_neon        6616.6 ( 3.43x)     1546.7 ( 6.00x)    182.5 ( 9.41x)
yadif12_neon        6616.5 ( 3.43x)     1546.8 ( 6.00x)    182.1 ( 9.46x)
yadif14_neon        6616.8 ( 3.43x)     1546.7 ( 6.00x)    185.0 ( 9.36x)
yadif16_neon        7731.0 ( 2.93x)     2124.0 ( 4.37x)    258.3 ( 6.73x)

Signed-off-by: DROOdotFOO <[email protected]>
---
 libavfilter/aarch64/Makefile        |   2 +
 libavfilter/aarch64/vf_yadif_init.c |  50 +++++
 libavfilter/aarch64/vf_yadif_neon.S | 299 ++++++++++++++++++++++++++++
 libavfilter/vf_yadif_init.h         |   2 +
 libavfilter/yadif.h                 |   1 +
 5 files changed, 354 insertions(+)
 create mode 100644 libavfilter/aarch64/vf_yadif_init.c
 create mode 100644 libavfilter/aarch64/vf_yadif_neon.S

diff --git a/libavfilter/aarch64/Makefile b/libavfilter/aarch64/Makefile
index d09f7e40806..83fa48c1526 100644
--- a/libavfilter/aarch64/Makefile
+++ b/libavfilter/aarch64/Makefile
@@ -2,8 +2,10 @@ OBJS-$(CONFIG_BWDIF_FILTER)                  += 
aarch64/vf_bwdif_init_aarch64.o
 OBJS-$(CONFIG_COLORDETECT_FILTER)            += aarch64/vf_colordetect_init.o
 OBJS-$(CONFIG_NLMEANS_FILTER)                += aarch64/vf_nlmeans_init.o
 OBJS-$(CONFIG_THRESHOLD_FILTER)              += aarch64/vf_threshold_init.o
+OBJS-$(CONFIG_YADIF_FILTER)                  += aarch64/vf_yadif_init.o
 
 NEON-OBJS-$(CONFIG_BWDIF_FILTER)             += aarch64/vf_bwdif_neon.o
 NEON-OBJS-$(CONFIG_COLORDETECT_FILTER)       += aarch64/vf_colordetect_neon.o
 NEON-OBJS-$(CONFIG_NLMEANS_FILTER)           += aarch64/vf_nlmeans_neon.o
 NEON-OBJS-$(CONFIG_THRESHOLD_FILTER)         += aarch64/vf_threshold_neon.o
+NEON-OBJS-$(CONFIG_YADIF_FILTER)             += aarch64/vf_yadif_neon.o
diff --git a/libavfilter/aarch64/vf_yadif_init.c 
b/libavfilter/aarch64/vf_yadif_init.c
new file mode 100644
index 00000000000..1aea39c47b4
--- /dev/null
+++ b/libavfilter/aarch64/vf_yadif_init.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2026 DROOdotFOO <[email protected]>
+ *
+ * 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/aarch64/cpu.h"
+#include "libavfilter/yadif.h"
+
+void ff_yadif_filter_line_neon(void *dst, void *prev, void *cur,
+                               void *next, int w, int prefs,
+                               int mrefs, int parity, int mode);
+void ff_yadif_filter_line_10bit_neon(void *dst, void *prev, void *cur,
+                                     void *next, int w, int prefs,
+                                     int mrefs, int parity, int mode);
+void ff_yadif_filter_line_16bit_neon(void *dst, void *prev, void *cur,
+                                     void *next, int w, int prefs,
+                                     int mrefs, int parity, int mode);
+
+av_cold void ff_yadif_init_aarch64(YADIFContext *yadif)
+{
+    int cpu_flags = av_get_cpu_flags();
+    int bit_depth = yadif->csp->comp[0].depth;
+
+    if (!have_neon(cpu_flags))
+        return;
+
+    if (bit_depth >= 15)
+        yadif->filter_line = ff_yadif_filter_line_16bit_neon;
+    else if (bit_depth >= 9)
+        yadif->filter_line = ff_yadif_filter_line_10bit_neon;
+    else
+        yadif->filter_line = ff_yadif_filter_line_neon;
+}
diff --git a/libavfilter/aarch64/vf_yadif_neon.S 
b/libavfilter/aarch64/vf_yadif_neon.S
new file mode 100644
index 00000000000..01c73054396
--- /dev/null
+++ b/libavfilter/aarch64/vf_yadif_neon.S
@@ -0,0 +1,299 @@
+/*
+ * Copyright (c) 2026 DROOdotFOO <[email protected]>
+ *
+ * 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/aarch64/asm.S"
+
+// x0 = dst, x1 = prev, x2 = cur, x3 = next, x8 = prev2, x9 = next2,
+// x10 = cur + mrefs, x11 = cur + prefs, x5 = prefs, x6 = mrefs,
+// x12 = 2 * mrefs, x13 = 2 * prefs, w4 = remaining width, w14 = mode.
+
+.macro widen r, kind
+.ifc \kind, u8
+        uxtl            v\r\().8h, v\r\().8b
+.endif
+.ifc \kind, u16w
+        uxtl            v\r\().4s, v\r\().4h
+.endif
+.endm
+
+.macro ldo lw, kind, r, base, off
+        ldur            \lw\r, [\base, #\off]
+        widen           \r, \kind
+.endm
+
+.macro ldx lw, kind, r, base, idx
+        ldr             \lw\r, [\base, \idx]
+        widen           \r, \kind
+.endm
+
+// Temporal prediction. Leaves c in v2, e in v3, d + diff in v18 and
+// d - diff in v19 (saturated).
+.macro temporal t, lw, kind, spatial_check
+        ldo             \lw, \kind, 0, x8, 0            // prev2[0]
+        ldo             \lw, \kind, 1, x9, 0            // next2[0]
+        ldo             \lw, \kind, 2, x10, 0           // c
+        ldo             \lw, \kind, 3, x11, 0           // e
+        ldx             \lw, \kind, 4, x1, x6           // prev[mrefs]
+        ldx             \lw, \kind, 5, x1, x5           // prev[prefs]
+        ldx             \lw, \kind, 6, x3, x6           // next[mrefs]
+        ldx             \lw, \kind, 7, x3, x5           // next[prefs]
+        uhadd           v16.\t, v0.\t, v1.\t            // d
+        uabd            v17.\t, v0.\t, v1.\t
+        ushr            v17.\t, v17.\t, #1
+        uabd            v4.\t, v4.\t, v2.\t
+        uabd            v5.\t, v5.\t, v3.\t
+        uhadd           v4.\t, v4.\t, v5.\t
+        uabd            v6.\t, v6.\t, v2.\t
+        uabd            v7.\t, v7.\t, v3.\t
+        uhadd           v6.\t, v6.\t, v7.\t
+        umax            v17.\t, v17.\t, v4.\t
+        umax            v17.\t, v17.\t, v6.\t           // diff
+.if \spatial_check
+        ldx             \lw, \kind, 0, x8, x12          // prev2[2 * mrefs]
+        ldx             \lw, \kind, 1, x9, x12          // next2[2 * mrefs]
+        ldx             \lw, \kind, 4, x8, x13          // prev2[2 * prefs]
+        ldx             \lw, \kind, 5, x9, x13          // next2[2 * prefs]
+        uhadd           v0.\t, v0.\t, v1.\t             // b
+        uhadd           v4.\t, v4.\t, v5.\t             // f
+        // max(min, 0) and max(-max, 0)
+        uqsub           v1.\t, v16.\t, v3.\t
+        uqsub           v5.\t, v16.\t, v2.\t
+        umin            v1.\t, v1.\t, v5.\t
+        uqsub           v5.\t, v0.\t, v2.\t
+        uqsub           v6.\t, v4.\t, v3.\t
+        umax            v5.\t, v5.\t, v6.\t
+        umin            v1.\t, v1.\t, v5.\t
+        uqsub           v5.\t, v3.\t, v16.\t
+        uqsub           v6.\t, v2.\t, v16.\t
+        umin            v5.\t, v5.\t, v6.\t
+        uqsub           v6.\t, v2.\t, v0.\t
+        uqsub           v7.\t, v3.\t, v4.\t
+        umax            v6.\t, v6.\t, v7.\t
+        umin            v5.\t, v5.\t, v6.\t
+        umax            v17.\t, v17.\t, v1.\t
+        umax            v17.\t, v17.\t, v5.\t
+.endif
+        uqadd           v18.\t, v16.\t, v17.\t
+        uqsub           v19.\t, v16.\t, v17.\t
+.endm
+
+// cur[mrefs + k] in v20-v22 (k = -3..-1) and v23-v25 (k = 1..3),
+// cur[prefs + k] in v26-v28 (k = -3..-1) and v29-v31 (k = 1..3).
+.macro load_spatial lw, kind, bpp
+        ldo             \lw, \kind, 20, x10, -3 * \bpp
+        ldo             \lw, \kind, 21, x10, -2 * \bpp
+        ldo             \lw, \kind, 22, x10, -1 * \bpp
+        ldo             \lw, \kind, 23, x10,  1 * \bpp
+        ldo             \lw, \kind, 24, x10,  2 * \bpp
+        ldo             \lw, \kind, 25, x10,  3 * \bpp
+        ldo             \lw, \kind, 26, x11, -3 * \bpp
+        ldo             \lw, \kind, 27, x11, -2 * \bpp
+        ldo             \lw, \kind, 28, x11, -1 * \bpp
+        ldo             \lw, \kind, 29, x11,  1 * \bpp
+        ldo             \lw, \kind, 30, x11,  2 * \bpp
+        ldo             \lw, \kind, 31, x11,  3 * \bpp
+.endm
+
+// Spatial score of one direction into v0.
+.macro score t, m0, p0, m1, p1, m2, p2
+        uabd            v0.\t, \m0\().\t, \p0\().\t
+        uaba            v0.\t, \m1\().\t, \p1\().\t
+        uaba            v0.\t, \m2\().\t, \p2\().\t
+.endm
+
+// Takes direction (mm, pp) if its score in v0 is below the best score
+// in v4 and, when nested, the previous direction (mask in prev) was taken.
+.macro take t, b, mm, pp, mask, prev
+.ifnb \prev
+        orn             v0.\b, v0.\b, \prev\().\b
+.endif
+        cmhi            \mask\().\t, v4.\t, v0.\t
+        bit             v4.\b, v0.\b, \mask\().\b
+        uhadd           v1.\t, \mm\().\t, \pp\().\t
+        bit             v5.\b, v1.\b, \mask\().\b
+.endm
+
+// Spatial prediction on halfword or word lanes, clamped to [v19, v18]
+// into v5.
+.macro spatial_wide t, b
+        score           \t, v22, v28, v2, v3, v23, v29
+        movi            v1.\t, #1
+        uqsub           v4.\t, v0.\t, v1.\t
+        uhadd           v5.\t, v2.\t, v3.\t
+        score           \t, v21, v3, v22, v29, v2, v30
+        take            \t, \b, v22, v29, v6
+        score           \t, v20, v29, v21, v30, v22, v31
+        take            \t, \b, v21, v30, v7, v6
+        score           \t, v2, v27, v23, v28, v24, v3
+        take            \t, \b, v23, v28, v6
+        score           \t, v23, v26, v24, v27, v25, v28
+        take            \t, \b, v24, v27, v7, v6
+        umin            v5.\t, v5.\t, v18.\t
+        umax            v5.\t, v5.\t, v19.\t
+.endm
+
+// Spatial score of one direction on a full vector of t lanes, widened to
+// st lanes, into v0 (low half) and v1 (high half).
+.macro score_split t, nt, st, m0, p0, m1, p1, m2, p2
+        uabdl           v0.\st, \m0\().\nt, \p0\().\nt
+        uabdl2          v1.\st, \m0\().\t,  \p0\().\t
+        uabal           v0.\st, \m1\().\nt, \p1\().\nt
+        uabal2          v1.\st, \m1\().\t,  \p1\().\t
+        uabal           v0.\st, \m2\().\nt, \p2\().\nt
+        uabal2          v1.\st, \m2\().\t,  \p2\().\t
+.endm
+
+// take with scores in widened halves: best score in v4/v5, prediction in
+// v6, direction masks in v16/v17.
+.macro take_split t, st, mm, pp, nested
+.if \nested
+        orn             v0.16b, v0.16b, v16.16b
+        orn             v1.16b, v1.16b, v17.16b
+.endif
+        cmhi            v16.\st, v4.\st, v0.\st
+        cmhi            v17.\st, v5.\st, v1.\st
+        bit             v4.16b, v0.16b, v16.16b
+        bit             v5.16b, v1.16b, v17.16b
+        uzp1            v7.\t, v16.\t, v17.\t
+        uhadd           v0.\t, \mm\().\t, \pp\().\t
+        bit             v6.16b, v0.16b, v7.16b
+.endm
+
+// Spatial prediction on a full vector of t lanes with scores widened to
+// st lanes, clamped to [v19, v18] into v6.
+.macro spatial_split t, nt, st
+        score_split     \t, \nt, \st, v22, v28, v2, v3, v23, v29
+        movi            v7.\st, #1
+        uqsub           v4.\st, v0.\st, v7.\st
+        uqsub           v5.\st, v1.\st, v7.\st
+        uhadd           v6.\t, v2.\t, v3.\t
+        score_split     \t, \nt, \st, v21, v3, v22, v29, v2, v30
+        take_split      \t, \st, v22, v29, 0
+        score_split     \t, \nt, \st, v20, v29, v21, v30, v22, v31
+        take_split      \t, \st, v21, v30, 1
+        score_split     \t, \nt, \st, v2, v27, v23, v28, v24, v3
+        take_split      \t, \st, v23, v28, 0
+        score_split     \t, \nt, \st, v23, v26, v24, v27, v25, v28
+        take_split      \t, \st, v24, v27, 1
+        umin            v6.\t, v6.\t, v18.\t
+        umax            v6.\t, v6.\t, v19.\t
+.endm
+
+.macro advance bytes
+        add             x1,  x1,  #\bytes
+        add             x3,  x3,  #\bytes
+        add             x8,  x8,  #\bytes
+        add             x9,  x9,  #\bytes
+        add             x10, x10, #\bytes
+        add             x11, x11, #\bytes
+.endm
+
+.macro filter_line8 spatial_check
+1:
+        cmp             w4, #8
+        b.le            2f
+        temporal        16b, q, none, \spatial_check
+        load_spatial    q, none, 1
+        spatial_split   16b, 8b, 8h
+        st1             {v6.16b}, [x0], #16
+        advance         16
+        sub             w4, w4, #16
+        b               1b
+2:
+        cmp             w4, #0
+        b.le            3f
+        temporal        8h, d, u8, \spatial_check
+        load_spatial    d, u8, 1
+        spatial_wide    8h, 16b
+        xtn             v5.8b, v5.8h
+        st1             {v5.8b}, [x0]
+3:
+.endm
+
+.macro filter_line10 spatial_check
+1:
+        cmp             w4, #4
+        b.le            2f
+        temporal        8h, q, none, \spatial_check
+        load_spatial    q, none, 2
+        spatial_wide    8h, 16b
+        st1             {v5.8h}, [x0], #16
+        advance         16
+        sub             w4, w4, #8
+        b               1b
+2:
+        cmp             w4, #0
+        b.le            3f
+        temporal        4h, d, none, \spatial_check
+        load_spatial    d, none, 2
+        spatial_wide    4h, 8b
+        st1             {v5.4h}, [x0]
+3:
+.endm
+
+.macro filter_line16 spatial_check
+1:
+        cmp             w4, #4
+        b.le            2f
+        temporal        8h, q, none, \spatial_check
+        load_spatial    q, none, 2
+        spatial_split   8h, 4h, 4s
+        st1             {v6.8h}, [x0], #16
+        advance         16
+        sub             w4, w4, #8
+        b               1b
+2:
+        cmp             w4, #0
+        b.le            3f
+        temporal        4s, d, u16w, \spatial_check
+        load_spatial    d, u16w, 2
+        spatial_wide    4s, 16b
+        xtn             v5.4h, v5.4s
+        st1             {v5.4h}, [x0]
+3:
+.endm
+
+// void ff_yadif_filter_line*_neon(void *dst, void *prev, void *cur,
+//                                 void *next, int w, int prefs,
+//                                 int mrefs, int parity, int mode)
+.macro yadif_func name, line
+function ff_yadif_filter_line\name\()_neon, export=1
+        ldr             w14, [sp]                       // mode
+        sxtw            x5,  w5
+        sxtw            x6,  w6
+        cmp             w7,  #0
+        csel            x8,  x1,  x2,  ne               // prev2
+        csel            x9,  x2,  x3,  ne               // next2
+        add             x10, x2,  x6
+        add             x11, x2,  x5
+        lsl             x12, x6,  #1
+        lsl             x13, x5,  #1
+        tbnz            w14, #1,  5f
+        \line           1
+        ret
+5:
+        \line           0
+        ret
+endfunc
+.endm
+
+yadif_func      ,       filter_line8
+yadif_func      _10bit, filter_line10
+yadif_func      _16bit, filter_line16
diff --git a/libavfilter/vf_yadif_init.h b/libavfilter/vf_yadif_init.h
index 7160e444ff6..7dab1805841 100644
--- a/libavfilter/vf_yadif_init.h
+++ b/libavfilter/vf_yadif_init.h
@@ -195,6 +195,8 @@ av_unused static void ff_yadif_init(YADIFContext *s)
 
 #if ARCH_X86 && HAVE_X86ASM
     ff_yadif_init_x86(s);
+#elif ARCH_AARCH64
+    ff_yadif_init_aarch64(s);
 #endif
 }
 
diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h
index 21c6df29c2c..e1f2076fd6a 100644
--- a/libavfilter/yadif.h
+++ b/libavfilter/yadif.h
@@ -91,6 +91,7 @@ typedef struct YADIFContext {
 } YADIFContext;
 
 void ff_yadif_init_x86(YADIFContext *yadif);
+void ff_yadif_init_aarch64(YADIFContext *yadif);
 
 int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame);
 
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to