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.
24 #include "libavfilter/af_afir.h"
25 #include "libavutil/internal.h"
30 #define randomize_buffer(buf) \
33 double bmg[2], stddev = 10.0, mean = 0.0; \
35 for (i = 0; i < LEN*2+8; i += 2) { \
36 av_bmg_get(&checkasm_lfg, bmg); \
37 buf[i] = bmg[0] * stddev + mean; \
38 buf[i + 1] = bmg[1] * stddev + mean; \
42 static void test_fcmul_add(const float *src0, const float *src1, const float *src2)
44 LOCAL_ALIGNED_32(float, cdst, [LEN*2+8]);
45 LOCAL_ALIGNED_32(float, odst, [LEN*2+8]);
48 declare_func(void, float *sum, const float *t, const float *c,
51 memcpy(cdst, src0, (LEN*2+8) * sizeof(float));
52 memcpy(odst, src0, (LEN*2+8) * sizeof(float));
53 call_ref(cdst, src1, src2, LEN);
54 call_new(odst, src1, src2, LEN);
55 for (i = 0; i <= LEN*2; i++) {
57 float cre = src2[idx];
58 float cim = src2[idx + 1];
59 float tre = src1[idx];
60 float tim = src1[idx + 1];
61 double t = fabs(src0[i]) +
62 fabs(tre) + fabs(tim) + fabs(cre) + fabs(cim) +
63 fabs(tre * cre) + fabs(tim * cim) +
64 fabs(tre * cim) + fabs(tim * cre) +
65 fabs(tre * cre - tim * cim) +
66 fabs(tre * cim + tim * cre) +
68 if (!float_near_abs_eps(cdst[i], odst[i], t * 2 * FLT_EPSILON)) {
69 fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
70 i, cdst[i], odst[i], cdst[i] - odst[i]);
75 memcpy(odst, src0, (LEN*2+8) * sizeof(float));
76 bench_new(odst, src1, src2, LEN);
79 void checkasm_check_afir(void)
81 LOCAL_ALIGNED_32(float, src0, [LEN*2+8]);
82 LOCAL_ALIGNED_32(float, src1, [LEN*2+8]);
83 LOCAL_ALIGNED_32(float, src2, [LEN*2+8]);
84 AudioFIRDSPContext fir = { 0 };
88 randomize_buffer(src0);
89 randomize_buffer(src1);
90 randomize_buffer(src2);
92 if (check_func(fir.fcmul_add, "fcmul_add"))
93 test_fcmul_add(src0, src1, src2);