FFmpeg
af_afir.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 "config.h"
20 
21 #include <float.h>
22 #include <stdint.h>
23 
24 #include "libavfilter/af_afirdsp.h"
25 #include "libavutil/internal.h"
26 #include "libavutil/mem_internal.h"
27 #include "checkasm.h"
28 
29 #define LEN 256
30 
31 #define randomize_buffer(buf) \
32 do { \
33  int i; \
34  double bmg[2], stddev = 10.0, mean = 0.0; \
35  \
36  for (i = 0; i < BUF_SIZE; i += 2) { \
37  av_bmg_get(&checkasm_lfg, bmg); \
38  buf[i] = bmg[0] * stddev + mean; \
39  buf[i + 1] = bmg[1] * stddev + mean; \
40  } \
41 } while(0);
42 
44 {
45 #define BUF_SIZE LEN*2+8
46  LOCAL_ALIGNED_32(float, src0, [BUF_SIZE]);
47  LOCAL_ALIGNED_32(float, src1, [BUF_SIZE]);
48  LOCAL_ALIGNED_32(float, src2, [BUF_SIZE]);
49 
53 
54  if (check_func(fir->fcmul_add, "fcmul_add")) {
55  LOCAL_ALIGNED_32(float, cdst, [BUF_SIZE]);
56  LOCAL_ALIGNED_32(float, odst, [BUF_SIZE]);
57  int i;
58 
59  declare_func(void, float *sum, const float *t, const float *c,
60  ptrdiff_t len);
61 
62  memcpy(cdst, src0, (BUF_SIZE) * sizeof(float));
63  memcpy(odst, src0, (BUF_SIZE) * sizeof(float));
64  call_ref(cdst, src1, src2, LEN);
65  call_new(odst, src1, src2, LEN);
66  for (i = 0; i <= LEN*2; i++) {
67  int idx = i & ~1;
68  float cre = src2[idx];
69  float cim = src2[idx + 1];
70  float tre = src1[idx];
71  float tim = src1[idx + 1];
72  double t = fabs(src0[i]) +
73  fabs(tre) + fabs(tim) + fabs(cre) + fabs(cim) +
74  fabs(tre * cre) + fabs(tim * cim) +
75  fabs(tre * cim) + fabs(tim * cre) +
76  fabs(tre * cre - tim * cim) +
77  fabs(tre * cim + tim * cre) +
78  fabs(cdst[i]) + 1.0;
79  if (!float_near_abs_eps(cdst[i], odst[i], t * 2 * FLT_EPSILON)) {
80  fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
81  i, cdst[i], odst[i], cdst[i] - odst[i]);
82  fail();
83  break;
84  }
85  }
86  memcpy(odst, src0, (BUF_SIZE) * sizeof(float));
87  bench_new(odst, src1, src2, LEN);
88  }
89 
90  report("fcmul_add");
91 }
92 
94 {
95 #define BUF_SIZE LEN*2+8
96  LOCAL_ALIGNED_32(double, src0, [BUF_SIZE]);
97  LOCAL_ALIGNED_32(double, src1, [BUF_SIZE]);
98  LOCAL_ALIGNED_32(double, src2, [BUF_SIZE]);
99 
103 
104  if (check_func(fir->dcmul_add, "dcmul_add")) {
105  LOCAL_ALIGNED_32(double, cdst, [BUF_SIZE]);
106  LOCAL_ALIGNED_32(double, odst, [BUF_SIZE]);
107  int i;
108 
109  declare_func(void, double *sum, const double *t, const double *c,
110  ptrdiff_t len);
111 
112  memcpy(cdst, src0, (BUF_SIZE) * sizeof(double));
113  memcpy(odst, src0, (BUF_SIZE) * sizeof(double));
114  call_ref(cdst, src1, src2, LEN);
115  call_new(odst, src1, src2, LEN);
116  for (i = 0; i <= LEN*2; i++) {
117  int idx = i & ~1;
118  double cre = src2[idx];
119  double cim = src2[idx + 1];
120  double tre = src1[idx];
121  double tim = src1[idx + 1];
122  double t = fabs(src0[i]) +
123  fabs(tre) + fabs(tim) + fabs(cre) + fabs(cim) +
124  fabs(tre * cre) + fabs(tim * cim) +
125  fabs(tre * cim) + fabs(tim * cre) +
126  fabs(tre * cre - tim * cim) +
127  fabs(tre * cim + tim * cre) +
128  fabs(cdst[i]) + 1.0;
129  if (!double_near_abs_eps(cdst[i], odst[i], t * 2 * FLT_EPSILON)) {
130  fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
131  i, cdst[i], odst[i], cdst[i] - odst[i]);
132  fail();
133  break;
134  }
135  }
136  memcpy(odst, src0, (BUF_SIZE) * sizeof(double));
137  bench_new(odst, src1, src2, LEN);
138  }
139 
140  report("dcmul_add");
141 }
142 
143 
145 {
146  AudioFIRDSPContext fir = { 0 };
147 
148  ff_afir_init(&fir);
149  test_fcmul_add(&fir);
150  test_dcmul_add(&fir);
151 }
mem_internal.h
src1
const pixel * src1
Definition: h264pred_template.c:421
checkasm_check_afir
void checkasm_check_afir(void)
Definition: af_afir.c:144
float_near_abs_eps
int float_near_abs_eps(float a, float b, float eps)
Definition: checkasm.c:403
check_func
#define check_func(func,...)
Definition: checkasm.h:174
AudioFIRDSPContext::fcmul_add
void(* fcmul_add)(float *sum, const float *t, const float *c, ptrdiff_t len)
Definition: af_afirdsp.h:30
float.h
call_ref
#define call_ref(...)
Definition: checkasm.h:189
test_dcmul_add
static void test_dcmul_add(AudioFIRDSPContext *fir)
Definition: af_afir.c:93
double_near_abs_eps
int double_near_abs_eps(double a, double b, double eps)
Definition: checkasm.c:443
af_afirdsp.h
fail
#define fail()
Definition: checkasm.h:183
checkasm.h
ff_afir_init
static av_unused void ff_afir_init(AudioFIRDSPContext *dsp)
Definition: af_afirdsp.h:73
test_fcmul_add
static void test_fcmul_add(AudioFIRDSPContext *fir)
Definition: af_afir.c:43
call_new
#define call_new(...)
Definition: checkasm.h:292
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:156
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AudioFIRDSPContext
Definition: af_afirdsp.h:29
LEN
#define LEN
Definition: af_afir.c:29
report
#define report
Definition: checkasm.h:186
bench_new
#define bench_new(...)
Definition: checkasm.h:363
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
internal.h
src2
const pixel * src2
Definition: h264pred_template.c:422
AudioFIRDSPContext::dcmul_add
void(* dcmul_add)(double *sum, const double *t, const double *c, ptrdiff_t len)
Definition: af_afirdsp.h:32
len
int len
Definition: vorbis_enc_data.h:426
randomize_buffer
#define randomize_buffer(buf)
Definition: af_afir.c:31
BUF_SIZE
#define BUF_SIZE
src0
const pixel *const src0
Definition: h264pred_template.c:420
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:178