FFmpeg
flacdsp_init.c
Go to the documentation of this file.
1 /*
2  * Copyright © 2023 Rémi Denis-Courmont.
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/flacdsp.h"
27 
28 void ff_flac_lpc16_rvv(int32_t *decoded, const int coeffs[32],
29  int pred_order, int qlevel, int len);
30 void ff_flac_lpc32_rvv(int32_t *decoded, const int coeffs[32],
31  int pred_order, int qlevel, int len);
32 void ff_flac_lpc32_rvv_simple(int32_t *decoded, const int coeffs[32],
33  int pred_order, int qlevel, int len);
34 void ff_flac_lpc33_rvv(int64_t *, const int32_t *, const int coeffs[32],
35  int pred_order, int qlevel, int len);
36 void ff_flac_wasted32_rvv(int32_t *, int shift, int len);
37 void ff_flac_wasted33_rvv(int64_t *, const int32_t *, int shift, int len);
38 void ff_flac_decorrelate_indep2_16_rvv(uint8_t **out, int32_t **in,
39  int channels, int len, int shift);
40 void ff_flac_decorrelate_indep4_16_rvv(uint8_t **out, int32_t **in,
41  int channels, int len, int shift);
42 void ff_flac_decorrelate_indep6_16_rvv(uint8_t **out, int32_t **in,
43  int channels, int len, int shift);
44 void ff_flac_decorrelate_indep8_16_rvv(uint8_t **out, int32_t **in,
45  int channels, int len, int shift);
46 void ff_flac_decorrelate_ls_16_rvv(uint8_t **out, int32_t **in,
47  int channels, int len, int shift);
48 void ff_flac_decorrelate_rs_16_rvv(uint8_t **out, int32_t **in,
49  int channels, int len, int shift);
50 void ff_flac_decorrelate_ms_16_rvv(uint8_t **out, int32_t **in,
51  int channels, int len, int shift);
52 void ff_flac_decorrelate_indep2_32_rvv(uint8_t **out, int32_t **in,
53  int channels, int len, int shift);
54 void ff_flac_decorrelate_indep4_32_rvv(uint8_t **out, int32_t **in,
55  int channels, int len, int shift);
56 void ff_flac_decorrelate_indep6_32_rvv(uint8_t **out, int32_t **in,
57  int channels, int len, int shift);
58 void ff_flac_decorrelate_indep8_32_rvv(uint8_t **out, int32_t **in,
59  int channels, int len, int shift);
60 void ff_flac_decorrelate_ls_32_rvv(uint8_t **out, int32_t **in,
61  int channels, int len, int shift);
62 void ff_flac_decorrelate_rs_32_rvv(uint8_t **out, int32_t **in,
63  int channels, int len, int shift);
64 void ff_flac_decorrelate_ms_32_rvv(uint8_t **out, int32_t **in,
65  int channels, int len, int shift);
66 
68  int channels)
69 {
70 #if HAVE_RVV
71  int flags = av_get_cpu_flags();
72 
74  int vlenb = ff_get_rv_vlenb();
75 
76  if ((flags & AV_CPU_FLAG_RVB_BASIC) && vlenb >= 16) {
77  c->lpc16 = ff_flac_lpc16_rvv;
78 
79 # if (__riscv_xlen >= 64)
80  if (flags & AV_CPU_FLAG_RVV_I64) {
81  if (vlenb > 16) {
82  c->lpc32 = ff_flac_lpc32_rvv_simple;
83  c->lpc33 = ff_flac_lpc33_rvv;
84  } else
85  c->lpc32 = ff_flac_lpc32_rvv;
86  }
87 # endif
88  }
89 
90  c->wasted32 = ff_flac_wasted32_rvv;
91 
93  c->wasted33 = ff_flac_wasted33_rvv;
94 
95 # if (__riscv_xlen >= 64)
96  switch (fmt) {
97  case AV_SAMPLE_FMT_S16:
98  switch (channels) {
99  case 2:
100  c->decorrelate[0] = ff_flac_decorrelate_indep2_16_rvv;
101  break;
102  case 4:
103  c->decorrelate[0] = ff_flac_decorrelate_indep4_16_rvv;
104  break;
105  case 6:
106  c->decorrelate[0] = ff_flac_decorrelate_indep6_16_rvv;
107  break;
108  case 8:
109  c->decorrelate[0] = ff_flac_decorrelate_indep8_16_rvv;
110  break;
111  }
112  c->decorrelate[1] = ff_flac_decorrelate_ls_16_rvv;
113  c->decorrelate[2] = ff_flac_decorrelate_rs_16_rvv;
114  c->decorrelate[3] = ff_flac_decorrelate_ms_16_rvv;
115  break;
116  case AV_SAMPLE_FMT_S32:
117  switch (channels) {
118  case 2:
119  c->decorrelate[0] = ff_flac_decorrelate_indep2_32_rvv;
120  break;
121  case 4:
122  c->decorrelate[0] = ff_flac_decorrelate_indep4_32_rvv;
123  break;
124  case 6:
125  c->decorrelate[0] = ff_flac_decorrelate_indep6_32_rvv;
126  break;
127  case 8:
128  c->decorrelate[0] = ff_flac_decorrelate_indep8_32_rvv;
129  break;
130  }
131  c->decorrelate[1] = ff_flac_decorrelate_ls_32_rvv;
132  c->decorrelate[2] = ff_flac_decorrelate_rs_32_rvv;
133  c->decorrelate[3] = ff_flac_decorrelate_ms_32_rvv;
134  break;
135  }
136 # endif
137  }
138 #endif
139 }
AV_CPU_FLAG_RVB_BASIC
#define AV_CPU_FLAG_RVB_BASIC
Basic bit-manipulations.
Definition: cpu.h:91
out
FILE * out
Definition: movenc.c:55
ff_flac_decorrelate_indep4_32_rvv
void ff_flac_decorrelate_indep4_32_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:103
flacdsp.h
ff_flac_decorrelate_indep2_32_rvv
void ff_flac_decorrelate_indep2_32_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
ff_flac_decorrelate_ls_32_rvv
void ff_flac_decorrelate_ls_32_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
ff_flac_decorrelate_indep8_16_rvv
void ff_flac_decorrelate_indep8_16_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
av_cold
#define av_cold
Definition: attributes.h:90
cpu.h
channels
channels
Definition: aptx.h:31
AV_CPU_FLAG_RVB_ADDR
#define AV_CPU_FLAG_RVB_ADDR
Address bit-manipulations.
Definition: cpu.h:92
ff_flac_decorrelate_indep6_16_rvv
void ff_flac_decorrelate_indep6_16_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
ff_flac_lpc32_rvv
void ff_flac_lpc32_rvv(int32_t *decoded, const int coeffs[32], int pred_order, int qlevel, int len)
ff_flac_decorrelate_ms_32_rvv
void ff_flac_decorrelate_ms_32_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
ff_flac_lpc32_rvv_simple
void ff_flac_lpc32_rvv_simple(int32_t *decoded, const int coeffs[32], int pred_order, int qlevel, int len)
ff_flacdsp_init_riscv
av_cold void ff_flacdsp_init_riscv(FLACDSPContext *c, enum AVSampleFormat fmt, int channels)
Definition: flacdsp_init.c:67
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_flac_decorrelate_indep8_32_rvv
void ff_flac_decorrelate_indep8_32_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
ff_flac_lpc16_rvv
void ff_flac_lpc16_rvv(int32_t *decoded, const int coeffs[32], int pred_order, int qlevel, int len)
shift
static int shift(int a, int b)
Definition: bonk.c:261
ff_flac_wasted33_rvv
void ff_flac_wasted33_rvv(int64_t *, const int32_t *, int shift, int len)
cpu.h
attributes.h
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
AV_CPU_FLAG_RVV_I32
#define AV_CPU_FLAG_RVV_I32
Vectors of 8/16/32-bit int's *‍/.
Definition: cpu.h:87
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
len
int len
Definition: vorbis_enc_data.h:426
ff_flac_wasted32_rvv
void ff_flac_wasted32_rvv(int32_t *, int shift, int len)
ff_flac_decorrelate_ls_16_rvv
void ff_flac_decorrelate_ls_16_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
ff_flac_decorrelate_indep6_32_rvv
void ff_flac_decorrelate_indep6_32_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
ff_flac_decorrelate_rs_32_rvv
void ff_flac_decorrelate_rs_32_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
ff_flac_decorrelate_indep4_16_rvv
void ff_flac_decorrelate_indep4_16_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
ff_flac_lpc33_rvv
void ff_flac_lpc33_rvv(int64_t *, const int32_t *, const int coeffs[32], int pred_order, int qlevel, int len)
ff_flac_decorrelate_rs_16_rvv
void ff_flac_decorrelate_rs_16_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
int32_t
int32_t
Definition: audioconvert.c:56
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
AV_CPU_FLAG_RVV_I64
#define AV_CPU_FLAG_RVV_I64
Vectors of 64-bit int's *‍/.
Definition: cpu.h:89
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:59
FLACDSPContext
Definition: flacdsp.h:26
ff_flac_decorrelate_ms_16_rvv
void ff_flac_decorrelate_ms_16_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)
ff_flac_decorrelate_indep2_16_rvv
void ff_flac_decorrelate_indep2_16_rvv(uint8_t **out, int32_t **in, int channels, int len, int shift)