| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (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 GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "libavutil/common.h" | ||
| 20 | #include "libavutil/intreadwrite.h" | ||
| 21 | #include "libavutil/mem_internal.h" | ||
| 22 | |||
| 23 | #include "libavcodec/mathops.h" | ||
| 24 | #include "libavcodec/mpegvideoencdsp.h" | ||
| 25 | |||
| 26 | #include "checkasm.h" | ||
| 27 | |||
| 28 | #define randomize_buffers(buf, size) \ | ||
| 29 | do { \ | ||
| 30 | for (int j = 0; j < size; j += 4) \ | ||
| 31 | AV_WN32((char*)buf + j, rnd()); \ | ||
| 32 | } while (0) | ||
| 33 | |||
| 34 | #define randomize_buffer_clipped(buf, min, max) \ | ||
| 35 | do { \ | ||
| 36 | for (size_t j = 0; j < FF_ARRAY_ELEMS(buf); ++j) \ | ||
| 37 | buf[j] = rnd() % (max - min + 1) + min; \ | ||
| 38 | } while (0) | ||
| 39 | |||
| 40 | 14 | static void check_denoise_dct(MpegvideoEncDSPContext *c) | |
| 41 | { | ||
| 42 | 14 | declare_func(void, int16_t block[64], int dct_error_sum[64], | |
| 43 | const uint16_t dct_offset[64]); | ||
| 44 | |||
| 45 |
2/2✓ Branch 3 taken 2 times.
✓ Branch 4 taken 12 times.
|
14 | if (check_func(c->denoise_dct, "denoise_dct")) { |
| 46 | DECLARE_ALIGNED(16, int16_t, block_ref)[64]; | ||
| 47 | DECLARE_ALIGNED(16, int16_t, block_new)[64]; | ||
| 48 | DECLARE_ALIGNED(16, int, dct_error_sum_ref)[64]; | ||
| 49 | DECLARE_ALIGNED(16, int, dct_error_sum_new)[64]; | ||
| 50 | DECLARE_ALIGNED(16, uint16_t, dct_offset)[64]; | ||
| 51 | |||
| 52 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 2 times.
|
130 | for (size_t i = 0; i < FF_ARRAY_ELEMS(block_ref); ++i) { |
| 53 | 128 | unsigned random = rnd(); | |
| 54 |
2/2✓ Branch 0 taken 61 times.
✓ Branch 1 taken 67 times.
|
128 | block_ref[i] = random & (1 << 16) ? random : 0; |
| 55 | } | ||
| 56 |
2/2✓ Branch 1 taken 64 times.
✓ Branch 2 taken 2 times.
|
66 | randomize_buffers(dct_offset, sizeof(dct_offset)); |
| 57 |
2/2✓ Branch 1 taken 128 times.
✓ Branch 2 taken 2 times.
|
130 | randomize_buffer_clipped(dct_error_sum_ref, 0, (1 << 24) - 1); |
| 58 | 2 | memcpy(block_new, block_ref, sizeof(block_new)); | |
| 59 | 2 | memcpy(dct_error_sum_new, dct_error_sum_ref, sizeof(dct_error_sum_ref)); | |
| 60 | |||
| 61 | 2 | call_ref(block_ref, dct_error_sum_ref, dct_offset); | |
| 62 | 2 | call_new(block_new, dct_error_sum_new, dct_offset); | |
| 63 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (memcmp(block_ref, block_new, sizeof(block_ref)) || |
| 64 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | memcmp(dct_error_sum_new, dct_error_sum_ref, sizeof(dct_error_sum_new))) |
| 65 | ✗ | fail(); | |
| 66 | |||
| 67 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
2 | bench_new(block_new, dct_error_sum_new, dct_offset); |
| 68 | } | ||
| 69 | 14 | } | |
| 70 | |||
| 71 | 14 | static void check_add_8x8basis(MpegvideoEncDSPContext *c) | |
| 72 | { | ||
| 73 | 14 | declare_func(void, int16_t rem[64], const int16_t basis[64], int scale); | |
| 74 |
2/2✓ Branch 3 taken 2 times.
✓ Branch 4 taken 12 times.
|
14 | if (check_func(c->add_8x8basis, "add_8x8basis")) { |
| 75 | // FIXME: What are the actual ranges for these values? | ||
| 76 | 2 | int scale = sign_extend(rnd(), 12); | |
| 77 | DECLARE_ALIGNED(16, int16_t, rem1)[64]; | ||
| 78 | DECLARE_ALIGNED(16, int16_t, rem2)[64]; | ||
| 79 | DECLARE_ALIGNED(16, int16_t, basis)[64]; | ||
| 80 | |||
| 81 |
2/2✓ Branch 1 taken 128 times.
✓ Branch 2 taken 2 times.
|
130 | randomize_buffer_clipped(basis, -15760, 15760); |
| 82 |
2/2✓ Branch 1 taken 64 times.
✓ Branch 2 taken 2 times.
|
66 | randomize_buffers(rem1, sizeof(rem1)); |
| 83 | 2 | memcpy(rem2, rem1, sizeof(rem2)); | |
| 84 | 2 | call_ref(rem1, basis, scale); | |
| 85 | 2 | call_new(rem2, basis, scale); | |
| 86 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (memcmp(rem1, rem2, sizeof(rem1))) |
| 87 | ✗ | fail(); | |
| 88 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
2 | bench_new(rem1, basis, scale); |
| 89 | } | ||
| 90 | 14 | } | |
| 91 | |||
| 92 | 14 | static void check_pix_sum(MpegvideoEncDSPContext *c) | |
| 93 | { | ||
| 94 | 14 | LOCAL_ALIGNED_16(uint8_t, src, [16 * 16]); | |
| 95 | |||
| 96 | 14 | declare_func(int, const uint8_t *pix, ptrdiff_t line_size); | |
| 97 | |||
| 98 |
2/2✓ Branch 1 taken 896 times.
✓ Branch 2 taken 14 times.
|
910 | randomize_buffers(src, 16 * 16); |
| 99 | |||
| 100 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14 times.
|
42 | for (int n = 0; n < 2; n++) { |
| 101 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
|
28 | const char *negstride_str = n ? "_negstride" : ""; |
| 102 |
2/2✓ Branch 3 taken 4 times.
✓ Branch 4 taken 24 times.
|
28 | if (check_func(c->pix_sum, "pix_sum%s", negstride_str)) { |
| 103 | int sum0, sum1; | ||
| 104 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | const uint8_t *pix = src + (n ? (15 * 16) : 0); |
| 105 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | ptrdiff_t line_size = 16 * (n ? -1 : 1); |
| 106 | 4 | sum0 = call_ref(pix, line_size); | |
| 107 | 4 | sum1 = call_new(pix, line_size); | |
| 108 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (sum0 != sum1) |
| 109 | ✗ | fail(); | |
| 110 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
4 | bench_new(pix, line_size); |
| 111 | } | ||
| 112 | } | ||
| 113 | 14 | } | |
| 114 | |||
| 115 | 14 | static void check_pix_norm1(MpegvideoEncDSPContext *c) | |
| 116 | { | ||
| 117 | 14 | LOCAL_ALIGNED_16(uint8_t, src, [16 * 16]); | |
| 118 | |||
| 119 | 14 | declare_func(int, const uint8_t *pix, ptrdiff_t line_size); | |
| 120 | |||
| 121 |
2/2✓ Branch 1 taken 896 times.
✓ Branch 2 taken 14 times.
|
910 | randomize_buffers(src, 16 * 16); |
| 122 | |||
| 123 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14 times.
|
42 | for (int n = 0; n < 2; n++) { |
| 124 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
|
28 | const char *negstride_str = n ? "_negstride" : ""; |
| 125 |
2/2✓ Branch 3 taken 4 times.
✓ Branch 4 taken 24 times.
|
28 | if (check_func(c->pix_norm1, "pix_norm1%s", negstride_str)) { |
| 126 | int sum0, sum1; | ||
| 127 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | const uint8_t *pix = src + (n ? (15 * 16) : 0); |
| 128 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | ptrdiff_t line_size = 16 * (n ? -1 : 1); |
| 129 | 4 | sum0 = call_ref(pix, line_size); | |
| 130 | 4 | sum1 = call_new(pix, line_size); | |
| 131 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (sum0 != sum1) |
| 132 | ✗ | fail(); | |
| 133 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
4 | bench_new(pix, line_size); |
| 134 | } | ||
| 135 | } | ||
| 136 | 14 | } | |
| 137 | |||
| 138 | #define NUM_LINES 4 | ||
| 139 | #define MAX_LINE_SIZE 1920 | ||
| 140 | #define EDGE_WIDTH 16 | ||
| 141 | #define LINESIZE (EDGE_WIDTH + MAX_LINE_SIZE + EDGE_WIDTH) | ||
| 142 | #define BUFSIZE ((EDGE_WIDTH + NUM_LINES + EDGE_WIDTH) * LINESIZE) | ||
| 143 | |||
| 144 | 14 | static void check_draw_edges(MpegvideoEncDSPContext *c) | |
| 145 | { | ||
| 146 | static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE, -MAX_LINE_SIZE}; | ||
| 147 | 14 | LOCAL_ALIGNED_16(uint8_t, buf0, [BUFSIZE]); | |
| 148 | 14 | LOCAL_ALIGNED_16(uint8_t, buf1, [BUFSIZE]); | |
| 149 | |||
| 150 | 14 | declare_func(void, uint8_t *buf, ptrdiff_t wrap, int width, int height, | |
| 151 | int w, int h, int sides); | ||
| 152 | |||
| 153 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 14 times.
|
84 | for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) { |
| 154 | 70 | int input_size = input_sizes[isi]; | |
| 155 | 70 | int negstride = input_size < 0; | |
| 156 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 56 times.
|
70 | const char *negstride_str = negstride ? "_negstride" : ""; |
| 157 | 70 | int width = FFABS(input_size); | |
| 158 | 70 | ptrdiff_t linesize = EDGE_WIDTH + width + EDGE_WIDTH; | |
| 159 | /* calculate height based on specified width to use the entire buffer. */ | ||
| 160 | 70 | int height = (BUFSIZE / linesize) - (2 * EDGE_WIDTH); | |
| 161 | 70 | uint8_t *dst0 = buf0 + EDGE_WIDTH * linesize + EDGE_WIDTH; | |
| 162 | 70 | uint8_t *dst1 = buf1 + EDGE_WIDTH * linesize + EDGE_WIDTH; | |
| 163 | |||
| 164 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 56 times.
|
70 | if (negstride) { |
| 165 | 14 | dst0 += (height - 1) * linesize; | |
| 166 | 14 | dst1 += (height - 1) * linesize; | |
| 167 | 14 | linesize *= -1; | |
| 168 | } | ||
| 169 | |||
| 170 |
2/2✓ Branch 0 taken 210 times.
✓ Branch 1 taken 70 times.
|
280 | for (int shift = 0; shift < 3; shift++) { |
| 171 | 210 | int edge = EDGE_WIDTH >> shift; | |
| 172 |
2/2✓ Branch 3 taken 30 times.
✓ Branch 4 taken 180 times.
|
210 | if (check_func(c->draw_edges, "draw_edges_%d_%d_%d%s", width, height, edge, negstride_str)) { |
| 173 |
2/2✓ Branch 1 taken 527040 times.
✓ Branch 2 taken 30 times.
|
527070 | randomize_buffers(buf0, BUFSIZE); |
| 174 | 30 | memcpy(buf1, buf0, BUFSIZE); | |
| 175 | 30 | call_ref(dst0, linesize, width, height, edge, edge, EDGE_BOTTOM | EDGE_TOP); | |
| 176 | 30 | call_new(dst1, linesize, width, height, edge, edge, EDGE_BOTTOM | EDGE_TOP); | |
| 177 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (memcmp(buf0, buf1, BUFSIZE)) |
| 178 | ✗ | fail(); | |
| 179 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
30 | bench_new(dst1, linesize, width, height, edge, edge, EDGE_BOTTOM | EDGE_TOP); |
| 180 | } | ||
| 181 | } | ||
| 182 | } | ||
| 183 | 14 | } | |
| 184 | |||
| 185 | #undef NUM_LINES | ||
| 186 | #undef MAX_LINE_SIZE | ||
| 187 | #undef EDGE_WIDTH | ||
| 188 | #undef LINESIZE | ||
| 189 | #undef BUFSIZE | ||
| 190 | |||
| 191 | 14 | void checkasm_check_mpegvideoencdsp(void) | |
| 192 | { | ||
| 193 | 14 | AVCodecContext avctx = { | |
| 194 | .bits_per_raw_sample = 8, | ||
| 195 | }; | ||
| 196 | 14 | MpegvideoEncDSPContext c = { 0 }; | |
| 197 | |||
| 198 | 14 | ff_mpegvideoencdsp_init(&c, &avctx); | |
| 199 | |||
| 200 | 14 | check_denoise_dct(&c); | |
| 201 | 14 | report("denoise_dct"); | |
| 202 | 14 | check_pix_sum(&c); | |
| 203 | 14 | report("pix_sum"); | |
| 204 | 14 | check_pix_norm1(&c); | |
| 205 | 14 | report("pix_norm1"); | |
| 206 | 14 | check_draw_edges(&c); | |
| 207 | 14 | report("draw_edges"); | |
| 208 | 14 | check_add_8x8basis(&c); | |
| 209 | 14 | report("add_8x8basis"); | |
| 210 | 14 | } | |
| 211 |