| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2016 Alexandra Hájková | ||
| 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 | |||
| 23 | #include "libavutil/intreadwrite.h" | ||
| 24 | #include "libavutil/mem.h" | ||
| 25 | #include "libavutil/mem_internal.h" | ||
| 26 | |||
| 27 | #include "libavcodec/huffyuvdsp.h" | ||
| 28 | |||
| 29 | #include "checkasm.h" | ||
| 30 | |||
| 31 | enum { | ||
| 32 | MAX_WIDTH = 16*128, ///< arbitrary limit used for the tests | ||
| 33 | }; | ||
| 34 | |||
| 35 | #define randomize_buffers(buf, size) \ | ||
| 36 | do { \ | ||
| 37 | int j; \ | ||
| 38 | for (j = 0; j < size; j++) \ | ||
| 39 | buf[j] = rnd() & 0xFFFF; \ | ||
| 40 | } while (0) | ||
| 41 | |||
| 42 | #define randomize_buffer_mask(buf, width, mask) \ | ||
| 43 | do { \ | ||
| 44 | unsigned mask2 = mask | (mask << 16); \ | ||
| 45 | for (size_t i = 0; i < (width & ~1); i += 2) \ | ||
| 46 | AV_WN32A((buf) + i, rnd() & mask2); \ | ||
| 47 | if (width & 1) \ | ||
| 48 | buf[width - 1] = rnd() & mask; \ | ||
| 49 | } while (0) | ||
| 50 | |||
| 51 | 28 | static void check_add_int16(HuffYUVDSPContext *c, unsigned mask, int width, const char * name) | |
| 52 | { | ||
| 53 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 2 taken 6 times.
|
28 | if (!check_func(c->add_int16, "%s", name)) |
| 54 | 22 | return; | |
| 55 | |||
| 56 | 6 | uint16_t *src0 = av_mallocz(width * sizeof(uint16_t)); | |
| 57 | 6 | uint16_t *src1 = av_mallocz(width * sizeof(uint16_t)); | |
| 58 | 6 | uint16_t *dst0 = av_mallocz(width * sizeof(uint16_t)); | |
| 59 | 6 | uint16_t *dst1 = av_mallocz(width * sizeof(uint16_t)); | |
| 60 | |||
| 61 | 6 | declare_func(void, uint16_t *dst, const uint16_t *src, unsigned mask, int w); | |
| 62 | |||
| 63 |
4/8✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6 times.
|
6 | if (!src0 || !src1 || !dst0 || !dst1) |
| 64 | ✗ | fail(); | |
| 65 | |||
| 66 |
2/2✓ Branch 1 taken 6276 times.
✓ Branch 2 taken 6 times.
|
6282 | randomize_buffers(src0, width); |
| 67 | 6 | memcpy(src1, src0, width * sizeof(uint16_t)); | |
| 68 | |||
| 69 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
6 | call_ref(dst0, src0, mask, width); |
| 70 | 6 | call_new(dst1, src1, mask, width); | |
| 71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (memcmp(dst0, dst1, width * sizeof(uint16_t))) |
| 72 | ✗ | fail(); | |
| 73 |
1/18✗ Branch 1 not taken.
✓ Branch 2 taken 6 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.
|
6 | bench_new(dst1, src1, mask, width); |
| 74 | |||
| 75 | 6 | av_free(src0); | |
| 76 | 6 | av_free(src1); | |
| 77 | 6 | av_free(dst0); | |
| 78 | 6 | av_free(dst1); | |
| 79 | } | ||
| 80 | |||
| 81 | 14 | static void check_add_hfyu_median_pred_int16(const HuffYUVDSPContext *c, unsigned mask, int width) | |
| 82 | { | ||
| 83 | 14 | declare_func(void, uint16_t *dst, const uint16_t *top, | |
| 84 | const uint16_t *diff, unsigned mask, | ||
| 85 | int w, int *left, int *left_top); | ||
| 86 | |||
| 87 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 2 taken 2 times.
|
14 | if (!check_func(c->add_hfyu_median_pred_int16, "add_hfyu_median_pred_int16")) |
| 88 | 12 | return; | |
| 89 | |||
| 90 | DECLARE_ALIGNED(16, uint16_t, top)[MAX_WIDTH]; | ||
| 91 | DECLARE_ALIGNED(16, uint16_t, diff)[MAX_WIDTH]; | ||
| 92 | DECLARE_ALIGNED(16, uint16_t, dst_new)[MAX_WIDTH]; | ||
| 93 | DECLARE_ALIGNED(16, uint16_t, dst_ref)[MAX_WIDTH]; | ||
| 94 | 2 | int left_new = rnd() & mask, left_ref = left_new; | |
| 95 | 2 | int lt_new = rnd() & mask, lt_ref = lt_new; | |
| 96 | |||
| 97 |
2/2✓ Branch 1 taken 2048 times.
✓ Branch 2 taken 2 times.
|
2050 | randomize_buffer_mask(top, MAX_WIDTH, mask); |
| 98 |
2/2✓ Branch 1 taken 2048 times.
✓ Branch 2 taken 2 times.
|
2050 | randomize_buffer_mask(diff, MAX_WIDTH, mask); |
| 99 | |||
| 100 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | call_ref(dst_ref, top, diff, mask, width, &left_ref, <_ref); |
| 101 | 2 | call_new(dst_new, top, diff, mask, width, &left_new, <_new); | |
| 102 | |||
| 103 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | if (left_ref != left_new || lt_ref != lt_new || |
| 104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | memcmp(dst_ref, dst_new, width * sizeof(dst_ref[0]))) |
| 105 | ✗ | fail(); | |
| 106 | |||
| 107 |
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_new, top, diff, mask, width, &left_new, <_new); |
| 108 | } | ||
| 109 | |||
| 110 | 14 | static void check_add_hfyu_left_pred_bgr32(HuffYUVDSPContext *c) | |
| 111 | { | ||
| 112 | #define BUF_SIZE 1080 | ||
| 113 | uint8_t src[4 * BUF_SIZE], dst0[4 * BUF_SIZE], dst1[4 * BUF_SIZE]; | ||
| 114 | uint8_t left[4], left0[4], left1[4]; | ||
| 115 | |||
| 116 | 14 | declare_func(void, uint8_t *d, const uint8_t *s, intptr_t w, uint8_t *l); | |
| 117 | |||
| 118 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 2 taken 2 times.
|
14 | if (!check_func(c->add_hfyu_left_pred_bgr32, "add_hfyu_left_pred_bgr32")) |
| 119 | 12 | return; | |
| 120 | |||
| 121 |
2/2✓ Branch 1 taken 8640 times.
✓ Branch 2 taken 2 times.
|
8642 | randomize_buffers(src, sizeof (src)); |
| 122 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
|
10 | randomize_buffers(left, sizeof (left)); |
| 123 | 2 | memcpy(left0, left, sizeof (left)); | |
| 124 | 2 | memcpy(left1, left, sizeof (left)); | |
| 125 | |||
| 126 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | call_ref(dst0, src, BUF_SIZE, left0); |
| 127 | 2 | call_new(dst1, src, BUF_SIZE, left1); | |
| 128 | |||
| 129 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (memcmp(dst0, dst1, sizeof (dst0)) != 0 || |
| 130 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | memcmp(left0, left1, sizeof (left0)) != 0) { |
| 131 | ✗ | fail(); | |
| 132 | } | ||
| 133 | |||
| 134 |
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(dst1, src, BUF_SIZE, left); |
| 135 | } | ||
| 136 | |||
| 137 | 14 | void checkasm_check_huffyuvdsp(void) | |
| 138 | { | ||
| 139 | HuffYUVDSPContext c; | ||
| 140 | |||
| 141 | 14 | ff_huffyuvdsp_init(&c); | |
| 142 | |||
| 143 | 14 | unsigned bps = 9 + rnd() % 8; | |
| 144 | 14 | unsigned mask = (1 << bps) - 1; | |
| 145 | 14 | int width = 1 + rnd() % MAX_WIDTH; | |
| 146 | |||
| 147 | /*! test width not multiple of mmsize */ | ||
| 148 | 14 | check_add_int16(&c, mask, width, "add_int16_rnd_width"); | |
| 149 | 14 | report("add_int16_rnd_width"); | |
| 150 | |||
| 151 | /*! test always with the same size (for perf test) */ | ||
| 152 | 14 | check_add_int16(&c, mask, MAX_WIDTH, "add_int16_128"); | |
| 153 | 14 | report("add_int16_128"); | |
| 154 | |||
| 155 | 14 | check_add_hfyu_median_pred_int16(&c, mask, width); | |
| 156 | 14 | report("add_hfyu_median_pred_int16"); | |
| 157 | |||
| 158 | 14 | check_add_hfyu_left_pred_bgr32(&c); | |
| 159 | 14 | report("add_hfyu_left_pred_bgr32"); | |
| 160 | 14 | } | |
| 161 |