You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

630 lines
24KB

  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. #include <math.h>
  21. #include <string.h>
  22. #include "checkasm.h"
  23. #include "libavcodec/vp9data.h"
  24. #include "libavcodec/vp9dsp.h"
  25. #include "libavutil/common.h"
  26. #include "libavutil/internal.h"
  27. #include "libavutil/intreadwrite.h"
  28. #include "libavutil/mathematics.h"
  29. static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
  30. #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
  31. #define randomize_buffers() \
  32. do { \
  33. uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
  34. int k; \
  35. for (k = -4; k < SIZEOF_PIXEL * FFMAX(8, size); k += 4) { \
  36. uint32_t r = rnd() & mask; \
  37. AV_WN32A(a + k, r); \
  38. } \
  39. for (k = 0; k < size * SIZEOF_PIXEL; k += 4) { \
  40. uint32_t r = rnd() & mask; \
  41. AV_WN32A(l + k, r); \
  42. } \
  43. } while (0)
  44. static void check_ipred(void)
  45. {
  46. LOCAL_ALIGNED_32(uint8_t, a_buf, [64 * 2]);
  47. uint8_t *a = &a_buf[32 * 2];
  48. LOCAL_ALIGNED_32(uint8_t, l, [32 * 2]);
  49. LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]);
  50. LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]);
  51. VP9DSPContext dsp;
  52. int tx, mode, bit_depth;
  53. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride,
  54. const uint8_t *left, const uint8_t *top);
  55. static const char *const mode_names[N_INTRA_PRED_MODES] = {
  56. [VERT_PRED] = "vert",
  57. [HOR_PRED] = "hor",
  58. [DC_PRED] = "dc",
  59. [DIAG_DOWN_LEFT_PRED] = "diag_downleft",
  60. [DIAG_DOWN_RIGHT_PRED] = "diag_downright",
  61. [VERT_RIGHT_PRED] = "vert_right",
  62. [HOR_DOWN_PRED] = "hor_down",
  63. [VERT_LEFT_PRED] = "vert_left",
  64. [HOR_UP_PRED] = "hor_up",
  65. [TM_VP8_PRED] = "tm",
  66. [LEFT_DC_PRED] = "dc_left",
  67. [TOP_DC_PRED] = "dc_top",
  68. [DC_128_PRED] = "dc_128",
  69. [DC_127_PRED] = "dc_127",
  70. [DC_129_PRED] = "dc_129",
  71. };
  72. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  73. ff_vp9dsp_init(&dsp, bit_depth, 0);
  74. for (tx = 0; tx < 4; tx++) {
  75. int size = 4 << tx;
  76. for (mode = 0; mode < N_INTRA_PRED_MODES; mode++) {
  77. if (check_func(dsp.intra_pred[tx][mode], "vp9_%s_%dx%d_%dbpp",
  78. mode_names[mode], size, size, bit_depth)) {
  79. randomize_buffers();
  80. call_ref(dst0, size * SIZEOF_PIXEL, l, a);
  81. call_new(dst1, size * SIZEOF_PIXEL, l, a);
  82. if (memcmp(dst0, dst1, size * size * SIZEOF_PIXEL))
  83. fail();
  84. bench_new(dst1, size * SIZEOF_PIXEL,l, a);
  85. }
  86. }
  87. }
  88. }
  89. report("ipred");
  90. }
  91. #undef randomize_buffers
  92. #define randomize_buffers() \
  93. do { \
  94. uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
  95. for (y = 0; y < sz; y++) { \
  96. for (x = 0; x < sz * SIZEOF_PIXEL; x += 4) { \
  97. uint32_t r = rnd() & mask; \
  98. AV_WN32A(dst + y * sz * SIZEOF_PIXEL + x, r); \
  99. AV_WN32A(src + y * sz * SIZEOF_PIXEL + x, rnd() & mask); \
  100. } \
  101. for (x = 0; x < sz; x++) { \
  102. if (bit_depth == 8) { \
  103. coef[y * sz + x] = src[y * sz + x] - dst[y * sz + x]; \
  104. } else { \
  105. ((int32_t *) coef)[y * sz + x] = \
  106. ((uint16_t *) src)[y * sz + x] - \
  107. ((uint16_t *) dst)[y * sz + x]; \
  108. } \
  109. } \
  110. } \
  111. } while(0)
  112. // wht function copied from libvpx
  113. static void fwht_1d(double *out, const double *in, int sz)
  114. {
  115. double t0 = in[0] + in[1];
  116. double t3 = in[3] - in[2];
  117. double t4 = trunc((t0 - t3) * 0.5);
  118. double t1 = t4 - in[1];
  119. double t2 = t4 - in[2];
  120. out[0] = t0 - t2;
  121. out[1] = t2;
  122. out[2] = t3 + t1;
  123. out[3] = t1;
  124. }
  125. // standard DCT-II
  126. static void fdct_1d(double *out, const double *in, int sz)
  127. {
  128. int k, n;
  129. for (k = 0; k < sz; k++) {
  130. out[k] = 0.0;
  131. for (n = 0; n < sz; n++)
  132. out[k] += in[n] * cos(M_PI * (2 * n + 1) * k / (sz * 2.0));
  133. }
  134. out[0] *= M_SQRT1_2;
  135. }
  136. // see "Towards jointly optimal spatial prediction and adaptive transform in
  137. // video/image coding", by J. Han, A. Saxena, and K. Rose
  138. // IEEE Proc. ICASSP, pp. 726-729, Mar. 2010.
  139. static void fadst4_1d(double *out, const double *in, int sz)
  140. {
  141. int k, n;
  142. for (k = 0; k < sz; k++) {
  143. out[k] = 0.0;
  144. for (n = 0; n < sz; n++)
  145. out[k] += in[n] * sin(M_PI * (n + 1) * (2 * k + 1) / (sz * 2.0 + 1.0));
  146. }
  147. }
  148. // see "A Butterfly Structured Design of The Hybrid Transform Coding Scheme",
  149. // by Jingning Han, Yaowu Xu, and Debargha Mukherjee
  150. // http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/41418.pdf
  151. static void fadst_1d(double *out, const double *in, int sz)
  152. {
  153. int k, n;
  154. for (k = 0; k < sz; k++) {
  155. out[k] = 0.0;
  156. for (n = 0; n < sz; n++)
  157. out[k] += in[n] * sin(M_PI * (2 * n + 1) * (2 * k + 1) / (sz * 4.0));
  158. }
  159. }
  160. typedef void (*ftx1d_fn)(double *out, const double *in, int sz);
  161. static void ftx_2d(double *out, const double *in, enum TxfmMode tx,
  162. enum TxfmType txtp, int sz)
  163. {
  164. static const double scaling_factors[5][4] = {
  165. { 4.0, 16.0 * M_SQRT1_2 / 3.0, 16.0 * M_SQRT1_2 / 3.0, 32.0 / 9.0 },
  166. { 2.0, 2.0, 2.0, 2.0 },
  167. { 1.0, 1.0, 1.0, 1.0 },
  168. { 0.25 },
  169. { 4.0 }
  170. };
  171. static const ftx1d_fn ftx1d_tbl[5][4][2] = {
  172. {
  173. { fdct_1d, fdct_1d },
  174. { fadst4_1d, fdct_1d },
  175. { fdct_1d, fadst4_1d },
  176. { fadst4_1d, fadst4_1d },
  177. }, {
  178. { fdct_1d, fdct_1d },
  179. { fadst_1d, fdct_1d },
  180. { fdct_1d, fadst_1d },
  181. { fadst_1d, fadst_1d },
  182. }, {
  183. { fdct_1d, fdct_1d },
  184. { fadst_1d, fdct_1d },
  185. { fdct_1d, fadst_1d },
  186. { fadst_1d, fadst_1d },
  187. }, {
  188. { fdct_1d, fdct_1d },
  189. }, {
  190. { fwht_1d, fwht_1d },
  191. },
  192. };
  193. double temp[1024];
  194. double scaling_factor = scaling_factors[tx][txtp];
  195. int i, j;
  196. // cols
  197. for (i = 0; i < sz; ++i) {
  198. double temp_out[32];
  199. ftx1d_tbl[tx][txtp][0](temp_out, &in[i * sz], sz);
  200. // scale and transpose
  201. for (j = 0; j < sz; ++j)
  202. temp[j * sz + i] = temp_out[j] * scaling_factor;
  203. }
  204. // rows
  205. for (i = 0; i < sz; i++)
  206. ftx1d_tbl[tx][txtp][1](&out[i * sz], &temp[i * sz], sz);
  207. }
  208. static void ftx(int16_t *buf, enum TxfmMode tx,
  209. enum TxfmType txtp, int sz, int bit_depth)
  210. {
  211. double ind[1024], outd[1024];
  212. int n;
  213. emms_c();
  214. for (n = 0; n < sz * sz; n++) {
  215. if (bit_depth == 8)
  216. ind[n] = buf[n];
  217. else
  218. ind[n] = ((int32_t *) buf)[n];
  219. }
  220. ftx_2d(outd, ind, tx, txtp, sz);
  221. for (n = 0; n < sz * sz; n++) {
  222. if (bit_depth == 8)
  223. buf[n] = lrint(outd[n]);
  224. else
  225. ((int32_t *) buf)[n] = lrint(outd[n]);
  226. }
  227. }
  228. static int copy_subcoefs(int16_t *out, const int16_t *in, enum TxfmMode tx,
  229. enum TxfmType txtp, int sz, int sub, int bit_depth)
  230. {
  231. // copy the topleft coefficients such that the return value (being the
  232. // coefficient scantable index for the eob token) guarantees that only
  233. // the topleft $sub out of $sz (where $sz >= $sub) coefficients in both
  234. // dimensions are non-zero. This leads to braching to specific optimized
  235. // simd versions (e.g. dc-only) so that we get full asm coverage in this
  236. // test
  237. int n;
  238. const int16_t *scan = vp9_scans[tx][txtp];
  239. int eob;
  240. for (n = 0; n < sz * sz; n++) {
  241. int rc = scan[n], rcx = rc % sz, rcy = rc / sz;
  242. // find eob for this sub-idct
  243. if (rcx >= sub || rcy >= sub)
  244. break;
  245. // copy coef
  246. if (bit_depth == 8) {
  247. out[rc] = in[rc];
  248. } else {
  249. AV_COPY32(&out[rc * 2], &in[rc * 2]);
  250. }
  251. }
  252. eob = n;
  253. for (; n < sz * sz; n++) {
  254. int rc = scan[n];
  255. // zero
  256. if (bit_depth == 8) {
  257. out[rc] = 0;
  258. } else {
  259. AV_ZERO32(&out[rc * 2]);
  260. }
  261. }
  262. return eob;
  263. }
  264. static int iszero(const int16_t *c, int sz)
  265. {
  266. int n;
  267. for (n = 0; n < sz / sizeof(int16_t); n += 2)
  268. if (AV_RN32A(&c[n]))
  269. return 0;
  270. return 1;
  271. }
  272. #define SIZEOF_COEF (2 * ((bit_depth + 7) / 8))
  273. static void check_itxfm(void)
  274. {
  275. LOCAL_ALIGNED_32(uint8_t, src, [32 * 32 * 2]);
  276. LOCAL_ALIGNED_32(uint8_t, dst, [32 * 32 * 2]);
  277. LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]);
  278. LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]);
  279. LOCAL_ALIGNED_32(int16_t, coef, [32 * 32 * 2]);
  280. LOCAL_ALIGNED_32(int16_t, subcoef0, [32 * 32 * 2]);
  281. LOCAL_ALIGNED_32(int16_t, subcoef1, [32 * 32 * 2]);
  282. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride, int16_t *block, int eob);
  283. VP9DSPContext dsp;
  284. int y, x, tx, txtp, bit_depth, sub;
  285. static const char *const txtp_types[N_TXFM_TYPES] = {
  286. [DCT_DCT] = "dct_dct", [DCT_ADST] = "adst_dct",
  287. [ADST_DCT] = "dct_adst", [ADST_ADST] = "adst_adst"
  288. };
  289. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  290. ff_vp9dsp_init(&dsp, bit_depth, 0);
  291. for (tx = TX_4X4; tx <= N_TXFM_SIZES /* 4 = lossless */; tx++) {
  292. int sz = 4 << (tx & 3);
  293. int n_txtps = tx < TX_32X32 ? N_TXFM_TYPES : 1;
  294. for (txtp = 0; txtp < n_txtps; txtp++) {
  295. // skip testing sub-IDCTs for WHT or ADST since they don't
  296. // implement it in any of the SIMD functions. If they do,
  297. // consider changing this to ensure we have complete test
  298. // coverage
  299. for (sub = (txtp == 0 && tx < 4) ? 1 : sz; sub <= sz; sub <<= 1) {
  300. if (check_func(dsp.itxfm_add[tx][txtp],
  301. "vp9_inv_%s_%dx%d_sub%d_add_%d",
  302. tx == 4 ? "wht_wht" : txtp_types[txtp],
  303. sz, sz, sub, bit_depth)) {
  304. int eob;
  305. randomize_buffers();
  306. ftx(coef, tx, txtp, sz, bit_depth);
  307. if (sub < sz) {
  308. eob = copy_subcoefs(subcoef0, coef, tx, txtp,
  309. sz, sub, bit_depth);
  310. } else {
  311. eob = sz * sz;
  312. memcpy(subcoef0, coef, sz * sz * SIZEOF_COEF);
  313. }
  314. memcpy(dst0, dst, sz * sz * SIZEOF_PIXEL);
  315. memcpy(dst1, dst, sz * sz * SIZEOF_PIXEL);
  316. memcpy(subcoef1, subcoef0, sz * sz * SIZEOF_COEF);
  317. call_ref(dst0, sz * SIZEOF_PIXEL, subcoef0, eob);
  318. call_new(dst1, sz * SIZEOF_PIXEL, subcoef1, eob);
  319. if (memcmp(dst0, dst1, sz * sz * SIZEOF_PIXEL) ||
  320. !iszero(subcoef0, sz * sz * SIZEOF_COEF) ||
  321. !iszero(subcoef1, sz * sz * SIZEOF_COEF))
  322. fail();
  323. bench_new(dst, sz * SIZEOF_PIXEL, coef, eob);
  324. }
  325. }
  326. }
  327. }
  328. }
  329. report("itxfm");
  330. }
  331. #undef randomize_buffers
  332. #define setpx(a,b,c) \
  333. do { \
  334. if (SIZEOF_PIXEL == 1) { \
  335. buf0[(a) + (b) * jstride] = av_clip_uint8(c); \
  336. } else { \
  337. ((uint16_t *)buf0)[(a) + (b) * jstride] = av_clip_uintp2(c, bit_depth); \
  338. } \
  339. } while (0)
  340. // c can be an assignment and must not be put under ()
  341. #define setdx(a,b,c,d) setpx(a,b,c-(d)+(rnd()%((d)*2+1)))
  342. #define setsx(a,b,c,d) setdx(a,b,c,(d) << (bit_depth - 8))
  343. static void randomize_loopfilter_buffers(int bidx, int lineoff, int str,
  344. int bit_depth, int dir, const int *E,
  345. const int *F, const int *H, const int *I,
  346. uint8_t *buf0, uint8_t *buf1)
  347. {
  348. uint32_t mask = (1 << bit_depth) - 1;
  349. int off = dir ? lineoff : lineoff * 16;
  350. int istride = dir ? 1 : 16;
  351. int jstride = dir ? str : 1;
  352. int i, j;
  353. for (i = 0; i < 2; i++) /* flat16 */ {
  354. int idx = off + i * istride, p0, q0;
  355. setpx(idx, 0, q0 = rnd() & mask);
  356. setsx(idx, -1, p0 = q0, E[bidx] >> 2);
  357. for (j = 1; j < 8; j++) {
  358. setsx(idx, -1 - j, p0, F[bidx]);
  359. setsx(idx, j, q0, F[bidx]);
  360. }
  361. }
  362. for (i = 2; i < 4; i++) /* flat8 */ {
  363. int idx = off + i * istride, p0, q0;
  364. setpx(idx, 0, q0 = rnd() & mask);
  365. setsx(idx, -1, p0 = q0, E[bidx] >> 2);
  366. for (j = 1; j < 4; j++) {
  367. setsx(idx, -1 - j, p0, F[bidx]);
  368. setsx(idx, j, q0, F[bidx]);
  369. }
  370. for (j = 4; j < 8; j++) {
  371. setpx(idx, -1 - j, rnd() & mask);
  372. setpx(idx, j, rnd() & mask);
  373. }
  374. }
  375. for (i = 4; i < 6; i++) /* regular */ {
  376. int idx = off + i * istride, p2, p1, p0, q0, q1, q2;
  377. setpx(idx, 0, q0 = rnd() & mask);
  378. setsx(idx, 1, q1 = q0, I[bidx]);
  379. setsx(idx, 2, q2 = q1, I[bidx]);
  380. setsx(idx, 3, q2, I[bidx]);
  381. setsx(idx, -1, p0 = q0, E[bidx] >> 2);
  382. setsx(idx, -2, p1 = p0, I[bidx]);
  383. setsx(idx, -3, p2 = p1, I[bidx]);
  384. setsx(idx, -4, p2, I[bidx]);
  385. for (j = 4; j < 8; j++) {
  386. setpx(idx, -1 - j, rnd() & mask);
  387. setpx(idx, j, rnd() & mask);
  388. }
  389. }
  390. for (i = 6; i < 8; i++) /* off */ {
  391. int idx = off + i * istride;
  392. for (j = 0; j < 8; j++) {
  393. setpx(idx, -1 - j, rnd() & mask);
  394. setpx(idx, j, rnd() & mask);
  395. }
  396. }
  397. }
  398. #define randomize_buffers(bidx, lineoff, str) \
  399. randomize_loopfilter_buffers(bidx, lineoff, str, bit_depth, dir, \
  400. E, F, H, I, buf0, buf1)
  401. static void check_loopfilter(void)
  402. {
  403. LOCAL_ALIGNED_32(uint8_t, base0, [32 + 16 * 16 * 2]);
  404. LOCAL_ALIGNED_32(uint8_t, base1, [32 + 16 * 16 * 2]);
  405. VP9DSPContext dsp;
  406. int dir, wd, wd2, bit_depth;
  407. static const char *const dir_name[2] = { "h", "v" };
  408. static const int E[2] = { 20, 28 }, I[2] = { 10, 16 };
  409. static const int H[2] = { 7, 11 }, F[2] = { 1, 1 };
  410. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride, int E, int I, int H);
  411. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  412. ff_vp9dsp_init(&dsp, bit_depth, 0);
  413. for (dir = 0; dir < 2; dir++) {
  414. int midoff = (dir ? 8 * 8 : 8) * SIZEOF_PIXEL;
  415. int midoff_aligned = (dir ? 8 * 8 : 16) * SIZEOF_PIXEL;
  416. uint8_t *buf0 = base0 + midoff_aligned;
  417. uint8_t *buf1 = base1 + midoff_aligned;
  418. for (wd = 0; wd < 3; wd++) {
  419. // 4/8/16wd_8px
  420. if (check_func(dsp.loop_filter_8[wd][dir],
  421. "vp9_loop_filter_%s_%d_8_%dbpp",
  422. dir_name[dir], 4 << wd, bit_depth)) {
  423. randomize_buffers(0, 0, 8);
  424. memcpy(buf1 - midoff, buf0 - midoff,
  425. 16 * 8 * SIZEOF_PIXEL);
  426. call_ref(buf0, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]);
  427. call_new(buf1, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]);
  428. if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 8 * SIZEOF_PIXEL))
  429. fail();
  430. bench_new(buf1, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]);
  431. }
  432. }
  433. midoff = (dir ? 16 * 8 : 8) * SIZEOF_PIXEL;
  434. midoff_aligned = (dir ? 16 * 8 : 16) * SIZEOF_PIXEL;
  435. buf0 = base0 + midoff_aligned;
  436. buf1 = base1 + midoff_aligned;
  437. // 16wd_16px loopfilter
  438. if (check_func(dsp.loop_filter_16[dir],
  439. "vp9_loop_filter_%s_16_16_%dbpp",
  440. dir_name[dir], bit_depth)) {
  441. randomize_buffers(0, 0, 16);
  442. randomize_buffers(0, 8, 16);
  443. memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 * SIZEOF_PIXEL);
  444. call_ref(buf0, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]);
  445. call_new(buf1, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]);
  446. if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 * SIZEOF_PIXEL))
  447. fail();
  448. bench_new(buf1, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]);
  449. }
  450. for (wd = 0; wd < 2; wd++) {
  451. for (wd2 = 0; wd2 < 2; wd2++) {
  452. // mix2 loopfilter
  453. if (check_func(dsp.loop_filter_mix2[wd][wd2][dir],
  454. "vp9_loop_filter_mix2_%s_%d%d_16_%dbpp",
  455. dir_name[dir], 4 << wd, 4 << wd2, bit_depth)) {
  456. randomize_buffers(0, 0, 16);
  457. randomize_buffers(1, 8, 16);
  458. memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 * SIZEOF_PIXEL);
  459. #define M(a) (((a)[1] << 8) | (a)[0])
  460. call_ref(buf0, 16 * SIZEOF_PIXEL, M(E), M(I), M(H));
  461. call_new(buf1, 16 * SIZEOF_PIXEL, M(E), M(I), M(H));
  462. if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 * SIZEOF_PIXEL))
  463. fail();
  464. bench_new(buf1, 16 * SIZEOF_PIXEL, M(E), M(I), M(H));
  465. #undef M
  466. }
  467. }
  468. }
  469. }
  470. }
  471. report("loopfilter");
  472. }
  473. #undef setsx
  474. #undef setpx
  475. #undef setdx
  476. #undef randomize_buffers
  477. #define DST_BUF_SIZE (size * size * SIZEOF_PIXEL)
  478. #define SRC_BUF_STRIDE 72
  479. #define SRC_BUF_SIZE ((size + 7) * SRC_BUF_STRIDE * SIZEOF_PIXEL)
  480. #define src (buf + 3 * SIZEOF_PIXEL * (SRC_BUF_STRIDE + 1))
  481. #define randomize_buffers() \
  482. do { \
  483. uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
  484. int k; \
  485. for (k = 0; k < SRC_BUF_SIZE; k += 4) { \
  486. uint32_t r = rnd() & mask; \
  487. AV_WN32A(buf + k, r); \
  488. } \
  489. if (op == 1) { \
  490. for (k = 0; k < DST_BUF_SIZE; k += 4) { \
  491. uint32_t r = rnd() & mask; \
  492. AV_WN32A(dst0 + k, r); \
  493. AV_WN32A(dst1 + k, r); \
  494. } \
  495. } \
  496. } while (0)
  497. static void check_mc(void)
  498. {
  499. LOCAL_ALIGNED_32(uint8_t, buf, [72 * 72 * 2]);
  500. LOCAL_ALIGNED_32(uint8_t, dst0, [64 * 64 * 2]);
  501. LOCAL_ALIGNED_32(uint8_t, dst1, [64 * 64 * 2]);
  502. VP9DSPContext dsp;
  503. int op, hsize, bit_depth, filter, dx, dy;
  504. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t dst_stride,
  505. const uint8_t *ref, ptrdiff_t ref_stride,
  506. int h, int mx, int my);
  507. static const char *const filter_names[4] = {
  508. "8tap_smooth", "8tap_regular", "8tap_sharp", "bilin"
  509. };
  510. static const char *const subpel_names[2][2] = { { "", "h" }, { "v", "hv" } };
  511. static const char *const op_names[2] = { "put", "avg" };
  512. char str[256];
  513. for (op = 0; op < 2; op++) {
  514. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  515. ff_vp9dsp_init(&dsp, bit_depth, 0);
  516. for (hsize = 0; hsize < 5; hsize++) {
  517. int size = 64 >> hsize;
  518. for (filter = 0; filter < 4; filter++) {
  519. for (dx = 0; dx < 2; dx++) {
  520. for (dy = 0; dy < 2; dy++) {
  521. if (dx || dy) {
  522. snprintf(str, sizeof(str),
  523. "%s_%s_%d%s", op_names[op],
  524. filter_names[filter], size,
  525. subpel_names[dy][dx]);
  526. } else {
  527. snprintf(str, sizeof(str),
  528. "%s%d", op_names[op], size);
  529. }
  530. if (check_func(dsp.mc[hsize][filter][op][dx][dy],
  531. "vp9_%s_%dbpp", str, bit_depth)) {
  532. int mx = dx ? 1 + (rnd() % 14) : 0;
  533. int my = dy ? 1 + (rnd() % 14) : 0;
  534. randomize_buffers();
  535. call_ref(dst0, size * SIZEOF_PIXEL,
  536. src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
  537. size, mx, my);
  538. call_new(dst1, size * SIZEOF_PIXEL,
  539. src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
  540. size, mx, my);
  541. if (memcmp(dst0, dst1, DST_BUF_SIZE))
  542. fail();
  543. // simd implementations for each filter of subpel
  544. // functions are identical
  545. if (filter >= 1 && filter <= 2) continue;
  546. // 10/12 bpp for bilin are identical
  547. if (bit_depth == 12 && filter == 3) continue;
  548. bench_new(dst1, size * SIZEOF_PIXEL,
  549. src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
  550. size, mx, my);
  551. }
  552. }
  553. }
  554. }
  555. }
  556. }
  557. }
  558. report("mc");
  559. }
  560. void checkasm_check_vp9dsp(void)
  561. {
  562. check_ipred();
  563. check_itxfm();
  564. check_loopfilter();
  565. check_mc();
  566. }