| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2024 Institute of Software Chinese Academy of Sciences (ISCAS). | ||
| 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 <stdint.h> | ||
| 23 | #include <string.h> | ||
| 24 | |||
| 25 | #include "libavutil/intreadwrite.h" | ||
| 26 | #include "libavutil/macros.h" | ||
| 27 | #include "libavutil/mem_internal.h" | ||
| 28 | |||
| 29 | #include "libavcodec/mathops.h" | ||
| 30 | #include "libavcodec/rv34dsp.h" | ||
| 31 | |||
| 32 | #include "checkasm.h" | ||
| 33 | |||
| 34 | #define randomize(buf, len) \ | ||
| 35 | do { \ | ||
| 36 | for (int i = 0; i < len; i++) \ | ||
| 37 | buf[i] = rnd(); \ | ||
| 38 | } while (0) | ||
| 39 | |||
| 40 | 14 | static void test_rv34_inv_transform_dc(RV34DSPContext *s) { | |
| 41 | 14 | declare_func(void, int16_t *block); | |
| 42 | |||
| 43 |
2/2✓ Branch 3 taken 2 times.
✓ Branch 4 taken 12 times.
|
14 | if (check_func(s->rv34_inv_transform_dc, "rv34_inv_transform_dc")) { |
| 44 | DECLARE_ALIGNED_16(int16_t, p1)[4*4]; | ||
| 45 | DECLARE_ALIGNED_16(int16_t, p2)[4*4]; | ||
| 46 | |||
| 47 |
2/2✓ Branch 1 taken 32 times.
✓ Branch 2 taken 2 times.
|
34 | randomize(p1, FF_ARRAY_ELEMS(p1)); |
| 48 | 2 | memcpy(p2, p1, sizeof(p1)); | |
| 49 | |||
| 50 | 2 | call_ref(p1); | |
| 51 | 2 | call_new(p2); | |
| 52 | |||
| 53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (memcmp(p1, p2, sizeof(p1))) { |
| 54 | ✗ | fail(); | |
| 55 | } | ||
| 56 | |||
| 57 |
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(p1); |
| 58 | } | ||
| 59 | |||
| 60 | 14 | report("rv34_inv_transform_dc"); | |
| 61 | 14 | } | |
| 62 | |||
| 63 | 14 | static void test_rv34_idct_dc_add(RV34DSPContext *s) { | |
| 64 | 14 | declare_func(void, uint8_t *dst, ptrdiff_t stride, int dc); | |
| 65 | |||
| 66 |
2/2✓ Branch 3 taken 3 times.
✓ Branch 4 taken 11 times.
|
14 | if (check_func(s->rv34_idct_dc_add, "rv34_idct_dc_add")) { |
| 67 | DECLARE_ALIGNED_16(uint8_t, p1)[4*4]; | ||
| 68 | DECLARE_ALIGNED_16(uint8_t, p2)[4*4]; | ||
| 69 | |||
| 70 |
2/2✓ Branch 1 taken 48 times.
✓ Branch 2 taken 3 times.
|
51 | randomize(p1, FF_ARRAY_ELEMS(p1)); |
| 71 | 3 | memcpy(p2, p1, sizeof(p1)); | |
| 72 | |||
| 73 | 3 | call_ref(p1, 4, 5); | |
| 74 | 3 | call_new(p2, 4, 5); | |
| 75 | |||
| 76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (memcmp(p1, p2, sizeof(p1))) { |
| 77 | ✗ | fail(); | |
| 78 | } | ||
| 79 | |||
| 80 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 3 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.
|
3 | bench_new(p1, 4, 5); |
| 81 | } | ||
| 82 | |||
| 83 | 14 | report("rv34_idct_dc_add"); | |
| 84 | 14 | } | |
| 85 | |||
| 86 | 14 | static void test_rv34_idct_add(const RV34DSPContext *const s) | |
| 87 | { | ||
| 88 | enum { | ||
| 89 | MAX_STRIDE = 256, ///< arbitrary, should be divisible by four | ||
| 90 | }; | ||
| 91 | 14 | declare_func(void, uint8_t *dst, ptrdiff_t stride, int16_t *block); | |
| 92 | |||
| 93 |
2/2✓ Branch 3 taken 2 times.
✓ Branch 4 taken 12 times.
|
14 | if (check_func(s->rv34_idct_add, "rv34_idct_add")) { |
| 94 | DECLARE_ALIGNED_16(int16_t, block_ref)[4*4]; | ||
| 95 | DECLARE_ALIGNED_16(int16_t, block_new)[4*4]; | ||
| 96 | |||
| 97 | DECLARE_ALIGNED_4(uint8_t, dst_ref)[4*MAX_STRIDE + 4]; | ||
| 98 | DECLARE_ALIGNED_4(uint8_t, dst_new)[4*MAX_STRIDE + 4]; | ||
| 99 | |||
| 100 | 2 | ptrdiff_t stride = FFALIGN(1 + rnd() % MAX_STRIDE, 4); | |
| 101 | 2 | uint8_t *dst_refp = dst_ref, *dst_newp = dst_new; | |
| 102 | |||
| 103 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if (rnd() & 1) { // negate stride |
| 104 | 2 | dst_refp += 3 * stride; | |
| 105 | 2 | dst_newp += 3 * stride; | |
| 106 | 2 | stride = -stride; | |
| 107 | } | ||
| 108 | |||
| 109 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 2 times.
|
34 | for (size_t i = 0; i < FF_ARRAY_ELEMS(block_ref); ++i) |
| 110 | 32 | block_ref[i] = sign_extend(rnd(), 10); | |
| 111 |
2/2✓ Branch 0 taken 514 times.
✓ Branch 1 taken 2 times.
|
516 | for (size_t i = 0; i < sizeof(dst_ref); i += 4) |
| 112 | 514 | AV_WN32A(dst_ref + i, rnd()); | |
| 113 | 2 | memcpy(block_new, block_ref, sizeof(block_new)); | |
| 114 | 2 | memcpy(dst_new, dst_ref, sizeof(dst_new)); | |
| 115 | |||
| 116 | 2 | call_ref(dst_refp, stride, block_ref); | |
| 117 | 2 | call_new(dst_newp, stride, block_new); | |
| 118 | |||
| 119 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (memcmp(dst_ref, dst_new, sizeof(dst_new)) || |
| 120 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | memcmp(block_ref, block_new, sizeof(block_new))) |
| 121 | ✗ | fail(); | |
| 122 | |||
| 123 |
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(dst_new, stride, block_new); |
| 124 | } | ||
| 125 | |||
| 126 | 14 | report("rv34_idct_add"); | |
| 127 | 14 | } | |
| 128 | |||
| 129 | 14 | void checkasm_check_rv34dsp(void) | |
| 130 | { | ||
| 131 | 14 | RV34DSPContext s = { 0 }; | |
| 132 | 14 | ff_rv34dsp_init(&s); | |
| 133 | |||
| 134 | 14 | test_rv34_inv_transform_dc(&s); | |
| 135 | 14 | test_rv34_idct_dc_add(&s); | |
| 136 | 14 | test_rv34_idct_add(&s); | |
| 137 | 14 | } | |
| 138 |