FFmpeg
Loading...
Searching...
No Matches
ac3dsp.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Institute of Software Chinese Academy of Sciences (ISCAS).
3 * Copyright (c) 2024 Geoff Hill <geoff@geoffhill.org>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#include <stdint.h>
23#include <string.h>
24
26
27#include "libavcodec/ac3defs.h"
28#include "libavcodec/ac3dsp.h"
29
30#include "checkasm.h"
31
32#define randomize_exp(buf, len) \
33 do { \
34 int i; \
35 for (i = 0; i < len; i++) { \
36 buf[i] = (uint8_t)rnd(); \
37 } \
38 } while (0)
39
40#define randomize_i24(buf, len) \
41 do { \
42 int i; \
43 for (i = 0; i < len; i++) { \
44 int32_t v = (int32_t)rnd(); \
45 int32_t u = (v & 0xFFFFFF); \
46 buf[i] = (v < 0) ? -u : u; \
47 } \
48 } while (0)
49
50#define randomize_float(buf, len) \
51 do { \
52 int i; \
53 for (i = 0; i < len; i++) { \
54 float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
55 buf[i] = f; \
56 } \
57 } while (0)
58
60#define MAX_COEFS 256
61#define MAX_CTXT 6
62#define EXP_SIZE (MAX_CTXT * MAX_COEFS)
63
64 LOCAL_ALIGNED_16(uint8_t, src, [EXP_SIZE]);
65 LOCAL_ALIGNED_16(uint8_t, v1, [EXP_SIZE]);
66 LOCAL_ALIGNED_16(uint8_t, v2, [EXP_SIZE]);
67 int n;
68
69 declare_func(void, uint8_t *, int, int);
70
71 for (n = 0; n < MAX_CTXT; ++n) {
72 if (check_func(c->ac3_exponent_min, "ac3_exponent_min_reuse%d", n)) {
74
75 memcpy(v1, src, EXP_SIZE);
76 memcpy(v2, src, EXP_SIZE);
77
78 call_ref(v1, n, MAX_COEFS);
79 call_new(v2, n, MAX_COEFS);
80
81 if (memcmp(v1, v2, EXP_SIZE) != 0)
82 fail();
83
84 bench_new(v2, n, MAX_COEFS);
85 }
86 }
87
88 report("ac3_exponent_min");
89}
90
92#define MAX_EXPS 3072
94 LOCAL_ALIGNED_16(uint8_t, v1, [MAX_EXPS]);
95 LOCAL_ALIGNED_16(uint8_t, v2, [MAX_EXPS]);
96 int n;
97
98 declare_func(void, uint8_t *, const int32_t *, int);
99
100 for (n = 512; n <= MAX_EXPS; n += 256) {
101 if (check_func(c->extract_exponents, "ac3_extract_exponents_n%d", n)) {
102 randomize_i24(src, n);
103
104 call_ref(v1, src, n);
105 call_new(v2, src, n);
106
107 if (memcmp(v1, v2, n) != 0)
108 fail();
109
110 bench_new(v1, src, n);
111 }
112 }
113
114 report("ac3_extract_exponents");
115}
116
118#define BUF_SIZE 1024
119 LOCAL_ALIGNED_32(float, src, [BUF_SIZE]);
120
121 declare_func(void, int32_t *, const float *, size_t);
122
124
125 if (check_func(c->float_to_fixed24, "float_to_fixed24")) {
128
130 call_new(dst2, src, BUF_SIZE);
131
132 if (memcmp(dst, dst2, BUF_SIZE) != 0)
133 fail();
134
136 }
137
138
139 report("float_to_fixed24");
140}
141
143{
144 declare_func(int, const uint16_t mant_cnt[6][16]);
145
146 if (!check_func(c->compute_mantissa_size, "compute_mantissa_size"))
147 return;
148
149 DECLARE_ALIGNED_16(uint16_t, mant_cnt)[AC3_MAX_BLOCKS][16];
150
151 // The maximum of a single value is 3*60 (max_bandwith_code) + 73 + 2
152 checkasm_randomize_mask16((uint16_t*)mant_cnt, AC3_MAX_BLOCKS*16, 0xFF);
153
154 int size_ref = call_ref(mant_cnt);
155 int size_new = call_new(mant_cnt);
156
157 if (size_ref != size_new)
158 fail();
159
160 bench_new(mant_cnt);
161
162 report("compute_mantissa_size");
163}
164
166#define ELEMS 240
169 LOCAL_ALIGNED_16(uint64_t, v1, [4]);
170 LOCAL_ALIGNED_16(uint64_t, v2, [4]);
171
172 declare_func(void, int64_t[4], const int32_t *, const int32_t *, int);
173
174 randomize_i24(lt, ELEMS);
175 randomize_i24(rt, ELEMS);
176
177 if (check_func(c->sum_square_butterfly_int32,
178 "ac3_sum_square_butterfly_int32")) {
179 call_ref(v1, lt, rt, ELEMS);
180 call_new(v2, lt, rt, ELEMS);
181
182 if (memcmp(v1, v2, sizeof(int64_t[4])) != 0)
183 fail();
184
185 bench_new(v2, lt, rt, ELEMS);
186 }
187
188 report("ac3_sum_square_butterfly_int32");
189}
190
192 LOCAL_ALIGNED_32(float, lt, [ELEMS]);
193 LOCAL_ALIGNED_32(float, rt, [ELEMS]);
194 LOCAL_ALIGNED_16(float, v1, [4]);
195 LOCAL_ALIGNED_16(float, v2, [4]);
196
197 declare_func(void, float[4], const float *, const float *, int);
198
201
202 if (check_func(c->sum_square_butterfly_float,
203 "ac3_sum_square_butterfly_float")) {
204 call_ref(v1, lt, rt, ELEMS);
205 call_new(v2, lt, rt, ELEMS);
206
207 if (!float_near_ulp_array(v1, v2, 15, 4))
208 fail();
209
210 bench_new(v2, lt, rt, ELEMS);
211 }
212
213 report("ac3_sum_square_butterfly_float");
214}
215
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
#define AC3_MAX_BLOCKS
Definition ac3defs.h:31
int32_t
long long int64_t
Definition coverity.c:34
#define declare_func
Definition test.h:489
#define fail
Definition test.h:479
#define bench_new
Definition test.h:487
#define check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define report
Definition test.h:480
#define float_near_ulp_array
Definition utils.h:451
CHECKASM_API void checkasm_randomize_mask16(uint16_t *buf, int width, uint16_t mask)
Fill a uint16_t buffer with random values chosen uniformly within a mask.
Definition utils.c:302
av_cold void ff_ac3dsp_init(AC3DSPContext *c)
Definition ac3dsp.c:377
#define LOCAL_ALIGNED_32(t, v,...)
#define LOCAL_ALIGNED_16(t, v,...)
#define DECLARE_ALIGNED_16(t, v)
#define BUF_SIZE
Definition setpts.c:159
static void check_ac3_sum_square_butterfly_float(AC3DSPContext *c)
Definition ac3dsp.c:191
#define EXP_SIZE
static void check_compute_mantissa_size(AC3DSPContext *const c)
Definition ac3dsp.c:142
static void check_ac3_extract_exponents(AC3DSPContext *c)
Definition ac3dsp.c:91
#define ELEMS
static void check_ac3_exponent_min(AC3DSPContext *c)
Definition ac3dsp.c:59
void checkasm_check_ac3dsp(void)
Definition ac3dsp.c:216
#define randomize_exp(buf, len)
Definition ac3dsp.c:32
#define randomize_i24(buf, len)
Definition ac3dsp.c:40
#define MAX_CTXT
#define MAX_COEFS
static void check_float_to_fixed24(AC3DSPContext *c)
Definition ac3dsp.c:117
#define MAX_EXPS
#define randomize_float(buf, len)
Definition ac3dsp.c:50
static void check_ac3_sum_square_butterfly_int32(AC3DSPContext *c)
Definition ac3dsp.c:165
#define src
Definition vp8dsp.c:248
static double c[64]