vp9dsp.c 23 KB

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