FFmpeg
h264qpel_init.c
Go to the documentation of this file.
1 /*
2  * RISC-V optimised DSP functions
3  * Copyright (c) 2024 Niklas Haas
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 <stdint.h>
23 
24 #include "config.h"
25 #include "libavutil/attributes.h"
26 #include "libavutil/riscv/cpu.h"
27 #include "libavcodec/h264qpel.h"
28 
29 #define DECL_QPEL_OPS(OP, SIZE, EXT) \
30 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc00_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
31 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc10_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
32 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc20_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
33 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc30_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
34 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc01_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
35 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc11_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
36 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc21_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
37 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc31_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
38 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc02_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
39 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc12_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
40 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc22_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
41 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc32_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
42 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc03_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
43 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc13_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
44 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc23_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
45 void ff_ ## OP ## _h264_qpel ## SIZE ## _mc33_ ## EXT(uint8_t *dst, const uint8_t *src, ptrdiff_t stride);
46 
47 DECL_QPEL_OPS(put, 16, rvv256)
48 DECL_QPEL_OPS(put, 8, rvv256)
49 // DECL_QPEL_OPS(put, 4, rvv256)
50 
51 DECL_QPEL_OPS(avg, 16, rvv256)
52 DECL_QPEL_OPS(avg, 8, rvv256)
53 // DECL_QPEL_OPS(avg, 4, rvv256)
54 
55 DECL_QPEL_OPS(put, 16, rvv)
56 DECL_QPEL_OPS(put, 8, rvv)
57 DECL_QPEL_OPS(put, 4, rvv)
58 
59 DECL_QPEL_OPS(avg, 16, rvv)
60 DECL_QPEL_OPS(avg, 8, rvv)
61 DECL_QPEL_OPS(avg, 4, rvv)
62 
63 #define SET_QPEL_FNS(OP, IDX, SIZE, EXT) \
64 do { \
65  c->OP ## _h264_qpel_pixels_tab[IDX][ 0] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc00_ ## EXT; \
66  c->OP ## _h264_qpel_pixels_tab[IDX][ 1] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc10_ ## EXT; \
67  c->OP ## _h264_qpel_pixels_tab[IDX][ 2] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc20_ ## EXT; \
68  c->OP ## _h264_qpel_pixels_tab[IDX][ 3] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc30_ ## EXT; \
69  c->OP ## _h264_qpel_pixels_tab[IDX][ 4] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc01_ ## EXT; \
70  c->OP ## _h264_qpel_pixels_tab[IDX][ 5] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc11_ ## EXT; \
71  c->OP ## _h264_qpel_pixels_tab[IDX][ 6] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc21_ ## EXT; \
72  c->OP ## _h264_qpel_pixels_tab[IDX][ 7] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc31_ ## EXT; \
73  c->OP ## _h264_qpel_pixels_tab[IDX][ 8] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc02_ ## EXT; \
74  c->OP ## _h264_qpel_pixels_tab[IDX][ 9] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc12_ ## EXT; \
75  c->OP ## _h264_qpel_pixels_tab[IDX][10] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc22_ ## EXT; \
76  c->OP ## _h264_qpel_pixels_tab[IDX][11] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc32_ ## EXT; \
77  c->OP ## _h264_qpel_pixels_tab[IDX][12] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc03_ ## EXT; \
78  c->OP ## _h264_qpel_pixels_tab[IDX][13] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc13_ ## EXT; \
79  c->OP ## _h264_qpel_pixels_tab[IDX][14] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc23_ ## EXT; \
80  c->OP ## _h264_qpel_pixels_tab[IDX][15] = ff_ ## OP ## _h264_qpel ## SIZE ## _mc33_ ## EXT; \
81 } while (0)
82 
84 {
85 #if HAVE_RVV
86  int flags = av_get_cpu_flags();
87  if (flags & AV_CPU_FLAG_RVV_I32) {
88  const int vlen = 8 * ff_get_rv_vlenb();
89 
90  switch (bit_depth) {
91  case 8:
92  if (vlen >= 256) {
93  SET_QPEL_FNS(put, 0, 16, rvv256);
94  SET_QPEL_FNS(put, 1, 8, rvv256);
95  SET_QPEL_FNS(put, 2, 4, rvv);
96 
97  SET_QPEL_FNS(avg, 0, 16, rvv256);
98  SET_QPEL_FNS(avg, 1, 8, rvv256);
99  SET_QPEL_FNS(avg, 2, 4, rvv);
100  } else if (vlen >= 128) {
101  SET_QPEL_FNS(put, 0, 16, rvv);
102  SET_QPEL_FNS(put, 1, 8, rvv);
103  SET_QPEL_FNS(put, 2, 4, rvv);
104 
105  SET_QPEL_FNS(avg, 0, 16, rvv);
106  SET_QPEL_FNS(avg, 1, 8, rvv);
107  SET_QPEL_FNS(avg, 2, 4, rvv);
108  }
109  break;
110  }
111  }
112 #endif
113 }
SET_QPEL_FNS
#define SET_QPEL_FNS(OP, IDX, SIZE, EXT)
Definition: h264qpel_init.c:63
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:107
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
h264qpel.h
av_cold
#define av_cold
Definition: attributes.h:90
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
ff_h264qpel_init_riscv
av_cold void ff_h264qpel_init_riscv(H264QpelContext *c, int bit_depth)
Definition: h264qpel_init.c:83
DECL_QPEL_OPS
#define DECL_QPEL_OPS(OP, SIZE, EXT)
Definition: h264qpel_init.c:29
avg
#define avg(a, b, c, d)
Definition: colorspacedsp_template.c:28
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
H264QpelContext
Definition: h264qpel.h:27
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482