| 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 <stddef.h> | ||
| 22 | #include <string.h> | ||
| 23 | |||
| 24 | #include "libavutil/cpu.h" | ||
| 25 | #include "libavutil/macros.h" | ||
| 26 | #include "libavutil/mem.h" | ||
| 27 | |||
| 28 | #include "libavcodec/lossless_videodsp.h" | ||
| 29 | |||
| 30 | #include "checkasm.h" | ||
| 31 | |||
| 32 | #define randomize_buffers(buf, size) \ | ||
| 33 | do { \ | ||
| 34 | int j; \ | ||
| 35 | uint8_t *tmp_buf = (uint8_t *)buf;\ | ||
| 36 | for (j = 0; j < size; j++) \ | ||
| 37 | tmp_buf[j] = rnd() & 0xFF; \ | ||
| 38 | } while (0) | ||
| 39 | |||
| 40 | #define init_buffer(a0, a1, type, width)\ | ||
| 41 | if (!a0 || !a1)\ | ||
| 42 | fail();\ | ||
| 43 | randomize_buffers(a0, width * sizeof(type));\ | ||
| 44 | memcpy(a1, a0, width*sizeof(type));\ | ||
| 45 | |||
| 46 | 3 | static void check_add_bytes(LLVidDSPContext *c, int width, size_t aligned_width) | |
| 47 | { | ||
| 48 | 3 | uint8_t *dst0 = av_mallocz(aligned_width); | |
| 49 | 3 | uint8_t *dst1 = av_mallocz(aligned_width); | |
| 50 | 3 | uint8_t *src0 = av_malloc(aligned_width); | |
| 51 | 3 | uint8_t *src1 = av_malloc(aligned_width); | |
| 52 | 3 | declare_func(void, uint8_t *dst, uint8_t *src, ptrdiff_t w); | |
| 53 | |||
| 54 |
4/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 6 taken 4227 times.
✓ Branch 7 taken 3 times.
|
4230 | init_buffer(src0, src1, uint8_t, width); |
| 55 | |||
| 56 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | if (!dst0 || !dst1) |
| 57 | ✗ | fail(); | |
| 58 | |||
| 59 | |||
| 60 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | call_ref(dst0, src0, width); |
| 61 | 3 | call_new(dst1, src1, width); | |
| 62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (memcmp(dst0, dst1, width)) |
| 63 | ✗ | fail(); | |
| 64 |
1/18✗ Branch 1 not taken.
✓ Branch 2 taken 3 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.
|
3 | bench_new(dst1, src1, width); |
| 65 | |||
| 66 | 3 | av_free(src0); | |
| 67 | 3 | av_free(src1); | |
| 68 | 3 | av_free(dst0); | |
| 69 | 3 | av_free(dst1); | |
| 70 | 3 | } | |
| 71 | |||
| 72 | 2 | static void check_add_median_pred(LLVidDSPContext *c, int width, size_t aligned_width) | |
| 73 | { | ||
| 74 | int a0, a1, b0, b1; | ||
| 75 | 2 | uint8_t *dst0 = av_mallocz(aligned_width); | |
| 76 | 2 | uint8_t *dst1 = av_mallocz(aligned_width); | |
| 77 | 2 | uint8_t *src0 = av_malloc(aligned_width); | |
| 78 | 2 | uint8_t *src1 = av_malloc(aligned_width); | |
| 79 | 2 | uint8_t *diff0 = av_malloc(aligned_width); | |
| 80 | 2 | uint8_t *diff1 = av_malloc(aligned_width); | |
| 81 | 2 | declare_func(void, uint8_t *dst, const uint8_t *src1, | |
| 82 | const uint8_t *diff, ptrdiff_t w, | ||
| 83 | int *left, int *left_top); | ||
| 84 | |||
| 85 |
4/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 2818 times.
✓ Branch 7 taken 2 times.
|
2820 | init_buffer(src0, src1, uint8_t, width); |
| 86 |
4/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 2818 times.
✓ Branch 7 taken 2 times.
|
2820 | init_buffer(diff0, diff1, uint8_t, width); |
| 87 | |||
| 88 | 2 | a0 = rnd() & 0xFF; | |
| 89 | 2 | b0 = rnd() & 0xFF; | |
| 90 | 2 | a1 = a0; | |
| 91 | 2 | b1 = b0; | |
| 92 | |||
| 93 | |||
| 94 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | call_ref(dst0, src0, diff0, width, &a0, &b0); |
| 95 | 2 | call_new(dst1, src1, diff1, width, &a1, &b1); | |
| 96 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | if (memcmp(dst0, dst1, width) || (a0 != a1) || (b0 != b1)) |
| 97 | ✗ | fail(); | |
| 98 |
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, src1, diff1, width, &a1, &b1); |
| 99 | |||
| 100 | 2 | av_free(src0); | |
| 101 | 2 | av_free(src1); | |
| 102 | 2 | av_free(diff0); | |
| 103 | 2 | av_free(diff1); | |
| 104 | 2 | av_free(dst0); | |
| 105 | 2 | av_free(dst1); | |
| 106 | 2 | } | |
| 107 | |||
| 108 | 6 | static void check_add_left_pred(LLVidDSPContext *c, int width, size_t aligned_width, int acc) | |
| 109 | { | ||
| 110 | int res0, res1; | ||
| 111 | 6 | declare_func(int, uint8_t *dst, const uint8_t *src, ptrdiff_t w, int acc); | |
| 112 | 6 | uint8_t *dst0 = av_mallocz(aligned_width); | |
| 113 | 6 | uint8_t *dst1 = av_mallocz(aligned_width); | |
| 114 | 6 | uint8_t *src0 = av_malloc(aligned_width); | |
| 115 | 6 | uint8_t *src1 = av_malloc(aligned_width); | |
| 116 | |||
| 117 |
4/6✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 6 taken 8454 times.
✓ Branch 7 taken 6 times.
|
8460 | init_buffer(src0, src1, uint8_t, width); |
| 118 | |||
| 119 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
6 | if (!dst0 || !dst1) |
| 120 | ✗ | fail(); | |
| 121 | |||
| 122 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
6 | res0 = call_ref(dst0, src0, width, acc); |
| 123 | 6 | res1 = call_new(dst1, src1, width, acc); | |
| 124 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
6 | if ((res0 & 0xFF) != (res1 & 0xFF) || memcmp(dst0, dst1, width)) |
| 125 | ✗ | fail(); | |
| 126 |
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, width, acc); |
| 127 | |||
| 128 | 6 | av_free(src0); | |
| 129 | 6 | av_free(src1); | |
| 130 | 6 | av_free(dst0); | |
| 131 | 6 | av_free(dst1); | |
| 132 | 6 | } | |
| 133 | |||
| 134 | 2 | static void check_add_left_pred_16(LLVidDSPContext *c, unsigned mask, int width, | |
| 135 | size_t align, unsigned acc) | ||
| 136 | { | ||
| 137 | int res0, res1; | ||
| 138 | uint16_t *dst0, *dst1, *src0, *src1; | ||
| 139 | 2 | size_t aligned_width = FFALIGN(width * sizeof(*dst0), align); | |
| 140 | 2 | declare_func(int, uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc); | |
| 141 | |||
| 142 | 2 | dst0 = av_mallocz(aligned_width); | |
| 143 | 2 | dst1 = av_mallocz(aligned_width); | |
| 144 | 2 | src0 = av_malloc(aligned_width); | |
| 145 | 2 | src1 = av_malloc(aligned_width); | |
| 146 | |||
| 147 |
4/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 5636 times.
✓ Branch 7 taken 2 times.
|
5638 | init_buffer(src0, src1, uint16_t, width); |
| 148 | |||
| 149 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (!dst0 || !dst1) |
| 150 | ✗ | fail(); | |
| 151 | |||
| 152 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | res0 = call_ref(dst0, src0, mask, width, acc); |
| 153 | 2 | res1 = call_new(dst1, src1, mask, width, acc); | |
| 154 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if ((res0 & 0xFFFF) != (res1 & 0xFFFF) || memcmp(dst0, dst1, width * sizeof(*dst0))) |
| 155 | ✗ | fail(); | |
| 156 |
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, src1, mask, width, acc); |
| 157 | |||
| 158 | 2 | av_free(src0); | |
| 159 | 2 | av_free(src1); | |
| 160 | 2 | av_free(dst0); | |
| 161 | 2 | av_free(dst1); | |
| 162 | 2 | } | |
| 163 | |||
| 164 | 3 | static void check_add_gradient_pred(LLVidDSPContext *c, int w, size_t align) | |
| 165 | { | ||
| 166 | int src_size, stride; | ||
| 167 | uint8_t *src0, *src1; | ||
| 168 | 3 | declare_func(void, uint8_t *src, const ptrdiff_t stride, | |
| 169 | const ptrdiff_t width); | ||
| 170 | |||
| 171 | 3 | stride = FFALIGN(w + 32, align); | |
| 172 | 3 | src_size = (stride + 32) * 2; /* dsp need previous line, and ignore the start of the line */ | |
| 173 | 3 | src0 = av_mallocz(src_size); | |
| 174 | 3 | src1 = av_mallocz(src_size); | |
| 175 | |||
| 176 |
4/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 6 taken 8944 times.
✓ Branch 7 taken 3 times.
|
8947 | init_buffer(src0, src1, uint8_t, src_size); |
| 177 | |||
| 178 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | call_ref(src0 + stride + 32, stride, w); |
| 179 | 3 | call_new(src1 + stride + 32, stride, w); | |
| 180 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (memcmp(src0, src1, stride)||/* previous line doesn't change */ |
| 181 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | memcmp(src0+stride, src1 + stride, w + 32)) { |
| 182 | ✗ | fail(); | |
| 183 | } | ||
| 184 |
1/18✗ Branch 1 not taken.
✓ Branch 2 taken 3 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.
|
3 | bench_new(src1 + stride + 32, stride, w); |
| 185 | |||
| 186 | 3 | av_free(src0); | |
| 187 | 3 | av_free(src1); | |
| 188 | 3 | } | |
| 189 | |||
| 190 | 14 | void checkasm_check_llviddsp(void) | |
| 191 | { | ||
| 192 | LLVidDSPContext c; | ||
| 193 | 14 | int accRnd = rnd() & 0xFF; | |
| 194 | |||
| 195 | 14 | size_t align = av_cpu_max_align(); | |
| 196 | 14 | int width = 1 + rnd() % 16*128; | |
| 197 | 14 | size_t aligned_width = FFALIGN(width, align); | |
| 198 | |||
| 199 | 14 | ff_llviddsp_init(&c); | |
| 200 | |||
| 201 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 11 times.
|
14 | if (check_func(c.add_bytes, "add_bytes")) |
| 202 | 3 | check_add_bytes(&c, width, aligned_width); | |
| 203 | 14 | report("add_bytes"); | |
| 204 | |||
| 205 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 12 times.
|
14 | if (check_func(c.add_median_pred, "add_median_pred")) |
| 206 | 2 | check_add_median_pred(&c, width, aligned_width); | |
| 207 | 14 | report("add_median_pred"); | |
| 208 | |||
| 209 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 11 times.
|
14 | if (check_func(c.add_left_pred, "add_left_pred_zero")) |
| 210 | 3 | check_add_left_pred(&c, width, aligned_width, 0); | |
| 211 | 14 | report("add_left_pred_zero"); | |
| 212 | |||
| 213 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 11 times.
|
14 | if (check_func(c.add_left_pred, "add_left_pred_rnd_acc")) |
| 214 | 3 | check_add_left_pred(&c, width, aligned_width, accRnd); | |
| 215 | 14 | report("add_left_pred_rnd_acc"); | |
| 216 | |||
| 217 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 12 times.
|
14 | if (check_func(c.add_left_pred_int16, "add_left_pred_int16")) |
| 218 | 2 | check_add_left_pred_16(&c, 255, width, align, accRnd); | |
| 219 | 14 | report("add_left_pred_int16"); | |
| 220 | |||
| 221 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 11 times.
|
14 | if (check_func(c.add_gradient_pred, "add_gradient_pred")) |
| 222 | 3 | check_add_gradient_pred(&c, width, align); | |
| 223 | 14 | report("add_gradient_pred"); | |
| 224 | 14 | } | |
| 225 |