FFmpeg
h264dsp_init.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 J. Dekker <jdek@itanimul.li>
3  * Copyright © 2024 Rémi Denis-Courmont.
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "config.h"
23 
24 #include <stdint.h>
25 #include <string.h>
26 
27 #include "libavutil/attributes.h"
28 #include "libavutil/cpu.h"
29 #include "libavutil/riscv/cpu.h"
30 #include "libavcodec/h264dsp.h"
31 
32 extern const struct {
36 
37 void ff_h264_v_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride,
38  int alpha, int beta, int8_t *tc0);
39 void ff_h264_h_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride,
40  int alpha, int beta, int8_t *tc0);
41 void ff_h264_h_loop_filter_luma_mbaff_8_rvv(uint8_t *pix, ptrdiff_t stride,
42  int alpha, int beta, int8_t *tc0);
43 void ff_h264_v_loop_filter_luma_intra_8_rvv(uint8_t *pix, ptrdiff_t stride,
44  int alpha, int beta);
45 void ff_h264_h_loop_filter_luma_intra_8_rvv(uint8_t *pix, ptrdiff_t stride,
46  int alpha, int beta);
47 void ff_h264_h_loop_filter_luma_mbaff_intra_8_rvv(uint8_t *pix, ptrdiff_t s,
48  int a, int b);
49 void ff_h264_v_loop_filter_chroma_8_rvv(uint8_t *pix, ptrdiff_t stride,
50  int alpha, int beta, int8_t *tc0);
51 void ff_h264_h_loop_filter_chroma_8_rvv(uint8_t *pix, ptrdiff_t stride,
52  int alpha, int beta, int8_t *tc0);
53 void ff_h264_h_loop_filter_chroma_mbaff_8_rvv(uint8_t *pix, ptrdiff_t stride,
54  int alpha, int beta,
55  int8_t *tc0);
56 void ff_h264_v_loop_filter_chroma_intra_8_rvv(uint8_t *pix, ptrdiff_t stride,
57  int alpha, int beta);
58 void ff_h264_h_loop_filter_chroma_intra_8_rvv(uint8_t *pix, ptrdiff_t stride,
59  int alpha, int beta);
61  ptrdiff_t stride,
62  int alpha, int beta);
63 
64 #define IDCT_DEPTH(depth) \
65 void ff_h264_idct_add_##depth##_rvv(uint8_t *d, int16_t *s, int stride); \
66 void ff_h264_idct8_add_##depth##_rvv(uint8_t *d, int16_t *s, int stride); \
67 void ff_h264_idct4_dc_add_##depth##_rvv(uint8_t *, int16_t *, int); \
68 void ff_h264_idct8_dc_add_##depth##_rvv(uint8_t *, int16_t *, int); \
69 void ff_h264_idct_add16_##depth##_rvv(uint8_t *d, const int *soffset, \
70  int16_t *s, int stride, \
71  const uint8_t nnzc[5 * 8]); \
72 void ff_h264_idct_add16intra_##depth##_rvv(uint8_t *d, const int *soffset, \
73  int16_t *s, int stride, \
74  const uint8_t nnzc[5 * 8]); \
75 void ff_h264_idct8_add4_##depth##_rvv(uint8_t *d, const int *soffset, \
76  int16_t *s, int stride, \
77  const uint8_t nnzc[5 * 8]); \
78 void ff_h264_idct4_add8_##depth##_rvv(uint8_t **d, const int *soffset, \
79  int16_t *s, int stride, \
80  const uint8_t nnzc[5 * 8]); \
81 void ff_h264_idct4_add8_422_##depth##_rvv(uint8_t **d, const int *soffset, \
82  int16_t *s, int stride, \
83  const uint8_t nnzc[5 * 8]);
84 
85 IDCT_DEPTH(8)
86 IDCT_DEPTH(9)
87 IDCT_DEPTH(10)
88 IDCT_DEPTH(12)
89 IDCT_DEPTH(14)
90 #undef IDCT_DEPTH
91 
92 void ff_h264_add_pixels8_8_rvv(uint8_t *dst, int16_t *block, int stride);
93 void ff_h264_add_pixels4_8_rvv(uint8_t *dst, int16_t *block, int stride);
94 void ff_h264_add_pixels8_16_rvv(uint8_t *dst, int16_t *block, int stride);
95 void ff_h264_add_pixels4_16_rvv(uint8_t *dst, int16_t *block, int stride);
96 
97 extern int ff_startcode_find_candidate_rvb(const uint8_t *, int);
98 extern int ff_startcode_find_candidate_rvv(const uint8_t *, int);
99 
101  const int chroma_format_idc)
102 {
103 #if HAVE_RV
104  int flags = av_get_cpu_flags();
105 
108 # if HAVE_RVV
109  if (flags & AV_CPU_FLAG_RVV_I32) {
110  const bool zvl128b = ff_rv_vlen_least(128);
111 
112  if (bit_depth == 8) {
113  if (zvl128b) {
114  if (flags & AV_CPU_FLAG_RVB)
115  dsp->weight_h264_pixels_tab[0] =
116  ff_h264_weight_funcs_8_rvv[0].weight;
117  dsp->biweight_h264_pixels_tab[0] =
118  ff_h264_weight_funcs_8_rvv[0].biweight;
119  }
120  if (flags & AV_CPU_FLAG_RVV_I64) {
121  dsp->weight_h264_pixels_tab[1] =
122  ff_h264_weight_funcs_8_rvv[1].weight;
123  dsp->biweight_h264_pixels_tab[1] =
124  ff_h264_weight_funcs_8_rvv[1].biweight;
125  }
126  dsp->weight_h264_pixels_tab[2] =
127  ff_h264_weight_funcs_8_rvv[2].weight;
128  dsp->biweight_h264_pixels_tab[2] =
129  ff_h264_weight_funcs_8_rvv[2].biweight;
130  dsp->weight_h264_pixels_tab[3] =
131  ff_h264_weight_funcs_8_rvv[3].weight;
132  dsp->biweight_h264_pixels_tab[3] =
133  ff_h264_weight_funcs_8_rvv[3].biweight;
134  }
135 
136  if (bit_depth == 8 && zvl128b) {
151 
152  if (chroma_format_idc <= 1) {
161  }
162 
163  dsp->h264_idct_add = ff_h264_idct_add_8_rvv;
164  dsp->h264_idct8_add = ff_h264_idct8_add_8_rvv;
165  if (flags & AV_CPU_FLAG_RVB) {
166  dsp->h264_idct_dc_add = ff_h264_idct4_dc_add_8_rvv;
167  dsp->h264_idct_add16 = ff_h264_idct_add16_8_rvv;
168  dsp->h264_idct_add16intra = ff_h264_idct_add16intra_8_rvv;
169 # if __riscv_xlen == 64
170  dsp->h264_idct8_add4 = ff_h264_idct8_add4_8_rvv;
171  if (chroma_format_idc <= 1)
172  dsp->h264_idct_add8 = ff_h264_idct4_add8_8_rvv;
173  else
174  dsp->h264_idct_add8 = ff_h264_idct4_add8_422_8_rvv;
175 # endif
176  }
177  if (flags & AV_CPU_FLAG_RVV_I64) {
179  if (flags & AV_CPU_FLAG_RVB)
180  dsp->h264_idct8_dc_add = ff_h264_idct8_dc_add_8_rvv;
181  }
183  }
184 
185 #define IDCT_DEPTH(depth) \
186  if (bit_depth == depth) { \
187  if (zvl128b) \
188  dsp->h264_idct_add = ff_h264_idct_add_##depth##_rvv; \
189  if (flags & AV_CPU_FLAG_RVB) \
190  dsp->h264_idct8_add = ff_h264_idct8_add_##depth##_rvv; \
191  if (zvl128b && (flags & AV_CPU_FLAG_RVB)) { \
192  dsp->h264_idct_dc_add = ff_h264_idct4_dc_add_##depth##_rvv; \
193  dsp->h264_idct8_dc_add = ff_h264_idct8_dc_add_##depth##_rvv; \
194  dsp->h264_idct_add16 = ff_h264_idct_add16_##depth##_rvv; \
195  dsp->h264_idct_add16intra = \
196  ff_h264_idct_add16intra_##depth##_rvv; \
197  if (__riscv_xlen == 64) { \
198  if (chroma_format_idc <= 1) \
199  dsp->h264_idct_add8 = \
200  ff_h264_idct4_add8_##depth##_rvv; \
201  else \
202  dsp->h264_idct_add8 = \
203  ff_h264_idct4_add8_422_##depth##_rvv; \
204  } \
205  } \
206  if (__riscv_xlen == 64 && (flags & AV_CPU_FLAG_RVB)) \
207  dsp->h264_idct8_add4 = ff_h264_idct8_add4_##depth##_rvv; \
208  }
209 
210  IDCT_DEPTH(9)
211  IDCT_DEPTH(10)
212  IDCT_DEPTH(12)
213  IDCT_DEPTH(14)
214 
215  if (bit_depth > 8 && zvl128b) {
219  }
220 
222  }
223 # endif
224 #endif
225 }
ff_h264_v_loop_filter_luma_8_rvv
void ff_h264_v_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
ff_h264_weight_funcs_8_rvv
const struct @214 ff_h264_weight_funcs_8_rvv[]
AV_CPU_FLAG_RVB_BASIC
#define AV_CPU_FLAG_RVB_BASIC
Basic bit-manipulations.
Definition: cpu.h:96
H264DSPContext::h264_idct_add8
void(* h264_idct_add8)(uint8_t **dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[15 *8])
Definition: h264dsp.h:96
ff_h264_add_pixels4_8_rvv
void ff_h264_add_pixels4_8_rvv(uint8_t *dst, int16_t *block, int stride)
h264_biweight_func
void(* h264_biweight_func)(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int height, int log2_denom, int weightd, int weights, int offset)
Definition: h264dsp.h:35
ff_h264dsp_init_riscv
av_cold void ff_h264dsp_init_riscv(H264DSPContext *dsp, const int bit_depth, const int chroma_format_idc)
Definition: h264dsp_init.c:100
ff_h264_h_loop_filter_luma_mbaff_intra_8_rvv
void ff_h264_h_loop_filter_luma_mbaff_intra_8_rvv(uint8_t *pix, ptrdiff_t s, int a, int b)
ff_h264_v_loop_filter_chroma_8_rvv
void ff_h264_v_loop_filter_chroma_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
b
#define b
Definition: input.c:41
H264DSPContext::h264_add_pixels8_clear
void(* h264_add_pixels8_clear)(uint8_t *dst, int16_t *block, int stride)
Definition: h264dsp.h:107
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:109
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
AV_CPU_FLAG_RVB
#define AV_CPU_FLAG_RVB
B (bit manipulations)
Definition: cpu.h:102
H264DSPContext::h264_idct_add16
void(* h264_idct_add16)(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[5 *8])
Definition: h264dsp.h:90
H264DSPContext::h264_v_loop_filter_chroma
void(* h264_v_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
Definition: h264dsp.h:61
weight
const h264_weight_func weight
Definition: h264dsp_init.c:33
av_cold
#define av_cold
Definition: attributes.h:90
s
#define s(width, name)
Definition: cbs_vp9.c:198
H264DSPContext::biweight_h264_pixels_tab
h264_biweight_func biweight_h264_pixels_tab[4]
Definition: h264dsp.h:45
cpu.h
ff_startcode_find_candidate_rvv
int ff_startcode_find_candidate_rvv(const uint8_t *, int)
ff_h264_h_loop_filter_luma_mbaff_8_rvv
void ff_h264_h_loop_filter_luma_mbaff_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
ff_h264_h_loop_filter_chroma_intra_8_rvv
void ff_h264_h_loop_filter_chroma_intra_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta)
ff_h264_add_pixels4_16_rvv
void ff_h264_add_pixels4_16_rvv(uint8_t *dst, int16_t *block, int stride)
H264DSPContext::h264_h_loop_filter_chroma_mbaff
void(* h264_h_loop_filter_chroma_mbaff)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
Definition: h264dsp.h:65
ff_h264_h_loop_filter_chroma_mbaff_intra_8_rvv
void ff_h264_h_loop_filter_chroma_mbaff_intra_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta)
H264DSPContext::startcode_find_candidate
int(* startcode_find_candidate)(const uint8_t *buf, int size)
Search buf from the start for up to size bytes.
Definition: h264dsp.h:117
H264DSPContext::h264_v_loop_filter_chroma_intra
void(* h264_v_loop_filter_chroma_intra)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta)
Definition: h264dsp.h:68
H264DSPContext::h264_idct8_dc_add
void(* h264_idct8_dc_add)(uint8_t *dst, int16_t *block, int stride)
Definition: h264dsp.h:87
H264DSPContext::h264_h_loop_filter_luma
void(* h264_h_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
Definition: h264dsp.h:50
h264dsp.h
ff_h264_v_loop_filter_luma_intra_8_rvv
void ff_h264_v_loop_filter_luma_intra_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta)
H264DSPContext::h264_h_loop_filter_chroma_mbaff_intra
void(* h264_h_loop_filter_chroma_mbaff_intra)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta)
Definition: h264dsp.h:72
ff_h264_add_pixels8_16_rvv
void ff_h264_add_pixels8_16_rvv(uint8_t *dst, int16_t *block, int stride)
H264DSPContext::h264_h_loop_filter_luma_intra
void(* h264_h_loop_filter_luma_intra)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta)
Definition: h264dsp.h:57
H264DSPContext
Context for storing H.264 DSP functions.
Definition: h264dsp.h:42
H264DSPContext::h264_h_loop_filter_luma_mbaff
void(* h264_h_loop_filter_luma_mbaff)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
Definition: h264dsp.h:52
h264_weight_func
void(* h264_weight_func)(uint8_t *block, ptrdiff_t stride, int height, int log2_denom, int weight, int offset)
Definition: h264dsp.h:33
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
H264DSPContext::weight_h264_pixels_tab
h264_weight_func weight_h264_pixels_tab[4]
Definition: h264dsp.h:44
H264DSPContext::h264_h_loop_filter_chroma_intra
void(* h264_h_loop_filter_chroma_intra)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta)
Definition: h264dsp.h:70
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
attributes.h
ff_h264_h_loop_filter_luma_intra_8_rvv
void ff_h264_h_loop_filter_luma_intra_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta)
AV_CPU_FLAG_RVV_I32
#define AV_CPU_FLAG_RVV_I32
Vectors of 8/16/32-bit int's *‍/.
Definition: cpu.h:92
H264DSPContext::h264_idct8_add
void(* h264_idct8_add)(uint8_t *dst, int16_t *block, int stride)
Definition: h264dsp.h:83
ff_h264_h_loop_filter_chroma_mbaff_8_rvv
void ff_h264_h_loop_filter_chroma_mbaff_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
biweight
const h264_biweight_func biweight
Definition: h264dsp_init.c:34
H264DSPContext::h264_v_loop_filter_luma_intra
void(* h264_v_loop_filter_luma_intra)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta)
Definition: h264dsp.h:55
H264DSPContext::h264_h_loop_filter_chroma
void(* h264_h_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
Definition: h264dsp.h:63
stride
#define stride
Definition: h264pred_template.c:537
H264DSPContext::h264_idct8_add4
void(* h264_idct8_add4)(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[5 *8])
Definition: h264dsp.h:93
H264DSPContext::h264_idct_dc_add
void(* h264_idct_dc_add)(uint8_t *dst, int16_t *block, int stride)
Definition: h264dsp.h:85
H264DSPContext::h264_add_pixels4_clear
void(* h264_add_pixels4_clear)(uint8_t *dst, int16_t *block, int stride)
Definition: h264dsp.h:108
ff_h264_h_loop_filter_luma_8_rvv
void ff_h264_h_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
H264DSPContext::h264_h_loop_filter_luma_mbaff_intra
void(* h264_h_loop_filter_luma_mbaff_intra)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta)
Definition: h264dsp.h:59
ff_h264_h_loop_filter_chroma_8_rvv
void ff_h264_h_loop_filter_chroma_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
H264DSPContext::h264_idct_add16intra
void(* h264_idct_add16intra)(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[5 *8])
Definition: h264dsp.h:99
H264DSPContext::h264_v_loop_filter_luma
void(* h264_v_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
Definition: h264dsp.h:48
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
ff_h264_add_pixels8_8_rvv
void ff_h264_add_pixels8_8_rvv(uint8_t *dst, int16_t *block, int stride)
ff_startcode_find_candidate_rvb
int ff_startcode_find_candidate_rvb(const uint8_t *, int)
IDCT_DEPTH
#define IDCT_DEPTH(depth)
Definition: h264dsp_init.c:64
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
AV_CPU_FLAG_RVV_I64
#define AV_CPU_FLAG_RVV_I64
Vectors of 64-bit int's *‍/.
Definition: cpu.h:94
ff_h264_v_loop_filter_chroma_intra_8_rvv
void ff_h264_v_loop_filter_chroma_intra_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta)
H264DSPContext::h264_idct_add
void(* h264_idct_add)(uint8_t *dst, int16_t *block, int stride)
Definition: h264dsp.h:81