1 /*
2 *
3 * This file is part of FFmpeg.
4 *
5 * FFmpeg is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * FFmpeg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <string.h>
21
25
28
30
31 #define randomize_buffers(buf, size) \
32 do { \
33 int j; \
34 for (j = 0; j < size; j+=4) \
35 AV_WN32(buf + j, rnd()); \
36 } while (0)
37
39 const int16_t **
src, uint8_t *dest,
int dstW,
41 {
42 // This corresponds to the yuv2planeX_8_c function
44 for (
i = 0;
i < dstW;
i++) {
46 int j;
47 for (j = 0; j < filterSize; j++)
49
51 }
52 }
53
55 {
56 for (
size_t i = 0;
i < n;
i++) {
58 return 1;
59 }
60 return 0;
61 }
62
64 {
66 for (;
i <
len;
i++) {
69 }
70 printf(
"0x%02x ", (uint32_t) p[
i]);
73 }
74 }
77 }
78 }
79
81 {
82 for (
size_t i = 0;
i <
len;
i++) {
84 size_t offset_of_mismatch =
i;
93 return offset_of_mismatch;
94 }
95 }
97 }
98
100 {
102 int osi, isi;
104 size_t fail_offset;
105 const int input_sizes[] = {8, 24, 128, 144, 256, 512};
106 const int INPUT_SIZES =
sizeof(input_sizes)/
sizeof(input_sizes[0]);
107 #define LARGEST_INPUT_SIZE 512
108
109 const int offsets[] = {0, 3, 8, 11, 16, 19};
111 const char *accurate_str = (accurate) ? "accurate" : "approximate";
112
114 const int16_t *
src, uint8_t *dest,
116
121
125 if (accurate)
129
132 dstW = input_sizes[isi];
133 for (osi = 0; osi < OFFSET_SIZES; osi++) {
138
145 printf(
"failing values: src: 0x%04x dither: 0x%02x dst-c: %02x dst-asm: %02x\n",
146 (int) src_pixels[fail_offset],
147 (
int)
dither[(fail_offset + fail_offset) & 7],
148 (int) dst0[fail_offset],
149 (int) dst1[fail_offset]);
150 }
153 }
154 }
155 }
157 }
158
160 {
162 int fsi, osi, isi,
i, j;
164 #define LARGEST_FILTER 16
165 // ff_yuv2planeX_8_sse2 can't handle odd filter sizes
166 const int filter_sizes[] = {2, 4, 8, 16};
167 const int FILTER_SIZES =
sizeof(filter_sizes)/
sizeof(filter_sizes[0]);
168 #define LARGEST_INPUT_SIZE 512
169 static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
170 const int INPUT_SIZES =
sizeof(input_sizes)/
sizeof(input_sizes[0]);
171 const char *accurate_str = (accurate) ? "accurate" : "approximate";
172
174 int filterSize,
const int16_t **
src, uint8_t *dest,
176
183 union VFilterData{
186 } *vFilterData;
187 uint8_t d_val =
rnd();
191 if (accurate)
195
198 dstW = input_sizes[isi];
199 for(osi = 0; osi < 64; osi += 16){
200 if (dstW <= osi)
201 continue;
203 // Generate filter coefficients for the given filter size,
204 // with some properties:
205 // - The coefficients add up to the intended sum (4096, 1<<12)
206 // - The coefficients contain negative values
207 // - The filter intermediates don't overflow for worst case
208 // inputs (all positive coefficients are coupled with
209 // input_max and all negative coefficients with input_min,
210 // or vice versa).
211 // Produce a filter with all coefficients set to
212 // -((1<<12)/(filter_size-1)) except for one (randomly chosen)
213 // which is set to ((1<<13)-1).
214 for (
i = 0;
i < filter_sizes[fsi]; ++
i)
215 filter_coeff[
i] = -((1 << 12) / (filter_sizes[fsi] - 1));
216 filter_coeff[
rnd() % filter_sizes[fsi]] = (1 << 13) - 1;
217
219 vFilterData =
av_malloc((filter_sizes[fsi] + 2) *
sizeof(
union VFilterData));
220 memset(vFilterData, 0, (filter_sizes[fsi] + 2) * sizeof(union VFilterData));
221 for (
i = 0;
i < filter_sizes[fsi]; ++
i) {
223 vFilterData[
i].src =
src[
i] - osi;
224 for(j = 0; j < 4; ++j)
225 vFilterData[
i].
coeff[j + 4] = filter_coeff[
i];
226 }
227 if (
check_func(
ctx->yuv2planeX,
"yuv2yuvX_%d_%d_%d_%s", filter_sizes[fsi], osi, dstW, accurate_str)){
228 // use vFilterData for the mmx function
229 const int16_t *
filter =
ctx->use_mmx_vfilter ? (
const int16_t*)vFilterData : &filter_coeff[0];
232
233 // We can't use call_ref here, because we don't know if use_mmx_vfilter was set for that
234 // function or not, so we can't pass it the parameters correctly.
236
240 printf(
"failed: yuv2yuvX_%d_%d_%d_%s\n", filter_sizes[fsi], osi, dstW, accurate_str);
242 }
244 bench_new((
const int16_t*)vFilterData, filter_sizes[fsi],
src, dst1, dstW - osi,
dither, osi);
245
246 }
249 }
250 }
251 }
253 #undef FILTER_SIZES
254 }
255
256 #undef SRC_PIXELS
257 #define SRC_PIXELS 512
258
260 {
261 #define MAX_FILTER_WIDTH 40
262 #define FILTER_SIZES 6
263 static const int filter_sizes[
FILTER_SIZES] = { 4, 8, 12, 16, 32, 40 };
264
265 #define HSCALE_PAIRS 2
267 { 8, 14 },
268 { 8, 18 },
269 };
270
271 #define LARGEST_INPUT_SIZE 512
272 #define INPUT_SIZES 6
273 static const int input_sizes[
INPUT_SIZES] = {8, 24, 128, 144, 256, 512};
274
275 int i, j, fsi, hpi,
width, dstWi;
277
278 // padded
282
283 // padded
288
289 // The dst parameter here is either int16_t or int32_t but we use void* to
290 // just cover both cases.
292 const uint8_t *
src,
const int16_t *
filter,
293 const int32_t *filterPos,
int filterSize);
294
298
300
304 width = filter_sizes[fsi];
305
306 ctx->srcBpc = hscale_pairs[hpi][0];
307 ctx->dstBpc = hscale_pairs[hpi][1];
309
313
314 // These filter cofficients are chosen to try break two corner
315 // cases, namely:
316 //
317 // - Negative filter coefficients. The filters output signed
318 // values, and it should be possible to end up with negative
319 // output values.
320 //
321 // - Positive clipping. The hscale filter function has clipping
322 // at (1<<15) - 1
323 //
324 // The coefficients sum to the 1.0 point for the hscale
325 // functions (1 << 14).
326
327 for (j = 0; j <
width; j++) {
329 }
331 }
332
334 // These values should be unused in SIMD implementations but
335 // may still be read, random coefficients here should help show
336 // issues where they are used in error.
337
339 }
340 ctx->dstW =
ctx->chrDstW = input_sizes[dstWi];
344
346 memset(dst0, 0,
SRC_PIXELS *
sizeof(dst0[0]));
347 memset(dst1, 0,
SRC_PIXELS *
sizeof(dst1[0]));
348
351 if (memcmp(dst0, dst1,
ctx->dstW *
sizeof(dst0[0])))
354 }
355 }
356 }
357 }
359 }
360
362 {
371 }