| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation; either version 2 of the License, or | ||
| 7 | * (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 | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License along | ||
| 15 | * with FFmpeg; if not, write to the Free Software Foundation, Inc., | ||
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <stddef.h> | ||
| 20 | #include <stdint.h> | ||
| 21 | |||
| 22 | #include "checkasm.h" | ||
| 23 | |||
| 24 | #include "libavutil/intreadwrite.h" | ||
| 25 | #include "libavutil/mem_internal.h" | ||
| 26 | #include "libavutil/pixelutils.h" | ||
| 27 | |||
| 28 | enum { | ||
| 29 | LOG2_MIN_DIMENSION = 1, | ||
| 30 | LOG2_MAX_DIMENSION = 5, | ||
| 31 | BUF_SIZE = 4096, ///< arbitrary | ||
| 32 | }; | ||
| 33 | |||
| 34 | #define randomize_buffer(buf) \ | ||
| 35 | do { \ | ||
| 36 | for (size_t k = 0; k < sizeof(buf); k += 4) { \ | ||
| 37 | uint32_t r = rnd(); \ | ||
| 38 | AV_WN32A(buf + k, r); \ | ||
| 39 | } \ | ||
| 40 | } while (0) | ||
| 41 | |||
| 42 | 14 | static void checkasm_check_sad(void) | |
| 43 | { | ||
| 44 | DECLARE_ALIGNED(32, uint8_t, buf1)[BUF_SIZE]; | ||
| 45 | DECLARE_ALIGNED(32, uint8_t, buf2)[BUF_SIZE]; | ||
| 46 | 14 | int inited = 0; | |
| 47 | |||
| 48 | 14 | declare_func(int, const uint8_t *src1, ptrdiff_t stride1, | |
| 49 | const uint8_t *src2, ptrdiff_t stride2); | ||
| 50 | |||
| 51 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 14 times.
|
84 | for (int i = LOG2_MIN_DIMENSION; i <= LOG2_MAX_DIMENSION; ++i) { |
| 52 | 70 | const size_t width = 1 << i, height = 1 << i; | |
| 53 | |||
| 54 |
2/2✓ Branch 0 taken 210 times.
✓ Branch 1 taken 70 times.
|
280 | for (int aligned = 0; aligned <= 2; ++aligned) { |
| 55 | 210 | av_pixelutils_sad_fn fn = av_pixelutils_get_sad_fn(i, i, aligned, NULL); | |
| 56 |
2/2✓ Branch 3 taken 27 times.
✓ Branch 4 taken 183 times.
|
210 | if (check_func(fn, "sad_%zux%zu_%d", width, width, aligned)) { |
| 57 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
|
27 | const uint8_t *src1 = buf1 + ((aligned != 0) ? 0 : rnd() % width); |
| 58 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
|
27 | const uint8_t *src2 = buf2 + ((aligned == 2) ? 0 : rnd() % width); |
| 59 | // stride * (height - 1) needs to be so small that the alignment offset | ||
| 60 | // and the last line fit into the remaining buffer. | ||
| 61 | 27 | size_t max_stride = (BUF_SIZE - 2 * width) / (height - 1); | |
| 62 | 27 | ptrdiff_t stride1 = 1 + rnd() % max_stride; | |
| 63 | 27 | ptrdiff_t stride2 = 1 + rnd() % max_stride; | |
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
|
27 | if (aligned != 0) |
| 66 | 18 | stride1 &= ~(width - 1); | |
| 67 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
|
27 | if (aligned == 2) |
| 68 | 9 | stride2 &= ~(width - 1); | |
| 69 | |||
| 70 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 13 times.
|
27 | if (rnd() & 1) { // negate stride |
| 71 | 14 | src1 += (height - 1) * stride1; | |
| 72 | 14 | stride1 = -stride1; | |
| 73 | } | ||
| 74 |
2/2✓ Branch 1 taken 11 times.
✓ Branch 2 taken 16 times.
|
27 | if (rnd() & 1) { // negate stride |
| 75 | 11 | src2 += (height - 1) * stride2; | |
| 76 | 11 | stride2 = -stride2; | |
| 77 | } | ||
| 78 | |||
| 79 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 24 times.
|
27 | if (!inited) { |
| 80 |
2/2✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3 times.
|
3075 | randomize_buffer(buf1); |
| 81 |
2/2✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3 times.
|
3075 | randomize_buffer(buf2); |
| 82 | 3 | inited = 1; | |
| 83 | } | ||
| 84 | 27 | int res_ref = call_ref(src1, stride1, src2, stride2); | |
| 85 | 27 | int ref_new = call_new(src1, stride1, src2, stride2); | |
| 86 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
|
27 | if (res_ref != ref_new) |
| 87 | ✗ | fail(); | |
| 88 | |||
| 89 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 27 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.
|
27 | bench_new(src1, stride1, src2, stride2); |
| 90 | } | ||
| 91 | } | ||
| 92 | } | ||
| 93 | 14 | } | |
| 94 | |||
| 95 | 14 | void checkasm_check_pixelutils(void) | |
| 96 | { | ||
| 97 | 14 | checkasm_check_sad(); | |
| 98 | 14 | report("sad"); | |
| 99 | 14 | } | |
| 100 |