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 <string.h>
20 
21 #include "libavutil/mem_internal.h"
22 
23 #include "libavcodec/sbrdsp.h"
24 #include <float.h>
25 
26 #include "checkasm.h"
27 
28 #define randomize(buf, len) do { \
29  int i; \
30  for (i = 0; i < len; i++) { \
31  const INTFLOAT f = (INTFLOAT)rnd() / UINT_MAX; \
32  (buf)[i] = f; \
33  } \
34 } while (0)
35 
36 #define EPS 0.0001
37 
38 static void test_sum64x5(void)
39 {
40  LOCAL_ALIGNED_16(INTFLOAT, dst0, [64 + 256]);
41  LOCAL_ALIGNED_16(INTFLOAT, dst1, [64 + 256]);
42 
43  declare_func(void, INTFLOAT *z);
44 
45  randomize((INTFLOAT *)dst0, 64 + 256);
46  memcpy(dst1, dst0, (64 + 256) * sizeof(INTFLOAT));
47  call_ref(dst0);
48  call_new(dst1);
49  if (!float_near_abs_eps_array(dst0, dst1, EPS, 64 + 256))
50  fail();
51  bench_new(dst1);
52 }
53 
54 static void test_sum_square(void)
55 {
56  INTFLOAT res0;
57  INTFLOAT res1;
58  LOCAL_ALIGNED_16(INTFLOAT, src, [256], [2]);
59  double t = 4 * 256;
60 
61  declare_func_float(INTFLOAT, INTFLOAT (*x)[2], int n);
62 
63  randomize((INTFLOAT *)src, 256 * 2);
64  res0 = call_ref(src, 256);
65  res1 = call_new(src, 256);
66  if (!float_near_abs_eps(res0, res1, t * 2 * FLT_EPSILON))
67  fail();
68  bench_new(src, 256);
69 }
70 
71 static void test_neg_odd_64(void)
72 {
73  LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
74  LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
75 
76  declare_func(void, INTFLOAT *x);
77 
78  randomize((INTFLOAT *)dst0, 64);
79  memcpy(dst1, dst0, (64) * sizeof(INTFLOAT));
80  call_ref(dst0);
81  call_new(dst1);
82  if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
83  fail();
84  bench_new(dst1);
85 }
86 
87 static void test_qmf_pre_shuffle(void)
88 {
89  LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
90  LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
91 
92  declare_func(void, INTFLOAT *z);
93 
94  randomize((INTFLOAT *)dst0, 128);
95  memcpy(dst1, dst0, (128) * sizeof(INTFLOAT));
96  call_ref(dst0);
97  call_new(dst1);
98  if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
99  fail();
100  bench_new(dst1);
101 }
102 
103 static void test_qmf_post_shuffle(void)
104 {
105  LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
106  LOCAL_ALIGNED_16(INTFLOAT, dst0, [32], [2]);
107  LOCAL_ALIGNED_16(INTFLOAT, dst1, [32], [2]);
108 
109  declare_func(void, INTFLOAT W[32][2], const INTFLOAT *z);
110 
111  randomize((INTFLOAT *)src, 64);
112  call_ref(dst0, src);
113  call_new(dst1, src);
114  if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 64))
115  fail();
116  bench_new(dst1, src);
117 }
118 
119 static void test_qmf_deint_neg(void)
120 {
121  LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
122  LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
123  LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
124 
125  declare_func(void, INTFLOAT *v, const INTFLOAT *src);
126 
127  randomize((INTFLOAT *)src, 64);
128  call_ref(dst0, src);
129  call_new(dst1, src);
130  if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
131  fail();
132  bench_new(dst1, src);
133 }
134 
135 static void test_qmf_deint_bfly(void)
136 {
139  LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
140  LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
141 
142  declare_func(void, INTFLOAT *v, const INTFLOAT *src0, const INTFLOAT *src1);
143 
144  memset(dst0, 0, 128 * sizeof(INTFLOAT));
145  memset(dst1, 0, 128 * sizeof(INTFLOAT));
146 
147  randomize((INTFLOAT *)src0, 64);
148  randomize((INTFLOAT *)src1, 64);
149  call_ref(dst0, src0, src1);
150  call_new(dst1, src0, src1);
151  if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
152  fail();
153  bench_new(dst1, src0, src1);
154 }
155 
156 static void test_autocorrelate(void)
157 {
158  LOCAL_ALIGNED_16(INTFLOAT, src, [40], [2]);
159  LOCAL_ALIGNED_16(INTFLOAT, dst0, [3], [2][2]);
160  LOCAL_ALIGNED_16(INTFLOAT, dst1, [3], [2][2]);
161 
162  declare_func(void, const INTFLOAT x[40][2], INTFLOAT phi[3][2][2]);
163 
164  memset(dst0, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
165  memset(dst1, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
166 
167  randomize((INTFLOAT *)src, 80);
168  call_ref(src, dst0);
169  call_new(src, dst1);
170  if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 3 * 2 * 2))
171  fail();
172  bench_new(src, dst1);
173 }
174 
175 static void test_hf_gen(void)
176 {
177  LOCAL_ALIGNED_16(INTFLOAT, low, [128], [2]);
178  LOCAL_ALIGNED_16(INTFLOAT, alpha0, [2]);
179  LOCAL_ALIGNED_16(INTFLOAT, alpha1, [2]);
180  LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
181  LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
182  INTFLOAT bw = (INTFLOAT)rnd() / UINT_MAX;
183  int i;
184 
185  declare_func(void, INTFLOAT (*X_high)[2], const INTFLOAT (*X_low)[2],
186  const INTFLOAT alpha0[2], const INTFLOAT alpha1[2],
187  INTFLOAT bw, int start, int end);
188 
189  randomize((INTFLOAT *)low, 128 * 2);
190  randomize((INTFLOAT *)alpha0, 2);
191  randomize((INTFLOAT *)alpha1, 2);
192  for (i = 2; i < 64; i += 2) {
193  memset(dst0, 0, 128 * 2 * sizeof(INTFLOAT));
194  memset(dst1, 0, 128 * 2 * sizeof(INTFLOAT));
195  call_ref(dst0, low, alpha0, alpha1, bw, i, 128);
196  call_new(dst1, low, alpha0, alpha1, bw, i, 128);
197  if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
198  fail();
199  bench_new(dst1, low, alpha0, alpha1, bw, i, 128);
200  }
201 }
202 
203 static void test_hf_g_filt(void)
204 {
205  LOCAL_ALIGNED_16(INTFLOAT, high, [128], [40][2]);
206  LOCAL_ALIGNED_16(INTFLOAT, g_filt, [128]);
207  LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
208  LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
209 
210  declare_func(void, INTFLOAT (*Y)[2], const INTFLOAT (*X_high)[40][2],
211  const INTFLOAT *g_filt, int m_max, intptr_t ixh);
212 
213  randomize((INTFLOAT *)high, 128 * 40 * 2);
214  randomize((INTFLOAT *)g_filt, 128);
215 
216  call_ref(dst0, high, g_filt, 128, 20);
217  call_new(dst1, high, g_filt, 128, 20);
218  if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
219  fail();
220  bench_new(dst1, high, g_filt, 128, 20);
221 }
222 
223 static void test_hf_apply_noise(const SBRDSPContext *sbrdsp)
224 {
225  LOCAL_ALIGNED_16(AAC_FLOAT, s_m, [128]);
226  LOCAL_ALIGNED_16(AAC_FLOAT, q_filt, [128]);
227  LOCAL_ALIGNED_16(INTFLOAT, ref, [128], [2]);
228  LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
229  LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
230  int noise = 0x2a;
231  int i, j;
232 
233  declare_func(void, INTFLOAT (*Y)[2], const AAC_FLOAT *s_m,
234  const AAC_FLOAT *q_filt, int noise,
235  int kx, int m_max);
236 
237  randomize((INTFLOAT *)ref, 128 * 2);
238 
239  for (int i = 0; i < 128; i++)
240  s_m[i] = (rnd() & 1) ? ((INTFLOAT)rnd() / UINT_MAX) : (INTFLOAT)0;
241 
242  randomize((INTFLOAT *)q_filt, 128);
243 
244  for (i = 0; i < 4; i++) {
245  if (check_func(sbrdsp->hf_apply_noise[i], "hf_apply_noise_%d", i)) {
246  for (j = 0; j < 2; j++) {
247  memcpy(dst0, ref, 128 * 2 * sizeof(INTFLOAT));
248  memcpy(dst1, ref, 128 * 2 * sizeof(INTFLOAT));
249  call_ref(dst0, s_m, q_filt, noise, j, 128);
250  call_new(dst1, s_m, q_filt, noise, j, 128);
251  if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
252  fail();
253  bench_new(dst1, s_m, q_filt, noise, j, 128);
254  }
255  }
256  }
257 }
258 
260 {
261  SBRDSPContext sbrdsp;
262 
263  ff_sbrdsp_init(&sbrdsp);
264 
265  if (check_func(sbrdsp.sum64x5, "sum64x5"))
266  test_sum64x5();
267  report("sum64x5");
268 
269  if (check_func(sbrdsp.sum_square, "sum_square"))
270  test_sum_square();
271  report("sum_square");
272 
273  if (check_func(sbrdsp.neg_odd_64, "neg_odd_64"))
274  test_neg_odd_64();
275  report("neg_odd_64");
276 
277  if (check_func(sbrdsp.qmf_pre_shuffle, "qmf_pre_shuffle"))
279  report("qmf_pre_shuffle");
280 
281  if (check_func(sbrdsp.qmf_post_shuffle, "qmf_post_shuffle"))
283  report("qmf_post_shuffle");
284 
285  if (check_func(sbrdsp.qmf_deint_neg, "qmf_deint_neg"))
287  report("qmf_deint_neg");
288 
289  if (check_func(sbrdsp.qmf_deint_bfly, "qmf_deint_bfly"))
291  report("qmf_deint_bfly");
292 
293  if (check_func(sbrdsp.autocorrelate, "autocorrelate"))
295  report("autocorrelate");
296 
297  if (check_func(sbrdsp.hf_gen, "hf_gen"))
298  test_hf_gen();
299  report("hf_gen");
300 
301  if (check_func(sbrdsp.hf_g_filt, "hf_g_filt"))
302  test_hf_g_filt();
303  report("hf_g_filt");
304 
305  test_hf_apply_noise(&sbrdsp);
306  report("hf_apply_noise");
307 }
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:36
INTFLOAT
#define INTFLOAT
Definition: dct32_template.c:44
mem_internal.h
SBRDSPContext
Definition: sbrdsp.h:27
test_qmf_deint_bfly
static void test_qmf_deint_bfly(void)
Definition: sbrdsp.c:135
src1
const pixel * src1
Definition: h264pred_template.c:420
high
int high
Definition: dovi_rpuenc.c:39
check_func
#define check_func
Definition: test.h:481
float.h
bench_new
#define bench_new
Definition: test.h:487
call_ref
#define call_ref
Definition: test.h:485
test_hf_apply_noise
static void test_hf_apply_noise(const SBRDSPContext *sbrdsp)
Definition: sbrdsp.c:223
noise
static int noise(AVBSFContext *ctx, AVPacket *pkt)
Definition: noise.c:124
checkasm.h
test_qmf_post_shuffle
static void test_qmf_post_shuffle(void)
Definition: sbrdsp.c:103
test_hf_g_filt
static void test_hf_g_filt(void)
Definition: sbrdsp.c:203
W
#define W(a, i, v)
Definition: jpegls.h:119
EPS
#define EPS
Definition: sbrdsp.c:36
test_hf_gen
static void test_hf_gen(void)
Definition: sbrdsp.c:175
declare_func
#define declare_func
Definition: test.h:489
LOCAL_ALIGNED_16
#define LOCAL_ALIGNED_16(t, v,...)
Definition: mem_internal.h:130
test_autocorrelate
static void test_autocorrelate(void)
Definition: sbrdsp.c:156
test_sum_square
static void test_sum_square(void)
Definition: sbrdsp.c:54
SBRDSPContext::autocorrelate
void(* autocorrelate)(const INTFLOAT x[40][2], AAC_FLOAT phi[3][2][2])
Definition: sbrdsp.h:35
fail
#define fail
Definition: test.h:479
float_near_abs_eps
#define float_near_abs_eps
Definition: utils.h:449
checkasm_check_sbrdsp
void checkasm_check_sbrdsp(void)
Definition: sbrdsp.c:259
test_sum64x5
static void test_sum64x5(void)
Definition: sbrdsp.c:38
SBRDSPContext::neg_odd_64
void(* neg_odd_64)(INTFLOAT *x)
Definition: sbrdsp.h:30
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:39
SBRDSPContext::qmf_deint_bfly
void(* qmf_deint_bfly)(INTFLOAT *v, const INTFLOAT *src0, const INTFLOAT *src1)
Definition: sbrdsp.h:34
SBRDSPContext::sum64x5
void(* sum64x5)(INTFLOAT *z)
Definition: sbrdsp.h:28
SBRDSPContext::qmf_pre_shuffle
void(* qmf_pre_shuffle)(INTFLOAT *z)
Definition: sbrdsp.h:31
test_qmf_pre_shuffle
static void test_qmf_pre_shuffle(void)
Definition: sbrdsp.c:87
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
test_qmf_deint_neg
static void test_qmf_deint_neg(void)
Definition: sbrdsp.c:119
rnd
#define rnd
Definition: checkasm.h:136
sbrdsp.h
SBRDSPContext::qmf_deint_neg
void(* qmf_deint_neg)(INTFLOAT *v, const INTFLOAT *src)
Definition: sbrdsp.h:33
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:41
Y
#define Y
Definition: boxblur.h:37
ff_sbrdsp_init
void AAC_RENAME() ff_sbrdsp_init(SBRDSPContext *s)
Definition: sbrdsp_template.c:80
declare_func_float
#define declare_func_float
Definition: checkasm.h:137
test_neg_odd_64
static void test_neg_odd_64(void)
Definition: sbrdsp.c:71
call_new
#define call_new
Definition: test.h:486
SBRDSPContext::qmf_post_shuffle
void(* qmf_post_shuffle)(INTFLOAT W[32][2], const INTFLOAT *z)
Definition: sbrdsp.h:32
randomize
#define randomize(buf, len)
Definition: sbrdsp.c:28
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
src0
const pixel *const src0
Definition: h264pred_template.c:419
report
#define report
Definition: test.h:480
float_near_abs_eps_array
#define float_near_abs_eps_array
Definition: utils.h:452
SBRDSPContext::sum_square
AAC_FLOAT(* sum_square)(INTFLOAT(*x)[2], int n)
Definition: sbrdsp.h:29
AAC_FLOAT
float AAC_FLOAT
Definition: aac_defines.h:105
INTFLOAT
float INTFLOAT
Definition: aac_defines.h:101
src
#define src
Definition: vp8dsp.c:248