FFmpeg
dsp_init.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 Institue of Software Chinese Academy of Sciences (ISCAS).
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "config.h"
22 
23 #include "libavutil/attributes.h"
24 #include "libavutil/cpu.h"
25 #include "libavutil/riscv/cpu.h"
26 #include "libavcodec/vvc/dsp.h"
27 #include "libavcodec/vvc/dec.h"
29 
30 #define bf(fn, bd, opt) fn##_##bd##_##opt
31 
32 #define AVG_PROTOTYPES(bd, opt) \
33 void bf(ff_vvc_avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride, \
34  const int16_t *src0, const int16_t *src1, int width, int height); \
35 void bf(ff_vvc_w_avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride, \
36  const int16_t *src0, const int16_t *src1, int width, int height, \
37  int denom, int w0, int w1, int o0, int o1);
38 
39 AVG_PROTOTYPES(8, rvv_128)
40 AVG_PROTOTYPES(8, rvv_256)
41 
42 #define DMVR_PROTOTYPES(bd, opt) \
43 void ff_vvc_dmvr_##bd##_##opt(int16_t *dst, const uint8_t *src, ptrdiff_t src_stride, \
44  int height, intptr_t mx, intptr_t my, int width); \
45 void ff_vvc_dmvr_h_##bd##_##opt(int16_t *dst, const uint8_t *src, ptrdiff_t src_stride, \
46  int height, intptr_t mx, intptr_t my, int width); \
47 void ff_vvc_dmvr_v_##bd##_##opt(int16_t *dst, const uint8_t *src, ptrdiff_t src_stride, \
48  int height, intptr_t mx, intptr_t my, int width); \
49 void ff_vvc_dmvr_hv_##bd##_##opt(int16_t *dst, const uint8_t *src, ptrdiff_t src_stride, \
50  int height, intptr_t mx, intptr_t my, int width); \
51 
52 DMVR_PROTOTYPES(8, rvv_128)
53 DMVR_PROTOTYPES(8, rvv_256)
54 
55 #define DMVR_INIT(bd, opt) do { \
56  c->inter.dmvr[0][0] = ff_vvc_dmvr_##bd##_##opt; \
57  c->inter.dmvr[0][1] = ff_vvc_dmvr_h_##bd##_##opt; \
58  c->inter.dmvr[1][0] = ff_vvc_dmvr_v_##bd##_##opt; \
59  c->inter.dmvr[1][1] = ff_vvc_dmvr_hv_##bd##_##opt; \
60 } while (0)
61 
62 int ff_vvc_sad_rvv_128(const int16_t *src0, const int16_t *src1, int dx, int dy, int block_w, int block_h);
63 int ff_vvc_sad_rvv_256(const int16_t *src0, const int16_t *src1, int dx, int dy, int block_w, int block_h);
64 
65 #define PUT_PIXELS_PROTOTYPES2(bd, opt) \
66 void bf(ff_vvc_put_pixels, bd, opt)(int16_t *dst, \
67  const uint8_t *_src, const ptrdiff_t _src_stride, \
68  const int height, const int8_t *hf, const int8_t *vf, const int width);
69 
70 PUT_PIXELS_PROTOTYPES2(8, rvv_128)
71 PUT_PIXELS_PROTOTYPES2(8, rvv_256)
72 
73 #define PEL_FUNC(dst, C, idx1, idx2, a) \
74  do { \
75  for (int w = 1; w < 7; w++) \
76  c->inter.dst[C][w][idx1][idx2] = a; \
77  } while (0) \
78 
79 #define FUNCS(C, opt) \
80  PEL_FUNC(put, C, 0, 0, ff_vvc_put_pixels_8_##opt); \
81 
82 void ff_vvc_dsp_init_riscv(VVCDSPContext *const c, const int bd)
83 {
84 #if HAVE_RVV
85  const int flags = av_get_cpu_flags();
86  int vlenb;
87 
89  return;
90 
91  vlenb = ff_get_rv_vlenb();
92  if (vlenb >= 32) {
93  switch (bd) {
94  case 8:
95  c->inter.avg = ff_vvc_avg_8_rvv_256;
96 # if (__riscv_xlen == 64)
97  c->inter.w_avg = ff_vvc_w_avg_8_rvv_256;
98 # endif
99  DMVR_INIT(8, rvv_256);
100  FUNCS(LUMA, rvv_256);
101  FUNCS(CHROMA, rvv_256);
102  break;
103  case 10:
104  c->inter.sad = ff_vvc_sad_rvv_256;
105  default:
106  break;
107  }
108  } else if (vlenb >= 16) {
109  switch (bd) {
110  case 8:
111  c->inter.avg = ff_vvc_avg_8_rvv_128;
112 # if (__riscv_xlen == 64)
113  c->inter.w_avg = ff_vvc_w_avg_8_rvv_128;
114 # endif
115  DMVR_INIT(8, rvv_128);
116  FUNCS(LUMA, rvv_128);
117  FUNCS(CHROMA, rvv_128);
118  break;
119  case 10:
120  c->inter.sad = ff_vvc_sad_rvv_128;
121  default:
122  break;
123  }
124  }
125 #endif
126 }
AVG_PROTOTYPES
#define AVG_PROTOTYPES(bd, opt)
Definition: dsp_init.c:32
LUMA
#define LUMA
Definition: filter.c:31
h2656dsp.h
src1
const pixel * src1
Definition: h264pred_template.c:421
PUT_PIXELS_PROTOTYPES2
#define PUT_PIXELS_PROTOTYPES2(bd, opt)
Definition: dsp_init.c:65
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:109
DMVR_PROTOTYPES
#define DMVR_PROTOTYPES(bd, opt)
Definition: dsp_init.c:42
AV_CPU_FLAG_RVB
#define AV_CPU_FLAG_RVB
B (bit manipulations)
Definition: cpu.h:102
ff_vvc_sad_rvv_256
int ff_vvc_sad_rvv_256(const int16_t *src0, const int16_t *src1, int dx, int dy, int block_w, int block_h)
dsp.h
cpu.h
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
cpu.h
DMVR_INIT
#define DMVR_INIT(bd, opt)
Definition: dsp_init.c:55
attributes.h
AV_CPU_FLAG_RVV_I32
#define AV_CPU_FLAG_RVV_I32
Vectors of 8/16/32-bit int's *‍/.
Definition: cpu.h:92
CHROMA
@ CHROMA
Definition: vf_waveform.c:49
FUNCS
#define FUNCS(C, opt)
Definition: dsp_init.c:79
ff_vvc_sad_rvv_128
int ff_vvc_sad_rvv_128(const int16_t *src0, const int16_t *src1, int dx, int dy, int block_w, int block_h)
ff_vvc_dsp_init_riscv
void ff_vvc_dsp_init_riscv(VVCDSPContext *const c, const int bd)
Definition: dsp_init.c:82
src0
const pixel *const src0
Definition: h264pred_template.c:420
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
dec.h
VVCDSPContext
Definition: dsp.h:169