| Line |
Branch |
Exec |
Source |
| 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 |
|
|
|
| 25 |
|
|
#include "libavutil/mem_internal.h" |
| 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 |
|
|
|
| 59 |
|
14 |
static void check_ac3_exponent_min(AC3DSPContext *c) { |
| 60 |
|
|
#define MAX_COEFS 256 |
| 61 |
|
|
#define MAX_CTXT 6 |
| 62 |
|
|
#define EXP_SIZE (MAX_CTXT * MAX_COEFS) |
| 63 |
|
|
|
| 64 |
|
14 |
LOCAL_ALIGNED_16(uint8_t, src, [EXP_SIZE]); |
| 65 |
|
14 |
LOCAL_ALIGNED_16(uint8_t, v1, [EXP_SIZE]); |
| 66 |
|
14 |
LOCAL_ALIGNED_16(uint8_t, v2, [EXP_SIZE]); |
| 67 |
|
|
int n; |
| 68 |
|
|
|
| 69 |
|
14 |
declare_func(void, uint8_t *, int, int); |
| 70 |
|
|
|
| 71 |
2/2
✓ Branch 83 → 3 taken 84 times.
✓ Branch 83 → 84 taken 14 times.
|
98 |
for (n = 0; n < MAX_CTXT; ++n) { |
| 72 |
2/2
✓ Branch 4 → 5 taken 12 times.
✓ Branch 4 → 82 taken 72 times.
|
84 |
if (check_func(c->ac3_exponent_min, "ac3_exponent_min_reuse%d", n)) { |
| 73 |
2/2
✓ Branch 8 → 6 taken 18432 times.
✓ Branch 8 → 9 taken 12 times.
|
18444 |
randomize_exp(src, EXP_SIZE); |
| 74 |
|
|
|
| 75 |
|
12 |
memcpy(v1, src, EXP_SIZE); |
| 76 |
|
12 |
memcpy(v2, src, EXP_SIZE); |
| 77 |
|
|
|
| 78 |
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 12 times.
|
12 |
call_ref(v1, n, MAX_COEFS); |
| 79 |
|
12 |
call_new(v2, n, MAX_COEFS); |
| 80 |
|
|
|
| 81 |
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 12 times.
|
12 |
if (memcmp(v1, v2, EXP_SIZE) != 0) |
| 82 |
|
✗ |
fail(); |
| 83 |
|
|
|
| 84 |
1/18
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 79 taken 12 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 66 not taken.
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 63 not taken.
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 62 not taken.
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 63 not taken.
✗ Branch 64 → 25 not taken.
✗ Branch 64 → 65 not taken.
✗ Branch 70 → 68 not taken.
✗ Branch 70 → 71 not taken.
✗ Branch 72 → 73 not taken.
✗ Branch 72 → 74 not taken.
✗ Branch 76 → 22 not taken.
✗ Branch 76 → 77 not taken.
|
12 |
bench_new(v2, n, MAX_COEFS); |
| 85 |
|
|
} |
| 86 |
|
|
} |
| 87 |
|
|
|
| 88 |
|
14 |
report("ac3_exponent_min"); |
| 89 |
|
14 |
} |
| 90 |
|
|
|
| 91 |
|
14 |
static void check_ac3_extract_exponents(AC3DSPContext *c) { |
| 92 |
|
|
#define MAX_EXPS 3072 |
| 93 |
|
14 |
LOCAL_ALIGNED_16(int32_t, src, [MAX_EXPS]); |
| 94 |
|
14 |
LOCAL_ALIGNED_16(uint8_t, v1, [MAX_EXPS]); |
| 95 |
|
14 |
LOCAL_ALIGNED_16(uint8_t, v2, [MAX_EXPS]); |
| 96 |
|
|
int n; |
| 97 |
|
|
|
| 98 |
|
14 |
declare_func(void, uint8_t *, const int32_t *, int); |
| 99 |
|
|
|
| 100 |
2/2
✓ Branch 86 → 3 taken 154 times.
✓ Branch 86 → 87 taken 14 times.
|
168 |
for (n = 512; n <= MAX_EXPS; n += 256) { |
| 101 |
2/2
✓ Branch 4 → 5 taken 33 times.
✓ Branch 4 → 85 taken 121 times.
|
154 |
if (check_func(c->extract_exponents, "ac3_extract_exponents_n%d", n)) { |
| 102 |
4/4
✓ Branch 7 → 8 taken 30141 times.
✓ Branch 7 → 9 taken 28995 times.
✓ Branch 11 → 6 taken 59136 times.
✓ Branch 11 → 12 taken 33 times.
|
59169 |
randomize_i24(src, n); |
| 103 |
|
|
|
| 104 |
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 33 times.
|
33 |
call_ref(v1, src, n); |
| 105 |
|
33 |
call_new(v2, src, n); |
| 106 |
|
|
|
| 107 |
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 33 times.
|
33 |
if (memcmp(v1, v2, n) != 0) |
| 108 |
|
✗ |
fail(); |
| 109 |
|
|
|
| 110 |
1/18
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 82 taken 33 times.
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 69 not taken.
✗ Branch 62 → 63 not taken.
✗ Branch 62 → 66 not taken.
✗ Branch 63 → 64 not taken.
✗ Branch 63 → 65 not taken.
✗ Branch 64 → 65 not taken.
✗ Branch 64 → 66 not taken.
✗ Branch 67 → 28 not taken.
✗ Branch 67 → 68 not taken.
✗ Branch 73 → 71 not taken.
✗ Branch 73 → 74 not taken.
✗ Branch 75 → 76 not taken.
✗ Branch 75 → 77 not taken.
✗ Branch 79 → 25 not taken.
✗ Branch 79 → 80 not taken.
|
33 |
bench_new(v1, src, n); |
| 111 |
|
|
} |
| 112 |
|
|
} |
| 113 |
|
|
|
| 114 |
|
14 |
report("ac3_extract_exponents"); |
| 115 |
|
14 |
} |
| 116 |
|
|
|
| 117 |
|
14 |
static void check_float_to_fixed24(AC3DSPContext *c) { |
| 118 |
|
|
#define BUF_SIZE 1024 |
| 119 |
|
14 |
LOCAL_ALIGNED_32(float, src, [BUF_SIZE]); |
| 120 |
|
|
|
| 121 |
|
14 |
declare_func(void, int32_t *, const float *, size_t); |
| 122 |
|
|
|
| 123 |
2/2
✓ Branch 5 → 3 taken 14336 times.
✓ Branch 5 → 6 taken 14 times.
|
14350 |
randomize_float(src, BUF_SIZE); |
| 124 |
|
|
|
| 125 |
2/2
✓ Branch 7 → 8 taken 3 times.
✓ Branch 7 → 82 taken 11 times.
|
14 |
if (check_func(c->float_to_fixed24, "float_to_fixed24")) { |
| 126 |
|
3 |
LOCAL_ALIGNED_32(int32_t, dst, [BUF_SIZE]); |
| 127 |
|
3 |
LOCAL_ALIGNED_32(int32_t, dst2, [BUF_SIZE]); |
| 128 |
|
|
|
| 129 |
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 3 times.
|
3 |
call_ref(dst, src, BUF_SIZE); |
| 130 |
|
3 |
call_new(dst2, src, BUF_SIZE); |
| 131 |
|
|
|
| 132 |
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 3 times.
|
3 |
if (memcmp(dst, dst2, BUF_SIZE * sizeof(*dst)) != 0) |
| 133 |
|
✗ |
fail(); |
| 134 |
|
|
|
| 135 |
1/18
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 78 taken 3 times.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 65 not taken.
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 62 not taken.
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 61 not taken.
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 62 not taken.
✗ Branch 63 → 24 not taken.
✗ Branch 63 → 64 not taken.
✗ Branch 69 → 67 not taken.
✗ Branch 69 → 70 not taken.
✗ Branch 71 → 72 not taken.
✗ Branch 71 → 73 not taken.
✗ Branch 75 → 21 not taken.
✗ Branch 75 → 76 not taken.
|
3 |
bench_new(dst, src, BUF_SIZE); |
| 136 |
|
|
} |
| 137 |
|
|
|
| 138 |
|
|
|
| 139 |
|
14 |
report("float_to_fixed24"); |
| 140 |
|
14 |
} |
| 141 |
|
|
|
| 142 |
|
14 |
static void check_compute_mantissa_size(AC3DSPContext *const c) |
| 143 |
|
|
{ |
| 144 |
|
14 |
declare_func(int, const uint16_t mant_cnt[6][16]); |
| 145 |
|
|
|
| 146 |
2/2
✓ Branch 3 → 4 taken 12 times.
✓ Branch 3 → 5 taken 2 times.
|
14 |
if (!check_func(c->compute_mantissa_size, "compute_mantissa_size")) |
| 147 |
|
12 |
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 |
|
2 |
checkasm_randomize_mask16((uint16_t*)mant_cnt, AC3_MAX_BLOCKS*16, 0xFF); |
| 153 |
|
|
|
| 154 |
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 2 times.
|
2 |
int size_ref = call_ref(mant_cnt); |
| 155 |
|
2 |
int size_new = call_new(mant_cnt); |
| 156 |
|
|
|
| 157 |
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 2 times.
|
2 |
if (size_ref != size_new) |
| 158 |
|
✗ |
fail(); |
| 159 |
|
|
|
| 160 |
1/18
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 76 taken 2 times.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 63 not taken.
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 60 not taken.
✗ Branch 57 → 58 not taken.
✗ Branch 57 → 59 not taken.
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 60 not taken.
✗ Branch 61 → 22 not taken.
✗ Branch 61 → 62 not taken.
✗ Branch 67 → 65 not taken.
✗ Branch 67 → 68 not taken.
✗ Branch 69 → 70 not taken.
✗ Branch 69 → 71 not taken.
✗ Branch 73 → 19 not taken.
✗ Branch 73 → 74 not taken.
|
2 |
bench_new(mant_cnt); |
| 161 |
|
|
|
| 162 |
|
2 |
report("compute_mantissa_size"); |
| 163 |
|
|
} |
| 164 |
|
|
|
| 165 |
|
14 |
static void check_ac3_sum_square_butterfly_int32(AC3DSPContext *c) { |
| 166 |
|
|
#define ELEMS 240 |
| 167 |
|
14 |
LOCAL_ALIGNED_16(int32_t, lt, [ELEMS]); |
| 168 |
|
14 |
LOCAL_ALIGNED_16(int32_t, rt, [ELEMS]); |
| 169 |
|
14 |
LOCAL_ALIGNED_16(uint64_t, v1, [4]); |
| 170 |
|
14 |
LOCAL_ALIGNED_16(uint64_t, v2, [4]); |
| 171 |
|
|
|
| 172 |
|
14 |
declare_func(void, int64_t[4], const int32_t *, const int32_t *, int); |
| 173 |
|
|
|
| 174 |
4/4
✓ Branch 4 → 5 taken 1774 times.
✓ Branch 4 → 6 taken 1586 times.
✓ Branch 8 → 3 taken 3360 times.
✓ Branch 8 → 9 taken 14 times.
|
3374 |
randomize_i24(lt, ELEMS); |
| 175 |
4/4
✓ Branch 11 → 12 taken 1837 times.
✓ Branch 11 → 13 taken 1523 times.
✓ Branch 15 → 10 taken 3360 times.
✓ Branch 15 → 16 taken 14 times.
|
3374 |
randomize_i24(rt, ELEMS); |
| 176 |
|
|
|
| 177 |
2/2
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 91 taken 13 times.
|
14 |
if (check_func(c->sum_square_butterfly_int32, |
| 178 |
|
|
"ac3_sum_square_butterfly_int32")) { |
| 179 |
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 1 time.
|
1 |
call_ref(v1, lt, rt, ELEMS); |
| 180 |
|
1 |
call_new(v2, lt, rt, ELEMS); |
| 181 |
|
|
|
| 182 |
1/2
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 1 time.
|
1 |
if (memcmp(v1, v2, sizeof(int64_t[4])) != 0) |
| 183 |
|
✗ |
fail(); |
| 184 |
|
|
|
| 185 |
1/18
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 88 taken 1 time.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 75 not taken.
✗ Branch 68 → 69 not taken.
✗ Branch 68 → 72 not taken.
✗ Branch 69 → 70 not taken.
✗ Branch 69 → 71 not taken.
✗ Branch 70 → 71 not taken.
✗ Branch 70 → 72 not taken.
✗ Branch 73 → 34 not taken.
✗ Branch 73 → 74 not taken.
✗ Branch 79 → 77 not taken.
✗ Branch 79 → 80 not taken.
✗ Branch 81 → 82 not taken.
✗ Branch 81 → 83 not taken.
✗ Branch 85 → 31 not taken.
✗ Branch 85 → 86 not taken.
|
1 |
bench_new(v2, lt, rt, ELEMS); |
| 186 |
|
|
} |
| 187 |
|
|
|
| 188 |
|
14 |
report("ac3_sum_square_butterfly_int32"); |
| 189 |
|
14 |
} |
| 190 |
|
|
|
| 191 |
|
14 |
static void check_ac3_sum_square_butterfly_float(AC3DSPContext *c) { |
| 192 |
|
14 |
LOCAL_ALIGNED_32(float, lt, [ELEMS]); |
| 193 |
|
14 |
LOCAL_ALIGNED_32(float, rt, [ELEMS]); |
| 194 |
|
14 |
LOCAL_ALIGNED_16(float, v1, [4]); |
| 195 |
|
14 |
LOCAL_ALIGNED_16(float, v2, [4]); |
| 196 |
|
|
|
| 197 |
|
14 |
declare_func(void, float[4], const float *, const float *, int); |
| 198 |
|
|
|
| 199 |
2/2
✓ Branch 5 → 3 taken 3360 times.
✓ Branch 5 → 6 taken 14 times.
|
3374 |
randomize_float(lt, ELEMS); |
| 200 |
2/2
✓ Branch 9 → 7 taken 3360 times.
✓ Branch 9 → 10 taken 14 times.
|
3374 |
randomize_float(rt, ELEMS); |
| 201 |
|
|
|
| 202 |
2/2
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 86 taken 13 times.
|
14 |
if (check_func(c->sum_square_butterfly_float, |
| 203 |
|
|
"ac3_sum_square_butterfly_float")) { |
| 204 |
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 1 time.
|
1 |
call_ref(v1, lt, rt, ELEMS); |
| 205 |
|
1 |
call_new(v2, lt, rt, ELEMS); |
| 206 |
|
|
|
| 207 |
1/2
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 23 taken 1 time.
|
1 |
if (!float_near_ulp_array(v1, v2, 15, 4)) |
| 208 |
|
✗ |
fail(); |
| 209 |
|
|
|
| 210 |
1/18
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 83 taken 1 time.
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 70 not taken.
✗ Branch 63 → 64 not taken.
✗ Branch 63 → 67 not taken.
✗ Branch 64 → 65 not taken.
✗ Branch 64 → 66 not taken.
✗ Branch 65 → 66 not taken.
✗ Branch 65 → 67 not taken.
✗ Branch 68 → 29 not taken.
✗ Branch 68 → 69 not taken.
✗ Branch 74 → 72 not taken.
✗ Branch 74 → 75 not taken.
✗ Branch 76 → 77 not taken.
✗ Branch 76 → 78 not taken.
✗ Branch 80 → 26 not taken.
✗ Branch 80 → 81 not taken.
|
1 |
bench_new(v2, lt, rt, ELEMS); |
| 211 |
|
|
} |
| 212 |
|
|
|
| 213 |
|
14 |
report("ac3_sum_square_butterfly_float"); |
| 214 |
|
14 |
} |
| 215 |
|
|
|
| 216 |
|
14 |
void checkasm_check_ac3dsp(void) |
| 217 |
|
|
{ |
| 218 |
|
|
AC3DSPContext c; |
| 219 |
|
14 |
ff_ac3dsp_init(&c); |
| 220 |
|
|
|
| 221 |
|
14 |
check_ac3_exponent_min(&c); |
| 222 |
|
14 |
check_ac3_extract_exponents(&c); |
| 223 |
|
14 |
check_float_to_fixed24(&c); |
| 224 |
|
14 |
check_compute_mantissa_size(&c); |
| 225 |
|
14 |
check_ac3_sum_square_butterfly_int32(&c); |
| 226 |
|
14 |
check_ac3_sum_square_butterfly_float(&c); |
| 227 |
|
14 |
} |
| 228 |
|
|
|