2 * This file is part of FFmpeg.
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.
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.
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.
19 #include "libavutil/mem_internal.h"
21 #include "libavcodec/sbrdsp.h"
26 #define randomize(buf, len) do { \
28 for (i = 0; i < len; i++) { \
29 const INTFLOAT f = (INTFLOAT)rnd() / UINT_MAX; \
36 static void test_sum64x5(void)
38 LOCAL_ALIGNED_16(INTFLOAT, dst0, [64 + 256]);
39 LOCAL_ALIGNED_16(INTFLOAT, dst1, [64 + 256]);
41 declare_func(void, INTFLOAT *z);
43 randomize((INTFLOAT *)dst0, 64 + 256);
44 memcpy(dst1, dst0, (64 + 256) * sizeof(INTFLOAT));
47 if (!float_near_abs_eps_array(dst0, dst1, EPS, 64 + 256))
52 static void test_sum_square(void)
56 LOCAL_ALIGNED_16(INTFLOAT, src, [256], [2]);
59 declare_func_float(INTFLOAT, INTFLOAT (*x)[2], int n);
61 randomize((INTFLOAT *)src, 256 * 2);
62 res0 = call_ref(src, 256);
63 res1 = call_new(src, 256);
64 if (!float_near_abs_eps(res0, res1, t * 2 * FLT_EPSILON))
69 static void test_neg_odd_64(void)
71 LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
72 LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
74 declare_func(void, INTFLOAT *x);
76 randomize((INTFLOAT *)dst0, 64);
77 memcpy(dst1, dst0, (64) * sizeof(INTFLOAT));
80 if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
85 static void test_qmf_pre_shuffle(void)
87 LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
88 LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
90 declare_func(void, INTFLOAT *z);
92 randomize((INTFLOAT *)dst0, 128);
93 memcpy(dst1, dst0, (128) * sizeof(INTFLOAT));
96 if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
101 static void test_qmf_post_shuffle(void)
103 LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
104 LOCAL_ALIGNED_16(INTFLOAT, dst0, [32], [2]);
105 LOCAL_ALIGNED_16(INTFLOAT, dst1, [32], [2]);
107 declare_func(void, INTFLOAT W[32][2], const INTFLOAT *z);
109 randomize((INTFLOAT *)src, 64);
112 if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 64))
114 bench_new(dst1, src);
117 static void test_qmf_deint_neg(void)
119 LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
120 LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
121 LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
123 declare_func(void, INTFLOAT *v, const INTFLOAT *src);
125 randomize((INTFLOAT *)src, 64);
128 if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
130 bench_new(dst1, src);
133 static void test_qmf_deint_bfly(void)
135 LOCAL_ALIGNED_16(INTFLOAT, src0, [64]);
136 LOCAL_ALIGNED_16(INTFLOAT, src1, [64]);
137 LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
138 LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
140 declare_func(void, INTFLOAT *v, const INTFLOAT *src0, const INTFLOAT *src1);
142 memset(dst0, 0, 128 * sizeof(INTFLOAT));
143 memset(dst1, 0, 128 * sizeof(INTFLOAT));
145 randomize((INTFLOAT *)src0, 64);
146 randomize((INTFLOAT *)src1, 64);
147 call_ref(dst0, src0, src1);
148 call_new(dst1, src0, src1);
149 if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
151 bench_new(dst1, src0, src1);
154 static void test_autocorrelate(void)
156 LOCAL_ALIGNED_16(INTFLOAT, src, [40], [2]);
157 LOCAL_ALIGNED_16(INTFLOAT, dst0, [3], [2][2]);
158 LOCAL_ALIGNED_16(INTFLOAT, dst1, [3], [2][2]);
160 declare_func(void, const INTFLOAT x[40][2], INTFLOAT phi[3][2][2]);
162 memset(dst0, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
163 memset(dst1, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
165 randomize((INTFLOAT *)src, 80);
168 if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 3 * 2 * 2))
170 bench_new(src, dst1);
173 static void test_hf_gen(void)
175 LOCAL_ALIGNED_16(INTFLOAT, low, [128], [2]);
176 LOCAL_ALIGNED_16(INTFLOAT, alpha0, [2]);
177 LOCAL_ALIGNED_16(INTFLOAT, alpha1, [2]);
178 LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
179 LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
180 INTFLOAT bw = (INTFLOAT)rnd() / UINT_MAX;
183 declare_func(void, INTFLOAT (*X_high)[2], const INTFLOAT (*X_low)[2],
184 const INTFLOAT alpha0[2], const INTFLOAT alpha1[2],
185 INTFLOAT bw, int start, int end);
187 randomize((INTFLOAT *)low, 128 * 2);
188 randomize((INTFLOAT *)alpha0, 2);
189 randomize((INTFLOAT *)alpha1, 2);
190 for (i = 2; i < 64; i += 2) {
191 memset(dst0, 0, 128 * 2 * sizeof(INTFLOAT));
192 memset(dst1, 0, 128 * 2 * sizeof(INTFLOAT));
193 call_ref(dst0, low, alpha0, alpha1, 0.0, i, 128);
194 call_new(dst1, low, alpha0, alpha1, 0.0, i, 128);
195 if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
197 bench_new(dst1, low, alpha0, alpha1, bw, i, 128);
201 static void test_hf_g_filt(void)
203 LOCAL_ALIGNED_16(INTFLOAT, high, [128], [40][2]);
204 LOCAL_ALIGNED_16(INTFLOAT, g_filt, [128]);
205 LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
206 LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
208 declare_func(void, INTFLOAT (*Y)[2], const INTFLOAT (*X_high)[40][2],
209 const INTFLOAT *g_filt, int m_max, intptr_t ixh);
211 randomize((INTFLOAT *)high, 128 * 40 * 2);
212 randomize((INTFLOAT *)g_filt, 128);
214 call_ref(dst0, high, g_filt, 128, 20);
215 call_new(dst1, high, g_filt, 128, 20);
216 if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
218 bench_new(dst1, high, g_filt, 128, 20);
221 static void test_hf_apply_noise(const SBRDSPContext *sbrdsp)
223 LOCAL_ALIGNED_16(AAC_FLOAT, s_m, [128]);
224 LOCAL_ALIGNED_16(AAC_FLOAT, q_filt, [128]);
225 LOCAL_ALIGNED_16(INTFLOAT, ref, [128], [2]);
226 LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
227 LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
231 declare_func(void, INTFLOAT (*Y)[2], const AAC_FLOAT *s_m,
232 const AAC_FLOAT *q_filt, int noise,
235 randomize((INTFLOAT *)ref, 128 * 2);
236 randomize((INTFLOAT *)s_m, 128);
237 randomize((INTFLOAT *)q_filt, 128);
239 for (i = 0; i < 4; i++) {
240 if (check_func(sbrdsp->hf_apply_noise[i], "hf_apply_noise_%d", i)) {
241 for (j = 0; j < 2; j++) {
242 memcpy(dst0, ref, 128 * 2 * sizeof(INTFLOAT));
243 memcpy(dst1, ref, 128 * 2 * sizeof(INTFLOAT));
244 call_ref(dst0, s_m, q_filt, noise, j, 128);
245 call_new(dst1, s_m, q_filt, noise, j, 128);
246 if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
248 bench_new(dst1, s_m, q_filt, noise, j, 128);
254 void checkasm_check_sbrdsp(void)
256 SBRDSPContext sbrdsp;
258 ff_sbrdsp_init(&sbrdsp);
260 if (check_func(sbrdsp.sum64x5, "sum64x5"))
264 if (check_func(sbrdsp.sum_square, "sum_square"))
266 report("sum_square");
268 if (check_func(sbrdsp.neg_odd_64, "neg_odd_64"))
270 report("neg_odd_64");
272 if (check_func(sbrdsp.qmf_pre_shuffle, "qmf_pre_shuffle"))
273 test_qmf_pre_shuffle();
274 report("qmf_pre_shuffle");
276 if (check_func(sbrdsp.qmf_post_shuffle, "qmf_post_shuffle"))
277 test_qmf_post_shuffle();
278 report("qmf_post_shuffle");
280 if (check_func(sbrdsp.qmf_deint_neg, "qmf_deint_neg"))
281 test_qmf_deint_neg();
282 report("qmf_deint_neg");
284 if (check_func(sbrdsp.qmf_deint_bfly, "qmf_deint_bfly"))
285 test_qmf_deint_bfly();
286 report("qmf_deint_bfly");
288 if (check_func(sbrdsp.autocorrelate, "autocorrelate"))
289 test_autocorrelate();
290 report("autocorrelate");
292 if (check_func(sbrdsp.hf_gen, "hf_gen"))
296 if (check_func(sbrdsp.hf_g_filt, "hf_g_filt"))
300 test_hf_apply_noise(&sbrdsp);
301 report("hf_apply_noise");