2 * bwdif aarch64 NEON optimisations
4 * Copyright (c) 2023 John Cox <jc@kynesim.co.uk>
6 * This file is part of FFmpeg.
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.
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.
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
23 #include "libavutil/common.h"
24 #include "libavfilter/bwdifdsp.h"
25 #include "libavutil/aarch64/cpu.h"
27 void ff_bwdif_filter_edge_neon(void *dst1, const void *prev1, const void *cur1, const void *next1,
28 int w, int prefs, int mrefs, int prefs2, int mrefs2,
29 int parity, int clip_max, int spat);
31 void ff_bwdif_filter_intra_neon(void *dst1, const void *cur1, int w, int prefs, int mrefs,
32 int prefs3, int mrefs3, int parity, int clip_max);
34 void ff_bwdif_filter_line_neon(void *dst1, const void *prev1, const void *cur1, const void *next1,
35 int w, int prefs, int mrefs, int prefs2, int mrefs2,
36 int prefs3, int mrefs3, int prefs4, int mrefs4,
37 int parity, int clip_max);
39 void ff_bwdif_filter_line3_neon(void * dst1, int d_stride,
40 const void * prev1, const void * cur1, const void * next1, int s_stride,
41 int w, int parity, int clip_max);
44 static void filter_line3_helper(void * dst1, int d_stride,
45 const void * prev1, const void * cur1, const void * next1, int s_stride,
46 int w, int parity, int clip_max)
48 // Asm works on 16 byte chunks
49 // If w is a multiple of 16 then all is good - if not then if width rounded
50 // up to nearest 16 will fit in both src & dst strides then allow the asm
51 // to write over the padding bytes as that is almost certainly faster than
52 // having to invoke the C version to clean up the tail.
53 const int w1 = FFALIGN(w, 16);
54 const int w0 = clip_max != 255 ? 0 :
55 d_stride <= w1 && s_stride <= w1 ? w : w & ~15;
57 ff_bwdif_filter_line3_neon(dst1, d_stride,
58 prev1, cur1, next1, s_stride,
59 w0, parity, clip_max);
62 ff_bwdif_filter_line3_c((char *)dst1 + w0, d_stride,
63 (const char *)prev1 + w0, (const char *)cur1 + w0, (const char *)next1 + w0, s_stride,
64 w - w0, parity, clip_max);
67 static void filter_line_helper(void *dst1, const void *prev1, const void *cur1, const void *next1,
68 int w, int prefs, int mrefs, int prefs2, int mrefs2,
69 int prefs3, int mrefs3, int prefs4, int mrefs4,
70 int parity, int clip_max)
72 const int w0 = clip_max != 255 ? 0 : w & ~15;
74 ff_bwdif_filter_line_neon(dst1, prev1, cur1, next1,
75 w0, prefs, mrefs, prefs2, mrefs2, prefs3, mrefs3, prefs4, mrefs4, parity, clip_max);
78 ff_bwdif_filter_line_c((char *)dst1 + w0, (char *)prev1 + w0, (char *)cur1 + w0, (char *)next1 + w0,
79 w - w0, prefs, mrefs, prefs2, mrefs2, prefs3, mrefs3, prefs4, mrefs4, parity, clip_max);
82 static void filter_edge_helper(void *dst1, const void *prev1, const void *cur1, const void *next1,
83 int w, int prefs, int mrefs, int prefs2, int mrefs2,
84 int parity, int clip_max, int spat)
86 const int w0 = clip_max != 255 ? 0 : w & ~15;
88 ff_bwdif_filter_edge_neon(dst1, prev1, cur1, next1, w0, prefs, mrefs, prefs2, mrefs2,
89 parity, clip_max, spat);
92 ff_bwdif_filter_edge_c((char *)dst1 + w0, (char *)prev1 + w0, (char *)cur1 + w0, (char *)next1 + w0,
93 w - w0, prefs, mrefs, prefs2, mrefs2,
94 parity, clip_max, spat);
97 static void filter_intra_helper(void *dst1, const void *cur1, int w, int prefs, int mrefs,
98 int prefs3, int mrefs3, int parity, int clip_max)
100 const int w0 = clip_max != 255 ? 0 : w & ~15;
102 ff_bwdif_filter_intra_neon(dst1, cur1, w0, prefs, mrefs, prefs3, mrefs3, parity, clip_max);
105 ff_bwdif_filter_intra_c((char *)dst1 + w0, (char *)cur1 + w0,
106 w - w0, prefs, mrefs, prefs3, mrefs3, parity, clip_max);
110 ff_bwdif_init_aarch64(BWDIFDSPContext *s, int bit_depth)
112 const int cpu_flags = av_get_cpu_flags();
117 if (!have_neon(cpu_flags))
120 s->filter_intra = filter_intra_helper;
121 s->filter_line = filter_line_helper;
122 s->filter_edge = filter_edge_helper;
123 s->filter_line3 = filter_line3_helper;