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.

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