| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2022 Ben Avison | ||
| 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 "checkasm.h" | ||
| 24 | |||
| 25 | #include "libavcodec/avcodec.h" | ||
| 26 | #include "libavcodec/idctdsp.h" | ||
| 27 | |||
| 28 | #include "libavutil/common.h" | ||
| 29 | #include "libavutil/internal.h" | ||
| 30 | #include "libavutil/intreadwrite.h" | ||
| 31 | #include "libavutil/mem_internal.h" | ||
| 32 | |||
| 33 | #define IDCTDSP_TEST(func) { #func, offsetof(IDCTDSPContext, func) }, | ||
| 34 | |||
| 35 | typedef struct { | ||
| 36 | const char *name; | ||
| 37 | size_t offset; | ||
| 38 | } test; | ||
| 39 | |||
| 40 | #define RANDOMIZE_BUFFER16(name, size) \ | ||
| 41 | do { \ | ||
| 42 | int i; \ | ||
| 43 | for (i = 0; i < size; ++i) { \ | ||
| 44 | uint16_t r = rnd() % 0x201 - 0x100; \ | ||
| 45 | AV_WN16A(name##0 + i, r); \ | ||
| 46 | AV_WN16A(name##1 + i, r); \ | ||
| 47 | } \ | ||
| 48 | } while (0) | ||
| 49 | |||
| 50 | #define RANDOMIZE_BUFFER8(name, size) \ | ||
| 51 | do { \ | ||
| 52 | int i; \ | ||
| 53 | for (i = 0; i < size; ++i) { \ | ||
| 54 | uint8_t r = rnd(); \ | ||
| 55 | name##0[i] = r; \ | ||
| 56 | name##1[i] = r; \ | ||
| 57 | } \ | ||
| 58 | } while (0) | ||
| 59 | |||
| 60 | 14 | static void check_add_put_clamped(void) | |
| 61 | { | ||
| 62 | /* Source buffers are only as big as needed, since any over-read won't affect results */ | ||
| 63 | 14 | LOCAL_ALIGNED_16(int16_t, src0, [64]); | |
| 64 | 14 | LOCAL_ALIGNED_16(int16_t, src1, [64]); | |
| 65 | /* Destination buffers have borders of one row above/below and 8 columns left/right to catch overflows */ | ||
| 66 | 14 | LOCAL_ALIGNED_8(uint8_t, dst0, [10 * 24]); | |
| 67 | 14 | LOCAL_ALIGNED_8(uint8_t, dst1, [10 * 24]); | |
| 68 | |||
| 69 | 14 | AVCodecContext avctx = { 0 }; | |
| 70 | IDCTDSPContext h; | ||
| 71 | |||
| 72 | 14 | const test tests[] = { | |
| 73 | IDCTDSP_TEST(add_pixels_clamped) | ||
| 74 | IDCTDSP_TEST(put_pixels_clamped) | ||
| 75 | IDCTDSP_TEST(put_signed_pixels_clamped) | ||
| 76 | }; | ||
| 77 | |||
| 78 | 14 | ff_idctdsp_init(&h, &avctx); | |
| 79 | |||
| 80 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 14 times.
|
56 | for (size_t t = 0; t < FF_ARRAY_ELEMS(tests); ++t) { |
| 81 | 42 | void (*func)(const int16_t *, uint8_t * ptrdiff_t) = *(void **)((intptr_t) &h + tests[t].offset); | |
| 82 |
2/2✓ Branch 3 taken 6 times.
✓ Branch 4 taken 36 times.
|
42 | if (check_func(func, "idctdsp.%s", tests[t].name)) { |
| 83 | 6 | declare_func(void, const int16_t *, uint8_t *, ptrdiff_t); | |
| 84 |
2/2✓ Branch 1 taken 384 times.
✓ Branch 2 taken 6 times.
|
390 | RANDOMIZE_BUFFER16(src, 64); |
| 85 |
2/2✓ Branch 1 taken 1440 times.
✓ Branch 2 taken 6 times.
|
1446 | RANDOMIZE_BUFFER8(dst, 10 * 24); |
| 86 | 6 | call_ref(src0, dst0 + 24 + 8, 24); | |
| 87 | 6 | call_new(src1, dst1 + 24 + 8, 24); | |
| 88 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (memcmp(dst0, dst1, 10 * 24)) |
| 89 | ✗ | fail(); | |
| 90 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 6 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.
|
6 | bench_new(src1, dst1 + 24 + 8, 24); |
| 91 | } | ||
| 92 | } | ||
| 93 | 14 | } | |
| 94 | |||
| 95 | 14 | void checkasm_check_idctdsp(void) | |
| 96 | { | ||
| 97 | 14 | check_add_put_clamped(); | |
| 98 | 14 | report("idctdsp"); | |
| 99 | 14 | } | |
| 100 |