FFmpeg
dsp_init.c
Go to the documentation of this file.
1 /*
2  * VVC filters DSP
3  *
4  * Copyright (C) 2024 Zhao Zhili
5  *
6  * This file is part of FFmpeg.
7  *
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.
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 GNU
16  * Lesser General Public License for more details.
17  *
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
21  */
22 
23 #include "libavutil/cpu.h"
24 #include "libavutil/aarch64/cpu.h"
26 #include "libavcodec/vvc/dsp.h"
27 #include "libavcodec/vvc/dec.h"
28 #include "libavcodec/vvc/ctu.h"
29 
30 #define BIT_DEPTH 8
31 #include "alf_template.c"
32 #undef BIT_DEPTH
33 
34 #define BIT_DEPTH 10
35 #include "alf_template.c"
36 #undef BIT_DEPTH
37 
38 #define BIT_DEPTH 12
39 #include "alf_template.c"
40 #undef BIT_DEPTH
41 
42 int ff_vvc_sad_neon(const int16_t *src0, const int16_t *src1, int dx, int dy,
43  const int block_w, const int block_h);
44 
45 void ff_vvc_avg_8_neon(uint8_t *dst, ptrdiff_t dst_stride,
46  const int16_t *src0, const int16_t *src1, int width,
47  int height);
48 void ff_vvc_avg_10_neon(uint8_t *dst, ptrdiff_t dst_stride,
49  const int16_t *src0, const int16_t *src1, int width,
50  int height);
51 void ff_vvc_avg_12_neon(uint8_t *dst, ptrdiff_t dst_stride,
52  const int16_t *src0, const int16_t *src1, int width,
53  int height);
54 
55 void ff_vvc_dsp_init_aarch64(VVCDSPContext *const c, const int bd)
56 {
58  if (!have_neon(cpu_flags))
59  return;
60 
61  if (bd == 8) {
62  c->inter.put[0][1][0][0] = ff_vvc_put_pel_pixels4_8_neon;
63  c->inter.put[0][2][0][0] = ff_vvc_put_pel_pixels8_8_neon;
64  c->inter.put[0][3][0][0] = ff_vvc_put_pel_pixels16_8_neon;
65  c->inter.put[0][4][0][0] = ff_vvc_put_pel_pixels32_8_neon;
66  c->inter.put[0][5][0][0] = ff_vvc_put_pel_pixels64_8_neon;
67  c->inter.put[0][6][0][0] = ff_vvc_put_pel_pixels128_8_neon;
68 
69  c->inter.put[0][1][0][1] = ff_vvc_put_qpel_h4_8_neon;
70  c->inter.put[0][2][0][1] = ff_vvc_put_qpel_h8_8_neon;
71  c->inter.put[0][3][0][1] = ff_vvc_put_qpel_h16_8_neon;
72  c->inter.put[0][4][0][1] =
73  c->inter.put[0][5][0][1] =
74  c->inter.put[0][6][0][1] = ff_vvc_put_qpel_h32_8_neon;
75 
76  c->inter.put[0][1][1][0] = ff_vvc_put_qpel_v4_8_neon;
77  c->inter.put[0][2][1][0] =
78  c->inter.put[0][3][1][0] =
79  c->inter.put[0][4][1][0] =
80  c->inter.put[0][5][1][0] =
81  c->inter.put[0][6][1][0] = ff_vvc_put_qpel_v8_8_neon;
82 
83  c->inter.put[0][1][1][1] = ff_vvc_put_qpel_hv4_8_neon;
84  c->inter.put[0][2][1][1] = ff_vvc_put_qpel_hv8_8_neon;
85  c->inter.put[0][3][1][1] = ff_vvc_put_qpel_hv16_8_neon;
86  c->inter.put[0][4][1][1] = ff_vvc_put_qpel_hv32_8_neon;
87  c->inter.put[0][5][1][1] = ff_vvc_put_qpel_hv64_8_neon;
88  c->inter.put[0][6][1][1] = ff_vvc_put_qpel_hv128_8_neon;
89 
90  c->inter.put[1][1][0][1] = ff_vvc_put_epel_h4_8_neon;
91  c->inter.put[1][2][0][1] = ff_vvc_put_epel_h8_8_neon;
92  c->inter.put[1][3][0][1] = ff_vvc_put_epel_h16_8_neon;
93  c->inter.put[1][4][0][1] =
94  c->inter.put[1][5][0][1] =
95  c->inter.put[1][6][0][1] = ff_vvc_put_epel_h32_8_neon;
96 
97  c->inter.put[1][1][1][1] = ff_vvc_put_epel_hv4_8_neon;
98  c->inter.put[1][2][1][1] = ff_vvc_put_epel_hv8_8_neon;
99  c->inter.put[1][3][1][1] = ff_vvc_put_epel_hv16_8_neon;
100  c->inter.put[1][4][1][1] = ff_vvc_put_epel_hv32_8_neon;
101  c->inter.put[1][5][1][1] = ff_vvc_put_epel_hv64_8_neon;
102  c->inter.put[1][6][1][1] = ff_vvc_put_epel_hv128_8_neon;
103 
104  c->inter.put_uni[0][1][0][0] = ff_vvc_put_pel_uni_pixels4_8_neon;
105  c->inter.put_uni[0][2][0][0] = ff_vvc_put_pel_uni_pixels8_8_neon;
106  c->inter.put_uni[0][3][0][0] = ff_vvc_put_pel_uni_pixels16_8_neon;
107  c->inter.put_uni[0][4][0][0] = ff_vvc_put_pel_uni_pixels32_8_neon;
108  c->inter.put_uni[0][5][0][0] = ff_vvc_put_pel_uni_pixels64_8_neon;
109  c->inter.put_uni[0][6][0][0] = ff_vvc_put_pel_uni_pixels128_8_neon;
110 
111  c->inter.put_uni[0][1][0][1] = ff_vvc_put_qpel_uni_h4_8_neon;
112  c->inter.put_uni[0][2][0][1] = ff_vvc_put_qpel_uni_h8_8_neon;
113  c->inter.put_uni[0][3][0][1] = ff_vvc_put_qpel_uni_h16_8_neon;
114  c->inter.put_uni[0][4][0][1] =
115  c->inter.put_uni[0][5][0][1] =
116  c->inter.put_uni[0][6][0][1] = ff_vvc_put_qpel_uni_h32_8_neon;
117 
118  c->inter.put_uni_w[0][1][0][0] = ff_vvc_put_pel_uni_w_pixels4_8_neon;
119  c->inter.put_uni_w[0][2][0][0] = ff_vvc_put_pel_uni_w_pixels8_8_neon;
120  c->inter.put_uni_w[0][3][0][0] = ff_vvc_put_pel_uni_w_pixels16_8_neon;
121  c->inter.put_uni_w[0][4][0][0] = ff_vvc_put_pel_uni_w_pixels32_8_neon;
122  c->inter.put_uni_w[0][5][0][0] = ff_vvc_put_pel_uni_w_pixels64_8_neon;
123  c->inter.put_uni_w[0][6][0][0] = ff_vvc_put_pel_uni_w_pixels128_8_neon;
124 
125  c->inter.avg = ff_vvc_avg_8_neon;
126 
127  for (int i = 0; i < FF_ARRAY_ELEMS(c->sao.band_filter); i++)
128  c->sao.band_filter[i] = ff_h26x_sao_band_filter_8x8_8_neon;
129  c->sao.edge_filter[0] = ff_vvc_sao_edge_filter_8x8_8_neon;
130  for (int i = 1; i < FF_ARRAY_ELEMS(c->sao.edge_filter); i++)
131  c->sao.edge_filter[i] = ff_vvc_sao_edge_filter_16x16_8_neon;
132  c->alf.filter[LUMA] = alf_filter_luma_8_neon;
133  c->alf.filter[CHROMA] = alf_filter_chroma_8_neon;
134 
135  if (have_i8mm(cpu_flags)) {
136  c->inter.put[0][1][0][1] = ff_vvc_put_qpel_h4_8_neon_i8mm;
137  c->inter.put[0][2][0][1] = ff_vvc_put_qpel_h8_8_neon_i8mm;
138  c->inter.put[0][3][0][1] = ff_vvc_put_qpel_h16_8_neon_i8mm;
139  c->inter.put[0][4][0][1] = ff_vvc_put_qpel_h32_8_neon_i8mm;
140  c->inter.put[0][5][0][1] = ff_vvc_put_qpel_h64_8_neon_i8mm;
141  c->inter.put[0][6][0][1] = ff_vvc_put_qpel_h128_8_neon_i8mm;
142 
143  c->inter.put[0][1][1][1] = ff_vvc_put_qpel_hv4_8_neon_i8mm;
144  c->inter.put[0][2][1][1] = ff_vvc_put_qpel_hv8_8_neon_i8mm;
145  c->inter.put[0][3][1][1] = ff_vvc_put_qpel_hv16_8_neon_i8mm;
146  c->inter.put[0][4][1][1] = ff_vvc_put_qpel_hv32_8_neon_i8mm;
147  c->inter.put[0][5][1][1] = ff_vvc_put_qpel_hv64_8_neon_i8mm;
148  c->inter.put[0][6][1][1] = ff_vvc_put_qpel_hv128_8_neon_i8mm;
149 
150  c->inter.put[1][1][0][1] = ff_vvc_put_epel_h4_8_neon_i8mm;
151  c->inter.put[1][2][0][1] = ff_vvc_put_epel_h8_8_neon_i8mm;
152  c->inter.put[1][3][0][1] = ff_vvc_put_epel_h16_8_neon_i8mm;
153  c->inter.put[1][4][0][1] = ff_vvc_put_epel_h32_8_neon_i8mm;
154  c->inter.put[1][5][0][1] = ff_vvc_put_epel_h64_8_neon_i8mm;
155  c->inter.put[1][6][0][1] = ff_vvc_put_epel_h128_8_neon_i8mm;
156 
157  c->inter.put[1][1][1][1] = ff_vvc_put_epel_hv4_8_neon_i8mm;
158  c->inter.put[1][2][1][1] = ff_vvc_put_epel_hv8_8_neon_i8mm;
159  c->inter.put[1][3][1][1] = ff_vvc_put_epel_hv16_8_neon_i8mm;
160  c->inter.put[1][4][1][1] = ff_vvc_put_epel_hv32_8_neon_i8mm;
161  c->inter.put[1][5][1][1] = ff_vvc_put_epel_hv64_8_neon_i8mm;
162  c->inter.put[1][6][1][1] = ff_vvc_put_epel_hv128_8_neon_i8mm;
163  }
164  } else if (bd == 10) {
165  c->inter.avg = ff_vvc_avg_10_neon;
166 
167  c->alf.filter[LUMA] = alf_filter_luma_10_neon;
168  c->alf.filter[CHROMA] = alf_filter_chroma_10_neon;
169  } else if (bd == 12) {
170  c->inter.avg = ff_vvc_avg_12_neon;
171 
172  c->alf.filter[LUMA] = alf_filter_luma_12_neon;
173  c->alf.filter[CHROMA] = alf_filter_chroma_12_neon;
174  }
175 
176  c->inter.sad = ff_vvc_sad_neon;
177 }
LUMA
#define LUMA
Definition: filter.c:31
src1
const pixel * src1
Definition: h264pred_template.c:421
ff_vvc_put_qpel_v8_8_neon
void ff_vvc_put_qpel_v8_8_neon(int16_t *dst, const uint8_t *_src, ptrdiff_t _srcstride, int height, const int8_t *hf, const int8_t *vf, int width)
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:107
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:56
ff_vvc_sad_neon
int ff_vvc_sad_neon(const int16_t *src0, const int16_t *src1, int dx, int dy, const int block_w, const int block_h)
dsp.h
ff_vvc_put_qpel_v4_8_neon
void ff_vvc_put_qpel_v4_8_neon(int16_t *dst, const uint8_t *_src, ptrdiff_t _srcstride, int height, const int8_t *hf, const int8_t *vf, int width)
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
dsp.h
ff_vvc_avg_12_neon
void ff_vvc_avg_12_neon(uint8_t *dst, ptrdiff_t dst_stride, const int16_t *src0, const int16_t *src1, int width, int height)
ff_vvc_avg_8_neon
void ff_vvc_avg_8_neon(uint8_t *dst, ptrdiff_t dst_stride, const int16_t *src0, const int16_t *src1, int width, int height)
if
if(ret)
Definition: filter_design.txt:179
ff_vvc_sao_edge_filter_8x8_8_neon
void ff_vvc_sao_edge_filter_8x8_8_neon(uint8_t *dst, const uint8_t *src, ptrdiff_t stride_dst, const int16_t *sao_offset_val, int eo, int width, int height)
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
have_i8mm
#define have_i8mm(flags)
Definition: cpu.h:29
height
#define height
Definition: dsp.h:85
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
cpu.h
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
have_neon
#define have_neon(flags)
Definition: cpu.h:26
ff_h26x_sao_band_filter_8x8_8_neon
void ff_h26x_sao_band_filter_8x8_8_neon(uint8_t *_dst, const uint8_t *_src, ptrdiff_t stride_dst, ptrdiff_t stride_src, const int16_t *sao_offset_val, int sao_left_class, int width, int height)
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_vvc_avg_10_neon
void ff_vvc_avg_10_neon(uint8_t *dst, ptrdiff_t dst_stride, const int16_t *src0, const int16_t *src1, int width, int height)
CHROMA
@ CHROMA
Definition: vf_waveform.c:49
ff_vvc_dsp_init_aarch64
void ff_vvc_dsp_init_aarch64(VVCDSPContext *const c, const int bd)
Definition: dsp_init.c:55
src0
const pixel *const src0
Definition: h264pred_template.c:420
ff_vvc_sao_edge_filter_16x16_8_neon
void ff_vvc_sao_edge_filter_16x16_8_neon(uint8_t *dst, const uint8_t *src, ptrdiff_t stride_dst, const int16_t *sao_offset_val, int eo, int width, int height)
alf_template.c
ctu.h
width
#define width
Definition: dsp.h:85
cpu.h
dec.h
VVCDSPContext
Definition: dsp.h:169