| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2015 James Almer | ||
| 3 | * | ||
| 4 | * This file is part of FFmpeg. | ||
| 5 | * | ||
| 6 | * FFmpeg is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License along | ||
| 17 | * with FFmpeg; if not, write to the Free Software Foundation, Inc., | ||
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <string.h> | ||
| 22 | #include "checkasm.h" | ||
| 23 | #include "libavcodec/flacdsp.h" | ||
| 24 | #include "libavcodec/mathops.h" | ||
| 25 | #include "libavutil/common.h" | ||
| 26 | #include "libavutil/internal.h" | ||
| 27 | #include "libavutil/intreadwrite.h" | ||
| 28 | #include "libavutil/mem_internal.h" | ||
| 29 | |||
| 30 | #define BUF_SIZE 256 | ||
| 31 | #define MAX_CHANNELS 8 | ||
| 32 | |||
| 33 | #define randomize_buffers() \ | ||
| 34 | do { \ | ||
| 35 | int i, j; \ | ||
| 36 | for (i = 0; i < BUF_SIZE; i += 4) { \ | ||
| 37 | for (j = 0; j < channels; j++) { \ | ||
| 38 | uint32_t r = rnd() & (1 << (bits - 2)) - 1; \ | ||
| 39 | AV_WN32A(ref_src[j] + i, r); \ | ||
| 40 | AV_WN32A(new_src[j] + i, r); \ | ||
| 41 | } \ | ||
| 42 | } \ | ||
| 43 | } while (0) | ||
| 44 | |||
| 45 | 32 | static void check_decorrelate(uint8_t **ref_dst, uint8_t **ref_src, uint8_t **new_dst, uint8_t **new_src, | |
| 46 | int channels, int bits) { | ||
| 47 | 32 | declare_func(void, uint8_t **out, int32_t **in, int channels, int len, int shift); | |
| 48 | |||
| 49 |
4/4✓ Branch 1 taken 8320 times.
✓ Branch 2 taken 2048 times.
✓ Branch 3 taken 2048 times.
✓ Branch 4 taken 32 times.
|
10400 | randomize_buffers(); |
| 50 | 32 | call_ref(ref_dst, (int32_t **)ref_src, channels, BUF_SIZE / sizeof(int32_t), 8); | |
| 51 | 32 | call_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8); | |
| 52 |
3/4✓ Branch 0 taken 15 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
|
32 | if (memcmp(*ref_dst, *new_dst, bits == 16 ? BUF_SIZE * (channels/2) : BUF_SIZE * channels) || |
| 53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | memcmp(*ref_src, *new_src, BUF_SIZE * channels)) |
| 54 | ✗ | fail(); | |
| 55 |
1/18✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
|
32 | bench_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8); |
| 56 | 32 | } | |
| 57 | |||
| 58 | 16 | static void check_lpc(int pred_order, int bps) | |
| 59 | { | ||
| 60 | 16 | int qlevel = rnd() % 16; | |
| 61 | 16 | int coeff_prec = (rnd() % 15) + 1; | |
| 62 | 16 | LOCAL_ALIGNED_16(int32_t, coeffs, [32]); | |
| 63 | 16 | LOCAL_ALIGNED_16(int32_t, dst, [BUF_SIZE]); | |
| 64 | 16 | LOCAL_ALIGNED_16(int32_t, dst0, [BUF_SIZE]); | |
| 65 | 16 | LOCAL_ALIGNED_16(int32_t, dst1, [BUF_SIZE]); | |
| 66 | |||
| 67 | 16 | declare_func(void, int32_t *, const int[32], int, int, int); | |
| 68 | |||
| 69 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
16 | if (bps <= 16) |
| 70 | 8 | coeff_prec = av_clip(coeff_prec, 0, 32 - bps - av_log2(pred_order)); | |
| 71 | |||
| 72 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 16 times.
|
528 | for (int i = 0; i < 32; i++) |
| 73 | 512 | coeffs[i] = sign_extend(rnd(), coeff_prec); | |
| 74 |
2/2✓ Branch 0 taken 4096 times.
✓ Branch 1 taken 16 times.
|
4112 | for (int i = 0; i < BUF_SIZE; i++) |
| 75 | 4096 | dst[i] = sign_extend(rnd(), bps); | |
| 76 | |||
| 77 | 16 | const int test_lens[] = { | |
| 78 | 0, | ||
| 79 | 16 | pred_order - 1, | |
| 80 | pred_order, | ||
| 81 | 16 | pred_order + 1, | |
| 82 | BUF_SIZE, | ||
| 83 | }; | ||
| 84 | |||
| 85 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 16 times.
|
96 | for (int k = 0; k < FF_ARRAY_ELEMS(test_lens); k++) { |
| 86 | 80 | int len = test_lens[k]; | |
| 87 |
2/4✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 80 times.
|
80 | if (len < 0 || len > BUF_SIZE) continue; |
| 88 | |||
| 89 | 80 | memcpy(dst0, dst, BUF_SIZE * sizeof (int32_t)); | |
| 90 | 80 | memcpy(dst1, dst, BUF_SIZE * sizeof (int32_t)); | |
| 91 | 80 | call_ref(dst0, coeffs, pred_order, qlevel, len); | |
| 92 | 80 | call_new(dst1, coeffs, pred_order, qlevel, len); | |
| 93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 80 times.
|
80 | if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int32_t)) != 0) |
| 94 | ✗ | fail(); | |
| 95 | } | ||
| 96 |
1/18✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
|
16 | bench_new(dst, coeffs, pred_order, qlevel, BUF_SIZE); |
| 97 | 16 | } | |
| 98 | |||
| 99 | 4 | static void check_lpc33(int pred_order) | |
| 100 | { | ||
| 101 | 4 | int qlevel = rnd() % 16; | |
| 102 | 4 | int coeff_prec = (rnd() % 15) + 1; | |
| 103 | 4 | LOCAL_ALIGNED_16(int64_t, dst, [BUF_SIZE]); | |
| 104 | 4 | LOCAL_ALIGNED_16(int64_t, dst0, [BUF_SIZE]); | |
| 105 | 4 | LOCAL_ALIGNED_16(int64_t, dst1, [BUF_SIZE]); | |
| 106 | 4 | LOCAL_ALIGNED_16(int32_t, residuals, [BUF_SIZE]); | |
| 107 | 4 | LOCAL_ALIGNED_16(int32_t, coeffs, [32]); | |
| 108 | |||
| 109 | 4 | declare_func(void, int64_t *, const int32_t *, const int[32], int, int, int); | |
| 110 | |||
| 111 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 4 times.
|
132 | for (int i = 0; i < 32; i++) |
| 112 | 128 | coeffs[i] = sign_extend(rnd(), coeff_prec); | |
| 113 | |||
| 114 |
2/2✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 4 times.
|
1028 | for (int i = 0; i < BUF_SIZE; i++) { |
| 115 | 1024 | residuals[i] = sign_extend(rnd(), pred_order); | |
| 116 | 1024 | dst[i] = sign_extend64(((int64_t)rnd() << 1) | (rnd() & 1), 33); | |
| 117 | } | ||
| 118 | |||
| 119 | 4 | const int test_lens[] = { | |
| 120 | 0, | ||
| 121 | 4 | pred_order - 1, | |
| 122 | pred_order, | ||
| 123 | 4 | pred_order + 1, | |
| 124 | BUF_SIZE, | ||
| 125 | }; | ||
| 126 | |||
| 127 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 4 times.
|
24 | for (int k = 0; k < FF_ARRAY_ELEMS(test_lens); k++) { |
| 128 | 20 | int len = test_lens[k]; | |
| 129 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
|
20 | if (len < 0 || len > BUF_SIZE) continue; |
| 130 | |||
| 131 | 20 | memcpy(dst0, dst, BUF_SIZE * sizeof (int64_t)); | |
| 132 | 20 | memcpy(dst1, dst, BUF_SIZE * sizeof (int64_t)); | |
| 133 | 20 | call_ref(dst0, residuals, coeffs, pred_order, qlevel, len); | |
| 134 | 20 | call_new(dst1, residuals, coeffs, pred_order, qlevel, len); | |
| 135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int64_t)) != 0) |
| 136 | ✗ | fail(); | |
| 137 | } | ||
| 138 |
1/18✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
|
4 | bench_new(dst, residuals, coeffs, pred_order, qlevel, BUF_SIZE); |
| 139 | 4 | } | |
| 140 | |||
| 141 | 2 | static void check_wasted32(void) | |
| 142 | { | ||
| 143 | 2 | int wasted = rnd() % 32; | |
| 144 | 2 | LOCAL_ALIGNED_16(int32_t, dst, [BUF_SIZE]); | |
| 145 | 2 | LOCAL_ALIGNED_16(int32_t, dst0, [BUF_SIZE]); | |
| 146 | 2 | LOCAL_ALIGNED_16(int32_t, dst1, [BUF_SIZE]); | |
| 147 | |||
| 148 | 2 | declare_func(void, int32_t *, int, int); | |
| 149 | |||
| 150 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 2 times.
|
514 | for (int i = 0; i < BUF_SIZE; i++) |
| 151 | 512 | dst[i] = rnd(); | |
| 152 | |||
| 153 | 2 | memcpy(dst0, dst, BUF_SIZE * sizeof (int32_t)); | |
| 154 | 2 | memcpy(dst1, dst, BUF_SIZE * sizeof (int32_t)); | |
| 155 | 2 | call_ref(dst0, wasted, BUF_SIZE); | |
| 156 | 2 | call_new(dst1, wasted, BUF_SIZE); | |
| 157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int32_t)) != 0) |
| 158 | ✗ | fail(); | |
| 159 |
1/18✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
|
2 | bench_new(dst, wasted, BUF_SIZE); |
| 160 | 2 | } | |
| 161 | |||
| 162 | 2 | static void check_wasted33(void) | |
| 163 | { | ||
| 164 | 2 | int wasted = rnd() % 33; | |
| 165 | 2 | LOCAL_ALIGNED_16(int64_t, dst0, [BUF_SIZE]); | |
| 166 | 2 | LOCAL_ALIGNED_16(int64_t, dst1, [BUF_SIZE]); | |
| 167 | 2 | LOCAL_ALIGNED_16(int32_t, residuals, [BUF_SIZE]); | |
| 168 | |||
| 169 | 2 | declare_func(void, int64_t *, const int32_t *, int, int); | |
| 170 | |||
| 171 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 2 times.
|
514 | for (int i = 0; i < BUF_SIZE; i++) |
| 172 | 512 | residuals[i] = rnd(); | |
| 173 | |||
| 174 | 2 | call_ref(dst0, residuals, wasted, BUF_SIZE); | |
| 175 | 2 | call_new(dst1, residuals, wasted, BUF_SIZE); | |
| 176 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int64_t)) != 0) |
| 177 | ✗ | fail(); | |
| 178 |
1/18✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
|
2 | bench_new(dst0, residuals, wasted, BUF_SIZE); |
| 179 | 2 | } | |
| 180 | |||
| 181 | 14 | void checkasm_check_flacdsp(void) | |
| 182 | { | ||
| 183 | 14 | LOCAL_ALIGNED_16(uint8_t, ref_dst, [BUF_SIZE*MAX_CHANNELS]); | |
| 184 | 14 | LOCAL_ALIGNED_16(uint8_t, ref_buf, [BUF_SIZE*MAX_CHANNELS]); | |
| 185 | 14 | LOCAL_ALIGNED_16(uint8_t, new_dst, [BUF_SIZE*MAX_CHANNELS]); | |
| 186 | 14 | LOCAL_ALIGNED_16(uint8_t, new_buf, [BUF_SIZE*MAX_CHANNELS]); | |
| 187 | 14 | uint8_t *ref_src[] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1], &ref_buf[BUF_SIZE*2], &ref_buf[BUF_SIZE*3], | |
| 188 | 14 | &ref_buf[BUF_SIZE*4], &ref_buf[BUF_SIZE*5], &ref_buf[BUF_SIZE*6], &ref_buf[BUF_SIZE*7] }; | |
| 189 | 14 | uint8_t *new_src[] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1], &new_buf[BUF_SIZE*2], &new_buf[BUF_SIZE*3], | |
| 190 | 14 | &new_buf[BUF_SIZE*4], &new_buf[BUF_SIZE*5], &new_buf[BUF_SIZE*6], &new_buf[BUF_SIZE*7] }; | |
| 191 | static const char * const names[3] = { "ls", "rs", "ms" }; | ||
| 192 | static const struct { | ||
| 193 | enum AVSampleFormat fmt; | ||
| 194 | int bits; | ||
| 195 | } fmts[] = { | ||
| 196 | { AV_SAMPLE_FMT_S16, 16 }, | ||
| 197 | { AV_SAMPLE_FMT_S32, 32 }, | ||
| 198 | }; | ||
| 199 | static const signed char pred_orders[] = { 13, 16, 29, 32 }; | ||
| 200 | FLACDSPContext h; | ||
| 201 | int i, j; | ||
| 202 | |||
| 203 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14 times.
|
42 | for (i = 0; i < 2; i++) { |
| 204 | 28 | ff_flacdsp_init(&h, fmts[i].fmt, 2); | |
| 205 |
2/2✓ Branch 0 taken 84 times.
✓ Branch 1 taken 28 times.
|
112 | for (j = 0; j < 3; j++) |
| 206 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 2 taken 72 times.
|
84 | if (check_func(h.decorrelate[j + 1], "flac_decorrelate_%s_%d", names[j], fmts[i].bits)) |
| 207 | 12 | check_decorrelate(&ref_dst, ref_src, &new_dst, new_src, 2, fmts[i].bits); | |
| 208 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 28 times.
|
140 | for (j = 2; j <= MAX_CHANNELS; j += 2) { |
| 209 | 112 | ff_flacdsp_init(&h, fmts[i].fmt, j); | |
| 210 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 2 taken 92 times.
|
112 | if (check_func(h.decorrelate[0], "flac_decorrelate_indep%d_%d", j, fmts[i].bits)) |
| 211 | 20 | check_decorrelate(&ref_dst, ref_src, &new_dst, new_src, j, fmts[i].bits); | |
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | 14 | report("decorrelate"); | |
| 216 | |||
| 217 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 14 times.
|
70 | for (i = 0; i < FF_ARRAY_ELEMS(pred_orders); i++) |
| 218 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 48 times.
|
56 | if (check_func(h.lpc16, "flac_lpc_16_%d", pred_orders[i])) |
| 219 | 8 | check_lpc(pred_orders[i], 16); | |
| 220 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 14 times.
|
70 | for (i = 0; i < FF_ARRAY_ELEMS(pred_orders); i++) |
| 221 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 48 times.
|
56 | if (check_func(h.lpc32, "flac_lpc_32_%d", pred_orders[i])) |
| 222 | 8 | check_lpc(pred_orders[i], 32); | |
| 223 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 14 times.
|
70 | for (i = 0; i < FF_ARRAY_ELEMS(pred_orders); i++) |
| 224 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 52 times.
|
56 | if (check_func(h.lpc33, "flac_lpc_33_%d", pred_orders[i])) |
| 225 | 4 | check_lpc33(pred_orders[i]); | |
| 226 | |||
| 227 | 14 | report("lpc"); | |
| 228 | |||
| 229 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 12 times.
|
14 | if (check_func(h.wasted32, "flac_wasted_32")) |
| 230 | 2 | check_wasted32(); | |
| 231 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 12 times.
|
14 | if (check_func(h.wasted33, "flac_wasted_33")) |
| 232 | 2 | check_wasted33(); | |
| 233 | |||
| 234 | 14 | report("wasted"); | |
| 235 | 14 | } | |
| 236 |