vp9dsp.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. 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 = ff_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. Test sub=1 for dc-only, then 2, 4, 8, 12, etc,
  299. // since the arm version can distinguish them at that level.
  300. for (sub = (txtp == 0 && tx < 4) ? 1 : sz; sub <= sz;
  301. sub < 4 ? (sub <<= 1) : (sub += 4)) {
  302. if (check_func(dsp.itxfm_add[tx][txtp],
  303. "vp9_inv_%s_%dx%d_sub%d_add_%d",
  304. tx == 4 ? "wht_wht" : txtp_types[txtp],
  305. sz, sz, sub, bit_depth)) {
  306. int eob;
  307. randomize_buffers();
  308. ftx(coef, tx, txtp, sz, bit_depth);
  309. if (sub < sz) {
  310. eob = copy_subcoefs(subcoef0, coef, tx, txtp,
  311. sz, sub, bit_depth);
  312. } else {
  313. eob = sz * sz;
  314. memcpy(subcoef0, coef, sz * sz * SIZEOF_COEF);
  315. }
  316. memcpy(dst0, dst, sz * sz * SIZEOF_PIXEL);
  317. memcpy(dst1, dst, sz * sz * SIZEOF_PIXEL);
  318. memcpy(subcoef1, subcoef0, sz * sz * SIZEOF_COEF);
  319. call_ref(dst0, sz * SIZEOF_PIXEL, subcoef0, eob);
  320. call_new(dst1, sz * SIZEOF_PIXEL, subcoef1, eob);
  321. if (memcmp(dst0, dst1, sz * sz * SIZEOF_PIXEL) ||
  322. !iszero(subcoef0, sz * sz * SIZEOF_COEF) ||
  323. !iszero(subcoef1, sz * sz * SIZEOF_COEF))
  324. fail();
  325. bench_new(dst, sz * SIZEOF_PIXEL, coef, eob);
  326. }
  327. }
  328. }
  329. }
  330. }
  331. report("itxfm");
  332. }
  333. #undef randomize_buffers
  334. #define setpx(a,b,c) \
  335. do { \
  336. if (SIZEOF_PIXEL == 1) { \
  337. buf0[(a) + (b) * jstride] = av_clip_uint8(c); \
  338. } else { \
  339. ((uint16_t *)buf0)[(a) + (b) * jstride] = av_clip_uintp2(c, bit_depth); \
  340. } \
  341. } while (0)
  342. // c can be an assignment and must not be put under ()
  343. #define setdx(a,b,c,d) setpx(a,b,c-(d)+(rnd()%((d)*2+1)))
  344. #define setsx(a,b,c,d) setdx(a,b,c,(d) << (bit_depth - 8))
  345. static void randomize_loopfilter_buffers(int bidx, int lineoff, int str,
  346. int bit_depth, int dir, const int *E,
  347. const int *F, const int *H, const int *I,
  348. uint8_t *buf0, uint8_t *buf1)
  349. {
  350. uint32_t mask = (1 << bit_depth) - 1;
  351. int off = dir ? lineoff : lineoff * 16;
  352. int istride = dir ? 1 : 16;
  353. int jstride = dir ? str : 1;
  354. int i, j;
  355. for (i = 0; i < 2; i++) /* flat16 */ {
  356. int idx = off + i * istride, p0, q0;
  357. setpx(idx, 0, q0 = rnd() & mask);
  358. setsx(idx, -1, p0 = q0, E[bidx] >> 2);
  359. for (j = 1; j < 8; j++) {
  360. setsx(idx, -1 - j, p0, F[bidx]);
  361. setsx(idx, j, q0, F[bidx]);
  362. }
  363. }
  364. for (i = 2; i < 4; i++) /* flat8 */ {
  365. int idx = off + i * istride, p0, q0;
  366. setpx(idx, 0, q0 = rnd() & mask);
  367. setsx(idx, -1, p0 = q0, E[bidx] >> 2);
  368. for (j = 1; j < 4; j++) {
  369. setsx(idx, -1 - j, p0, F[bidx]);
  370. setsx(idx, j, q0, F[bidx]);
  371. }
  372. for (j = 4; j < 8; j++) {
  373. setpx(idx, -1 - j, rnd() & mask);
  374. setpx(idx, j, rnd() & mask);
  375. }
  376. }
  377. for (i = 4; i < 6; i++) /* regular */ {
  378. int idx = off + i * istride, p2, p1, p0, q0, q1, q2;
  379. setpx(idx, 0, q0 = rnd() & mask);
  380. setsx(idx, 1, q1 = q0, I[bidx]);
  381. setsx(idx, 2, q2 = q1, I[bidx]);
  382. setsx(idx, 3, q2, I[bidx]);
  383. setsx(idx, -1, p0 = q0, E[bidx] >> 2);
  384. setsx(idx, -2, p1 = p0, I[bidx]);
  385. setsx(idx, -3, p2 = p1, I[bidx]);
  386. setsx(idx, -4, p2, I[bidx]);
  387. for (j = 4; j < 8; j++) {
  388. setpx(idx, -1 - j, rnd() & mask);
  389. setpx(idx, j, rnd() & mask);
  390. }
  391. }
  392. for (i = 6; i < 8; i++) /* off */ {
  393. int idx = off + i * istride;
  394. for (j = 0; j < 8; j++) {
  395. setpx(idx, -1 - j, rnd() & mask);
  396. setpx(idx, j, rnd() & mask);
  397. }
  398. }
  399. }
  400. #define randomize_buffers(bidx, lineoff, str) \
  401. randomize_loopfilter_buffers(bidx, lineoff, str, bit_depth, dir, \
  402. E, F, H, I, buf0, buf1)
  403. static void check_loopfilter(void)
  404. {
  405. LOCAL_ALIGNED_32(uint8_t, base0, [32 + 16 * 16 * 2]);
  406. LOCAL_ALIGNED_32(uint8_t, base1, [32 + 16 * 16 * 2]);
  407. VP9DSPContext dsp;
  408. int dir, wd, wd2, bit_depth;
  409. static const char *const dir_name[2] = { "h", "v" };
  410. static const int E[2] = { 20, 28 }, I[2] = { 10, 16 };
  411. static const int H[2] = { 7, 11 }, F[2] = { 1, 1 };
  412. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride, int E, int I, int H);
  413. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  414. ff_vp9dsp_init(&dsp, bit_depth, 0);
  415. for (dir = 0; dir < 2; dir++) {
  416. int midoff = (dir ? 8 * 8 : 8) * SIZEOF_PIXEL;
  417. int midoff_aligned = (dir ? 8 * 8 : 16) * SIZEOF_PIXEL;
  418. uint8_t *buf0 = base0 + midoff_aligned;
  419. uint8_t *buf1 = base1 + midoff_aligned;
  420. for (wd = 0; wd < 3; wd++) {
  421. // 4/8/16wd_8px
  422. if (check_func(dsp.loop_filter_8[wd][dir],
  423. "vp9_loop_filter_%s_%d_8_%dbpp",
  424. dir_name[dir], 4 << wd, bit_depth)) {
  425. randomize_buffers(0, 0, 8);
  426. memcpy(buf1 - midoff, buf0 - midoff,
  427. 16 * 8 * SIZEOF_PIXEL);
  428. call_ref(buf0, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]);
  429. call_new(buf1, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]);
  430. if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 8 * SIZEOF_PIXEL))
  431. fail();
  432. bench_new(buf1, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]);
  433. }
  434. }
  435. midoff = (dir ? 16 * 8 : 8) * SIZEOF_PIXEL;
  436. midoff_aligned = (dir ? 16 * 8 : 16) * SIZEOF_PIXEL;
  437. buf0 = base0 + midoff_aligned;
  438. buf1 = base1 + midoff_aligned;
  439. // 16wd_16px loopfilter
  440. if (check_func(dsp.loop_filter_16[dir],
  441. "vp9_loop_filter_%s_16_16_%dbpp",
  442. dir_name[dir], bit_depth)) {
  443. randomize_buffers(0, 0, 16);
  444. randomize_buffers(0, 8, 16);
  445. memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 * SIZEOF_PIXEL);
  446. call_ref(buf0, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]);
  447. call_new(buf1, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]);
  448. if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 * SIZEOF_PIXEL))
  449. fail();
  450. bench_new(buf1, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]);
  451. }
  452. for (wd = 0; wd < 2; wd++) {
  453. for (wd2 = 0; wd2 < 2; wd2++) {
  454. // mix2 loopfilter
  455. if (check_func(dsp.loop_filter_mix2[wd][wd2][dir],
  456. "vp9_loop_filter_mix2_%s_%d%d_16_%dbpp",
  457. dir_name[dir], 4 << wd, 4 << wd2, bit_depth)) {
  458. randomize_buffers(0, 0, 16);
  459. randomize_buffers(1, 8, 16);
  460. memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 * SIZEOF_PIXEL);
  461. #define M(a) (((a)[1] << 8) | (a)[0])
  462. call_ref(buf0, 16 * SIZEOF_PIXEL, M(E), M(I), M(H));
  463. call_new(buf1, 16 * SIZEOF_PIXEL, M(E), M(I), M(H));
  464. if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 * SIZEOF_PIXEL))
  465. fail();
  466. bench_new(buf1, 16 * SIZEOF_PIXEL, M(E), M(I), M(H));
  467. #undef M
  468. }
  469. }
  470. }
  471. }
  472. }
  473. report("loopfilter");
  474. }
  475. #undef setsx
  476. #undef setpx
  477. #undef setdx
  478. #undef randomize_buffers
  479. #define DST_BUF_SIZE (size * size * SIZEOF_PIXEL)
  480. #define SRC_BUF_STRIDE 72
  481. #define SRC_BUF_SIZE ((size + 7) * SRC_BUF_STRIDE * SIZEOF_PIXEL)
  482. #define src (buf + 3 * SIZEOF_PIXEL * (SRC_BUF_STRIDE + 1))
  483. #define randomize_buffers() \
  484. do { \
  485. uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
  486. int k; \
  487. for (k = 0; k < SRC_BUF_SIZE; k += 4) { \
  488. uint32_t r = rnd() & mask; \
  489. AV_WN32A(buf + k, r); \
  490. } \
  491. if (op == 1) { \
  492. for (k = 0; k < DST_BUF_SIZE; k += 4) { \
  493. uint32_t r = rnd() & mask; \
  494. AV_WN32A(dst0 + k, r); \
  495. AV_WN32A(dst1 + k, r); \
  496. } \
  497. } \
  498. } while (0)
  499. static void check_mc(void)
  500. {
  501. LOCAL_ALIGNED_32(uint8_t, buf, [72 * 72 * 2]);
  502. LOCAL_ALIGNED_32(uint8_t, dst0, [64 * 64 * 2]);
  503. LOCAL_ALIGNED_32(uint8_t, dst1, [64 * 64 * 2]);
  504. VP9DSPContext dsp;
  505. int op, hsize, bit_depth, filter, dx, dy;
  506. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t dst_stride,
  507. const uint8_t *ref, ptrdiff_t ref_stride,
  508. int h, int mx, int my);
  509. static const char *const filter_names[4] = {
  510. "8tap_smooth", "8tap_regular", "8tap_sharp", "bilin"
  511. };
  512. static const char *const subpel_names[2][2] = { { "", "h" }, { "v", "hv" } };
  513. static const char *const op_names[2] = { "put", "avg" };
  514. char str[256];
  515. for (op = 0; op < 2; op++) {
  516. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  517. ff_vp9dsp_init(&dsp, bit_depth, 0);
  518. for (hsize = 0; hsize < 5; hsize++) {
  519. int size = 64 >> hsize;
  520. for (filter = 0; filter < 4; filter++) {
  521. for (dx = 0; dx < 2; dx++) {
  522. for (dy = 0; dy < 2; dy++) {
  523. if (dx || dy) {
  524. snprintf(str, sizeof(str),
  525. "%s_%s_%d%s", op_names[op],
  526. filter_names[filter], size,
  527. subpel_names[dy][dx]);
  528. } else {
  529. snprintf(str, sizeof(str),
  530. "%s%d", op_names[op], size);
  531. }
  532. if (check_func(dsp.mc[hsize][filter][op][dx][dy],
  533. "vp9_%s_%dbpp", str, bit_depth)) {
  534. int mx = dx ? 1 + (rnd() % 14) : 0;
  535. int my = dy ? 1 + (rnd() % 14) : 0;
  536. randomize_buffers();
  537. call_ref(dst0, size * SIZEOF_PIXEL,
  538. src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
  539. size, mx, my);
  540. call_new(dst1, size * SIZEOF_PIXEL,
  541. src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
  542. size, mx, my);
  543. if (memcmp(dst0, dst1, DST_BUF_SIZE))
  544. fail();
  545. // simd implementations for each filter of subpel
  546. // functions are identical
  547. if (filter >= 1 && filter <= 2) continue;
  548. // 10/12 bpp for bilin are identical
  549. if (bit_depth == 12 && filter == 3) continue;
  550. bench_new(dst1, size * SIZEOF_PIXEL,
  551. src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
  552. size, mx, my);
  553. }
  554. }
  555. }
  556. }
  557. }
  558. }
  559. }
  560. report("mc");
  561. }
  562. void checkasm_check_vp9dsp(void)
  563. {
  564. check_ipred();
  565. check_itxfm();
  566. check_loopfilter();
  567. check_mc();
  568. }