FFmpeg
sbrdsp.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #include "libavcodec/sbrdsp.h"
20 
21 #include "checkasm.h"
22 
23 #define randomize(buf, len) do { \
24  int i; \
25  for (i = 0; i < len; i++) { \
26  const INTFLOAT f = (INTFLOAT)rnd() / UINT_MAX; \
27  (buf)[i] = f; \
28  } \
29 } while (0)
30 
31 #define EPS 0.0001
32 
33 static void test_sum64x5(void)
34 {
35  LOCAL_ALIGNED_16(INTFLOAT, dst0, [64 + 256]);
36  LOCAL_ALIGNED_16(INTFLOAT, dst1, [64 + 256]);
37 
38  declare_func(void, INTFLOAT *z);
39 
40  randomize((INTFLOAT *)dst0, 64 + 256);
41  memcpy(dst1, dst0, (64 + 256) * sizeof(INTFLOAT));
42  call_ref(dst0);
43  call_new(dst1);
44  if (!float_near_abs_eps_array(dst0, dst1, EPS, 64 + 256))
45  fail();
46  bench_new(dst1);
47 }
48 
49 static void test_sum_square(void)
50 {
51  INTFLOAT res0;
52  INTFLOAT res1;
53  LOCAL_ALIGNED_16(INTFLOAT, src, [256], [2]);
54 
55  declare_func_float(INTFLOAT, INTFLOAT (*x)[2], int n);
56 
57  randomize((INTFLOAT *)src, 256 * 2);
58  res0 = call_ref(src, 256);
59  res1 = call_new(src, 256);
60  if (!float_near_abs_eps(res0, res1, EPS))
61  fail();
62  bench_new(src, 256);
63 }
64 
65 static void test_neg_odd_64(void)
66 {
67  LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
68  LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
69 
70  declare_func(void, INTFLOAT *x);
71 
72  randomize((INTFLOAT *)dst0, 64);
73  memcpy(dst1, dst0, (64) * sizeof(INTFLOAT));
74  call_ref(dst0);
75  call_new(dst1);
76  if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
77  fail();
78  bench_new(dst1);
79 }
80 
81 static void test_qmf_pre_shuffle(void)
82 {
83  LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
84  LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
85 
86  declare_func(void, INTFLOAT *z);
87 
88  randomize((INTFLOAT *)dst0, 128);
89  memcpy(dst1, dst0, (128) * sizeof(INTFLOAT));
90  call_ref(dst0);
91  call_new(dst1);
92  if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
93  fail();
94  bench_new(dst1);
95 }
96 
97 static void test_qmf_post_shuffle(void)
98 {
100  LOCAL_ALIGNED_16(INTFLOAT, dst0, [32], [2]);
101  LOCAL_ALIGNED_16(INTFLOAT, dst1, [32], [2]);
102 
103  declare_func(void, INTFLOAT W[32][2], const INTFLOAT *z);
104 
105  randomize((INTFLOAT *)src, 64);
106  call_ref(dst0, src);
107  call_new(dst1, src);
108  if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 64))
109  fail();
110  bench_new(dst1, src);
111 }
112 
113 static void test_qmf_deint_neg(void)
114 {
115  LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
116  LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
117  LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
118 
119  declare_func(void, INTFLOAT *v, const INTFLOAT *src);
120 
121  randomize((INTFLOAT *)src, 64);
122  call_ref(dst0, src);
123  call_new(dst1, src);
124  if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
125  fail();
126  bench_new(dst1, src);
127 }
128 
129 static void test_qmf_deint_bfly(void)
130 {
133  LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
134  LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
135 
136  declare_func(void, INTFLOAT *v, const INTFLOAT *src0, const INTFLOAT *src1);
137 
138  memset(dst0, 0, 128 * sizeof(INTFLOAT));
139  memset(dst1, 0, 128 * sizeof(INTFLOAT));
140 
141  randomize((INTFLOAT *)src0, 64);
142  randomize((INTFLOAT *)src1, 64);
143  call_ref(dst0, src0, src1);
144  call_new(dst1, src0, src1);
145  if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
146  fail();
147  bench_new(dst1, src0, src1);
148 }
149 
150 static void test_autocorrelate(void)
151 {
152  LOCAL_ALIGNED_16(INTFLOAT, src, [40], [2]);
153  LOCAL_ALIGNED_16(INTFLOAT, dst0, [3], [2][2]);
154  LOCAL_ALIGNED_16(INTFLOAT, dst1, [3], [2][2]);
155 
156  declare_func(void, const INTFLOAT x[40][2], INTFLOAT phi[3][2][2]);
157 
158  memset(dst0, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
159  memset(dst1, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
160 
161  randomize((INTFLOAT *)src, 80);
162  call_ref(src, dst0);
163  call_new(src, dst1);
164  if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 3 * 2 * 2))
165  fail();
166  bench_new(src, dst1);
167 }
168 
169 static void test_hf_gen(void)
170 {
171  LOCAL_ALIGNED_16(INTFLOAT, low, [128], [2]);
172  LOCAL_ALIGNED_16(INTFLOAT, alpha0, [2]);
173  LOCAL_ALIGNED_16(INTFLOAT, alpha1, [2]);
174  LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
175  LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
176  INTFLOAT bw = (INTFLOAT)rnd() / UINT_MAX;
177  int i;
178 
179  declare_func(void, INTFLOAT (*X_high)[2], const INTFLOAT (*X_low)[2],
180  const INTFLOAT alpha0[2], const INTFLOAT alpha1[2],
181  INTFLOAT bw, int start, int end);
182 
183  randomize((INTFLOAT *)low, 128 * 2);
184  randomize((INTFLOAT *)alpha0, 2);
185  randomize((INTFLOAT *)alpha1, 2);
186  for (i = 2; i < 64; i += 2) {
187  memset(dst0, 0, 128 * 2 * sizeof(INTFLOAT));
188  memset(dst1, 0, 128 * 2 * sizeof(INTFLOAT));
189  call_ref(dst0, low, alpha0, alpha1, 0.0, i, 128);
190  call_new(dst1, low, alpha0, alpha1, 0.0, i, 128);
191  if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
192  fail();
193  bench_new(dst1, low, alpha0, alpha1, bw, i, 128);
194  }
195 }
196 
197 static void test_hf_g_filt(void)
198 {
199  LOCAL_ALIGNED_16(INTFLOAT, high, [128], [40][2]);
200  LOCAL_ALIGNED_16(INTFLOAT, g_filt, [128]);
201  LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
202  LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
203 
204  declare_func(void, INTFLOAT (*Y)[2], const INTFLOAT (*X_high)[40][2],
205  const INTFLOAT *g_filt, int m_max, intptr_t ixh);
206 
207  randomize((INTFLOAT *)high, 128 * 40 * 2);
208  randomize((INTFLOAT *)g_filt, 128);
209 
210  call_ref(dst0, high, g_filt, 128, 20);
211  call_new(dst1, high, g_filt, 128, 20);
212  if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
213  fail();
214  bench_new(dst1, high, g_filt, 128, 20);
215 }
216 
217 static void test_hf_apply_noise(const SBRDSPContext *sbrdsp)
218 {
219  LOCAL_ALIGNED_16(AAC_FLOAT, s_m, [128]);
220  LOCAL_ALIGNED_16(AAC_FLOAT, q_filt, [128]);
221  LOCAL_ALIGNED_16(INTFLOAT, ref, [128], [2]);
222  LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
223  LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
224  int noise = 0x2a;
225  int i, j;
226 
227  declare_func(void, INTFLOAT (*Y)[2], const AAC_FLOAT *s_m,
228  const AAC_FLOAT *q_filt, int noise,
229  int kx, int m_max);
230 
231  randomize((INTFLOAT *)ref, 128 * 2);
232  randomize((INTFLOAT *)s_m, 128);
233  randomize((INTFLOAT *)q_filt, 128);
234 
235  for (i = 0; i < 4; i++) {
236  if (check_func(sbrdsp->hf_apply_noise[i], "hf_apply_noise_%d", i)) {
237  for (j = 0; j < 2; j++) {
238  memcpy(dst0, ref, 128 * 2 * sizeof(INTFLOAT));
239  memcpy(dst1, ref, 128 * 2 * sizeof(INTFLOAT));
240  call_ref(dst0, s_m, q_filt, noise, j, 128);
241  call_new(dst1, s_m, q_filt, noise, j, 128);
242  if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
243  fail();
244  bench_new(dst1, s_m, q_filt, noise, j, 128);
245  }
246  }
247  }
248 }
249 
251 {
252  SBRDSPContext sbrdsp;
253 
254  ff_sbrdsp_init(&sbrdsp);
255 
256  if (check_func(sbrdsp.sum64x5, "sum64x5"))
257  test_sum64x5();
258  report("sum64x5");
259 
260  if (check_func(sbrdsp.sum_square, "sum_square"))
261  test_sum_square();
262  report("sum_square");
263 
264  if (check_func(sbrdsp.neg_odd_64, "neg_odd_64"))
265  test_neg_odd_64();
266  report("neg_odd_64");
267 
268  if (check_func(sbrdsp.qmf_pre_shuffle, "qmf_pre_shuffle"))
270  report("qmf_pre_shuffle");
271 
272  if (check_func(sbrdsp.qmf_post_shuffle, "qmf_post_shuffle"))
274  report("qmf_post_shuffle");
275 
276  if (check_func(sbrdsp.qmf_deint_neg, "qmf_deint_neg"))
278  report("qmf_deint_neg");
279 
280  if (check_func(sbrdsp.qmf_deint_bfly, "qmf_deint_bfly"))
282  report("qmf_deint_bfly");
283 
284  if (check_func(sbrdsp.autocorrelate, "autocorrelate"))
286  report("autocorrelate");
287 
288  if (check_func(sbrdsp.hf_gen, "hf_gen"))
289  test_hf_gen();
290  report("hf_gen");
291 
292  if (check_func(sbrdsp.hf_g_filt, "hf_g_filt"))
293  test_hf_g_filt();
294  report("hf_g_filt");
295 
296  test_hf_apply_noise(&sbrdsp);
297  report("hf_apply_noise");
298 }
SBRDSPContext::hf_gen
void(* hf_gen)(INTFLOAT(*X_high)[2], const INTFLOAT(*X_low)[2], const INTFLOAT alpha0[2], const INTFLOAT alpha1[2], INTFLOAT bw, int start, int end)
Definition: sbrdsp.h:37
INTFLOAT
#define INTFLOAT
Definition: dct32_template.c:44
SBRDSPContext
Definition: sbrdsp.h:28
test_qmf_deint_bfly
static void test_qmf_deint_bfly(void)
Definition: sbrdsp.c:129
n
int n
Definition: avisynth_c.h:760
float_near_abs_eps_array
int float_near_abs_eps_array(const float *a, const float *b, float eps, unsigned len)
Definition: checkasm.c:317
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
float_near_abs_eps
int float_near_abs_eps(float a, float b, float eps)
Definition: checkasm.c:306
check_func
#define check_func(func,...)
Definition: checkasm.h:111
declare_func_float
#define declare_func_float(ret,...)
Definition: checkasm.h:116
call_ref
#define call_ref(...)
Definition: checkasm.h:126
fail
#define fail()
Definition: checkasm.h:120
start
void INT64 start
Definition: avisynth_c.h:767
test_hf_apply_noise
static void test_hf_apply_noise(const SBRDSPContext *sbrdsp)
Definition: sbrdsp.c:217
checkasm.h
src
#define src
Definition: vp8dsp.c:254
test_qmf_post_shuffle
static void test_qmf_post_shuffle(void)
Definition: sbrdsp.c:97
rnd
#define rnd()
Definition: checkasm.h:104
test_hf_g_filt
static void test_hf_g_filt(void)
Definition: sbrdsp.c:197
W
#define W(a, i, v)
Definition: jpegls.h:124
EPS
#define EPS
Definition: sbrdsp.c:31
test_hf_gen
static void test_hf_gen(void)
Definition: sbrdsp.c:169
test_autocorrelate
static void test_autocorrelate(void)
Definition: sbrdsp.c:150
test_sum_square
static void test_sum_square(void)
Definition: sbrdsp.c:49
SBRDSPContext::autocorrelate
void(* autocorrelate)(const INTFLOAT x[40][2], AAC_FLOAT phi[3][2][2])
Definition: sbrdsp.h:36
call_new
#define call_new(...)
Definition: checkasm.h:193
checkasm_check_sbrdsp
void checkasm_check_sbrdsp(void)
Definition: sbrdsp.c:250
test_sum64x5
static void test_sum64x5(void)
Definition: sbrdsp.c:33
SBRDSPContext::neg_odd_64
void(* neg_odd_64)(INTFLOAT *x)
Definition: sbrdsp.h:31
SBRDSPContext::hf_g_filt
void(* hf_g_filt)(INTFLOAT(*Y)[2], const INTFLOAT(*X_high)[40][2], const AAC_FLOAT *g_filt, int m_max, intptr_t ixh)
Definition: sbrdsp.h:40
SBRDSPContext::qmf_deint_bfly
void(* qmf_deint_bfly)(INTFLOAT *v, const INTFLOAT *src0, const INTFLOAT *src1)
Definition: sbrdsp.h:35
SBRDSPContext::sum64x5
void(* sum64x5)(INTFLOAT *z)
Definition: sbrdsp.h:29
SBRDSPContext::qmf_pre_shuffle
void(* qmf_pre_shuffle)(INTFLOAT *z)
Definition: sbrdsp.h:32
test_qmf_pre_shuffle
static void test_qmf_pre_shuffle(void)
Definition: sbrdsp.c:81
test_qmf_deint_neg
static void test_qmf_deint_neg(void)
Definition: sbrdsp.c:113
sbrdsp.h
SBRDSPContext::qmf_deint_neg
void(* qmf_deint_neg)(INTFLOAT *v, const INTFLOAT *src)
Definition: sbrdsp.h:34
SBRDSPContext::hf_apply_noise
void(* hf_apply_noise[4])(INTFLOAT(*Y)[2], const AAC_FLOAT *s_m, const AAC_FLOAT *q_filt, int noise, int kx, int m_max)
Definition: sbrdsp.h:42
Y
#define Y
Definition: boxblur.h:38
src0
#define src0
Definition: h264pred.c:138
ff_sbrdsp_init
void AAC_RENAME() ff_sbrdsp_init(SBRDSPContext *s)
Definition: sbrdsp_template.c:76
src1
#define src1
Definition: h264pred.c:139
report
#define report
Definition: checkasm.h:123
bench_new
#define bench_new(...)
Definition: checkasm.h:253
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
test_neg_odd_64
static void test_neg_odd_64(void)
Definition: sbrdsp.c:65
SBRDSPContext::qmf_post_shuffle
void(* qmf_post_shuffle)(INTFLOAT W[32][2], const INTFLOAT *z)
Definition: sbrdsp.h:33
noise
static int noise(AVBSFContext *ctx, AVPacket *pkt)
Definition: noise_bsf.c:38
randomize
#define randomize(buf, len)
Definition: sbrdsp.c:23
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
SBRDSPContext::sum_square
AAC_FLOAT(* sum_square)(INTFLOAT(*x)[2], int n)
Definition: sbrdsp.h:30
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:115
LOCAL_ALIGNED_16
#define LOCAL_ALIGNED_16(t, v,...)
Definition: internal.h:131
AAC_FLOAT
float AAC_FLOAT
Definition: aac_defines.h:90
INTFLOAT
float INTFLOAT
Definition: aac_defines.h:86