vp9dsp.c 24 KB

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