27 static void vector_fmul_c(
float *dst,
const float *src0,
const float *src1,
31 for (i = 0; i <
len; i++)
32 dst[i] = src0[i] * src1[i];
39 for (i = 0; i <
len; i++)
40 dst[i] += src[i] * mul;
47 for (i = 0; i <
len; i++)
48 dst[i] = src[i] * mul;
55 for (i = 0; i <
len; i++)
56 dst[i] = src[i] * mul;
60 const float *src1,
const float *win,
int len)
68 for (i = -len, j = len - 1; i < 0; i++, j--) {
73 dst[i] = s0 * wj - s1 * wi;
74 dst[j] = s0 * wi + s1 * wj;
79 const float *src2,
int len){
82 for (i = 0; i <
len; i++)
83 dst[i] = src0[i] * src1[i] + src2[i];
87 const float *src1,
int len)
92 for (i = 0; i <
len; i++)
93 dst[i] = src0[i] * src1[-i];
101 for (i = 0; i <
len; i++) {
102 float t = v1[i] - v2[i];
113 for (i = 0; i <
len; i++)
168 #include "internal.h"
175 static void fill_float_array(
AVLFG *lfg,
float *
a,
int len)
178 double bmg[2], stddev = 10.0, mean = 0.0;
180 for (i = 0; i <
len; i += 2) {
182 a[i] = bmg[0] * stddev + mean;
183 a[i + 1] = bmg[1] * stddev + mean;
186 static int compare_floats(
const float *a,
const float *
b,
int len,
190 for (i = 0; i <
len; i++) {
191 if (fabsf(a[i] - b[i]) > max_diff) {
193 i, a[i], b[i], a[i] - b[i]);
200 static void fill_double_array(
AVLFG *lfg,
double *a,
int len)
203 double bmg[2], stddev = 10.0, mean = 0.0;
205 for (i = 0; i <
len; i += 2) {
207 a[i] = bmg[0] * stddev + mean;
208 a[i + 1] = bmg[1] * stddev + mean;
212 static int compare_doubles(
const double *a,
const double *b,
int len,
217 for (i = 0; i <
len; i++) {
218 if (fabs(a[i] - b[i]) > max_diff) {
220 i, a[i], b[i], a[i] - b[i]);
228 const float *v1,
const float *v2)
237 if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
243 #define ARBITRARY_FMAC_SCALAR_CONST 0.005
245 const float *v1,
const float *src0,
float scale)
251 memcpy(cdst, v1, LEN *
sizeof(*v1));
252 memcpy(odst, v1, LEN *
sizeof(*v1));
257 if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMAC_SCALAR_CONST))
264 const float *v1,
float scale)
273 if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
280 const double *v1,
double scale)
289 if (ret = compare_doubles(cdst, odst, LEN, DBL_EPSILON))
295 #define ARBITRARY_FMUL_WINDOW_CONST 0.008
297 const float *v1,
const float *v2,
const float *v3)
306 if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_WINDOW_CONST))
312 #define ARBITRARY_FMUL_ADD_CONST 0.005
314 const float *v1,
const float *v2,
const float *v3)
323 if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_ADD_CONST))
330 const float *v1,
const float *v2)
339 if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
346 const float *v1,
const float *v2)
354 memcpy(cv1, v1, LEN *
sizeof(*v1));
355 memcpy(cv2, v2, LEN *
sizeof(*v2));
356 memcpy(ov1, v1, LEN *
sizeof(*v1));
357 memcpy(ov2, v2, LEN *
sizeof(*v2));
362 if ((ret = compare_floats(cv1, ov1, LEN, FLT_EPSILON)) ||
363 (ret = compare_floats(cv2, ov2, LEN, FLT_EPSILON)))
369 #define ARBITRARY_SCALARPRODUCT_CONST 0.2
371 const float *v1,
const float *v2)
379 if (ret = compare_floats(&cprod, &oprod, 1, ARBITRARY_SCALARPRODUCT_CONST))
385 int main(
int argc,
char **argv)
387 int ret = 0, seeded = 0;
404 seed = strtoul(
optarg, NULL, 10);
422 av_log(NULL,
AV_LOG_INFO,
"float_dsp-test: %s %u\n", seeded ?
"seed" :
"random seed", seed);
426 fill_float_array(&lfg, src0, LEN);
427 fill_float_array(&lfg, src1, LEN);
428 fill_float_array(&lfg, src2, LEN);
430 fill_double_array(&lfg, dbl_src0, LEN);
431 fill_double_array(&lfg, dbl_src1, LEN);
437 if (test_vector_fmul(&fdsp, &cdsp, src0, src1))
439 if (test_vector_fmac_scalar(&fdsp, &cdsp, src2, src0, src1[0]))
441 if (test_vector_fmul_scalar(&fdsp, &cdsp, src0, src1[0]))
443 if (test_vector_fmul_window(&fdsp, &cdsp, src0, src1, src2))
445 if (test_vector_fmul_add(&fdsp, &cdsp, src0, src1, src2))
447 if (test_vector_fmul_reverse(&fdsp, &cdsp, src0, src1))
449 if (test_butterflies_float(&fdsp, &cdsp, src0, src1))
451 if (test_scalarproduct_float(&fdsp, &cdsp, src0, src1))
453 if (test_vector_dmul_scalar(&fdsp, &cdsp, dbl_src0, dbl_src1[0]))