FFmpeg
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 
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mem_internal.h"
26 #include "libavutil/pixelutils.h"
27 
28 enum {
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 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  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 }
mem_internal.h
checkasm_check_sad
static void checkasm_check_sad(void)
Definition: pixelutils.c:42
src1
const pixel * src1
Definition: h264pred_template.c:420
av_pixelutils_sad_fn
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
check_func
#define check_func(func,...)
Definition: checkasm.h:210
call_ref
#define call_ref(...)
Definition: checkasm.h:226
fail
#define fail()
Definition: checkasm.h:220
checkasm.h
checkasm_check_pixelutils
void checkasm_check_pixelutils(void)
Definition: pixelutils.c:95
av_pixelutils_get_sad_fn
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
fn
Definition: ops_tmpl_float.c:123
aligned
static int aligned(int val)
Definition: dashdec.c:172
rnd
#define rnd()
Definition: checkasm.h:203
intreadwrite.h
call_new
#define call_new(...)
Definition: checkasm.h:234
NULL
#define NULL
Definition: coverity.c:32
height
#define height
Definition: dsp.h:89
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:104
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
pixelutils.h
report
#define report
Definition: checkasm.h:223
bench_new
#define bench_new(...)
Definition: checkasm.h:425
src2
const pixel * src2
Definition: h264pred_template.c:421
randomize_buffer
#define randomize_buffer(buf)
Definition: pixelutils.c:34
LOG2_MIN_DIMENSION
@ LOG2_MIN_DIMENSION
Definition: pixelutils.c:29
BUF_SIZE
@ BUF_SIZE
arbitrary
Definition: pixelutils.c:31
LOG2_MAX_DIMENSION
@ LOG2_MAX_DIMENSION
Definition: pixelutils.c:30
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:215
width
#define width
Definition: dsp.h:89