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>
31
32 static const uint32_t
pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
33 #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
34
35 #define randomize_buffers() \
36 do { \
37 uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
38 int k; \
39 for (k = -4; k < SIZEOF_PIXEL * FFMAX(8, size); k += 4) { \
40 uint32_t r = rnd() & mask; \
41 AV_WN32A(a + k, r); \
42 } \
43 for (k = 0; k < size * SIZEOF_PIXEL; k += 4) { \
44 uint32_t r = rnd() & mask; \
45 AV_WN32A(l + k, r); \
46 } \
47 } while (0)
48
50 {
52 uint8_t *
a = &a_buf[32 * 2];
59 const uint8_t *
left,
const uint8_t *top);
76 };
77
80 for (tx = 0; tx < 4; tx++) {
82
92 }
93 }
94 }
95 }
97 }
98
99 #undef randomize_buffers
100
101 #define randomize_buffers() \
102 do { \
103 uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
104 for (y = 0; y < sz; y++) { \
105 for (x = 0; x < sz * SIZEOF_PIXEL; x += 4) { \
106 uint32_t r = rnd() & mask; \
107 AV_WN32A(dst + y * sz * SIZEOF_PIXEL + x, r); \
108 AV_WN32A(src + y * sz * SIZEOF_PIXEL + x, rnd() & mask); \
109 } \
110 for (x = 0; x < sz; x++) { \
111 if (bit_depth == 8) { \
112 coef[y * sz + x] = src[y * sz + x] - dst[y * sz + x]; \
113 } else { \
114 ((int32_t *) coef)[y * sz + x] = \
115 ((uint16_t *) src)[y * sz + x] - \
116 ((uint16_t *) dst)[y * sz + x]; \
117 } \
118 } \
119 } \
120 } while(0)
121
122 // wht function copied from libvpx
124 {
125 double t0 = in[0] + in[1];
126 double t3 = in[3] - in[2];
128 double t1 =
t4 - in[1];
129 double t2 =
t4 - in[2];
130
135 }
136
137 // standard DCT-II
139 {
140 int k, n;
141
142 for (k = 0; k < sz; k++) {
144 for (n = 0; n < sz; n++)
145 out[k] += in[n] * cos(
M_PI * (2 * n + 1) * k / (sz * 2.0));
146 }
148 }
149
150 // see "Towards jointly optimal spatial prediction and adaptive transform in
151 // video/image coding", by J. Han, A. Saxena, and K. Rose
152 // IEEE Proc. ICASSP, pp. 726-729, Mar. 2010.
154 {
155 int k, n;
156
157 for (k = 0; k < sz; k++) {
159 for (n = 0; n < sz; n++)
160 out[k] += in[n] * sin(
M_PI * (n + 1) * (2 * k + 1) / (sz * 2.0 + 1.0));
161 }
162 }
163
164 // see "A Butterfly Structured Design of The Hybrid Transform Coding Scheme",
165 // by Jingning Han, Yaowu Xu, and Debargha Mukherjee
166 // http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/41418.pdf
168 {
169 int k, n;
170
171 for (k = 0; k < sz; k++) {
173 for (n = 0; n < sz; n++)
174 out[k] += in[n] * sin(
M_PI * (2 * n + 1) * (2 * k + 1) / (sz * 4.0));
175 }
176 }
177
181 {
182 static const double scaling_factors[5][4] = {
184 { 2.0, 2.0, 2.0, 2.0 },
185 { 1.0, 1.0, 1.0, 1.0 },
186 { 0.25 },
187 { 4.0 }
188 };
189 static const ftx1d_fn ftx1d_tbl[5][4][2] = {
190 {
195 }, {
200 }, {
205 }, {
207 }, {
209 },
210 };
212 double scaling_factor = scaling_factors[tx][txtp];
214
215 // cols
216 for (
i = 0;
i < sz; ++
i) {
217 double temp_out[32];
218
219 ftx1d_tbl[tx][txtp][0](temp_out, &in[
i * sz], sz);
220 // scale and transpose
221 for (j = 0; j < sz; ++j)
222 temp[j * sz +
i] = temp_out[j] * scaling_factor;
223 }
224
225 // rows
226 for (
i = 0;
i < sz;
i++)
227 ftx1d_tbl[tx][txtp][1](&
out[
i * sz], &
temp[
i * sz], sz);
228 }
229
232 {
233 double ind[1024], outd[1024];
234 int n;
235
236 emms_c();
237 for (n = 0; n < sz * sz; n++) {
239 ind[n] = buf[n];
240 else
242 }
243 ftx_2d(outd, ind, tx, txtp, sz);
244 for (n = 0; n < sz * sz; n++) {
246 buf[n] =
lrint(outd[n]);
247 else
249 }
250 }
251
254 {
255 // copy the topleft coefficients such that the return value (being the
256 // coefficient scantable index for the eob token) guarantees that only
257 // the topleft $sub out of $sz (where $sz >= $sub) coefficients in both
258 // dimensions are non-zero. This leads to braching to specific optimized
259 // simd versions (e.g. dc-only) so that we get full asm coverage in this
260 // test
261
262 int n;
264 int eob;
265
266 for (n = 0; n < sz * sz; n++) {
267 int rc = scan[n], rcx = rc % sz, rcy = rc / sz;
268
269 // find eob for this sub-idct
270 if (rcx >=
sub || rcy >=
sub)
271 break;
272
273 // copy coef
276 } else {
278 }
279 }
280
281 eob = n;
282
283 for (; n < sz * sz; n++) {
284 int rc = scan[n];
285
286 // zero
289 } else {
291 }
292 }
293
294 return eob;
295 }
296
298 {
299 int n;
300
301 for (n = 0; n < sz / sizeof(int16_t); n += 2)
303 return 0;
304
305 return 1;
306 }
307
308 #define SIZEOF_COEF (2 * ((bit_depth + 7) / 8))
309
311 {
325 };
326
329
331 int sz = 4 << (tx & 3);
333
334 for (txtp = 0; txtp < n_txtps; txtp++) {
335 // skip testing sub-IDCTs for WHT or ADST since they don't
336 // implement it in any of the SIMD functions. If they do,
337 // consider changing this to ensure we have complete test
338 // coverage. Test sub=1 for dc-only, then 2, 4, 8, 12, etc,
339 // since the arm version can distinguish them at that level.
340 for (
sub = (txtp == 0 && tx < 4) ? 1 : sz;
sub <= sz;
343 "vp9_inv_%s_%dx%d_sub%d_add_%d",
344 tx == 4 ? "wht_wht" : txtp_types[txtp],
346 int eob;
347
350
354 } else {
355 eob = sz * sz;
357 }
358
368
370 }
371 }
372 }
373 }
374 }
376 }
377
378 #undef randomize_buffers
379
380 #define setpx(a,b,c) \
381 do { \
382 if (SIZEOF_PIXEL == 1) { \
383 buf0[(a) + (b) * jstride] = av_clip_uint8(c); \
384 } else { \
385 ((uint16_t *)buf0)[(a) + (b) * jstride] = av_clip_uintp2(c, bit_depth); \
386 } \
387 } while (0)
388
389 // c can be an assignment and must not be put under ()
390 #define setdx(a,b,c,d) setpx(a,b,c-(d)+(rnd()%((d)*2+1)))
391 #define setsx(a,b,c,d) setdx(a,b,c,(d) << (bit_depth - 8))
394 const int *
F,
const int *
H,
const int *I,
395 uint8_t *buf0, uint8_t *buf1)
396 {
398 int off = dir ? lineoff : lineoff * 16;
399 int istride = dir ? 1 : 16;
400 int jstride = dir ?
str : 1;
402 for (
i = 0;
i < 2;
i++)
/* flat16 */ {
403 int idx = off +
i * istride, p0,
q0;
405 setsx(idx, -1, p0 =
q0,
E[bidx] >> 2);
406 for (j = 1; j < 8; j++) {
407 setsx(idx, -1 - j, p0,
F[bidx]);
409 }
410 }
411 for (
i = 2;
i < 4;
i++)
/* flat8 */ {
412 int idx = off +
i * istride, p0,
q0;
414 setsx(idx, -1, p0 =
q0,
E[bidx] >> 2);
415 for (j = 1; j < 4; j++) {
416 setsx(idx, -1 - j, p0,
F[bidx]);
418 }
419 for (j = 4; j < 8; j++) {
422 }
423 }
424 for (
i = 4;
i < 6;
i++)
/* regular */ {
425 int idx = off +
i * istride, p2, p1, p0,
q0,
q1, q2;
428 setsx(idx, 2, q2 =
q1, I[bidx]);
429 setsx(idx, 3, q2, I[bidx]);
430 setsx(idx, -1, p0 =
q0,
E[bidx] >> 2);
431 setsx(idx, -2, p1 = p0, I[bidx]);
432 setsx(idx, -3, p2 = p1, I[bidx]);
433 setsx(idx, -4, p2, I[bidx]);
434 for (j = 4; j < 8; j++) {
437 }
438 }
439 for (
i = 6;
i < 8;
i++)
/* off */ {
440 int idx = off +
i * istride;
441 for (j = 0; j < 8; j++) {
444 }
445 }
446 }
447 #define randomize_buffers(bidx, lineoff, str) \
448 randomize_loopfilter_buffers(bidx, lineoff, str, bit_depth, dir, \
449 E, F, H, I, buf0, buf1)
450
452 {
457 static const char *const dir_name[2] = { "h", "v" };
458 static const int E[2] = { 20, 28 }, I[2] = { 10, 16 };
459 static const int H[2] = { 7, 11 },
F[2] = { 1, 1 };
461
464
465 for (dir = 0; dir < 2; dir++) {
468 uint8_t *buf0 = base0 + midoff_aligned;
469 uint8_t *buf1 = base1 + midoff_aligned;
470
471 for (wd = 0; wd < 3; wd++) {
472 // 4/8/16wd_8px
474 "vp9_loop_filter_%s_%d_8_%dbpp",
477 memcpy(buf1 - midoff, buf0 - midoff,
481 if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 8 *
SIZEOF_PIXEL))
484 }
485 }
486
489
490 buf0 = base0 + midoff_aligned;
491 buf1 = base1 + midoff_aligned;
492
493 // 16wd_16px loopfilter
495 "vp9_loop_filter_%s_16_16_%dbpp",
499 memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 *
SIZEOF_PIXEL);
502 if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 *
SIZEOF_PIXEL))
505 }
506
507 for (wd = 0; wd < 2; wd++) {
508 for (wd2 = 0; wd2 < 2; wd2++) {
509 // mix2 loopfilter
511 "vp9_loop_filter_mix2_%s_%d%d_16_%dbpp",
512 dir_name[dir], 4 << wd, 4 << wd2,
bit_depth)) {
515 memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 *
SIZEOF_PIXEL);
516 #define M(a) (((a)[1] << 8) | (a)[0])
519 if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 *
SIZEOF_PIXEL))
522 #undef M
523 }
524 }
525 }
526 }
527 }
529 }
530
531 #undef setsx
532 #undef setpx
533 #undef setdx
534 #undef randomize_buffers
535
536 #define DST_BUF_SIZE (size * size * SIZEOF_PIXEL)
537 #define SRC_BUF_STRIDE 72
538 #define SRC_BUF_SIZE ((size + 7) * SRC_BUF_STRIDE * SIZEOF_PIXEL)
539 #define src (buf + 3 * SIZEOF_PIXEL * (SRC_BUF_STRIDE + 1))
540
541 #define randomize_buffers() \
542 do { \
543 uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
544 int k; \
545 for (k = 0; k < SRC_BUF_SIZE; k += 4) { \
546 uint32_t r = rnd() & mask; \
547 AV_WN32A(buf + k, r); \
548 } \
549 if (op == 1) { \
550 for (k = 0; k < DST_BUF_SIZE; k += 4) { \
551 uint32_t r = rnd() & mask; \
552 AV_WN32A(dst0 + k, r); \
553 AV_WN32A(dst1 + k, r); \
554 } \
555 } \
556 } while (0)
557
559 {
566 const uint8_t *
ref, ptrdiff_t ref_stride,
567 int h,
int mx,
int my);
568 static const char *const filter_names[4] = {
569 "8tap_smooth", "8tap_regular", "8tap_sharp", "bilin"
570 };
571 static const char *const subpel_names[2][2] = { { "", "h" }, { "v", "hv" } };
572 static const char *const op_names[2] = { "put", "avg" };
574
575 for (
op = 0;
op < 2;
op++) {
578 for (hsize = 0; hsize < 5; hsize++) {
579 int size = 64 >> hsize;
580
582 for (dx = 0; dx < 2; dx++) {
583 for (dy = 0; dy < 2; dy++) {
584 if (dx || dy) {
586 "%s_%s_%d%s", op_names[
op],
588 subpel_names[dy][dx]);
589 } else {
591 "%s%d", op_names[
op],
size);
592 }
595 int mx = dx ? 1 + (
rnd() % 14) : 0;
596 int my = dy ? 1 + (
rnd() % 14) : 0;
606
607 // simd implementations for each filter of subpel
608 // functions are identical
610 // 10/12 bpp for bilin are identical
612
616 }
617 }
618 }
619 }
620 }
621 }
622 }
624 }
625
627 {
632 }