vp8dsp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /*
  2. * Copyright (c) 2016 Martin Storsjo
  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 <string.h>
  21. #include "libavcodec/avcodec.h"
  22. #include "libavcodec/vp8dsp.h"
  23. #include "libavutil/common.h"
  24. #include "libavutil/intreadwrite.h"
  25. #include "checkasm.h"
  26. #define PIXEL_STRIDE 16
  27. #define randomize_buffers(src, dst, stride, coef) \
  28. do { \
  29. int x, y; \
  30. for (y = 0; y < 4; y++) { \
  31. AV_WN32A((src) + y * (stride), rnd()); \
  32. AV_WN32A((dst) + y * (stride), rnd()); \
  33. for (x = 0; x < 4; x++) \
  34. (coef)[y * 4 + x] = (src)[y * (stride) + x] - \
  35. (dst)[y * (stride) + x]; \
  36. } \
  37. } while (0)
  38. static void dct4x4(int16_t *coef)
  39. {
  40. int i;
  41. for (i = 0; i < 4; i++) {
  42. const int a1 = (coef[i*4 + 0] + coef[i*4 + 3]) * 8;
  43. const int b1 = (coef[i*4 + 1] + coef[i*4 + 2]) * 8;
  44. const int c1 = (coef[i*4 + 1] - coef[i*4 + 2]) * 8;
  45. const int d1 = (coef[i*4 + 0] - coef[i*4 + 3]) * 8;
  46. coef[i*4 + 0] = a1 + b1;
  47. coef[i*4 + 1] = (c1 * 2217 + d1 * 5352 + 14500) >> 12;
  48. coef[i*4 + 2] = a1 - b1;
  49. coef[i*4 + 3] = (d1 * 2217 - c1 * 5352 + 7500) >> 12;
  50. }
  51. for (i = 0; i < 4; i++) {
  52. const int a1 = coef[i + 0*4] + coef[i + 3*4];
  53. const int b1 = coef[i + 1*4] + coef[i + 2*4];
  54. const int c1 = coef[i + 1*4] - coef[i + 2*4];
  55. const int d1 = coef[i + 0*4] - coef[i + 3*4];
  56. coef[i + 0*4] = (a1 + b1 + 7) >> 4;
  57. coef[i + 1*4] = ((c1 * 2217 + d1 * 5352 + 12000) >> 16) + !!d1;
  58. coef[i + 2*4] = (a1 - b1 + 7) >> 4;
  59. coef[i + 3*4] = (d1 * 2217 - c1 * 5352 + 51000) >> 16;
  60. }
  61. }
  62. static void wht4x4(int16_t *coef)
  63. {
  64. int i;
  65. for (i = 0; i < 4; i++) {
  66. int a1 = coef[0 * 4 + i];
  67. int b1 = coef[1 * 4 + i];
  68. int c1 = coef[2 * 4 + i];
  69. int d1 = coef[3 * 4 + i];
  70. int e1;
  71. a1 += b1;
  72. d1 -= c1;
  73. e1 = (a1 - d1) >> 1;
  74. b1 = e1 - b1;
  75. c1 = e1 - c1;
  76. a1 -= c1;
  77. d1 += b1;
  78. coef[0 * 4 + i] = a1;
  79. coef[1 * 4 + i] = c1;
  80. coef[2 * 4 + i] = d1;
  81. coef[3 * 4 + i] = b1;
  82. }
  83. for (i = 0; i < 4; i++) {
  84. int a1 = coef[i * 4 + 0];
  85. int b1 = coef[i * 4 + 1];
  86. int c1 = coef[i * 4 + 2];
  87. int d1 = coef[i * 4 + 3];
  88. int e1;
  89. a1 += b1;
  90. d1 -= c1;
  91. e1 = (a1 - d1) >> 1;
  92. b1 = e1 - b1;
  93. c1 = e1 - c1;
  94. a1 -= c1;
  95. d1 += b1;
  96. coef[i * 4 + 0] = a1 * 2;
  97. coef[i * 4 + 1] = c1 * 2;
  98. coef[i * 4 + 2] = d1 * 2;
  99. coef[i * 4 + 3] = b1 * 2;
  100. }
  101. }
  102. static void check_idct(void)
  103. {
  104. LOCAL_ALIGNED_16(uint8_t, src, [4 * 4]);
  105. LOCAL_ALIGNED_16(uint8_t, dst, [4 * 4]);
  106. LOCAL_ALIGNED_16(uint8_t, dst0, [4 * 4]);
  107. LOCAL_ALIGNED_16(uint8_t, dst1, [4 * 4]);
  108. LOCAL_ALIGNED_16(int16_t, coef, [4 * 4]);
  109. LOCAL_ALIGNED_16(int16_t, subcoef0, [4 * 4]);
  110. LOCAL_ALIGNED_16(int16_t, subcoef1, [4 * 4]);
  111. VP8DSPContext d;
  112. int dc;
  113. declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t *block, ptrdiff_t stride);
  114. ff_vp8dsp_init(&d);
  115. randomize_buffers(src, dst, 4, coef);
  116. dct4x4(coef);
  117. for (dc = 0; dc <= 1; dc++) {
  118. void (*idct)(uint8_t *, int16_t *, ptrdiff_t) = dc ? d.vp8_idct_dc_add : d.vp8_idct_add;
  119. if (check_func(idct, "vp8_idct_%sadd", dc ? "dc_" : "")) {
  120. if (dc) {
  121. memset(subcoef0, 0, 4 * 4 * sizeof(int16_t));
  122. subcoef0[0] = coef[0];
  123. } else {
  124. memcpy(subcoef0, coef, 4 * 4 * sizeof(int16_t));
  125. }
  126. memcpy(dst0, dst, 4 * 4);
  127. memcpy(dst1, dst, 4 * 4);
  128. memcpy(subcoef1, subcoef0, 4 * 4 * sizeof(int16_t));
  129. // Note, this uses a pixel stride of 4, even though the real decoder uses a stride as a
  130. // multiple of 16. If optimizations want to take advantage of that, this test needs to be
  131. // updated to make it more like the h264dsp tests.
  132. call_ref(dst0, subcoef0, 4);
  133. call_new(dst1, subcoef1, 4);
  134. if (memcmp(dst0, dst1, 4 * 4) ||
  135. memcmp(subcoef0, subcoef1, 4 * 4 * sizeof(int16_t)))
  136. fail();
  137. bench_new(dst1, subcoef1, 4);
  138. }
  139. }
  140. }
  141. static void check_idct_dc4(void)
  142. {
  143. LOCAL_ALIGNED_16(uint8_t, src, [4 * 4 * 4]);
  144. LOCAL_ALIGNED_16(uint8_t, dst, [4 * 4 * 4]);
  145. LOCAL_ALIGNED_16(uint8_t, dst0, [4 * 4 * 4]);
  146. LOCAL_ALIGNED_16(uint8_t, dst1, [4 * 4 * 4]);
  147. LOCAL_ALIGNED_16(int16_t, coef, [4], [4 * 4]);
  148. LOCAL_ALIGNED_16(int16_t, subcoef0, [4], [4 * 4]);
  149. LOCAL_ALIGNED_16(int16_t, subcoef1, [4], [4 * 4]);
  150. VP8DSPContext d;
  151. int i, chroma;
  152. declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t block[4][16], ptrdiff_t stride);
  153. ff_vp8dsp_init(&d);
  154. for (chroma = 0; chroma <= 1; chroma++) {
  155. void (*idct4dc)(uint8_t *, int16_t[4][16], ptrdiff_t) = chroma ? d.vp8_idct_dc_add4uv : d.vp8_idct_dc_add4y;
  156. if (check_func(idct4dc, "vp8_idct_dc_add4%s", chroma ? "uv" : "y")) {
  157. ptrdiff_t stride = chroma ? 8 : 16;
  158. int w = chroma ? 2 : 4;
  159. for (i = 0; i < 4; i++) {
  160. int blockx = 4 * (i % w);
  161. int blocky = 4 * (i / w);
  162. randomize_buffers(src + stride * blocky + blockx, dst + stride * blocky + blockx, stride, coef[i]);
  163. dct4x4(coef[i]);
  164. memset(&coef[i][1], 0, 15 * sizeof(int16_t));
  165. }
  166. memcpy(dst0, dst, 4 * 4 * 4);
  167. memcpy(dst1, dst, 4 * 4 * 4);
  168. memcpy(subcoef0, coef, 4 * 4 * 4 * sizeof(int16_t));
  169. memcpy(subcoef1, coef, 4 * 4 * 4 * sizeof(int16_t));
  170. call_ref(dst0, subcoef0, stride);
  171. call_new(dst1, subcoef1, stride);
  172. if (memcmp(dst0, dst1, 4 * 4 * 4) ||
  173. memcmp(subcoef0, subcoef1, 4 * 4 * 4 * sizeof(int16_t)))
  174. fail();
  175. bench_new(dst1, subcoef1, stride);
  176. }
  177. }
  178. }
  179. static void check_luma_dc_wht(void)
  180. {
  181. LOCAL_ALIGNED_16(int16_t, dc, [4 * 4]);
  182. LOCAL_ALIGNED_16(int16_t, dc0, [4 * 4]);
  183. LOCAL_ALIGNED_16(int16_t, dc1, [4 * 4]);
  184. int16_t block[4][4][16];
  185. LOCAL_ALIGNED_16(int16_t, block0, [4], [4][16]);
  186. LOCAL_ALIGNED_16(int16_t, block1, [4], [4][16]);
  187. VP8DSPContext d;
  188. int dc_only;
  189. int blockx, blocky;
  190. declare_func_emms(AV_CPU_FLAG_MMX, void, int16_t block[4][4][16], int16_t dc[16]);
  191. ff_vp8dsp_init(&d);
  192. for (blocky = 0; blocky < 4; blocky++) {
  193. for (blockx = 0; blockx < 4; blockx++) {
  194. uint8_t src[16], dst[16];
  195. randomize_buffers(src, dst, 4, block[blocky][blockx]);
  196. dct4x4(block[blocky][blockx]);
  197. dc[blocky * 4 + blockx] = block[blocky][blockx][0];
  198. block[blocky][blockx][0] = rnd();
  199. }
  200. }
  201. wht4x4(dc);
  202. for (dc_only = 0; dc_only <= 1; dc_only++) {
  203. void (*idct)(int16_t [4][4][16], int16_t [16]) = dc_only ? d.vp8_luma_dc_wht_dc : d.vp8_luma_dc_wht;
  204. if (check_func(idct, "vp8_luma_dc_wht%s", dc_only ? "_dc" : "")) {
  205. if (dc_only) {
  206. memset(dc0, 0, 16 * sizeof(int16_t));
  207. dc0[0] = dc[0];
  208. } else {
  209. memcpy(dc0, dc, 16 * sizeof(int16_t));
  210. }
  211. memcpy(dc1, dc0, 16 * sizeof(int16_t));
  212. memcpy(block0, block, 4 * 4 * 16 * sizeof(int16_t));
  213. memcpy(block1, block, 4 * 4 * 16 * sizeof(int16_t));
  214. call_ref(block0, dc0);
  215. call_new(block1, dc1);
  216. if (memcmp(block0, block1, 4 * 4 * 16 * sizeof(int16_t)) ||
  217. memcmp(dc0, dc1, 16 * sizeof(int16_t)))
  218. fail();
  219. bench_new(block1, dc1);
  220. }
  221. }
  222. }
  223. #define SRC_BUF_STRIDE 32
  224. #define SRC_BUF_SIZE (((size << (size < 16)) + 5) * SRC_BUF_STRIDE)
  225. // The mc subpixel interpolation filter needs the 2 previous pixels in either
  226. // direction, the +1 is to make sure the actual load addresses always are
  227. // unaligned.
  228. #define src (buf + 2 * SRC_BUF_STRIDE + 2 + 1)
  229. #undef randomize_buffers
  230. #define randomize_buffers() \
  231. do { \
  232. int k; \
  233. for (k = 0; k < SRC_BUF_SIZE; k += 4) { \
  234. AV_WN32A(buf + k, rnd()); \
  235. } \
  236. } while (0)
  237. static void check_mc(void)
  238. {
  239. LOCAL_ALIGNED_16(uint8_t, buf, [32 * 32]);
  240. LOCAL_ALIGNED_16(uint8_t, dst0, [16 * 16]);
  241. LOCAL_ALIGNED_16(uint8_t, dst1, [16 * 16]);
  242. VP8DSPContext d;
  243. int type, k, dx, dy;
  244. declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *, ptrdiff_t, uint8_t *, ptrdiff_t, int, int, int);
  245. ff_vp78dsp_init(&d);
  246. for (type = 0; type < 2; type++) {
  247. vp8_mc_func (*tab)[3][3] = type ? d.put_vp8_bilinear_pixels_tab : d.put_vp8_epel_pixels_tab;
  248. for (k = 1; k < 8; k++) {
  249. int hsize = k / 3;
  250. int size = 16 >> hsize;
  251. int height = (size << 1) >> (k % 3);
  252. for (dy = 0; dy < 3; dy++) {
  253. for (dx = 0; dx < 3; dx++) {
  254. char str[100];
  255. if (dx || dy) {
  256. if (type == 0) {
  257. static const char *dx_names[] = { "", "h4", "h6" };
  258. static const char *dy_names[] = { "", "v4", "v6" };
  259. snprintf(str, sizeof(str), "epel%d_%s%s", size, dx_names[dx], dy_names[dy]);
  260. } else {
  261. snprintf(str, sizeof(str), "bilin%d_%s%s", size, dx ? "h" : "", dy ? "v" : "");
  262. }
  263. } else {
  264. snprintf(str, sizeof(str), "pixels%d", size);
  265. }
  266. if (check_func(tab[hsize][dy][dx], "vp8_put_%s", str)) {
  267. int mx, my;
  268. int i;
  269. if (type == 0) {
  270. mx = dx == 2 ? 2 + 2 * (rnd() % 3) : dx == 1 ? 1 + 2 * (rnd() % 4) : 0;
  271. my = dy == 2 ? 2 + 2 * (rnd() % 3) : dy == 1 ? 1 + 2 * (rnd() % 4) : 0;
  272. } else {
  273. mx = dx ? 1 + (rnd() % 7) : 0;
  274. my = dy ? 1 + (rnd() % 7) : 0;
  275. }
  276. randomize_buffers();
  277. for (i = -2; i <= 3; i++) {
  278. int val = (i == -1 || i == 2) ? 0 : 0xff;
  279. // Set pixels in the first row and column to the maximum pattern,
  280. // to test for potential overflows in the filter.
  281. src[i ] = val;
  282. src[i * SRC_BUF_STRIDE] = val;
  283. }
  284. call_ref(dst0, size, src, SRC_BUF_STRIDE, height, mx, my);
  285. call_new(dst1, size, src, SRC_BUF_STRIDE, height, mx, my);
  286. if (memcmp(dst0, dst1, size * height))
  287. fail();
  288. bench_new(dst1, size, src, SRC_BUF_STRIDE, height, mx, my);
  289. }
  290. }
  291. }
  292. }
  293. }
  294. }
  295. #undef randomize_buffers
  296. #define setpx(a, b, c) buf[(a) + (b) * jstride] = av_clip_uint8(c)
  297. // Set the pixel to c +/- [0,d]
  298. #define setdx(a, b, c, d) setpx(a, b, c - (d) + (rnd() % ((d) * 2 + 1)))
  299. // Set the pixel to c +/- [d,d+e] (making sure it won't be clipped)
  300. #define setdx2(a, b, o, c, d, e) setpx(a, b, o = c + ((d) + (rnd() % (e))) * (c >= 128 ? -1 : 1))
  301. static void randomize_loopfilter_buffers(int lineoff, int str,
  302. int dir, int flim_E, int flim_I,
  303. int hev_thresh, uint8_t *buf,
  304. int force_hev)
  305. {
  306. uint32_t mask = 0xff;
  307. int off = dir ? lineoff : lineoff * str;
  308. int istride = dir ? 1 : str;
  309. int jstride = dir ? str : 1;
  310. int i;
  311. for (i = 0; i < 8; i += 2) {
  312. // Row 0 will trigger hev for q0/q1, row 2 will trigger hev for p0/p1,
  313. // rows 4 and 6 will not trigger hev.
  314. // force_hev 1 will make sure all rows trigger hev, while force_hev -1
  315. // makes none of them trigger it.
  316. int idx = off + i * istride, p2, p1, p0, q0, q1, q2;
  317. setpx(idx, 0, q0 = rnd() & mask);
  318. if (i == 0 && force_hev >= 0 || force_hev > 0)
  319. setdx2(idx, 1, q1, q0, hev_thresh + 1, flim_I - hev_thresh - 1);
  320. else
  321. setdx(idx, 1, q1 = q0, hev_thresh);
  322. setdx(idx, 2, q2 = q1, flim_I);
  323. setdx(idx, 3, q2, flim_I);
  324. setdx(idx, -1, p0 = q0, flim_E >> 2);
  325. if (i == 2 && force_hev >= 0 || force_hev > 0)
  326. setdx2(idx, -2, p1, p0, hev_thresh + 1, flim_I - hev_thresh - 1);
  327. else
  328. setdx(idx, -2, p1 = p0, hev_thresh);
  329. setdx(idx, -3, p2 = p1, flim_I);
  330. setdx(idx, -4, p2, flim_I);
  331. }
  332. }
  333. // Fill the buffer with random pixels
  334. static void fill_loopfilter_buffers(uint8_t *buf, ptrdiff_t stride, int w, int h)
  335. {
  336. int x, y;
  337. for (y = 0; y < h; y++)
  338. for (x = 0; x < w; x++)
  339. buf[y * stride + x] = rnd() & 0xff;
  340. }
  341. #define randomize_buffers(buf, lineoff, str, force_hev) \
  342. randomize_loopfilter_buffers(lineoff, str, dir, flim_E, flim_I, hev_thresh, buf, force_hev)
  343. static void check_loopfilter_16y(void)
  344. {
  345. LOCAL_ALIGNED_16(uint8_t, base0, [32 + 16 * 16]);
  346. LOCAL_ALIGNED_16(uint8_t, base1, [32 + 16 * 16]);
  347. VP8DSPContext d;
  348. int dir, edge, force_hev;
  349. int flim_E = 20, flim_I = 10, hev_thresh = 7;
  350. declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *, ptrdiff_t, int, int, int);
  351. ff_vp8dsp_init(&d);
  352. for (dir = 0; dir < 2; dir++) {
  353. int midoff = dir ? 4 * 16 : 4;
  354. int midoff_aligned = dir ? 4 * 16 : 16;
  355. uint8_t *buf0 = base0 + midoff_aligned;
  356. uint8_t *buf1 = base1 + midoff_aligned;
  357. for (edge = 0; edge < 2; edge++) {
  358. void (*func)(uint8_t *, ptrdiff_t, int, int, int) = NULL;
  359. switch (dir << 1 | edge) {
  360. case (0 << 1) | 0: func = d.vp8_h_loop_filter16y; break;
  361. case (1 << 1) | 0: func = d.vp8_v_loop_filter16y; break;
  362. case (0 << 1) | 1: func = d.vp8_h_loop_filter16y_inner; break;
  363. case (1 << 1) | 1: func = d.vp8_v_loop_filter16y_inner; break;
  364. }
  365. if (check_func(func, "vp8_loop_filter16y%s_%s", edge ? "_inner" : "", dir ? "v" : "h")) {
  366. for (force_hev = -1; force_hev <= 1; force_hev++) {
  367. fill_loopfilter_buffers(buf0 - midoff, 16, 16, 16);
  368. randomize_buffers(buf0, 0, 16, force_hev);
  369. randomize_buffers(buf0, 8, 16, force_hev);
  370. memcpy(buf1 - midoff, buf0 - midoff, 16 * 16);
  371. call_ref(buf0, 16, flim_E, flim_I, hev_thresh);
  372. call_new(buf1, 16, flim_E, flim_I, hev_thresh);
  373. if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16))
  374. fail();
  375. }
  376. fill_loopfilter_buffers(buf0 - midoff, 16, 16, 16);
  377. randomize_buffers(buf0, 0, 16, 0);
  378. randomize_buffers(buf0, 8, 16, 0);
  379. bench_new(buf0, 16, flim_E, flim_I, hev_thresh);
  380. }
  381. }
  382. }
  383. }
  384. static void check_loopfilter_8uv(void)
  385. {
  386. LOCAL_ALIGNED_16(uint8_t, base0u, [32 + 16 * 16]);
  387. LOCAL_ALIGNED_16(uint8_t, base0v, [32 + 16 * 16]);
  388. LOCAL_ALIGNED_16(uint8_t, base1u, [32 + 16 * 16]);
  389. LOCAL_ALIGNED_16(uint8_t, base1v, [32 + 16 * 16]);
  390. VP8DSPContext d;
  391. int dir, edge, force_hev;
  392. int flim_E = 20, flim_I = 10, hev_thresh = 7;
  393. declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *, uint8_t *, ptrdiff_t, int, int, int);
  394. ff_vp8dsp_init(&d);
  395. for (dir = 0; dir < 2; dir++) {
  396. int midoff = dir ? 4 * 16 : 4;
  397. int midoff_aligned = dir ? 4 * 16 : 16;
  398. uint8_t *buf0u = base0u + midoff_aligned;
  399. uint8_t *buf0v = base0v + midoff_aligned;
  400. uint8_t *buf1u = base1u + midoff_aligned;
  401. uint8_t *buf1v = base1v + midoff_aligned;
  402. for (edge = 0; edge < 2; edge++) {
  403. void (*func)(uint8_t *, uint8_t *, ptrdiff_t, int, int, int) = NULL;
  404. switch (dir << 1 | edge) {
  405. case (0 << 1) | 0: func = d.vp8_h_loop_filter8uv; break;
  406. case (1 << 1) | 0: func = d.vp8_v_loop_filter8uv; break;
  407. case (0 << 1) | 1: func = d.vp8_h_loop_filter8uv_inner; break;
  408. case (1 << 1) | 1: func = d.vp8_v_loop_filter8uv_inner; break;
  409. }
  410. if (check_func(func, "vp8_loop_filter8uv%s_%s", edge ? "_inner" : "", dir ? "v" : "h")) {
  411. for (force_hev = -1; force_hev <= 1; force_hev++) {
  412. fill_loopfilter_buffers(buf0u - midoff, 16, 16, 16);
  413. fill_loopfilter_buffers(buf0v - midoff, 16, 16, 16);
  414. randomize_buffers(buf0u, 0, 16, force_hev);
  415. randomize_buffers(buf0v, 0, 16, force_hev);
  416. memcpy(buf1u - midoff, buf0u - midoff, 16 * 16);
  417. memcpy(buf1v - midoff, buf0v - midoff, 16 * 16);
  418. call_ref(buf0u, buf0v, 16, flim_E, flim_I, hev_thresh);
  419. call_new(buf1u, buf1v, 16, flim_E, flim_I, hev_thresh);
  420. if (memcmp(buf0u - midoff, buf1u - midoff, 16 * 16) ||
  421. memcmp(buf0v - midoff, buf1v - midoff, 16 * 16))
  422. fail();
  423. }
  424. fill_loopfilter_buffers(buf0u - midoff, 16, 16, 16);
  425. fill_loopfilter_buffers(buf0v - midoff, 16, 16, 16);
  426. randomize_buffers(buf0u, 0, 16, 0);
  427. randomize_buffers(buf0v, 0, 16, 0);
  428. bench_new(buf0u, buf0v, 16, flim_E, flim_I, hev_thresh);
  429. }
  430. }
  431. }
  432. }
  433. static void check_loopfilter_simple(void)
  434. {
  435. LOCAL_ALIGNED_16(uint8_t, base0, [32 + 16 * 16]);
  436. LOCAL_ALIGNED_16(uint8_t, base1, [32 + 16 * 16]);
  437. VP8DSPContext d;
  438. int dir;
  439. int flim_E = 20, flim_I = 30, hev_thresh = 0;
  440. declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *, ptrdiff_t, int);
  441. ff_vp8dsp_init(&d);
  442. for (dir = 0; dir < 2; dir++) {
  443. int midoff = dir ? 4 * 16 : 4;
  444. int midoff_aligned = dir ? 4 * 16 : 16;
  445. uint8_t *buf0 = base0 + midoff_aligned;
  446. uint8_t *buf1 = base1 + midoff_aligned;
  447. void (*func)(uint8_t *, ptrdiff_t, int) = dir ? d.vp8_v_loop_filter_simple : d.vp8_h_loop_filter_simple;
  448. if (check_func(func, "vp8_loop_filter_simple_%s", dir ? "v" : "h")) {
  449. fill_loopfilter_buffers(buf0 - midoff, 16, 16, 16);
  450. randomize_buffers(buf0, 0, 16, -1);
  451. randomize_buffers(buf0, 8, 16, -1);
  452. memcpy(buf1 - midoff, buf0 - midoff, 16 * 16);
  453. call_ref(buf0, 16, flim_E);
  454. call_new(buf1, 16, flim_E);
  455. if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16))
  456. fail();
  457. bench_new(buf0, 16, flim_E);
  458. }
  459. }
  460. }
  461. void checkasm_check_vp8dsp(void)
  462. {
  463. check_idct();
  464. check_idct_dc4();
  465. check_luma_dc_wht();
  466. report("idct");
  467. check_mc();
  468. report("mc");
  469. check_loopfilter_16y();
  470. check_loopfilter_8uv();
  471. check_loopfilter_simple();
  472. report("loopfilter");
  473. }