FFmpeg
Loading...
Searching...
No Matches
pixelutils.c
Go to the documentation of this file.
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
27
28enum {
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
42static 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 int inited = 0;
47
48 declare_func(int, const uint8_t *src1, ptrdiff_t stride1,
49 const uint8_t *src2, ptrdiff_t stride2);
50
51 for (int i = LOG2_MIN_DIMENSION; i <= LOG2_MAX_DIMENSION; ++i) {
52 const size_t width = 1 << i, height = 1 << i;
53
54 for (int aligned = 0; aligned <= 2; ++aligned) {
56 if (check_func(fn, "sad_%zux%zu_%d", width, width, aligned)) {
57 const uint8_t *src1 = buf1 + ((aligned != 0) ? 0 : rnd() % width);
58 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 size_t max_stride = (BUF_SIZE - 2 * width) / (height - 1);
62 ptrdiff_t stride1 = 1 + rnd() % max_stride;
63 ptrdiff_t stride2 = 1 + rnd() % max_stride;
64
65 if (aligned != 0)
66 stride1 &= ~(width - 1);
67 if (aligned == 2)
68 stride2 &= ~(width - 1);
69
70 if (rnd() & 1) { // negate stride
71 src1 += (height - 1) * stride1;
72 stride1 = -stride1;
73 }
74 if (rnd() & 1) { // negate stride
75 src2 += (height - 1) * stride2;
76 stride2 = -stride2;
77 }
78
79 if (!inited) {
80 randomize_buffer(buf1);
81 randomize_buffer(buf2);
82 inited = 1;
83 }
84 int res_ref = call_ref(src1, stride1, src2, stride2);
85 int ref_new = call_new(src1, stride1, src2, stride2);
86 if (res_ref != ref_new)
87 fail();
88
89 bench_new(src1, stride1, src2, stride2);
90 }
91 }
92 }
93}
94
96{
98 report("sad");
99}
#define fn(a)
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define rnd
Definition checkasm.h:136
#define NULL
Definition coverity.c:32
static int aligned(int val)
Definition dashdec.c:178
#define declare_func
Definition test.h:489
#define fail
Definition test.h:479
#define bench_new
Definition test.h:487
#define check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define report
Definition test.h:480
const pixel * src2
av_pixelutils_sad_fn av_pixelutils_get_sad_fn(int w_bits, int h_bits, int aligned, void *log_ctx)
Get a potentially optimized pointer to a Sum-of-absolute-differences function (see the av_pixelutils_...
Definition pixelutils.c:82
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
int(* av_pixelutils_sad_fn)(const uint8_t *src1, ptrdiff_t stride1, const uint8_t *src2, ptrdiff_t stride2)
Sum of abs(src1[x] - src2[x])
Definition pixelutils.h:28
#define BUF_SIZE
Definition setpts.c:159
#define src1
Definition h264pred.c:141
static void checkasm_check_sad(void)
Definition pixelutils.c:42
@ LOG2_MIN_DIMENSION
Definition pixelutils.c:29
@ LOG2_MAX_DIMENSION
Definition pixelutils.c:30
#define randomize_buffer(buf)
Definition pixelutils.c:34
void checkasm_check_pixelutils(void)
Definition pixelutils.c:95
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89