FFmpeg
vf_fspp.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 #include "libavfilter/vf_fsppdsp.h"
24 #include "libavcodec/mathops.h"
25 #include "libavutil/mem_internal.h"
26 
27 #define randomize_buffers(buf) \
28  do { \
29  for (size_t j = 0; j < FF_ARRAY_ELEMS(buf); ++j) \
30  buf[j] = rnd(); \
31  } while (0)
32 
33 #define randomize_mask_buffers(buf, buf2, nb_elems, nb_bits)\
34  do { \
35  for (size_t j = 0; j < nb_elems; ++j) \
36  buf[j] = buf2[j] = sign_extend(rnd(), nb_bits); \
37  } while (0)
38 
39 #define randomize_buffer_range(buf, min, max) \
40  do { \
41  for (size_t j = 0; j < FF_ARRAY_ELEMS(buf); ++j) \
42  buf[j] = min + rnd() % (max - min + 1); \
43  } while (0)
44 
45 static void check_store_slice(void)
46 {
47  enum {
48  MAX_WIDTH = 256,
49  /// in elements, not in bytes; 32 is arbitrary
50  MAX_STRIDE = MAX_WIDTH + 32,
51  MAX_HEIGHT = 8,
52  };
53  FSPPDSPContext fspp;
54  ff_fsppdsp_init(&fspp);
55  declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t *src,
56  ptrdiff_t dst_stride, ptrdiff_t src_stride,
57  ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale);
58 
59  for (int i = 0; i < 2; ++i) {
60  if (check_func(i ? fspp.store_slice2 : fspp.store_slice, "store_slice%s", i ? "2" : "")) {
61  // store slice resets the row eight lines above the current one
62  DECLARE_ALIGNED(16, int16_t, src_ref1)[MAX_STRIDE * ( 8 + MAX_HEIGHT - 1) + MAX_WIDTH];
63  DECLARE_ALIGNED(16, int16_t, src_new1)[MAX_STRIDE * ( 8 + MAX_HEIGHT - 1) + MAX_WIDTH];
64  // store_slice2 resets the row 16 lines below the current one
65  DECLARE_ALIGNED(16, int16_t, src_ref2)[MAX_STRIDE * (16 + MAX_HEIGHT - 1) + MAX_WIDTH];
66  DECLARE_ALIGNED(16, int16_t, src_new2)[MAX_STRIDE * (16 + MAX_HEIGHT - 1) + MAX_WIDTH];
67  uint8_t dstbuf_new[MAX_STRIDE * (MAX_HEIGHT - 1) + MAX_WIDTH], dstbuf_ref[MAX_STRIDE * (MAX_HEIGHT - 1) + MAX_WIDTH];
68  uint8_t *dst_new = dstbuf_new, *dst_ref = dstbuf_ref;
69  int16_t *src_ref, *src_new, *or_src_ref, *or_src_new;
70  ptrdiff_t width = 1 + rnd() % MAX_WIDTH;
71  ptrdiff_t src_stride = FFALIGN(width + 1 + rnd() % (MAX_STRIDE - MAX_WIDTH), 8);
72  ptrdiff_t dst_stride = FFALIGN(width + 1 + rnd() % (MAX_STRIDE - MAX_WIDTH), 8);
73  ptrdiff_t height = 1 + rnd() % 8;
74  size_t nb_elems;
75 
76  if (i) {
77  src_ref = src_ref2;
78  src_new = src_new2;
79  or_src_ref = src_ref2;
80  or_src_new = src_new2;
81  nb_elems = FF_ARRAY_ELEMS(src_ref2);
82  } else {
83  src_ref = src_ref1 + 8 * src_stride;
84  src_new = src_new1 + 8 * src_stride;
85  or_src_ref = src_ref1;
86  or_src_new = src_new1;
87  nb_elems = FF_ARRAY_ELEMS(src_ref1);
88  }
89  if (rnd() & 1) {
90  dst_ref += dst_stride * (height - 1);
91  dst_new += dst_stride * (height - 1);
92  dst_stride *= -1;
93  }
94  randomize_buffers(dstbuf_new);
95  memcpy(dstbuf_ref, dstbuf_new, sizeof(dstbuf_ref));
96  randomize_mask_buffers(or_src_ref, or_src_new, nb_elems, 14);
97 
98  ptrdiff_t log2_scale = rnd() & 1;
99  call_ref(dst_ref, src_ref, dst_stride, src_stride, width, height, log2_scale);
100  call_new(dst_new, src_new, dst_stride, src_stride, width, height, log2_scale);
101  if (memcmp(dstbuf_new, dstbuf_ref, sizeof(dstbuf_ref)) ||
102  memcmp(or_src_ref, or_src_new, sizeof(*or_src_new) * nb_elems))
103  fail();
104  // don't use random parameters for benchmarks
105  src_ref = or_src_ref + !i * 8 * MAX_STRIDE;
106  bench_new(dstbuf_new, src_ref,
107  MAX_STRIDE, MAX_STRIDE, MAX_WIDTH, 8, 1);
108  }
109  }
110 }
111 
112 static void check_mul_thrmat(void)
113 {
114  FSPPDSPContext fspp;
115  DECLARE_ALIGNED(16, int16_t, src)[64];
116  DECLARE_ALIGNED(16, int16_t, dst_ref)[64];
117  DECLARE_ALIGNED(16, int16_t, dst_new)[64];
118  const int q = (uint8_t)rnd();
119  declare_func(void, const int16_t *thr_adr_noq, int16_t *thr_adr, int q);
120 
121  ff_fsppdsp_init(&fspp);
122 
123  if (check_func(fspp.mul_thrmat, "mul_thrmat")) {
125  call_ref(src, dst_ref, q);
126  call_new(src, dst_new, q);
127  if (memcmp(dst_ref, dst_new, sizeof(dst_ref)))
128  fail();
129  bench_new(src, dst_new, q);
130  }
131 }
132 
133 static void check_column_fidct(void)
134 {
135  enum {
136  NB_BLOCKS = 8, ///< arbitrary
137  };
138  FSPPDSPContext fspp;
139  declare_func(void, const int16_t *thr_adr, const int16_t *data,
140  int16_t *output, int cnt);
141 
142  ff_fsppdsp_init(&fspp);
143 
144  if (check_func(fspp.column_fidct, "column_fidct")) {
145  DECLARE_ALIGNED(16, int16_t, threshold)[64];
146  DECLARE_ALIGNED(16, int16_t, src)[8*(8*NB_BLOCKS + 6)];
147  DECLARE_ALIGNED(16, int16_t, dst_new)[8*(8*NB_BLOCKS + 6)];
148  DECLARE_ALIGNED(16, int16_t, dst_ref)[8*(8*NB_BLOCKS + 6)];
149 
150  randomize_buffer_range(threshold, 0, INT16_MAX);
151  randomize_buffer_range(src, -1284, 1284);
152  randomize_buffers(dst_new);
153  memcpy(dst_ref, dst_new, sizeof(dst_ref));
154 
155  call_ref(threshold, src, dst_ref, NB_BLOCKS * 8);
156  call_new(threshold, src, dst_new, NB_BLOCKS * 8);
157 
158  if (memcmp(dst_new, dst_ref, sizeof(dst_new)))
159  fail();
160 
161  bench_new(threshold, src, dst_new, NB_BLOCKS * 8);
162  }
163 }
164 
166 {
170 }
declare_func_emms
#define declare_func_emms(cpu_flags, ret,...)
Definition: checkasm.h:204
mem_internal.h
randomize_buffer_range
#define randomize_buffer_range(buf, min, max)
Definition: vf_fspp.c:39
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:226
FSPPDSPContext::store_slice
void(* store_slice)(uint8_t *restrict dst, int16_t *restrict src, ptrdiff_t dst_stride, ptrdiff_t src_stride, ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale)
Definition: vf_fsppdsp.h:34
check_func
#define check_func(func,...)
Definition: checkasm.h:198
data
const char data[16]
Definition: mxf.c:149
checkasm_check_vf_fspp
void checkasm_check_vf_fspp(void)
Definition: vf_fspp.c:165
randomize_buffers
#define randomize_buffers(buf)
Definition: vf_fspp.c:27
call_ref
#define call_ref(...)
Definition: checkasm.h:213
vf_fsppdsp.h
fail
#define fail()
Definition: checkasm.h:207
FSPPDSPContext::mul_thrmat
void(* mul_thrmat)(const int16_t *restrict thr_adr_noq, int16_t *restrict thr_adr, int q)
Definition: vf_fsppdsp.h:42
checkasm.h
FSPPDSPContext
Definition: vf_fsppdsp.h:33
rnd
#define rnd()
Definition: checkasm.h:191
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
check_store_slice
static void check_store_slice(void)
Definition: vf_fspp.c:45
FSPPDSPContext::column_fidct
void(* column_fidct)(const int16_t *restrict thr_adr, const int16_t *restrict data, int16_t *restrict output, int cnt)
Definition: vf_fsppdsp.h:45
MAX_HEIGHT
#define MAX_HEIGHT
Definition: hpeldsp.c:30
call_new
#define call_new(...)
Definition: checkasm.h:316
FSPPDSPContext::store_slice2
void(* store_slice2)(uint8_t *restrict dst, int16_t *restrict src, ptrdiff_t dst_stride, ptrdiff_t src_stride, ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale)
Definition: vf_fsppdsp.h:38
mathops.h
height
#define height
Definition: dsp.h:89
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:104
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
randomize_mask_buffers
#define randomize_mask_buffers(buf, buf2, nb_elems, nb_bits)
Definition: vf_fspp.c:33
check_column_fidct
static void check_column_fidct(void)
Definition: vf_fspp.c:133
bench_new
#define bench_new(...)
Definition: checkasm.h:401
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AV_CPU_FLAG_MMX
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:32
MAX_STRIDE
#define MAX_STRIDE
Definition: hpeldsp.c:31
check_mul_thrmat
static void check_mul_thrmat(void)
Definition: vf_fspp.c:112
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:202
ff_fsppdsp_init
static FF_VISIBILITY_POP_HIDDEN void ff_fsppdsp_init(FSPPDSPContext *fspp)
Definition: vf_fsppdsp.h:75
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
width
#define width
Definition: dsp.h:89
src
#define src
Definition: vp8dsp.c:248