1 /*
2 * Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.com>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include <math.h>
22 #include <string.h>
32
33 static const uint32_t
pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
34 #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
35
36 #define randomize_buffers() \
37 do { \
38 uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
39 int k; \
40 for (k = -4; k < SIZEOF_PIXEL * FFMAX(8, size); k += 4) { \
41 uint32_t r = rnd() & mask; \
42 AV_WN32A(a + k, r); \
43 } \
44 for (k = 0; k < size * SIZEOF_PIXEL; k += 4) { \
45 uint32_t r = rnd() & mask; \
46 AV_WN32A(l + k, r); \
47 } \
48 } while (0)
49
51 {
53 uint8_t *
a = &a_buf[32 * 2];
60 const uint8_t *
left,
const uint8_t *top);
77 };
78
81 for (tx = 0; tx < 4; tx++) {
83
93 }
94 }
95 }
96 }
98 }
99
100 #undef randomize_buffers
101
102 #define randomize_buffers() \
103 do { \
104 uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
105 for (y = 0; y < sz; y++) { \
106 for (x = 0; x < sz * SIZEOF_PIXEL; x += 4) { \
107 uint32_t r = rnd() & mask; \
108 AV_WN32A(dst + y * sz * SIZEOF_PIXEL + x, r); \
109 AV_WN32A(src + y * sz * SIZEOF_PIXEL + x, rnd() & mask); \
110 } \
111 for (x = 0; x < sz; x++) { \
112 if (bit_depth == 8) { \
113 coef[y * sz + x] = src[y * sz + x] - dst[y * sz + x]; \
114 } else { \
115 ((int32_t *) coef)[y * sz + x] = \
116 ((uint16_t *) src)[y * sz + x] - \
117 ((uint16_t *) dst)[y * sz + x]; \
118 } \
119 } \
120 } \
121 } while(0)
122
123 // wht function copied from libvpx
125 {
126 double t0 = in[0] + in[1];
127 double t3 = in[3] - in[2];
128 double t4 =
trunc((t0 - t3) * 0.5);
129 double t1 = t4 - in[1];
130 double t2 = t4 - in[2];
131
136 }
137
138 // standard DCT-II
140 {
141 int k, n;
142
143 for (k = 0; k < sz; k++) {
145 for (n = 0; n < sz; n++)
146 out[k] += in[n] * cos(
M_PI * (2 * n + 1) * k / (sz * 2.0));
147 }
149 }
150
151 // see "Towards jointly optimal spatial prediction and adaptive transform in
152 // video/image coding", by J. Han, A. Saxena, and K. Rose
153 // IEEE Proc. ICASSP, pp. 726-729, Mar. 2010.
155 {
156 int k, n;
157
158 for (k = 0; k < sz; k++) {
160 for (n = 0; n < sz; n++)
161 out[k] += in[n] * sin(
M_PI * (n + 1) * (2 * k + 1) / (sz * 2.0 + 1.0));
162 }
163 }
164
165 // see "A Butterfly Structured Design of The Hybrid Transform Coding Scheme",
166 // by Jingning Han, Yaowu Xu, and Debargha Mukherjee
167 // http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/41418.pdf
169 {
170 int k, n;
171
172 for (k = 0; k < sz; k++) {
174 for (n = 0; n < sz; n++)
175 out[k] += in[n] * sin(
M_PI * (2 * n + 1) * (2 * k + 1) / (sz * 4.0));
176 }
177 }
178
182 {
183 static const double scaling_factors[5][4] = {
185 { 2.0, 2.0, 2.0, 2.0 },
186 { 1.0, 1.0, 1.0, 1.0 },
187 { 0.25 },
188 { 4.0 }
189 };
190 static const ftx1d_fn ftx1d_tbl[5][4][2] = {
191 {
196 }, {
201 }, {
206 }, {
208 }, {
210 },
211 };
213 double scaling_factor = scaling_factors[tx][txtp];
215
216 // cols
217 for (
i = 0;
i < sz; ++
i) {
218 double temp_out[32];
219
220 ftx1d_tbl[tx][txtp][0](temp_out, &in[
i * sz], sz);
221 // scale and transpose
222 for (j = 0; j < sz; ++j)
223 temp[j * sz +
i] = temp_out[j] * scaling_factor;
224 }
225
226 // rows
227 for (
i = 0;
i < sz;
i++)
228 ftx1d_tbl[tx][txtp][1](&
out[
i * sz], &
temp[
i * sz], sz);
229 }
230
233 {
234 double ind[1024], outd[1024];
235 int n;
236
238 for (n = 0; n < sz * sz; n++) {
240 ind[n] = buf[n];
241 else
243 }
244 ftx_2d(outd, ind, tx, txtp, sz);
245 for (n = 0; n < sz * sz; n++) {
247 buf[n] =
lrint(outd[n]);
248 else
250 }
251 }
252
255 {
256 // copy the topleft coefficients such that the return value (being the
257 // coefficient scantable index for the eob token) guarantees that only
258 // the topleft $sub out of $sz (where $sz >= $sub) coefficients in both
259 // dimensions are non-zero. This leads to braching to specific optimized
260 // simd versions (e.g. dc-only) so that we get full asm coverage in this
261 // test
262
263 int n;
265 int eob;
266
267 for (n = 0; n < sz * sz; n++) {
268 int rc = scan[n], rcx = rc % sz, rcy = rc / sz;
269
270 // find eob for this sub-idct
271 if (rcx >= sub || rcy >= sub)
272 break;
273
274 // copy coef
277 } else {
279 }
280 }
281
282 eob = n;
283
284 for (; n < sz * sz; n++) {
285 int rc = scan[n];
286
287 // zero
290 } else {
292 }
293 }
294
295 return eob;
296 }
297
299 {
300 int n;
301
302 for (n = 0; n < sz / sizeof(int16_t); n += 2)
304 return 0;
305
306 return 1;
307 }
308
309 #define SIZEOF_COEF (2 * ((bit_depth + 7) / 8))
310
312 {
326 };
327
330
332 int sz = 4 << (tx & 3);
334
335 for (txtp = 0; txtp < n_txtps; txtp++) {
336 // skip testing sub-IDCTs for WHT or ADST since they don't
337 // implement it in any of the SIMD functions. If they do,
338 // consider changing this to ensure we have complete test
339 // coverage. Test sub=1 for dc-only, then 2, 4, 8, 12, etc,
340 // since the arm version can distinguish them at that level.
341 for (sub = (txtp == 0 && tx < 4) ? 1 : sz; sub <= sz;
342 sub < 4 ? (sub <<= 1) : (sub += 4)) {
344 "vp9_inv_%s_%dx%d_sub%d_add_%d",
345 tx == 4 ? "wht_wht" : txtp_types[txtp],
347 int eob;
348
351
352 if (sub < sz) {
355 } else {
356 eob = sz * sz;
358 }
359
369
371 }
372 }
373 }
374 }
375 }
377 }
378
379 #undef randomize_buffers
380
381 #define setpx(a,b,c) \
382 do { \
383 if (SIZEOF_PIXEL == 1) { \
384 buf0[(a) + (b) * jstride] = av_clip_uint8(c); \
385 } else { \
386 ((uint16_t *)buf0)[(a) + (b) * jstride] = av_clip_uintp2(c, bit_depth); \
387 } \
388 } while (0)
389
390 // c can be an assignment and must not be put under ()
391 #define setdx(a,b,c,d) setpx(a,b,c-(d)+(rnd()%((d)*2+1)))
392 #define setsx(a,b,c,d) setdx(a,b,c,(d) << (bit_depth - 8))
395 const int *
F,
const int *
H,
const int *I,
396 uint8_t *buf0, uint8_t *buf1)
397 {
399 int off = dir ? lineoff : lineoff * 16;
400 int istride = dir ? 1 : 16;
401 int jstride = dir ? str : 1;
403 for (
i = 0;
i < 2;
i++)
/* flat16 */ {
404 int idx = off +
i * istride, p0,
q0;
406 setsx(idx, -1, p0 =
q0,
E[bidx] >> 2);
407 for (j = 1; j < 8; j++) {
408 setsx(idx, -1 - j, p0,
F[bidx]);
410 }
411 }
412 for (
i = 2;
i < 4;
i++)
/* flat8 */ {
413 int idx = off +
i * istride, p0,
q0;
415 setsx(idx, -1, p0 =
q0,
E[bidx] >> 2);
416 for (j = 1; j < 4; j++) {
417 setsx(idx, -1 - j, p0,
F[bidx]);
419 }
420 for (j = 4; j < 8; j++) {
423 }
424 }
425 for (
i = 4;
i < 6;
i++)
/* regular */ {
426 int idx = off +
i * istride, p2, p1, p0,
q0,
q1, q2;
429 setsx(idx, 2, q2 =
q1, I[bidx]);
430 setsx(idx, 3, q2, I[bidx]);
431 setsx(idx, -1, p0 =
q0,
E[bidx] >> 2);
432 setsx(idx, -2, p1 = p0, I[bidx]);
433 setsx(idx, -3, p2 = p1, I[bidx]);
434 setsx(idx, -4, p2, I[bidx]);
435 for (j = 4; j < 8; j++) {
438 }
439 }
440 for (
i = 6;
i < 8;
i++)
/* off */ {
441 int idx = off +
i * istride;
442 for (j = 0; j < 8; j++) {
445 }
446 }
447 }
448 #define randomize_buffers(bidx, lineoff, str) \
449 randomize_loopfilter_buffers(bidx, lineoff, str, bit_depth, dir, \
450 E, F, H, I, buf0, buf1)
451
453 {
458 static const char *const dir_name[2] = { "h", "v" };
459 static const int E[2] = { 20, 28 }, I[2] = { 10, 16 };
460 static const int H[2] = { 7, 11 },
F[2] = { 1, 1 };
462
465
466 for (dir = 0; dir < 2; dir++) {
469 uint8_t *buf0 = base0 + midoff_aligned;
470 uint8_t *buf1 = base1 + midoff_aligned;
471
472 for (wd = 0; wd < 3; wd++) {
473 // 4/8/16wd_8px
475 "vp9_loop_filter_%s_%d_8_%dbpp",
478 memcpy(buf1 - midoff, buf0 - midoff,
482 if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 8 *
SIZEOF_PIXEL))
485 }
486 }
487
490
491 buf0 = base0 + midoff_aligned;
492 buf1 = base1 + midoff_aligned;
493
494 // 16wd_16px loopfilter
496 "vp9_loop_filter_%s_16_16_%dbpp",
500 memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 *
SIZEOF_PIXEL);
503 if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 *
SIZEOF_PIXEL))
506 }
507
508 for (wd = 0; wd < 2; wd++) {
509 for (wd2 = 0; wd2 < 2; wd2++) {
510 // mix2 loopfilter
512 "vp9_loop_filter_mix2_%s_%d%d_16_%dbpp",
513 dir_name[dir], 4 << wd, 4 << wd2,
bit_depth)) {
516 memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 *
SIZEOF_PIXEL);
517 #define M(a) (((a)[1] << 8) | (a)[0])
520 if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 *
SIZEOF_PIXEL))
523 #undef M
524 }
525 }
526 }
527 }
528 }
530 }
531
532 #undef setsx
533 #undef setpx
534 #undef setdx
535 #undef randomize_buffers
536
537 #define DST_BUF_SIZE (size * size * SIZEOF_PIXEL)
538 #define SRC_BUF_STRIDE 72
539 #define SRC_BUF_SIZE ((size + 7) * SRC_BUF_STRIDE * SIZEOF_PIXEL)
540 #define src (buf + 3 * SIZEOF_PIXEL * (SRC_BUF_STRIDE + 1))
541
542 #define randomize_buffers() \
543 do { \
544 uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
545 int k; \
546 for (k = 0; k < SRC_BUF_SIZE; k += 4) { \
547 uint32_t r = rnd() & mask; \
548 AV_WN32A(buf + k, r); \
549 } \
550 if (op == 1) { \
551 for (k = 0; k < DST_BUF_SIZE; k += 4) { \
552 uint32_t r = rnd() & mask; \
553 AV_WN32A(dst0 + k, r); \
554 AV_WN32A(dst1 + k, r); \
555 } \
556 } \
557 } while (0)
558
560 {
567 const uint8_t *
ref, ptrdiff_t ref_stride,
568 int h,
int mx,
int my);
569 static const char *const filter_names[4] = {
570 "8tap_smooth", "8tap_regular", "8tap_sharp", "bilin"
571 };
572 static const char *const subpel_names[2][2] = { { "", "h" }, { "v", "hv" } };
573 static const char *const op_names[2] = { "put", "avg" };
574 char str[256];
575
576 for (
op = 0;
op < 2;
op++) {
579 for (hsize = 0; hsize < 5; hsize++) {
580 int size = 64 >> hsize;
581
583 for (dx = 0; dx < 2; dx++) {
584 for (dy = 0; dy < 2; dy++) {
585 if (dx || dy) {
587 "%s_%s_%d%s", op_names[
op],
589 subpel_names[dy][dx]);
590 } else {
592 "%s%d", op_names[
op],
size);
593 }
596 int mx = dx ? 1 + (
rnd() % 14) : 0;
597 int my = dy ? 1 + (
rnd() % 14) : 0;
607
608 // simd implementations for each filter of subpel
609 // functions are identical
611 // 10/12 bpp for bilin are identical
613
617 }
618 }
619 }
620 }
621 }
622 }
623 }
625 }
626
628 {
633 }