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.

2547 lines
85KB

  1. /*
  2. * VP9 compatible video decoder
  3. *
  4. * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
  5. * Copyright (C) 2013 Clément Bœsch <u pkh me>
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include "libavutil/common.h"
  24. #include "bit_depth_template.c"
  25. #include "vp9dsp.h"
  26. #if BIT_DEPTH != 12
  27. // FIXME see whether we can merge parts of this (perhaps at least 4x4 and 8x8)
  28. // back with h264pred.[ch]
  29. static void vert_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  30. const uint8_t *left, const uint8_t *_top)
  31. {
  32. pixel *dst = (pixel *) _dst;
  33. const pixel *top = (const pixel *) _top;
  34. pixel4 p4 = AV_RN4PA(top);
  35. stride /= sizeof(pixel);
  36. AV_WN4PA(dst + stride * 0, p4);
  37. AV_WN4PA(dst + stride * 1, p4);
  38. AV_WN4PA(dst + stride * 2, p4);
  39. AV_WN4PA(dst + stride * 3, p4);
  40. }
  41. static void vert_8x8_c(uint8_t *_dst, ptrdiff_t stride,
  42. const uint8_t *left, const uint8_t *_top)
  43. {
  44. pixel *dst = (pixel *) _dst;
  45. const pixel *top = (const pixel *) _top;
  46. pixel4 p4a = AV_RN4PA(top + 0);
  47. pixel4 p4b = AV_RN4PA(top + 4);
  48. int y;
  49. stride /= sizeof(pixel);
  50. for (y = 0; y < 8; y++) {
  51. AV_WN4PA(dst + 0, p4a);
  52. AV_WN4PA(dst + 4, p4b);
  53. dst += stride;
  54. }
  55. }
  56. static void vert_16x16_c(uint8_t *_dst, ptrdiff_t stride,
  57. const uint8_t *left, const uint8_t *_top)
  58. {
  59. pixel *dst = (pixel *) _dst;
  60. const pixel *top = (const pixel *) _top;
  61. pixel4 p4a = AV_RN4PA(top + 0);
  62. pixel4 p4b = AV_RN4PA(top + 4);
  63. pixel4 p4c = AV_RN4PA(top + 8);
  64. pixel4 p4d = AV_RN4PA(top + 12);
  65. int y;
  66. stride /= sizeof(pixel);
  67. for (y = 0; y < 16; y++) {
  68. AV_WN4PA(dst + 0, p4a);
  69. AV_WN4PA(dst + 4, p4b);
  70. AV_WN4PA(dst + 8, p4c);
  71. AV_WN4PA(dst + 12, p4d);
  72. dst += stride;
  73. }
  74. }
  75. static void vert_32x32_c(uint8_t *_dst, ptrdiff_t stride,
  76. const uint8_t *left, const uint8_t *_top)
  77. {
  78. pixel *dst = (pixel *) _dst;
  79. const pixel *top = (const pixel *) _top;
  80. pixel4 p4a = AV_RN4PA(top + 0);
  81. pixel4 p4b = AV_RN4PA(top + 4);
  82. pixel4 p4c = AV_RN4PA(top + 8);
  83. pixel4 p4d = AV_RN4PA(top + 12);
  84. pixel4 p4e = AV_RN4PA(top + 16);
  85. pixel4 p4f = AV_RN4PA(top + 20);
  86. pixel4 p4g = AV_RN4PA(top + 24);
  87. pixel4 p4h = AV_RN4PA(top + 28);
  88. int y;
  89. stride /= sizeof(pixel);
  90. for (y = 0; y < 32; y++) {
  91. AV_WN4PA(dst + 0, p4a);
  92. AV_WN4PA(dst + 4, p4b);
  93. AV_WN4PA(dst + 8, p4c);
  94. AV_WN4PA(dst + 12, p4d);
  95. AV_WN4PA(dst + 16, p4e);
  96. AV_WN4PA(dst + 20, p4f);
  97. AV_WN4PA(dst + 24, p4g);
  98. AV_WN4PA(dst + 28, p4h);
  99. dst += stride;
  100. }
  101. }
  102. static void hor_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  103. const uint8_t *_left, const uint8_t *top)
  104. {
  105. pixel *dst = (pixel *) _dst;
  106. const pixel *left = (const pixel *) _left;
  107. stride /= sizeof(pixel);
  108. AV_WN4PA(dst + stride * 0, PIXEL_SPLAT_X4(left[3]));
  109. AV_WN4PA(dst + stride * 1, PIXEL_SPLAT_X4(left[2]));
  110. AV_WN4PA(dst + stride * 2, PIXEL_SPLAT_X4(left[1]));
  111. AV_WN4PA(dst + stride * 3, PIXEL_SPLAT_X4(left[0]));
  112. }
  113. static void hor_8x8_c(uint8_t *_dst, ptrdiff_t stride,
  114. const uint8_t *_left, const uint8_t *top)
  115. {
  116. pixel *dst = (pixel *) _dst;
  117. const pixel *left = (const pixel *) _left;
  118. int y;
  119. stride /= sizeof(pixel);
  120. for (y = 0; y < 8; y++) {
  121. pixel4 p4 = PIXEL_SPLAT_X4(left[7 - y]);
  122. AV_WN4PA(dst + 0, p4);
  123. AV_WN4PA(dst + 4, p4);
  124. dst += stride;
  125. }
  126. }
  127. static void hor_16x16_c(uint8_t *_dst, ptrdiff_t stride,
  128. const uint8_t *_left, const uint8_t *top)
  129. {
  130. pixel *dst = (pixel *) _dst;
  131. const pixel *left = (const pixel *) _left;
  132. int y;
  133. stride /= sizeof(pixel);
  134. for (y = 0; y < 16; y++) {
  135. pixel4 p4 = PIXEL_SPLAT_X4(left[15 - y]);
  136. AV_WN4PA(dst + 0, p4);
  137. AV_WN4PA(dst + 4, p4);
  138. AV_WN4PA(dst + 8, p4);
  139. AV_WN4PA(dst + 12, p4);
  140. dst += stride;
  141. }
  142. }
  143. static void hor_32x32_c(uint8_t *_dst, ptrdiff_t stride,
  144. const uint8_t *_left, const uint8_t *top)
  145. {
  146. pixel *dst = (pixel *) _dst;
  147. const pixel *left = (const pixel *) _left;
  148. int y;
  149. stride /= sizeof(pixel);
  150. for (y = 0; y < 32; y++) {
  151. pixel4 p4 = PIXEL_SPLAT_X4(left[31 - y]);
  152. AV_WN4PA(dst + 0, p4);
  153. AV_WN4PA(dst + 4, p4);
  154. AV_WN4PA(dst + 8, p4);
  155. AV_WN4PA(dst + 12, p4);
  156. AV_WN4PA(dst + 16, p4);
  157. AV_WN4PA(dst + 20, p4);
  158. AV_WN4PA(dst + 24, p4);
  159. AV_WN4PA(dst + 28, p4);
  160. dst += stride;
  161. }
  162. }
  163. #endif /* BIT_DEPTH != 12 */
  164. static void tm_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  165. const uint8_t *_left, const uint8_t *_top)
  166. {
  167. pixel *dst = (pixel *) _dst;
  168. const pixel *left = (const pixel *) _left;
  169. const pixel *top = (const pixel *) _top;
  170. int y, tl = top[-1];
  171. stride /= sizeof(pixel);
  172. for (y = 0; y < 4; y++) {
  173. int l_m_tl = left[3 - y] - tl;
  174. dst[0] = av_clip_pixel(top[0] + l_m_tl);
  175. dst[1] = av_clip_pixel(top[1] + l_m_tl);
  176. dst[2] = av_clip_pixel(top[2] + l_m_tl);
  177. dst[3] = av_clip_pixel(top[3] + l_m_tl);
  178. dst += stride;
  179. }
  180. }
  181. static void tm_8x8_c(uint8_t *_dst, ptrdiff_t stride,
  182. const uint8_t *_left, const uint8_t *_top)
  183. {
  184. pixel *dst = (pixel *) _dst;
  185. const pixel *left = (const pixel *) _left;
  186. const pixel *top = (const pixel *) _top;
  187. int y, tl = top[-1];
  188. stride /= sizeof(pixel);
  189. for (y = 0; y < 8; y++) {
  190. int l_m_tl = left[7 - y] - tl;
  191. dst[0] = av_clip_pixel(top[0] + l_m_tl);
  192. dst[1] = av_clip_pixel(top[1] + l_m_tl);
  193. dst[2] = av_clip_pixel(top[2] + l_m_tl);
  194. dst[3] = av_clip_pixel(top[3] + l_m_tl);
  195. dst[4] = av_clip_pixel(top[4] + l_m_tl);
  196. dst[5] = av_clip_pixel(top[5] + l_m_tl);
  197. dst[6] = av_clip_pixel(top[6] + l_m_tl);
  198. dst[7] = av_clip_pixel(top[7] + l_m_tl);
  199. dst += stride;
  200. }
  201. }
  202. static void tm_16x16_c(uint8_t *_dst, ptrdiff_t stride,
  203. const uint8_t *_left, const uint8_t *_top)
  204. {
  205. pixel *dst = (pixel *) _dst;
  206. const pixel *left = (const pixel *) _left;
  207. const pixel *top = (const pixel *) _top;
  208. int y, tl = top[-1];
  209. stride /= sizeof(pixel);
  210. for (y = 0; y < 16; y++) {
  211. int l_m_tl = left[15 - y] - tl;
  212. dst[ 0] = av_clip_pixel(top[ 0] + l_m_tl);
  213. dst[ 1] = av_clip_pixel(top[ 1] + l_m_tl);
  214. dst[ 2] = av_clip_pixel(top[ 2] + l_m_tl);
  215. dst[ 3] = av_clip_pixel(top[ 3] + l_m_tl);
  216. dst[ 4] = av_clip_pixel(top[ 4] + l_m_tl);
  217. dst[ 5] = av_clip_pixel(top[ 5] + l_m_tl);
  218. dst[ 6] = av_clip_pixel(top[ 6] + l_m_tl);
  219. dst[ 7] = av_clip_pixel(top[ 7] + l_m_tl);
  220. dst[ 8] = av_clip_pixel(top[ 8] + l_m_tl);
  221. dst[ 9] = av_clip_pixel(top[ 9] + l_m_tl);
  222. dst[10] = av_clip_pixel(top[10] + l_m_tl);
  223. dst[11] = av_clip_pixel(top[11] + l_m_tl);
  224. dst[12] = av_clip_pixel(top[12] + l_m_tl);
  225. dst[13] = av_clip_pixel(top[13] + l_m_tl);
  226. dst[14] = av_clip_pixel(top[14] + l_m_tl);
  227. dst[15] = av_clip_pixel(top[15] + l_m_tl);
  228. dst += stride;
  229. }
  230. }
  231. static void tm_32x32_c(uint8_t *_dst, ptrdiff_t stride,
  232. const uint8_t *_left, const uint8_t *_top)
  233. {
  234. pixel *dst = (pixel *) _dst;
  235. const pixel *left = (const pixel *) _left;
  236. const pixel *top = (const pixel *) _top;
  237. int y, tl = top[-1];
  238. stride /= sizeof(pixel);
  239. for (y = 0; y < 32; y++) {
  240. int l_m_tl = left[31 - y] - tl;
  241. dst[ 0] = av_clip_pixel(top[ 0] + l_m_tl);
  242. dst[ 1] = av_clip_pixel(top[ 1] + l_m_tl);
  243. dst[ 2] = av_clip_pixel(top[ 2] + l_m_tl);
  244. dst[ 3] = av_clip_pixel(top[ 3] + l_m_tl);
  245. dst[ 4] = av_clip_pixel(top[ 4] + l_m_tl);
  246. dst[ 5] = av_clip_pixel(top[ 5] + l_m_tl);
  247. dst[ 6] = av_clip_pixel(top[ 6] + l_m_tl);
  248. dst[ 7] = av_clip_pixel(top[ 7] + l_m_tl);
  249. dst[ 8] = av_clip_pixel(top[ 8] + l_m_tl);
  250. dst[ 9] = av_clip_pixel(top[ 9] + l_m_tl);
  251. dst[10] = av_clip_pixel(top[10] + l_m_tl);
  252. dst[11] = av_clip_pixel(top[11] + l_m_tl);
  253. dst[12] = av_clip_pixel(top[12] + l_m_tl);
  254. dst[13] = av_clip_pixel(top[13] + l_m_tl);
  255. dst[14] = av_clip_pixel(top[14] + l_m_tl);
  256. dst[15] = av_clip_pixel(top[15] + l_m_tl);
  257. dst[16] = av_clip_pixel(top[16] + l_m_tl);
  258. dst[17] = av_clip_pixel(top[17] + l_m_tl);
  259. dst[18] = av_clip_pixel(top[18] + l_m_tl);
  260. dst[19] = av_clip_pixel(top[19] + l_m_tl);
  261. dst[20] = av_clip_pixel(top[20] + l_m_tl);
  262. dst[21] = av_clip_pixel(top[21] + l_m_tl);
  263. dst[22] = av_clip_pixel(top[22] + l_m_tl);
  264. dst[23] = av_clip_pixel(top[23] + l_m_tl);
  265. dst[24] = av_clip_pixel(top[24] + l_m_tl);
  266. dst[25] = av_clip_pixel(top[25] + l_m_tl);
  267. dst[26] = av_clip_pixel(top[26] + l_m_tl);
  268. dst[27] = av_clip_pixel(top[27] + l_m_tl);
  269. dst[28] = av_clip_pixel(top[28] + l_m_tl);
  270. dst[29] = av_clip_pixel(top[29] + l_m_tl);
  271. dst[30] = av_clip_pixel(top[30] + l_m_tl);
  272. dst[31] = av_clip_pixel(top[31] + l_m_tl);
  273. dst += stride;
  274. }
  275. }
  276. #if BIT_DEPTH != 12
  277. static void dc_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  278. const uint8_t *_left, const uint8_t *_top)
  279. {
  280. pixel *dst = (pixel *) _dst;
  281. const pixel *left = (const pixel *) _left;
  282. const pixel *top = (const pixel *) _top;
  283. pixel4 dc = PIXEL_SPLAT_X4((left[0] + left[1] + left[2] + left[3] +
  284. top[0] + top[1] + top[2] + top[3] + 4) >> 3);
  285. stride /= sizeof(pixel);
  286. AV_WN4PA(dst + stride * 0, dc);
  287. AV_WN4PA(dst + stride * 1, dc);
  288. AV_WN4PA(dst + stride * 2, dc);
  289. AV_WN4PA(dst + stride * 3, dc);
  290. }
  291. static void dc_8x8_c(uint8_t *_dst, ptrdiff_t stride,
  292. const uint8_t *_left, const uint8_t *_top)
  293. {
  294. pixel *dst = (pixel *) _dst;
  295. const pixel *left = (const pixel *) _left;
  296. const pixel *top = (const pixel *) _top;
  297. pixel4 dc = PIXEL_SPLAT_X4
  298. ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] +
  299. left[6] + left[7] + top[0] + top[1] + top[2] + top[3] +
  300. top[4] + top[5] + top[6] + top[7] + 8) >> 4);
  301. int y;
  302. stride /= sizeof(pixel);
  303. for (y = 0; y < 8; y++) {
  304. AV_WN4PA(dst + 0, dc);
  305. AV_WN4PA(dst + 4, dc);
  306. dst += stride;
  307. }
  308. }
  309. static void dc_16x16_c(uint8_t *_dst, ptrdiff_t stride,
  310. const uint8_t *_left, const uint8_t *_top)
  311. {
  312. pixel *dst = (pixel *) _dst;
  313. const pixel *left = (const pixel *) _left;
  314. const pixel *top = (const pixel *) _top;
  315. pixel4 dc = PIXEL_SPLAT_X4
  316. ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] + left[6] +
  317. left[7] + left[8] + left[9] + left[10] + left[11] + left[12] +
  318. left[13] + left[14] + left[15] + top[0] + top[1] + top[2] + top[3] +
  319. top[4] + top[5] + top[6] + top[7] + top[8] + top[9] + top[10] +
  320. top[11] + top[12] + top[13] + top[14] + top[15] + 16) >> 5);
  321. int y;
  322. stride /= sizeof(pixel);
  323. for (y = 0; y < 16; y++) {
  324. AV_WN4PA(dst + 0, dc);
  325. AV_WN4PA(dst + 4, dc);
  326. AV_WN4PA(dst + 8, dc);
  327. AV_WN4PA(dst + 12, dc);
  328. dst += stride;
  329. }
  330. }
  331. static void dc_32x32_c(uint8_t *_dst, ptrdiff_t stride,
  332. const uint8_t *_left, const uint8_t *_top)
  333. {
  334. pixel *dst = (pixel *) _dst;
  335. const pixel *left = (const pixel *) _left;
  336. const pixel *top = (const pixel *) _top;
  337. pixel4 dc = PIXEL_SPLAT_X4
  338. ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] + left[6] +
  339. left[7] + left[8] + left[9] + left[10] + left[11] + left[12] +
  340. left[13] + left[14] + left[15] + left[16] + left[17] + left[18] +
  341. left[19] + left[20] + left[21] + left[22] + left[23] + left[24] +
  342. left[25] + left[26] + left[27] + left[28] + left[29] + left[30] +
  343. left[31] + top[0] + top[1] + top[2] + top[3] + top[4] + top[5] +
  344. top[6] + top[7] + top[8] + top[9] + top[10] + top[11] + top[12] +
  345. top[13] + top[14] + top[15] + top[16] + top[17] + top[18] + top[19] +
  346. top[20] + top[21] + top[22] + top[23] + top[24] + top[25] + top[26] +
  347. top[27] + top[28] + top[29] + top[30] + top[31] + 32) >> 6);
  348. int y;
  349. stride /= sizeof(pixel);
  350. for (y = 0; y < 32; y++) {
  351. AV_WN4PA(dst + 0, dc);
  352. AV_WN4PA(dst + 4, dc);
  353. AV_WN4PA(dst + 8, dc);
  354. AV_WN4PA(dst + 12, dc);
  355. AV_WN4PA(dst + 16, dc);
  356. AV_WN4PA(dst + 20, dc);
  357. AV_WN4PA(dst + 24, dc);
  358. AV_WN4PA(dst + 28, dc);
  359. dst += stride;
  360. }
  361. }
  362. static void dc_left_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  363. const uint8_t *_left, const uint8_t *top)
  364. {
  365. pixel *dst = (pixel *) _dst;
  366. const pixel *left = (const pixel *) _left;
  367. pixel4 dc = PIXEL_SPLAT_X4((left[0] + left[1] + left[2] + left[3] + 2) >> 2);
  368. stride /= sizeof(pixel);
  369. AV_WN4PA(dst + stride * 0, dc);
  370. AV_WN4PA(dst + stride * 1, dc);
  371. AV_WN4PA(dst + stride * 2, dc);
  372. AV_WN4PA(dst + stride * 3, dc);
  373. }
  374. static void dc_left_8x8_c(uint8_t *_dst, ptrdiff_t stride,
  375. const uint8_t *_left, const uint8_t *top)
  376. {
  377. pixel *dst = (pixel *) _dst;
  378. const pixel *left = (const pixel *) _left;
  379. pixel4 dc = PIXEL_SPLAT_X4
  380. ((left[0] + left[1] + left[2] + left[3] +
  381. left[4] + left[5] + left[6] + left[7] + 4) >> 3);
  382. int y;
  383. stride /= sizeof(pixel);
  384. for (y = 0; y < 8; y++) {
  385. AV_WN4PA(dst + 0, dc);
  386. AV_WN4PA(dst + 4, dc);
  387. dst += stride;
  388. }
  389. }
  390. static void dc_left_16x16_c(uint8_t *_dst, ptrdiff_t stride,
  391. const uint8_t *_left, const uint8_t *top)
  392. {
  393. pixel *dst = (pixel *) _dst;
  394. const pixel *left = (const pixel *) _left;
  395. pixel4 dc = PIXEL_SPLAT_X4
  396. ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] +
  397. left[6] + left[7] + left[8] + left[9] + left[10] + left[11] +
  398. left[12] + left[13] + left[14] + left[15] + 8) >> 4);
  399. int y;
  400. stride /= sizeof(pixel);
  401. for (y = 0; y < 16; y++) {
  402. AV_WN4PA(dst + 0, dc);
  403. AV_WN4PA(dst + 4, dc);
  404. AV_WN4PA(dst + 8, dc);
  405. AV_WN4PA(dst + 12, dc);
  406. dst += stride;
  407. }
  408. }
  409. static void dc_left_32x32_c(uint8_t *_dst, ptrdiff_t stride,
  410. const uint8_t *_left, const uint8_t *top)
  411. {
  412. pixel *dst = (pixel *) _dst;
  413. const pixel *left = (const pixel *) _left;
  414. pixel4 dc = PIXEL_SPLAT_X4
  415. ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] +
  416. left[6] + left[7] + left[8] + left[9] + left[10] + left[11] +
  417. left[12] + left[13] + left[14] + left[15] + left[16] + left[17] +
  418. left[18] + left[19] + left[20] + left[21] + left[22] + left[23] +
  419. left[24] + left[25] + left[26] + left[27] + left[28] + left[29] +
  420. left[30] + left[31] + 16) >> 5);
  421. int y;
  422. stride /= sizeof(pixel);
  423. for (y = 0; y < 32; y++) {
  424. AV_WN4PA(dst + 0, dc);
  425. AV_WN4PA(dst + 4, dc);
  426. AV_WN4PA(dst + 8, dc);
  427. AV_WN4PA(dst + 12, dc);
  428. AV_WN4PA(dst + 16, dc);
  429. AV_WN4PA(dst + 20, dc);
  430. AV_WN4PA(dst + 24, dc);
  431. AV_WN4PA(dst + 28, dc);
  432. dst += stride;
  433. }
  434. }
  435. static void dc_top_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  436. const uint8_t *left, const uint8_t *_top)
  437. {
  438. pixel *dst = (pixel *) _dst;
  439. const pixel *top = (const pixel *) _top;
  440. pixel4 dc = PIXEL_SPLAT_X4((top[0] + top[1] + top[2] + top[3] + 2) >> 2);
  441. stride /= sizeof(pixel);
  442. AV_WN4PA(dst + stride * 0, dc);
  443. AV_WN4PA(dst + stride * 1, dc);
  444. AV_WN4PA(dst + stride * 2, dc);
  445. AV_WN4PA(dst + stride * 3, dc);
  446. }
  447. static void dc_top_8x8_c(uint8_t *_dst, ptrdiff_t stride,
  448. const uint8_t *left, const uint8_t *_top)
  449. {
  450. pixel *dst = (pixel *) _dst;
  451. const pixel *top = (const pixel *) _top;
  452. pixel4 dc = PIXEL_SPLAT_X4
  453. ((top[0] + top[1] + top[2] + top[3] +
  454. top[4] + top[5] + top[6] + top[7] + 4) >> 3);
  455. int y;
  456. stride /= sizeof(pixel);
  457. for (y = 0; y < 8; y++) {
  458. AV_WN4PA(dst + 0, dc);
  459. AV_WN4PA(dst + 4, dc);
  460. dst += stride;
  461. }
  462. }
  463. static void dc_top_16x16_c(uint8_t *_dst, ptrdiff_t stride,
  464. const uint8_t *left, const uint8_t *_top)
  465. {
  466. pixel *dst = (pixel *) _dst;
  467. const pixel *top = (const pixel *) _top;
  468. pixel4 dc = PIXEL_SPLAT_X4
  469. ((top[0] + top[1] + top[2] + top[3] + top[4] + top[5] +
  470. top[6] + top[7] + top[8] + top[9] + top[10] + top[11] +
  471. top[12] + top[13] + top[14] + top[15] + 8) >> 4);
  472. int y;
  473. stride /= sizeof(pixel);
  474. for (y = 0; y < 16; y++) {
  475. AV_WN4PA(dst + 0, dc);
  476. AV_WN4PA(dst + 4, dc);
  477. AV_WN4PA(dst + 8, dc);
  478. AV_WN4PA(dst + 12, dc);
  479. dst += stride;
  480. }
  481. }
  482. static void dc_top_32x32_c(uint8_t *_dst, ptrdiff_t stride,
  483. const uint8_t *left, const uint8_t *_top)
  484. {
  485. pixel *dst = (pixel *) _dst;
  486. const pixel *top = (const pixel *) _top;
  487. pixel4 dc = PIXEL_SPLAT_X4
  488. ((top[0] + top[1] + top[2] + top[3] + top[4] + top[5] +
  489. top[6] + top[7] + top[8] + top[9] + top[10] + top[11] +
  490. top[12] + top[13] + top[14] + top[15] + top[16] + top[17] +
  491. top[18] + top[19] + top[20] + top[21] + top[22] + top[23] +
  492. top[24] + top[25] + top[26] + top[27] + top[28] + top[29] +
  493. top[30] + top[31] + 16) >> 5);
  494. int y;
  495. stride /= sizeof(pixel);
  496. for (y = 0; y < 32; y++) {
  497. AV_WN4PA(dst + 0, dc);
  498. AV_WN4PA(dst + 4, dc);
  499. AV_WN4PA(dst + 8, dc);
  500. AV_WN4PA(dst + 12, dc);
  501. AV_WN4PA(dst + 16, dc);
  502. AV_WN4PA(dst + 20, dc);
  503. AV_WN4PA(dst + 24, dc);
  504. AV_WN4PA(dst + 28, dc);
  505. dst += stride;
  506. }
  507. }
  508. #endif /* BIT_DEPTH != 12 */
  509. static void dc_128_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  510. const uint8_t *left, const uint8_t *top)
  511. {
  512. pixel *dst = (pixel *) _dst;
  513. pixel4 val = PIXEL_SPLAT_X4(128 << (BIT_DEPTH - 8));
  514. stride /= sizeof(pixel);
  515. AV_WN4PA(dst + stride * 0, val);
  516. AV_WN4PA(dst + stride * 1, val);
  517. AV_WN4PA(dst + stride * 2, val);
  518. AV_WN4PA(dst + stride * 3, val);
  519. }
  520. static void dc_128_8x8_c(uint8_t *_dst, ptrdiff_t stride,
  521. const uint8_t *left, const uint8_t *top)
  522. {
  523. pixel *dst = (pixel *) _dst;
  524. pixel4 val = PIXEL_SPLAT_X4(128 << (BIT_DEPTH - 8));
  525. int y;
  526. stride /= sizeof(pixel);
  527. for (y = 0; y < 8; y++) {
  528. AV_WN4PA(dst + 0, val);
  529. AV_WN4PA(dst + 4, val);
  530. dst += stride;
  531. }
  532. }
  533. static void dc_128_16x16_c(uint8_t *_dst, ptrdiff_t stride,
  534. const uint8_t *left, const uint8_t *top)
  535. {
  536. pixel *dst = (pixel *) _dst;
  537. pixel4 val = PIXEL_SPLAT_X4(128 << (BIT_DEPTH - 8));
  538. int y;
  539. stride /= sizeof(pixel);
  540. for (y = 0; y < 16; y++) {
  541. AV_WN4PA(dst + 0, val);
  542. AV_WN4PA(dst + 4, val);
  543. AV_WN4PA(dst + 8, val);
  544. AV_WN4PA(dst + 12, val);
  545. dst += stride;
  546. }
  547. }
  548. static void dc_128_32x32_c(uint8_t *_dst, ptrdiff_t stride,
  549. const uint8_t *left, const uint8_t *top)
  550. {
  551. pixel *dst = (pixel *) _dst;
  552. pixel4 val = PIXEL_SPLAT_X4(128 << (BIT_DEPTH - 8));
  553. int y;
  554. stride /= sizeof(pixel);
  555. for (y = 0; y < 32; y++) {
  556. AV_WN4PA(dst + 0, val);
  557. AV_WN4PA(dst + 4, val);
  558. AV_WN4PA(dst + 8, val);
  559. AV_WN4PA(dst + 12, val);
  560. AV_WN4PA(dst + 16, val);
  561. AV_WN4PA(dst + 20, val);
  562. AV_WN4PA(dst + 24, val);
  563. AV_WN4PA(dst + 28, val);
  564. dst += stride;
  565. }
  566. }
  567. static void dc_127_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  568. const uint8_t *left, const uint8_t *top)
  569. {
  570. pixel *dst = (pixel *) _dst;
  571. pixel4 val = PIXEL_SPLAT_X4((128 << (BIT_DEPTH - 8)) - 1);
  572. stride /= sizeof(pixel);
  573. AV_WN4PA(dst + stride * 0, val);
  574. AV_WN4PA(dst + stride * 1, val);
  575. AV_WN4PA(dst + stride * 2, val);
  576. AV_WN4PA(dst + stride * 3, val);}
  577. static void dc_127_8x8_c(uint8_t *_dst, ptrdiff_t stride,
  578. const uint8_t *left, const uint8_t *top)
  579. {
  580. pixel *dst = (pixel *) _dst;
  581. pixel4 val = PIXEL_SPLAT_X4((128 << (BIT_DEPTH - 8)) - 1);
  582. int y;
  583. stride /= sizeof(pixel);
  584. for (y = 0; y < 8; y++) {
  585. AV_WN4PA(dst + 0, val);
  586. AV_WN4PA(dst + 4, val);
  587. dst += stride;
  588. }
  589. }
  590. static void dc_127_16x16_c(uint8_t *_dst, ptrdiff_t stride,
  591. const uint8_t *left, const uint8_t *top)
  592. {
  593. pixel *dst = (pixel *) _dst;
  594. pixel4 val = PIXEL_SPLAT_X4((128 << (BIT_DEPTH - 8)) - 1);
  595. int y;
  596. stride /= sizeof(pixel);
  597. for (y = 0; y < 16; y++) {
  598. AV_WN4PA(dst + 0, val);
  599. AV_WN4PA(dst + 4, val);
  600. AV_WN4PA(dst + 8, val);
  601. AV_WN4PA(dst + 12, val);
  602. dst += stride;
  603. }
  604. }
  605. static void dc_127_32x32_c(uint8_t *_dst, ptrdiff_t stride,
  606. const uint8_t *left, const uint8_t *top)
  607. {
  608. pixel *dst = (pixel *) _dst;
  609. pixel4 val = PIXEL_SPLAT_X4((128 << (BIT_DEPTH - 8)) - 1);
  610. int y;
  611. stride /= sizeof(pixel);
  612. for (y = 0; y < 32; y++) {
  613. AV_WN4PA(dst + 0, val);
  614. AV_WN4PA(dst + 4, val);
  615. AV_WN4PA(dst + 8, val);
  616. AV_WN4PA(dst + 12, val);
  617. AV_WN4PA(dst + 16, val);
  618. AV_WN4PA(dst + 20, val);
  619. AV_WN4PA(dst + 24, val);
  620. AV_WN4PA(dst + 28, val);
  621. dst += stride;
  622. }
  623. }
  624. static void dc_129_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  625. const uint8_t *left, const uint8_t *top)
  626. {
  627. pixel *dst = (pixel *) _dst;
  628. pixel4 val = PIXEL_SPLAT_X4((128 << (BIT_DEPTH - 8)) + 1);
  629. stride /= sizeof(pixel);
  630. AV_WN4PA(dst + stride * 0, val);
  631. AV_WN4PA(dst + stride * 1, val);
  632. AV_WN4PA(dst + stride * 2, val);
  633. AV_WN4PA(dst + stride * 3, val);
  634. }
  635. static void dc_129_8x8_c(uint8_t *_dst, ptrdiff_t stride,
  636. const uint8_t *left, const uint8_t *top)
  637. {
  638. pixel *dst = (pixel *) _dst;
  639. pixel4 val = PIXEL_SPLAT_X4((128 << (BIT_DEPTH - 8)) + 1);
  640. int y;
  641. stride /= sizeof(pixel);
  642. for (y = 0; y < 8; y++) {
  643. AV_WN4PA(dst + 0, val);
  644. AV_WN4PA(dst + 4, val);
  645. dst += stride;
  646. }
  647. }
  648. static void dc_129_16x16_c(uint8_t *_dst, ptrdiff_t stride,
  649. const uint8_t *left, const uint8_t *top)
  650. {
  651. pixel *dst = (pixel *) _dst;
  652. pixel4 val = PIXEL_SPLAT_X4((128 << (BIT_DEPTH - 8)) + 1);
  653. int y;
  654. stride /= sizeof(pixel);
  655. for (y = 0; y < 16; y++) {
  656. AV_WN4PA(dst + 0, val);
  657. AV_WN4PA(dst + 4, val);
  658. AV_WN4PA(dst + 8, val);
  659. AV_WN4PA(dst + 12, val);
  660. dst += stride;
  661. }
  662. }
  663. static void dc_129_32x32_c(uint8_t *_dst, ptrdiff_t stride,
  664. const uint8_t *left, const uint8_t *top)
  665. {
  666. pixel *dst = (pixel *) _dst;
  667. pixel4 val = PIXEL_SPLAT_X4((128 << (BIT_DEPTH - 8)) + 1);
  668. int y;
  669. stride /= sizeof(pixel);
  670. for (y = 0; y < 32; y++) {
  671. AV_WN4PA(dst + 0, val);
  672. AV_WN4PA(dst + 4, val);
  673. AV_WN4PA(dst + 8, val);
  674. AV_WN4PA(dst + 12, val);
  675. AV_WN4PA(dst + 16, val);
  676. AV_WN4PA(dst + 20, val);
  677. AV_WN4PA(dst + 24, val);
  678. AV_WN4PA(dst + 28, val);
  679. dst += stride;
  680. }
  681. }
  682. #if BIT_DEPTH != 12
  683. #if BIT_DEPTH == 8
  684. #define memset_bpc memset
  685. #else
  686. static inline void memset_bpc(uint16_t *dst, int val, int len) {
  687. int n;
  688. for (n = 0; n < len; n++) {
  689. dst[n] = val;
  690. }
  691. }
  692. #endif
  693. #define DST(x, y) dst[(x) + (y) * stride]
  694. static void diag_downleft_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  695. const uint8_t *left, const uint8_t *_top)
  696. {
  697. pixel *dst = (pixel *) _dst;
  698. const pixel *top = (const pixel *) _top;
  699. int a0 = top[0], a1 = top[1], a2 = top[2], a3 = top[3],
  700. a4 = top[4], a5 = top[5], a6 = top[6], a7 = top[7];
  701. stride /= sizeof(pixel);
  702. DST(0,0) = (a0 + a1 * 2 + a2 + 2) >> 2;
  703. DST(1,0) = DST(0,1) = (a1 + a2 * 2 + a3 + 2) >> 2;
  704. DST(2,0) = DST(1,1) = DST(0,2) = (a2 + a3 * 2 + a4 + 2) >> 2;
  705. DST(3,0) = DST(2,1) = DST(1,2) = DST(0,3) = (a3 + a4 * 2 + a5 + 2) >> 2;
  706. DST(3,1) = DST(2,2) = DST(1,3) = (a4 + a5 * 2 + a6 + 2) >> 2;
  707. DST(3,2) = DST(2,3) = (a5 + a6 * 2 + a7 + 2) >> 2;
  708. DST(3,3) = a7; // note: this is different from vp8 and such
  709. }
  710. #define def_diag_downleft(size) \
  711. static void diag_downleft_##size##x##size##_c(uint8_t *_dst, ptrdiff_t stride, \
  712. const uint8_t *left, const uint8_t *_top) \
  713. { \
  714. pixel *dst = (pixel *) _dst; \
  715. const pixel *top = (const pixel *) _top; \
  716. int i, j; \
  717. pixel v[size - 1]; \
  718. \
  719. stride /= sizeof(pixel); \
  720. for (i = 0; i < size - 2; i++) \
  721. v[i] = (top[i] + top[i + 1] * 2 + top[i + 2] + 2) >> 2; \
  722. v[size - 2] = (top[size - 2] + top[size - 1] * 3 + 2) >> 2; \
  723. \
  724. for (j = 0; j < size; j++) { \
  725. memcpy(dst + j*stride, v + j, (size - 1 - j) * sizeof(pixel)); \
  726. memset_bpc(dst + j*stride + size - 1 - j, top[size - 1], j + 1); \
  727. } \
  728. }
  729. def_diag_downleft(8)
  730. def_diag_downleft(16)
  731. def_diag_downleft(32)
  732. static void diag_downright_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  733. const uint8_t *_left, const uint8_t *_top)
  734. {
  735. pixel *dst = (pixel *) _dst;
  736. const pixel *top = (const pixel *) _top;
  737. const pixel *left = (const pixel *) _left;
  738. int tl = top[-1], a0 = top[0], a1 = top[1], a2 = top[2], a3 = top[3],
  739. l0 = left[3], l1 = left[2], l2 = left[1], l3 = left[0];
  740. stride /= sizeof(pixel);
  741. DST(0,3) = (l1 + l2 * 2 + l3 + 2) >> 2;
  742. DST(0,2) = DST(1,3) = (l0 + l1 * 2 + l2 + 2) >> 2;
  743. DST(0,1) = DST(1,2) = DST(2,3) = (tl + l0 * 2 + l1 + 2) >> 2;
  744. DST(0,0) = DST(1,1) = DST(2,2) = DST(3,3) = (l0 + tl * 2 + a0 + 2) >> 2;
  745. DST(1,0) = DST(2,1) = DST(3,2) = (tl + a0 * 2 + a1 + 2) >> 2;
  746. DST(2,0) = DST(3,1) = (a0 + a1 * 2 + a2 + 2) >> 2;
  747. DST(3,0) = (a1 + a2 * 2 + a3 + 2) >> 2;
  748. }
  749. #define def_diag_downright(size) \
  750. static void diag_downright_##size##x##size##_c(uint8_t *_dst, ptrdiff_t stride, \
  751. const uint8_t *_left, const uint8_t *_top) \
  752. { \
  753. pixel *dst = (pixel *) _dst; \
  754. const pixel *top = (const pixel *) _top; \
  755. const pixel *left = (const pixel *) _left; \
  756. int i, j; \
  757. pixel v[size + size - 1]; \
  758. \
  759. stride /= sizeof(pixel); \
  760. for (i = 0; i < size - 2; i++) { \
  761. v[i ] = (left[i] + left[i + 1] * 2 + left[i + 2] + 2) >> 2; \
  762. v[size + 1 + i] = (top[i] + top[i + 1] * 2 + top[i + 2] + 2) >> 2; \
  763. } \
  764. v[size - 2] = (left[size - 2] + left[size - 1] * 2 + top[-1] + 2) >> 2; \
  765. v[size - 1] = (left[size - 1] + top[-1] * 2 + top[ 0] + 2) >> 2; \
  766. v[size ] = (top[-1] + top[0] * 2 + top[ 1] + 2) >> 2; \
  767. \
  768. for (j = 0; j < size; j++) \
  769. memcpy(dst + j*stride, v + size - 1 - j, size * sizeof(pixel)); \
  770. }
  771. def_diag_downright(8)
  772. def_diag_downright(16)
  773. def_diag_downright(32)
  774. static void vert_right_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  775. const uint8_t *_left, const uint8_t *_top)
  776. {
  777. pixel *dst = (pixel *) _dst;
  778. const pixel *top = (const pixel *) _top;
  779. const pixel *left = (const pixel *) _left;
  780. int tl = top[-1], a0 = top[0], a1 = top[1], a2 = top[2], a3 = top[3],
  781. l0 = left[3], l1 = left[2], l2 = left[1];
  782. stride /= sizeof(pixel);
  783. DST(0,3) = (l0 + l1 * 2 + l2 + 2) >> 2;
  784. DST(0,2) = (tl + l0 * 2 + l1 + 2) >> 2;
  785. DST(0,0) = DST(1,2) = (tl + a0 + 1) >> 1;
  786. DST(0,1) = DST(1,3) = (l0 + tl * 2 + a0 + 2) >> 2;
  787. DST(1,0) = DST(2,2) = (a0 + a1 + 1) >> 1;
  788. DST(1,1) = DST(2,3) = (tl + a0 * 2 + a1 + 2) >> 2;
  789. DST(2,0) = DST(3,2) = (a1 + a2 + 1) >> 1;
  790. DST(2,1) = DST(3,3) = (a0 + a1 * 2 + a2 + 2) >> 2;
  791. DST(3,0) = (a2 + a3 + 1) >> 1;
  792. DST(3,1) = (a1 + a2 * 2 + a3 + 2) >> 2;
  793. }
  794. #define def_vert_right(size) \
  795. static void vert_right_##size##x##size##_c(uint8_t *_dst, ptrdiff_t stride, \
  796. const uint8_t *_left, const uint8_t *_top) \
  797. { \
  798. pixel *dst = (pixel *) _dst; \
  799. const pixel *top = (const pixel *) _top; \
  800. const pixel *left = (const pixel *) _left; \
  801. int i, j; \
  802. pixel ve[size + size/2 - 1], vo[size + size/2 - 1]; \
  803. \
  804. stride /= sizeof(pixel); \
  805. for (i = 0; i < size/2 - 2; i++) { \
  806. vo[i] = (left[i*2 + 3] + left[i*2 + 2] * 2 + left[i*2 + 1] + 2) >> 2; \
  807. ve[i] = (left[i*2 + 4] + left[i*2 + 3] * 2 + left[i*2 + 2] + 2) >> 2; \
  808. } \
  809. vo[size/2 - 2] = (left[size - 1] + left[size - 2] * 2 + left[size - 3] + 2) >> 2; \
  810. ve[size/2 - 2] = (top[-1] + left[size - 1] * 2 + left[size - 2] + 2) >> 2; \
  811. \
  812. ve[size/2 - 1] = (top[-1] + top[0] + 1) >> 1; \
  813. vo[size/2 - 1] = (left[size - 1] + top[-1] * 2 + top[0] + 2) >> 2; \
  814. for (i = 0; i < size - 1; i++) { \
  815. ve[size/2 + i] = (top[i] + top[i + 1] + 1) >> 1; \
  816. vo[size/2 + i] = (top[i - 1] + top[i] * 2 + top[i + 1] + 2) >> 2; \
  817. } \
  818. \
  819. for (j = 0; j < size / 2; j++) { \
  820. memcpy(dst + j*2 *stride, ve + size/2 - 1 - j, size * sizeof(pixel)); \
  821. memcpy(dst + (j*2 + 1)*stride, vo + size/2 - 1 - j, size * sizeof(pixel)); \
  822. } \
  823. }
  824. def_vert_right(8)
  825. def_vert_right(16)
  826. def_vert_right(32)
  827. static void hor_down_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  828. const uint8_t *_left, const uint8_t *_top)
  829. {
  830. pixel *dst = (pixel *) _dst;
  831. const pixel *top = (const pixel *) _top;
  832. const pixel *left = (const pixel *) _left;
  833. int l0 = left[3], l1 = left[2], l2 = left[1], l3 = left[0],
  834. tl = top[-1], a0 = top[0], a1 = top[1], a2 = top[2];
  835. stride /= sizeof(pixel);
  836. DST(2,0) = (tl + a0 * 2 + a1 + 2) >> 2;
  837. DST(3,0) = (a0 + a1 * 2 + a2 + 2) >> 2;
  838. DST(0,0) = DST(2,1) = (tl + l0 + 1) >> 1;
  839. DST(1,0) = DST(3,1) = (a0 + tl * 2 + l0 + 2) >> 2;
  840. DST(0,1) = DST(2,2) = (l0 + l1 + 1) >> 1;
  841. DST(1,1) = DST(3,2) = (tl + l0 * 2 + l1 + 2) >> 2;
  842. DST(0,2) = DST(2,3) = (l1 + l2 + 1) >> 1;
  843. DST(1,2) = DST(3,3) = (l0 + l1 * 2 + l2 + 2) >> 2;
  844. DST(0,3) = (l2 + l3 + 1) >> 1;
  845. DST(1,3) = (l1 + l2 * 2 + l3 + 2) >> 2;
  846. }
  847. #define def_hor_down(size) \
  848. static void hor_down_##size##x##size##_c(uint8_t *_dst, ptrdiff_t stride, \
  849. const uint8_t *_left, const uint8_t *_top) \
  850. { \
  851. pixel *dst = (pixel *) _dst; \
  852. const pixel *top = (const pixel *) _top; \
  853. const pixel *left = (const pixel *) _left; \
  854. int i, j; \
  855. pixel v[size * 3 - 2]; \
  856. \
  857. stride /= sizeof(pixel); \
  858. for (i = 0; i < size - 2; i++) { \
  859. v[i*2 ] = (left[i + 1] + left[i + 0] + 1) >> 1; \
  860. v[i*2 + 1] = (left[i + 2] + left[i + 1] * 2 + left[i + 0] + 2) >> 2; \
  861. v[size*2 + i] = (top[i - 1] + top[i] * 2 + top[i + 1] + 2) >> 2; \
  862. } \
  863. v[size*2 - 2] = (top[-1] + left[size - 1] + 1) >> 1; \
  864. v[size*2 - 4] = (left[size - 1] + left[size - 2] + 1) >> 1; \
  865. v[size*2 - 1] = (top[0] + top[-1] * 2 + left[size - 1] + 2) >> 2; \
  866. v[size*2 - 3] = (top[-1] + left[size - 1] * 2 + left[size - 2] + 2) >> 2; \
  867. \
  868. for (j = 0; j < size; j++) \
  869. memcpy(dst + j*stride, v + size*2 - 2 - j*2, size * sizeof(pixel)); \
  870. }
  871. def_hor_down(8)
  872. def_hor_down(16)
  873. def_hor_down(32)
  874. static void vert_left_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  875. const uint8_t *left, const uint8_t *_top)
  876. {
  877. pixel *dst = (pixel *) _dst;
  878. const pixel *top = (const pixel *) _top;
  879. int a0 = top[0], a1 = top[1], a2 = top[2], a3 = top[3],
  880. a4 = top[4], a5 = top[5], a6 = top[6];
  881. stride /= sizeof(pixel);
  882. DST(0,0) = (a0 + a1 + 1) >> 1;
  883. DST(0,1) = (a0 + a1 * 2 + a2 + 2) >> 2;
  884. DST(1,0) = DST(0,2) = (a1 + a2 + 1) >> 1;
  885. DST(1,1) = DST(0,3) = (a1 + a2 * 2 + a3 + 2) >> 2;
  886. DST(2,0) = DST(1,2) = (a2 + a3 + 1) >> 1;
  887. DST(2,1) = DST(1,3) = (a2 + a3 * 2 + a4 + 2) >> 2;
  888. DST(3,0) = DST(2,2) = (a3 + a4 + 1) >> 1;
  889. DST(3,1) = DST(2,3) = (a3 + a4 * 2 + a5 + 2) >> 2;
  890. DST(3,2) = (a4 + a5 + 1) >> 1;
  891. DST(3,3) = (a4 + a5 * 2 + a6 + 2) >> 2;
  892. }
  893. #define def_vert_left(size) \
  894. static void vert_left_##size##x##size##_c(uint8_t *_dst, ptrdiff_t stride, \
  895. const uint8_t *left, const uint8_t *_top) \
  896. { \
  897. pixel *dst = (pixel *) _dst; \
  898. const pixel *top = (const pixel *) _top; \
  899. int i, j; \
  900. pixel ve[size - 1], vo[size - 1]; \
  901. \
  902. stride /= sizeof(pixel); \
  903. for (i = 0; i < size - 2; i++) { \
  904. ve[i] = (top[i] + top[i + 1] + 1) >> 1; \
  905. vo[i] = (top[i] + top[i + 1] * 2 + top[i + 2] + 2) >> 2; \
  906. } \
  907. ve[size - 2] = (top[size - 2] + top[size - 1] + 1) >> 1; \
  908. vo[size - 2] = (top[size - 2] + top[size - 1] * 3 + 2) >> 2; \
  909. \
  910. for (j = 0; j < size / 2; j++) { \
  911. memcpy(dst + j*2 * stride, ve + j, (size - j - 1) * sizeof(pixel)); \
  912. memset_bpc(dst + j*2 * stride + size - j - 1, top[size - 1], j + 1); \
  913. memcpy(dst + (j*2 + 1) * stride, vo + j, (size - j - 1) * sizeof(pixel)); \
  914. memset_bpc(dst + (j*2 + 1) * stride + size - j - 1, top[size - 1], j + 1); \
  915. } \
  916. }
  917. def_vert_left(8)
  918. def_vert_left(16)
  919. def_vert_left(32)
  920. static void hor_up_4x4_c(uint8_t *_dst, ptrdiff_t stride,
  921. const uint8_t *_left, const uint8_t *top)
  922. {
  923. pixel *dst = (pixel *) _dst;
  924. const pixel *left = (const pixel *) _left;
  925. int l0 = left[0], l1 = left[1], l2 = left[2], l3 = left[3];
  926. stride /= sizeof(pixel);
  927. DST(0,0) = (l0 + l1 + 1) >> 1;
  928. DST(1,0) = (l0 + l1 * 2 + l2 + 2) >> 2;
  929. DST(0,1) = DST(2,0) = (l1 + l2 + 1) >> 1;
  930. DST(1,1) = DST(3,0) = (l1 + l2 * 2 + l3 + 2) >> 2;
  931. DST(0,2) = DST(2,1) = (l2 + l3 + 1) >> 1;
  932. DST(1,2) = DST(3,1) = (l2 + l3 * 3 + 2) >> 2;
  933. DST(0,3) = DST(1,3) = DST(2,2) = DST(2,3) = DST(3,2) = DST(3,3) = l3;
  934. }
  935. #define def_hor_up(size) \
  936. static void hor_up_##size##x##size##_c(uint8_t *_dst, ptrdiff_t stride, \
  937. const uint8_t *_left, const uint8_t *top) \
  938. { \
  939. pixel *dst = (pixel *) _dst; \
  940. const pixel *left = (const pixel *) _left; \
  941. int i, j; \
  942. pixel v[size*2 - 2]; \
  943. \
  944. stride /= sizeof(pixel); \
  945. for (i = 0; i < size - 2; i++) { \
  946. v[i*2 ] = (left[i] + left[i + 1] + 1) >> 1; \
  947. v[i*2 + 1] = (left[i] + left[i + 1] * 2 + left[i + 2] + 2) >> 2; \
  948. } \
  949. v[size*2 - 4] = (left[size - 2] + left[size - 1] + 1) >> 1; \
  950. v[size*2 - 3] = (left[size - 2] + left[size - 1] * 3 + 2) >> 2; \
  951. \
  952. for (j = 0; j < size / 2; j++) \
  953. memcpy(dst + j*stride, v + j*2, size * sizeof(pixel)); \
  954. for (j = size / 2; j < size; j++) { \
  955. memcpy(dst + j*stride, v + j*2, (size*2 - 2 - j*2) * sizeof(pixel)); \
  956. memset_bpc(dst + j*stride + size*2 - 2 - j*2, left[size - 1], \
  957. 2 + j*2 - size); \
  958. } \
  959. }
  960. def_hor_up(8)
  961. def_hor_up(16)
  962. def_hor_up(32)
  963. #undef DST
  964. #endif /* BIT_DEPTH != 12 */
  965. #if BIT_DEPTH != 8
  966. void ff_vp9dsp_intrapred_init_10(VP9DSPContext *dsp);
  967. #endif
  968. #if BIT_DEPTH != 10
  969. static
  970. #endif
  971. av_cold void FUNC(ff_vp9dsp_intrapred_init)(VP9DSPContext *dsp)
  972. {
  973. #define init_intra_pred_bd_aware(tx, sz) \
  974. dsp->intra_pred[tx][TM_VP8_PRED] = tm_##sz##_c; \
  975. dsp->intra_pred[tx][DC_128_PRED] = dc_128_##sz##_c; \
  976. dsp->intra_pred[tx][DC_127_PRED] = dc_127_##sz##_c; \
  977. dsp->intra_pred[tx][DC_129_PRED] = dc_129_##sz##_c
  978. #if BIT_DEPTH == 12
  979. ff_vp9dsp_intrapred_init_10(dsp);
  980. #define init_intra_pred(tx, sz) \
  981. init_intra_pred_bd_aware(tx, sz)
  982. #else
  983. #define init_intra_pred(tx, sz) \
  984. dsp->intra_pred[tx][VERT_PRED] = vert_##sz##_c; \
  985. dsp->intra_pred[tx][HOR_PRED] = hor_##sz##_c; \
  986. dsp->intra_pred[tx][DC_PRED] = dc_##sz##_c; \
  987. dsp->intra_pred[tx][DIAG_DOWN_LEFT_PRED] = diag_downleft_##sz##_c; \
  988. dsp->intra_pred[tx][DIAG_DOWN_RIGHT_PRED] = diag_downright_##sz##_c; \
  989. dsp->intra_pred[tx][VERT_RIGHT_PRED] = vert_right_##sz##_c; \
  990. dsp->intra_pred[tx][HOR_DOWN_PRED] = hor_down_##sz##_c; \
  991. dsp->intra_pred[tx][VERT_LEFT_PRED] = vert_left_##sz##_c; \
  992. dsp->intra_pred[tx][HOR_UP_PRED] = hor_up_##sz##_c; \
  993. dsp->intra_pred[tx][LEFT_DC_PRED] = dc_left_##sz##_c; \
  994. dsp->intra_pred[tx][TOP_DC_PRED] = dc_top_##sz##_c; \
  995. init_intra_pred_bd_aware(tx, sz)
  996. #endif
  997. init_intra_pred(TX_4X4, 4x4);
  998. init_intra_pred(TX_8X8, 8x8);
  999. init_intra_pred(TX_16X16, 16x16);
  1000. init_intra_pred(TX_32X32, 32x32);
  1001. #undef init_intra_pred
  1002. #undef init_intra_pred_bd_aware
  1003. }
  1004. #define itxfm_wrapper(type_a, type_b, sz, bits, has_dconly) \
  1005. static void type_a##_##type_b##_##sz##x##sz##_add_c(uint8_t *_dst, \
  1006. ptrdiff_t stride, \
  1007. int16_t *_block, int eob) \
  1008. { \
  1009. int i, j; \
  1010. pixel *dst = (pixel *) _dst; \
  1011. dctcoef *block = (dctcoef *) _block, tmp[sz * sz], out[sz]; \
  1012. \
  1013. stride /= sizeof(pixel); \
  1014. if (has_dconly && eob == 1) { \
  1015. const int t = ((((dctint) block[0] * 11585 + (1 << 13)) >> 14) \
  1016. * 11585 + (1 << 13)) >> 14; \
  1017. block[0] = 0; \
  1018. for (i = 0; i < sz; i++) { \
  1019. for (j = 0; j < sz; j++) \
  1020. dst[j * stride] = av_clip_pixel(dst[j * stride] + \
  1021. (bits ? \
  1022. (t + (1 << (bits - 1))) >> bits : \
  1023. t)); \
  1024. dst++; \
  1025. } \
  1026. return; \
  1027. } \
  1028. \
  1029. for (i = 0; i < sz; i++) \
  1030. type_a##sz##_1d(block + i, sz, tmp + i * sz, 0); \
  1031. memset(block, 0, sz * sz * sizeof(*block)); \
  1032. for (i = 0; i < sz; i++) { \
  1033. type_b##sz##_1d(tmp + i, sz, out, 1); \
  1034. for (j = 0; j < sz; j++) \
  1035. dst[j * stride] = av_clip_pixel(dst[j * stride] + \
  1036. (bits ? \
  1037. (out[j] + (1 << (bits - 1))) >> bits : \
  1038. out[j])); \
  1039. dst++; \
  1040. } \
  1041. }
  1042. #define itxfm_wrap(sz, bits) \
  1043. itxfm_wrapper(idct, idct, sz, bits, 1) \
  1044. itxfm_wrapper(iadst, idct, sz, bits, 0) \
  1045. itxfm_wrapper(idct, iadst, sz, bits, 0) \
  1046. itxfm_wrapper(iadst, iadst, sz, bits, 0)
  1047. #define IN(x) ((dctint) in[(x) * stride])
  1048. static av_always_inline void idct4_1d(const dctcoef *in, ptrdiff_t stride,
  1049. dctcoef *out, int pass)
  1050. {
  1051. dctint t0, t1, t2, t3;
  1052. t0 = ((IN(0) + IN(2)) * 11585 + (1 << 13)) >> 14;
  1053. t1 = ((IN(0) - IN(2)) * 11585 + (1 << 13)) >> 14;
  1054. t2 = (IN(1) * 6270 - IN(3) * 15137 + (1 << 13)) >> 14;
  1055. t3 = (IN(1) * 15137 + IN(3) * 6270 + (1 << 13)) >> 14;
  1056. out[0] = t0 + t3;
  1057. out[1] = t1 + t2;
  1058. out[2] = t1 - t2;
  1059. out[3] = t0 - t3;
  1060. }
  1061. static av_always_inline void iadst4_1d(const dctcoef *in, ptrdiff_t stride,
  1062. dctcoef *out, int pass)
  1063. {
  1064. dctint t0, t1, t2, t3;
  1065. t0 = 5283 * IN(0) + 15212 * IN(2) + 9929 * IN(3);
  1066. t1 = 9929 * IN(0) - 5283 * IN(2) - 15212 * IN(3);
  1067. t2 = 13377 * (IN(0) - IN(2) + IN(3));
  1068. t3 = 13377 * IN(1);
  1069. out[0] = (t0 + t3 + (1 << 13)) >> 14;
  1070. out[1] = (t1 + t3 + (1 << 13)) >> 14;
  1071. out[2] = (t2 + (1 << 13)) >> 14;
  1072. out[3] = (t0 + t1 - t3 + (1 << 13)) >> 14;
  1073. }
  1074. itxfm_wrap(4, 4)
  1075. static av_always_inline void idct8_1d(const dctcoef *in, ptrdiff_t stride,
  1076. dctcoef *out, int pass)
  1077. {
  1078. dctint t0, t0a, t1, t1a, t2, t2a, t3, t3a, t4, t4a, t5, t5a, t6, t6a, t7, t7a;
  1079. t0a = ((IN(0) + IN(4)) * 11585 + (1 << 13)) >> 14;
  1080. t1a = ((IN(0) - IN(4)) * 11585 + (1 << 13)) >> 14;
  1081. t2a = (IN(2) * 6270 - IN(6) * 15137 + (1 << 13)) >> 14;
  1082. t3a = (IN(2) * 15137 + IN(6) * 6270 + (1 << 13)) >> 14;
  1083. t4a = (IN(1) * 3196 - IN(7) * 16069 + (1 << 13)) >> 14;
  1084. t5a = (IN(5) * 13623 - IN(3) * 9102 + (1 << 13)) >> 14;
  1085. t6a = (IN(5) * 9102 + IN(3) * 13623 + (1 << 13)) >> 14;
  1086. t7a = (IN(1) * 16069 + IN(7) * 3196 + (1 << 13)) >> 14;
  1087. t0 = t0a + t3a;
  1088. t1 = t1a + t2a;
  1089. t2 = t1a - t2a;
  1090. t3 = t0a - t3a;
  1091. t4 = t4a + t5a;
  1092. t5a = t4a - t5a;
  1093. t7 = t7a + t6a;
  1094. t6a = t7a - t6a;
  1095. t5 = ((t6a - t5a) * 11585 + (1 << 13)) >> 14;
  1096. t6 = ((t6a + t5a) * 11585 + (1 << 13)) >> 14;
  1097. out[0] = t0 + t7;
  1098. out[1] = t1 + t6;
  1099. out[2] = t2 + t5;
  1100. out[3] = t3 + t4;
  1101. out[4] = t3 - t4;
  1102. out[5] = t2 - t5;
  1103. out[6] = t1 - t6;
  1104. out[7] = t0 - t7;
  1105. }
  1106. static av_always_inline void iadst8_1d(const dctcoef *in, ptrdiff_t stride,
  1107. dctcoef *out, int pass)
  1108. {
  1109. dctint t0, t0a, t1, t1a, t2, t2a, t3, t3a, t4, t4a, t5, t5a, t6, t6a, t7, t7a;
  1110. t0a = 16305 * IN(7) + 1606 * IN(0);
  1111. t1a = 1606 * IN(7) - 16305 * IN(0);
  1112. t2a = 14449 * IN(5) + 7723 * IN(2);
  1113. t3a = 7723 * IN(5) - 14449 * IN(2);
  1114. t4a = 10394 * IN(3) + 12665 * IN(4);
  1115. t5a = 12665 * IN(3) - 10394 * IN(4);
  1116. t6a = 4756 * IN(1) + 15679 * IN(6);
  1117. t7a = 15679 * IN(1) - 4756 * IN(6);
  1118. t0 = (t0a + t4a + (1 << 13)) >> 14;
  1119. t1 = (t1a + t5a + (1 << 13)) >> 14;
  1120. t2 = (t2a + t6a + (1 << 13)) >> 14;
  1121. t3 = (t3a + t7a + (1 << 13)) >> 14;
  1122. t4 = (t0a - t4a + (1 << 13)) >> 14;
  1123. t5 = (t1a - t5a + (1 << 13)) >> 14;
  1124. t6 = (t2a - t6a + (1 << 13)) >> 14;
  1125. t7 = (t3a - t7a + (1 << 13)) >> 14;
  1126. t4a = 15137 * t4 + 6270 * t5;
  1127. t5a = 6270 * t4 - 15137 * t5;
  1128. t6a = 15137 * t7 - 6270 * t6;
  1129. t7a = 6270 * t7 + 15137 * t6;
  1130. out[0] = t0 + t2;
  1131. out[7] = -(t1 + t3);
  1132. t2 = t0 - t2;
  1133. t3 = t1 - t3;
  1134. out[1] = -((t4a + t6a + (1 << 13)) >> 14);
  1135. out[6] = (t5a + t7a + (1 << 13)) >> 14;
  1136. t6 = (t4a - t6a + (1 << 13)) >> 14;
  1137. t7 = (t5a - t7a + (1 << 13)) >> 14;
  1138. out[3] = -(((t2 + t3) * 11585 + (1 << 13)) >> 14);
  1139. out[4] = ((t2 - t3) * 11585 + (1 << 13)) >> 14;
  1140. out[2] = ((t6 + t7) * 11585 + (1 << 13)) >> 14;
  1141. out[5] = -(((t6 - t7) * 11585 + (1 << 13)) >> 14);
  1142. }
  1143. itxfm_wrap(8, 5)
  1144. static av_always_inline void idct16_1d(const dctcoef *in, ptrdiff_t stride,
  1145. dctcoef *out, int pass)
  1146. {
  1147. dctint t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
  1148. dctint t0a, t1a, t2a, t3a, t4a, t5a, t6a, t7a;
  1149. dctint t8a, t9a, t10a, t11a, t12a, t13a, t14a, t15a;
  1150. t0a = ((IN(0) + IN(8)) * 11585 + (1 << 13)) >> 14;
  1151. t1a = ((IN(0) - IN(8)) * 11585 + (1 << 13)) >> 14;
  1152. t2a = (IN(4) * 6270 - IN(12) * 15137 + (1 << 13)) >> 14;
  1153. t3a = (IN(4) * 15137 + IN(12) * 6270 + (1 << 13)) >> 14;
  1154. t4a = (IN(2) * 3196 - IN(14) * 16069 + (1 << 13)) >> 14;
  1155. t7a = (IN(2) * 16069 + IN(14) * 3196 + (1 << 13)) >> 14;
  1156. t5a = (IN(10) * 13623 - IN(6) * 9102 + (1 << 13)) >> 14;
  1157. t6a = (IN(10) * 9102 + IN(6) * 13623 + (1 << 13)) >> 14;
  1158. t8a = (IN(1) * 1606 - IN(15) * 16305 + (1 << 13)) >> 14;
  1159. t15a = (IN(1) * 16305 + IN(15) * 1606 + (1 << 13)) >> 14;
  1160. t9a = (IN(9) * 12665 - IN(7) * 10394 + (1 << 13)) >> 14;
  1161. t14a = (IN(9) * 10394 + IN(7) * 12665 + (1 << 13)) >> 14;
  1162. t10a = (IN(5) * 7723 - IN(11) * 14449 + (1 << 13)) >> 14;
  1163. t13a = (IN(5) * 14449 + IN(11) * 7723 + (1 << 13)) >> 14;
  1164. t11a = (IN(13) * 15679 - IN(3) * 4756 + (1 << 13)) >> 14;
  1165. t12a = (IN(13) * 4756 + IN(3) * 15679 + (1 << 13)) >> 14;
  1166. t0 = t0a + t3a;
  1167. t1 = t1a + t2a;
  1168. t2 = t1a - t2a;
  1169. t3 = t0a - t3a;
  1170. t4 = t4a + t5a;
  1171. t5 = t4a - t5a;
  1172. t6 = t7a - t6a;
  1173. t7 = t7a + t6a;
  1174. t8 = t8a + t9a;
  1175. t9 = t8a - t9a;
  1176. t10 = t11a - t10a;
  1177. t11 = t11a + t10a;
  1178. t12 = t12a + t13a;
  1179. t13 = t12a - t13a;
  1180. t14 = t15a - t14a;
  1181. t15 = t15a + t14a;
  1182. t5a = ((t6 - t5) * 11585 + (1 << 13)) >> 14;
  1183. t6a = ((t6 + t5) * 11585 + (1 << 13)) >> 14;
  1184. t9a = ( t14 * 6270 - t9 * 15137 + (1 << 13)) >> 14;
  1185. t14a = ( t14 * 15137 + t9 * 6270 + (1 << 13)) >> 14;
  1186. t10a = (-(t13 * 15137 + t10 * 6270) + (1 << 13)) >> 14;
  1187. t13a = ( t13 * 6270 - t10 * 15137 + (1 << 13)) >> 14;
  1188. t0a = t0 + t7;
  1189. t1a = t1 + t6a;
  1190. t2a = t2 + t5a;
  1191. t3a = t3 + t4;
  1192. t4 = t3 - t4;
  1193. t5 = t2 - t5a;
  1194. t6 = t1 - t6a;
  1195. t7 = t0 - t7;
  1196. t8a = t8 + t11;
  1197. t9 = t9a + t10a;
  1198. t10 = t9a - t10a;
  1199. t11a = t8 - t11;
  1200. t12a = t15 - t12;
  1201. t13 = t14a - t13a;
  1202. t14 = t14a + t13a;
  1203. t15a = t15 + t12;
  1204. t10a = ((t13 - t10) * 11585 + (1 << 13)) >> 14;
  1205. t13a = ((t13 + t10) * 11585 + (1 << 13)) >> 14;
  1206. t11 = ((t12a - t11a) * 11585 + (1 << 13)) >> 14;
  1207. t12 = ((t12a + t11a) * 11585 + (1 << 13)) >> 14;
  1208. out[ 0] = t0a + t15a;
  1209. out[ 1] = t1a + t14;
  1210. out[ 2] = t2a + t13a;
  1211. out[ 3] = t3a + t12;
  1212. out[ 4] = t4 + t11;
  1213. out[ 5] = t5 + t10a;
  1214. out[ 6] = t6 + t9;
  1215. out[ 7] = t7 + t8a;
  1216. out[ 8] = t7 - t8a;
  1217. out[ 9] = t6 - t9;
  1218. out[10] = t5 - t10a;
  1219. out[11] = t4 - t11;
  1220. out[12] = t3a - t12;
  1221. out[13] = t2a - t13a;
  1222. out[14] = t1a - t14;
  1223. out[15] = t0a - t15a;
  1224. }
  1225. static av_always_inline void iadst16_1d(const dctcoef *in, ptrdiff_t stride,
  1226. dctcoef *out, int pass)
  1227. {
  1228. dctint t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
  1229. dctint t0a, t1a, t2a, t3a, t4a, t5a, t6a, t7a;
  1230. dctint t8a, t9a, t10a, t11a, t12a, t13a, t14a, t15a;
  1231. t0 = IN(15) * 16364 + IN(0) * 804;
  1232. t1 = IN(15) * 804 - IN(0) * 16364;
  1233. t2 = IN(13) * 15893 + IN(2) * 3981;
  1234. t3 = IN(13) * 3981 - IN(2) * 15893;
  1235. t4 = IN(11) * 14811 + IN(4) * 7005;
  1236. t5 = IN(11) * 7005 - IN(4) * 14811;
  1237. t6 = IN(9) * 13160 + IN(6) * 9760;
  1238. t7 = IN(9) * 9760 - IN(6) * 13160;
  1239. t8 = IN(7) * 11003 + IN(8) * 12140;
  1240. t9 = IN(7) * 12140 - IN(8) * 11003;
  1241. t10 = IN(5) * 8423 + IN(10) * 14053;
  1242. t11 = IN(5) * 14053 - IN(10) * 8423;
  1243. t12 = IN(3) * 5520 + IN(12) * 15426;
  1244. t13 = IN(3) * 15426 - IN(12) * 5520;
  1245. t14 = IN(1) * 2404 + IN(14) * 16207;
  1246. t15 = IN(1) * 16207 - IN(14) * 2404;
  1247. t0a = (t0 + t8 + (1 << 13)) >> 14;
  1248. t1a = (t1 + t9 + (1 << 13)) >> 14;
  1249. t2a = (t2 + t10 + (1 << 13)) >> 14;
  1250. t3a = (t3 + t11 + (1 << 13)) >> 14;
  1251. t4a = (t4 + t12 + (1 << 13)) >> 14;
  1252. t5a = (t5 + t13 + (1 << 13)) >> 14;
  1253. t6a = (t6 + t14 + (1 << 13)) >> 14;
  1254. t7a = (t7 + t15 + (1 << 13)) >> 14;
  1255. t8a = (t0 - t8 + (1 << 13)) >> 14;
  1256. t9a = (t1 - t9 + (1 << 13)) >> 14;
  1257. t10a = (t2 - t10 + (1 << 13)) >> 14;
  1258. t11a = (t3 - t11 + (1 << 13)) >> 14;
  1259. t12a = (t4 - t12 + (1 << 13)) >> 14;
  1260. t13a = (t5 - t13 + (1 << 13)) >> 14;
  1261. t14a = (t6 - t14 + (1 << 13)) >> 14;
  1262. t15a = (t7 - t15 + (1 << 13)) >> 14;
  1263. t8 = t8a * 16069 + t9a * 3196;
  1264. t9 = t8a * 3196 - t9a * 16069;
  1265. t10 = t10a * 9102 + t11a * 13623;
  1266. t11 = t10a * 13623 - t11a * 9102;
  1267. t12 = t13a * 16069 - t12a * 3196;
  1268. t13 = t13a * 3196 + t12a * 16069;
  1269. t14 = t15a * 9102 - t14a * 13623;
  1270. t15 = t15a * 13623 + t14a * 9102;
  1271. t0 = t0a + t4a;
  1272. t1 = t1a + t5a;
  1273. t2 = t2a + t6a;
  1274. t3 = t3a + t7a;
  1275. t4 = t0a - t4a;
  1276. t5 = t1a - t5a;
  1277. t6 = t2a - t6a;
  1278. t7 = t3a - t7a;
  1279. t8a = (t8 + t12 + (1 << 13)) >> 14;
  1280. t9a = (t9 + t13 + (1 << 13)) >> 14;
  1281. t10a = (t10 + t14 + (1 << 13)) >> 14;
  1282. t11a = (t11 + t15 + (1 << 13)) >> 14;
  1283. t12a = (t8 - t12 + (1 << 13)) >> 14;
  1284. t13a = (t9 - t13 + (1 << 13)) >> 14;
  1285. t14a = (t10 - t14 + (1 << 13)) >> 14;
  1286. t15a = (t11 - t15 + (1 << 13)) >> 14;
  1287. t4a = t4 * 15137 + t5 * 6270;
  1288. t5a = t4 * 6270 - t5 * 15137;
  1289. t6a = t7 * 15137 - t6 * 6270;
  1290. t7a = t7 * 6270 + t6 * 15137;
  1291. t12 = t12a * 15137 + t13a * 6270;
  1292. t13 = t12a * 6270 - t13a * 15137;
  1293. t14 = t15a * 15137 - t14a * 6270;
  1294. t15 = t15a * 6270 + t14a * 15137;
  1295. out[ 0] = t0 + t2;
  1296. out[15] = -(t1 + t3);
  1297. t2a = t0 - t2;
  1298. t3a = t1 - t3;
  1299. out[ 3] = -((t4a + t6a + (1 << 13)) >> 14);
  1300. out[12] = (t5a + t7a + (1 << 13)) >> 14;
  1301. t6 = (t4a - t6a + (1 << 13)) >> 14;
  1302. t7 = (t5a - t7a + (1 << 13)) >> 14;
  1303. out[ 1] = -(t8a + t10a);
  1304. out[14] = t9a + t11a;
  1305. t10 = t8a - t10a;
  1306. t11 = t9a - t11a;
  1307. out[ 2] = (t12 + t14 + (1 << 13)) >> 14;
  1308. out[13] = -((t13 + t15 + (1 << 13)) >> 14);
  1309. t14a = (t12 - t14 + (1 << 13)) >> 14;
  1310. t15a = (t13 - t15 + (1 << 13)) >> 14;
  1311. out[ 7] = ((t2a + t3a) * -11585 + (1 << 13)) >> 14;
  1312. out[ 8] = ((t2a - t3a) * 11585 + (1 << 13)) >> 14;
  1313. out[ 4] = ((t7 + t6) * 11585 + (1 << 13)) >> 14;
  1314. out[11] = ((t7 - t6) * 11585 + (1 << 13)) >> 14;
  1315. out[ 6] = ((t11 + t10) * 11585 + (1 << 13)) >> 14;
  1316. out[ 9] = ((t11 - t10) * 11585 + (1 << 13)) >> 14;
  1317. out[ 5] = ((t14a + t15a) * -11585 + (1 << 13)) >> 14;
  1318. out[10] = ((t14a - t15a) * 11585 + (1 << 13)) >> 14;
  1319. }
  1320. itxfm_wrap(16, 6)
  1321. static av_always_inline void idct32_1d(const dctcoef *in, ptrdiff_t stride,
  1322. dctcoef *out, int pass)
  1323. {
  1324. dctint t0a = (dctint)((IN(0) + IN(16)) * 11585U + (1 << 13)) >> 14;
  1325. dctint t1a = (dctint)((IN(0) - IN(16)) * 11585U + (1 << 13)) >> 14;
  1326. dctint t2a = (dctint)(IN( 8) * 6270U - IN(24) * 15137U + (1 << 13)) >> 14;
  1327. dctint t3a = (dctint)(IN( 8) * 15137U + IN(24) * 6270U + (1 << 13)) >> 14;
  1328. dctint t4a = (dctint)(IN( 4) * 3196U - IN(28) * 16069U + (1 << 13)) >> 14;
  1329. dctint t7a = (dctint)(IN( 4) * 16069U + IN(28) * 3196U + (1 << 13)) >> 14;
  1330. dctint t5a = (dctint)(IN(20) * 13623U - IN(12) * 9102U + (1 << 13)) >> 14;
  1331. dctint t6a = (dctint)(IN(20) * 9102U + IN(12) * 13623U + (1 << 13)) >> 14;
  1332. dctint t8a = (dctint)(IN( 2) * 1606U - IN(30) * 16305U + (1 << 13)) >> 14;
  1333. dctint t15a = (dctint)(IN( 2) * 16305U + IN(30) * 1606U + (1 << 13)) >> 14;
  1334. dctint t9a = (dctint)(IN(18) * 12665U - IN(14) * 10394U + (1 << 13)) >> 14;
  1335. dctint t14a = (dctint)(IN(18) * 10394U + IN(14) * 12665U + (1 << 13)) >> 14;
  1336. dctint t10a = (dctint)(IN(10) * 7723U - IN(22) * 14449U + (1 << 13)) >> 14;
  1337. dctint t13a = (dctint)(IN(10) * 14449U + IN(22) * 7723U + (1 << 13)) >> 14;
  1338. dctint t11a = (dctint)(IN(26) * 15679U - IN( 6) * 4756U + (1 << 13)) >> 14;
  1339. dctint t12a = (dctint)(IN(26) * 4756U + IN( 6) * 15679U + (1 << 13)) >> 14;
  1340. dctint t16a = (dctint)(IN( 1) * 804U - IN(31) * 16364U + (1 << 13)) >> 14;
  1341. dctint t31a = (dctint)(IN( 1) * 16364U + IN(31) * 804U + (1 << 13)) >> 14;
  1342. dctint t17a = (dctint)(IN(17) * 12140U - IN(15) * 11003U + (1 << 13)) >> 14;
  1343. dctint t30a = (dctint)(IN(17) * 11003U + IN(15) * 12140U + (1 << 13)) >> 14;
  1344. dctint t18a = (dctint)(IN( 9) * 7005U - IN(23) * 14811U + (1 << 13)) >> 14;
  1345. dctint t29a = (dctint)(IN( 9) * 14811U + IN(23) * 7005U + (1 << 13)) >> 14;
  1346. dctint t19a = (dctint)(IN(25) * 15426U - IN( 7) * 5520U + (1 << 13)) >> 14;
  1347. dctint t28a = (dctint)(IN(25) * 5520U + IN( 7) * 15426U + (1 << 13)) >> 14;
  1348. dctint t20a = (dctint)(IN( 5) * 3981U - IN(27) * 15893U + (1 << 13)) >> 14;
  1349. dctint t27a = (dctint)(IN( 5) * 15893U + IN(27) * 3981U + (1 << 13)) >> 14;
  1350. dctint t21a = (dctint)(IN(21) * 14053U - IN(11) * 8423U + (1 << 13)) >> 14;
  1351. dctint t26a = (dctint)(IN(21) * 8423U + IN(11) * 14053U + (1 << 13)) >> 14;
  1352. dctint t22a = (dctint)(IN(13) * 9760U - IN(19) * 13160U + (1 << 13)) >> 14;
  1353. dctint t25a = (dctint)(IN(13) * 13160U + IN(19) * 9760U + (1 << 13)) >> 14;
  1354. dctint t23a = (dctint)(IN(29) * 16207U - IN( 3) * 2404U + (1 << 13)) >> 14;
  1355. dctint t24a = (dctint)(IN(29) * 2404U + IN( 3) * 16207U + (1 << 13)) >> 14;
  1356. dctint t0 = t0a + t3a;
  1357. dctint t1 = t1a + t2a;
  1358. dctint t2 = t1a - t2a;
  1359. dctint t3 = t0a - t3a;
  1360. dctint t4 = t4a + t5a;
  1361. dctint t5 = t4a - t5a;
  1362. dctint t6 = t7a - t6a;
  1363. dctint t7 = t7a + t6a;
  1364. dctint t8 = t8a + t9a;
  1365. dctint t9 = t8a - t9a;
  1366. dctint t10 = t11a - t10a;
  1367. dctint t11 = t11a + t10a;
  1368. dctint t12 = t12a + t13a;
  1369. dctint t13 = t12a - t13a;
  1370. dctint t14 = t15a - t14a;
  1371. dctint t15 = t15a + t14a;
  1372. dctint t16 = t16a + t17a;
  1373. dctint t17 = t16a - t17a;
  1374. dctint t18 = t19a - t18a;
  1375. dctint t19 = t19a + t18a;
  1376. dctint t20 = t20a + t21a;
  1377. dctint t21 = t20a - t21a;
  1378. dctint t22 = t23a - t22a;
  1379. dctint t23 = t23a + t22a;
  1380. dctint t24 = t24a + t25a;
  1381. dctint t25 = t24a - t25a;
  1382. dctint t26 = t27a - t26a;
  1383. dctint t27 = t27a + t26a;
  1384. dctint t28 = t28a + t29a;
  1385. dctint t29 = t28a - t29a;
  1386. dctint t30 = t31a - t30a;
  1387. dctint t31 = t31a + t30a;
  1388. t5a = (dctint)((t6 - t5) * 11585U + (1 << 13)) >> 14;
  1389. t6a = (dctint)((t6 + t5) * 11585U + (1 << 13)) >> 14;
  1390. t9a = (dctint)( t14 * 6270U - t9 * 15137U + (1 << 13)) >> 14;
  1391. t14a = (dctint)( t14 * 15137U + t9 * 6270U + (1 << 13)) >> 14;
  1392. t10a = (dctint)(-(t13 * 15137U + t10 * 6270U) + (1 << 13)) >> 14;
  1393. t13a = (dctint)( t13 * 6270U - t10 * 15137U + (1 << 13)) >> 14;
  1394. t17a = (dctint)( t30 * 3196U - t17 * 16069U + (1 << 13)) >> 14;
  1395. t30a = (dctint)( t30 * 16069U + t17 * 3196U + (1 << 13)) >> 14;
  1396. t18a = (dctint)(-(t29 * 16069U + t18 * 3196U) + (1 << 13)) >> 14;
  1397. t29a = (dctint)( t29 * 3196U - t18 * 16069U + (1 << 13)) >> 14;
  1398. t21a = (dctint)( t26 * 13623U - t21 * 9102U + (1 << 13)) >> 14;
  1399. t26a = (dctint)( t26 * 9102U + t21 * 13623U + (1 << 13)) >> 14;
  1400. t22a = (dctint)(-(t25 * 9102U + t22 * 13623U) + (1 << 13)) >> 14;
  1401. t25a = (dctint)( t25 * 13623U - t22 * 9102U + (1 << 13)) >> 14;
  1402. t0a = t0 + t7;
  1403. t1a = t1 + t6a;
  1404. t2a = t2 + t5a;
  1405. t3a = t3 + t4;
  1406. t4a = t3 - t4;
  1407. t5 = t2 - t5a;
  1408. t6 = t1 - t6a;
  1409. t7a = t0 - t7;
  1410. t8a = t8 + t11;
  1411. t9 = t9a + t10a;
  1412. t10 = t9a - t10a;
  1413. t11a = t8 - t11;
  1414. t12a = t15 - t12;
  1415. t13 = t14a - t13a;
  1416. t14 = t14a + t13a;
  1417. t15a = t15 + t12;
  1418. t16a = t16 + t19;
  1419. t17 = t17a + t18a;
  1420. t18 = t17a - t18a;
  1421. t19a = t16 - t19;
  1422. t20a = t23 - t20;
  1423. t21 = t22a - t21a;
  1424. t22 = t22a + t21a;
  1425. t23a = t23 + t20;
  1426. t24a = t24 + t27;
  1427. t25 = t25a + t26a;
  1428. t26 = t25a - t26a;
  1429. t27a = t24 - t27;
  1430. t28a = t31 - t28;
  1431. t29 = t30a - t29a;
  1432. t30 = t30a + t29a;
  1433. t31a = t31 + t28;
  1434. t10a = (dctint)((t13 - t10) * 11585U + (1 << 13)) >> 14;
  1435. t13a = (dctint)((t13 + t10) * 11585U + (1 << 13)) >> 14;
  1436. t11 = (dctint)((t12a - t11a) * 11585U + (1 << 13)) >> 14;
  1437. t12 = (dctint)((t12a + t11a) * 11585U + (1 << 13)) >> 14;
  1438. t18a = (dctint)( t29 * 6270U - t18 * 15137U + (1 << 13)) >> 14;
  1439. t29a = (dctint)( t29 * 15137U + t18 * 6270U + (1 << 13)) >> 14;
  1440. t19 = (dctint)( t28a * 6270U - t19a * 15137U + (1 << 13)) >> 14;
  1441. t28 = (dctint)( t28a * 15137U + t19a * 6270U + (1 << 13)) >> 14;
  1442. t20 = (dctint)(-(t27a * 15137U + t20a * 6270U) + (1 << 13)) >> 14;
  1443. t27 = (dctint)( t27a * 6270U - t20a * 15137U + (1 << 13)) >> 14;
  1444. t21a = (dctint)(-(t26 * 15137U + t21 * 6270U) + (1 << 13)) >> 14;
  1445. t26a = (dctint)( t26 * 6270U - t21 * 15137U + (1 << 13)) >> 14;
  1446. t0 = t0a + t15a;
  1447. t1 = t1a + t14;
  1448. t2 = t2a + t13a;
  1449. t3 = t3a + t12;
  1450. t4 = t4a + t11;
  1451. t5a = t5 + t10a;
  1452. t6a = t6 + t9;
  1453. t7 = t7a + t8a;
  1454. t8 = t7a - t8a;
  1455. t9a = t6 - t9;
  1456. t10 = t5 - t10a;
  1457. t11a = t4a - t11;
  1458. t12a = t3a - t12;
  1459. t13 = t2a - t13a;
  1460. t14a = t1a - t14;
  1461. t15 = t0a - t15a;
  1462. t16 = t16a + t23a;
  1463. t17a = t17 + t22;
  1464. t18 = t18a + t21a;
  1465. t19a = t19 + t20;
  1466. t20a = t19 - t20;
  1467. t21 = t18a - t21a;
  1468. t22a = t17 - t22;
  1469. t23 = t16a - t23a;
  1470. t24 = t31a - t24a;
  1471. t25a = t30 - t25;
  1472. t26 = t29a - t26a;
  1473. t27a = t28 - t27;
  1474. t28a = t28 + t27;
  1475. t29 = t29a + t26a;
  1476. t30a = t30 + t25;
  1477. t31 = t31a + t24a;
  1478. t20 = (dctint)((t27a - t20a) * 11585U + (1 << 13)) >> 14;
  1479. t27 = (dctint)((t27a + t20a) * 11585U + (1 << 13)) >> 14;
  1480. t21a = (dctint)((t26 - t21 ) * 11585U + (1 << 13)) >> 14;
  1481. t26a = (dctint)((t26 + t21 ) * 11585U + (1 << 13)) >> 14;
  1482. t22 = (dctint)((t25a - t22a) * 11585U + (1 << 13)) >> 14;
  1483. t25 = (dctint)((t25a + t22a) * 11585U + (1 << 13)) >> 14;
  1484. t23a = (dctint)((t24 - t23 ) * 11585U + (1 << 13)) >> 14;
  1485. t24a = (dctint)((t24 + t23 ) * 11585U + (1 << 13)) >> 14;
  1486. out[ 0] = t0 + t31;
  1487. out[ 1] = t1 + t30a;
  1488. out[ 2] = t2 + t29;
  1489. out[ 3] = t3 + t28a;
  1490. out[ 4] = t4 + t27;
  1491. out[ 5] = t5a + t26a;
  1492. out[ 6] = t6a + t25;
  1493. out[ 7] = t7 + t24a;
  1494. out[ 8] = t8 + t23a;
  1495. out[ 9] = t9a + t22;
  1496. out[10] = t10 + t21a;
  1497. out[11] = t11a + t20;
  1498. out[12] = t12a + t19a;
  1499. out[13] = t13 + t18;
  1500. out[14] = t14a + t17a;
  1501. out[15] = t15 + t16;
  1502. out[16] = t15 - t16;
  1503. out[17] = t14a - t17a;
  1504. out[18] = t13 - t18;
  1505. out[19] = t12a - t19a;
  1506. out[20] = t11a - t20;
  1507. out[21] = t10 - t21a;
  1508. out[22] = t9a - t22;
  1509. out[23] = t8 - t23a;
  1510. out[24] = t7 - t24a;
  1511. out[25] = t6a - t25;
  1512. out[26] = t5a - t26a;
  1513. out[27] = t4 - t27;
  1514. out[28] = t3 - t28a;
  1515. out[29] = t2 - t29;
  1516. out[30] = t1 - t30a;
  1517. out[31] = t0 - t31;
  1518. }
  1519. itxfm_wrapper(idct, idct, 32, 6, 1)
  1520. static av_always_inline void iwht4_1d(const dctcoef *in, ptrdiff_t stride,
  1521. dctcoef *out, int pass)
  1522. {
  1523. int t0, t1, t2, t3, t4;
  1524. if (pass == 0) {
  1525. t0 = IN(0) >> 2;
  1526. t1 = IN(3) >> 2;
  1527. t2 = IN(1) >> 2;
  1528. t3 = IN(2) >> 2;
  1529. } else {
  1530. t0 = IN(0);
  1531. t1 = IN(3);
  1532. t2 = IN(1);
  1533. t3 = IN(2);
  1534. }
  1535. t0 += t2;
  1536. t3 -= t1;
  1537. t4 = (t0 - t3) >> 1;
  1538. t1 = t4 - t1;
  1539. t2 = t4 - t2;
  1540. t0 -= t1;
  1541. t3 += t2;
  1542. out[0] = t0;
  1543. out[1] = t1;
  1544. out[2] = t2;
  1545. out[3] = t3;
  1546. }
  1547. itxfm_wrapper(iwht, iwht, 4, 0, 0)
  1548. #undef IN
  1549. #undef itxfm_wrapper
  1550. #undef itxfm_wrap
  1551. static av_cold void vp9dsp_itxfm_init(VP9DSPContext *dsp)
  1552. {
  1553. #define init_itxfm(tx, sz) \
  1554. dsp->itxfm_add[tx][DCT_DCT] = idct_idct_##sz##_add_c; \
  1555. dsp->itxfm_add[tx][DCT_ADST] = iadst_idct_##sz##_add_c; \
  1556. dsp->itxfm_add[tx][ADST_DCT] = idct_iadst_##sz##_add_c; \
  1557. dsp->itxfm_add[tx][ADST_ADST] = iadst_iadst_##sz##_add_c
  1558. #define init_idct(tx, nm) \
  1559. dsp->itxfm_add[tx][DCT_DCT] = \
  1560. dsp->itxfm_add[tx][ADST_DCT] = \
  1561. dsp->itxfm_add[tx][DCT_ADST] = \
  1562. dsp->itxfm_add[tx][ADST_ADST] = nm##_add_c
  1563. init_itxfm(TX_4X4, 4x4);
  1564. init_itxfm(TX_8X8, 8x8);
  1565. init_itxfm(TX_16X16, 16x16);
  1566. init_idct(TX_32X32, idct_idct_32x32);
  1567. init_idct(4 /* lossless */, iwht_iwht_4x4);
  1568. #undef init_itxfm
  1569. #undef init_idct
  1570. }
  1571. static av_always_inline void loop_filter(pixel *dst, int E, int I, int H,
  1572. ptrdiff_t stridea, ptrdiff_t strideb,
  1573. int wd)
  1574. {
  1575. int i, F = 1 << (BIT_DEPTH - 8);
  1576. E <<= (BIT_DEPTH - 8);
  1577. I <<= (BIT_DEPTH - 8);
  1578. H <<= (BIT_DEPTH - 8);
  1579. for (i = 0; i < 8; i++, dst += stridea) {
  1580. int p7, p6, p5, p4;
  1581. int p3 = dst[strideb * -4], p2 = dst[strideb * -3];
  1582. int p1 = dst[strideb * -2], p0 = dst[strideb * -1];
  1583. int q0 = dst[strideb * +0], q1 = dst[strideb * +1];
  1584. int q2 = dst[strideb * +2], q3 = dst[strideb * +3];
  1585. int q4, q5, q6, q7;
  1586. int fm = FFABS(p3 - p2) <= I && FFABS(p2 - p1) <= I &&
  1587. FFABS(p1 - p0) <= I && FFABS(q1 - q0) <= I &&
  1588. FFABS(q2 - q1) <= I && FFABS(q3 - q2) <= I &&
  1589. FFABS(p0 - q0) * 2 + (FFABS(p1 - q1) >> 1) <= E;
  1590. int flat8out, flat8in;
  1591. if (!fm)
  1592. continue;
  1593. if (wd >= 16) {
  1594. p7 = dst[strideb * -8];
  1595. p6 = dst[strideb * -7];
  1596. p5 = dst[strideb * -6];
  1597. p4 = dst[strideb * -5];
  1598. q4 = dst[strideb * +4];
  1599. q5 = dst[strideb * +5];
  1600. q6 = dst[strideb * +6];
  1601. q7 = dst[strideb * +7];
  1602. flat8out = FFABS(p7 - p0) <= F && FFABS(p6 - p0) <= F &&
  1603. FFABS(p5 - p0) <= F && FFABS(p4 - p0) <= F &&
  1604. FFABS(q4 - q0) <= F && FFABS(q5 - q0) <= F &&
  1605. FFABS(q6 - q0) <= F && FFABS(q7 - q0) <= F;
  1606. }
  1607. if (wd >= 8)
  1608. flat8in = FFABS(p3 - p0) <= F && FFABS(p2 - p0) <= F &&
  1609. FFABS(p1 - p0) <= F && FFABS(q1 - q0) <= F &&
  1610. FFABS(q2 - q0) <= F && FFABS(q3 - q0) <= F;
  1611. if (wd >= 16 && flat8out && flat8in) {
  1612. dst[strideb * -7] = (p7 + p7 + p7 + p7 + p7 + p7 + p7 + p6 * 2 +
  1613. p5 + p4 + p3 + p2 + p1 + p0 + q0 + 8) >> 4;
  1614. dst[strideb * -6] = (p7 + p7 + p7 + p7 + p7 + p7 + p6 + p5 * 2 +
  1615. p4 + p3 + p2 + p1 + p0 + q0 + q1 + 8) >> 4;
  1616. dst[strideb * -5] = (p7 + p7 + p7 + p7 + p7 + p6 + p5 + p4 * 2 +
  1617. p3 + p2 + p1 + p0 + q0 + q1 + q2 + 8) >> 4;
  1618. dst[strideb * -4] = (p7 + p7 + p7 + p7 + p6 + p5 + p4 + p3 * 2 +
  1619. p2 + p1 + p0 + q0 + q1 + q2 + q3 + 8) >> 4;
  1620. dst[strideb * -3] = (p7 + p7 + p7 + p6 + p5 + p4 + p3 + p2 * 2 +
  1621. p1 + p0 + q0 + q1 + q2 + q3 + q4 + 8) >> 4;
  1622. dst[strideb * -2] = (p7 + p7 + p6 + p5 + p4 + p3 + p2 + p1 * 2 +
  1623. p0 + q0 + q1 + q2 + q3 + q4 + q5 + 8) >> 4;
  1624. dst[strideb * -1] = (p7 + p6 + p5 + p4 + p3 + p2 + p1 + p0 * 2 +
  1625. q0 + q1 + q2 + q3 + q4 + q5 + q6 + 8) >> 4;
  1626. dst[strideb * +0] = (p6 + p5 + p4 + p3 + p2 + p1 + p0 + q0 * 2 +
  1627. q1 + q2 + q3 + q4 + q5 + q6 + q7 + 8) >> 4;
  1628. dst[strideb * +1] = (p5 + p4 + p3 + p2 + p1 + p0 + q0 + q1 * 2 +
  1629. q2 + q3 + q4 + q5 + q6 + q7 + q7 + 8) >> 4;
  1630. dst[strideb * +2] = (p4 + p3 + p2 + p1 + p0 + q0 + q1 + q2 * 2 +
  1631. q3 + q4 + q5 + q6 + q7 + q7 + q7 + 8) >> 4;
  1632. dst[strideb * +3] = (p3 + p2 + p1 + p0 + q0 + q1 + q2 + q3 * 2 +
  1633. q4 + q5 + q6 + q7 + q7 + q7 + q7 + 8) >> 4;
  1634. dst[strideb * +4] = (p2 + p1 + p0 + q0 + q1 + q2 + q3 + q4 * 2 +
  1635. q5 + q6 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;
  1636. dst[strideb * +5] = (p1 + p0 + q0 + q1 + q2 + q3 + q4 + q5 * 2 +
  1637. q6 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;
  1638. dst[strideb * +6] = (p0 + q0 + q1 + q2 + q3 + q4 + q5 + q6 * 2 +
  1639. q7 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;
  1640. } else if (wd >= 8 && flat8in) {
  1641. dst[strideb * -3] = (p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0 + 4) >> 3;
  1642. dst[strideb * -2] = (p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1 + 4) >> 3;
  1643. dst[strideb * -1] = (p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2 + 4) >> 3;
  1644. dst[strideb * +0] = (p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3 + 4) >> 3;
  1645. dst[strideb * +1] = (p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3 + 4) >> 3;
  1646. dst[strideb * +2] = (p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3 + 4) >> 3;
  1647. } else {
  1648. int hev = FFABS(p1 - p0) > H || FFABS(q1 - q0) > H;
  1649. if (hev) {
  1650. int f = av_clip_intp2(p1 - q1, BIT_DEPTH - 1), f1, f2;
  1651. f = av_clip_intp2(3 * (q0 - p0) + f, BIT_DEPTH - 1);
  1652. f1 = FFMIN(f + 4, (1 << (BIT_DEPTH - 1)) - 1) >> 3;
  1653. f2 = FFMIN(f + 3, (1 << (BIT_DEPTH - 1)) - 1) >> 3;
  1654. dst[strideb * -1] = av_clip_pixel(p0 + f2);
  1655. dst[strideb * +0] = av_clip_pixel(q0 - f1);
  1656. } else {
  1657. int f = av_clip_intp2(3 * (q0 - p0), BIT_DEPTH - 1), f1, f2;
  1658. f1 = FFMIN(f + 4, (1 << (BIT_DEPTH - 1)) - 1) >> 3;
  1659. f2 = FFMIN(f + 3, (1 << (BIT_DEPTH - 1)) - 1) >> 3;
  1660. dst[strideb * -1] = av_clip_pixel(p0 + f2);
  1661. dst[strideb * +0] = av_clip_pixel(q0 - f1);
  1662. f = (f1 + 1) >> 1;
  1663. dst[strideb * -2] = av_clip_pixel(p1 + f);
  1664. dst[strideb * +1] = av_clip_pixel(q1 - f);
  1665. }
  1666. }
  1667. }
  1668. }
  1669. #define lf_8_fn(dir, wd, stridea, strideb) \
  1670. static void loop_filter_##dir##_##wd##_8_c(uint8_t *_dst, \
  1671. ptrdiff_t stride, \
  1672. int E, int I, int H) \
  1673. { \
  1674. pixel *dst = (pixel *) _dst; \
  1675. stride /= sizeof(pixel); \
  1676. loop_filter(dst, E, I, H, stridea, strideb, wd); \
  1677. }
  1678. #define lf_8_fns(wd) \
  1679. lf_8_fn(h, wd, stride, 1) \
  1680. lf_8_fn(v, wd, 1, stride)
  1681. lf_8_fns(4)
  1682. lf_8_fns(8)
  1683. lf_8_fns(16)
  1684. #undef lf_8_fn
  1685. #undef lf_8_fns
  1686. #define lf_16_fn(dir, stridea) \
  1687. static void loop_filter_##dir##_16_16_c(uint8_t *dst, \
  1688. ptrdiff_t stride, \
  1689. int E, int I, int H) \
  1690. { \
  1691. loop_filter_##dir##_16_8_c(dst, stride, E, I, H); \
  1692. loop_filter_##dir##_16_8_c(dst + 8 * stridea, stride, E, I, H); \
  1693. }
  1694. lf_16_fn(h, stride)
  1695. lf_16_fn(v, sizeof(pixel))
  1696. #undef lf_16_fn
  1697. #define lf_mix_fn(dir, wd1, wd2, stridea) \
  1698. static void loop_filter_##dir##_##wd1##wd2##_16_c(uint8_t *dst, \
  1699. ptrdiff_t stride, \
  1700. int E, int I, int H) \
  1701. { \
  1702. loop_filter_##dir##_##wd1##_8_c(dst, stride, E & 0xff, I & 0xff, H & 0xff); \
  1703. loop_filter_##dir##_##wd2##_8_c(dst + 8 * stridea, stride, E >> 8, I >> 8, H >> 8); \
  1704. }
  1705. #define lf_mix_fns(wd1, wd2) \
  1706. lf_mix_fn(h, wd1, wd2, stride) \
  1707. lf_mix_fn(v, wd1, wd2, sizeof(pixel))
  1708. lf_mix_fns(4, 4)
  1709. lf_mix_fns(4, 8)
  1710. lf_mix_fns(8, 4)
  1711. lf_mix_fns(8, 8)
  1712. #undef lf_mix_fn
  1713. #undef lf_mix_fns
  1714. static av_cold void vp9dsp_loopfilter_init(VP9DSPContext *dsp)
  1715. {
  1716. dsp->loop_filter_8[0][0] = loop_filter_h_4_8_c;
  1717. dsp->loop_filter_8[0][1] = loop_filter_v_4_8_c;
  1718. dsp->loop_filter_8[1][0] = loop_filter_h_8_8_c;
  1719. dsp->loop_filter_8[1][1] = loop_filter_v_8_8_c;
  1720. dsp->loop_filter_8[2][0] = loop_filter_h_16_8_c;
  1721. dsp->loop_filter_8[2][1] = loop_filter_v_16_8_c;
  1722. dsp->loop_filter_16[0] = loop_filter_h_16_16_c;
  1723. dsp->loop_filter_16[1] = loop_filter_v_16_16_c;
  1724. dsp->loop_filter_mix2[0][0][0] = loop_filter_h_44_16_c;
  1725. dsp->loop_filter_mix2[0][0][1] = loop_filter_v_44_16_c;
  1726. dsp->loop_filter_mix2[0][1][0] = loop_filter_h_48_16_c;
  1727. dsp->loop_filter_mix2[0][1][1] = loop_filter_v_48_16_c;
  1728. dsp->loop_filter_mix2[1][0][0] = loop_filter_h_84_16_c;
  1729. dsp->loop_filter_mix2[1][0][1] = loop_filter_v_84_16_c;
  1730. dsp->loop_filter_mix2[1][1][0] = loop_filter_h_88_16_c;
  1731. dsp->loop_filter_mix2[1][1][1] = loop_filter_v_88_16_c;
  1732. }
  1733. #if BIT_DEPTH != 12
  1734. static av_always_inline void copy_c(uint8_t *dst, ptrdiff_t dst_stride,
  1735. const uint8_t *src, ptrdiff_t src_stride,
  1736. int w, int h)
  1737. {
  1738. do {
  1739. memcpy(dst, src, w * sizeof(pixel));
  1740. dst += dst_stride;
  1741. src += src_stride;
  1742. } while (--h);
  1743. }
  1744. static av_always_inline void avg_c(uint8_t *_dst, ptrdiff_t dst_stride,
  1745. const uint8_t *_src, ptrdiff_t src_stride,
  1746. int w, int h)
  1747. {
  1748. pixel *dst = (pixel *) _dst;
  1749. const pixel *src = (const pixel *) _src;
  1750. dst_stride /= sizeof(pixel);
  1751. src_stride /= sizeof(pixel);
  1752. do {
  1753. int x;
  1754. for (x = 0; x < w; x += 4)
  1755. AV_WN4PA(&dst[x], rnd_avg_pixel4(AV_RN4PA(&dst[x]), AV_RN4P(&src[x])));
  1756. dst += dst_stride;
  1757. src += src_stride;
  1758. } while (--h);
  1759. }
  1760. #define fpel_fn(type, sz) \
  1761. static void type##sz##_c(uint8_t *dst, ptrdiff_t dst_stride, \
  1762. const uint8_t *src, ptrdiff_t src_stride, \
  1763. int h, int mx, int my) \
  1764. { \
  1765. type##_c(dst, dst_stride, src, src_stride, sz, h); \
  1766. }
  1767. #define copy_avg_fn(sz) \
  1768. fpel_fn(copy, sz) \
  1769. fpel_fn(avg, sz)
  1770. copy_avg_fn(64)
  1771. copy_avg_fn(32)
  1772. copy_avg_fn(16)
  1773. copy_avg_fn(8)
  1774. copy_avg_fn(4)
  1775. #undef fpel_fn
  1776. #undef copy_avg_fn
  1777. #endif /* BIT_DEPTH != 12 */
  1778. #define FILTER_8TAP(src, x, F, stride) \
  1779. av_clip_pixel((F[0] * src[x + -3 * stride] + \
  1780. F[1] * src[x + -2 * stride] + \
  1781. F[2] * src[x + -1 * stride] + \
  1782. F[3] * src[x + +0 * stride] + \
  1783. F[4] * src[x + +1 * stride] + \
  1784. F[5] * src[x + +2 * stride] + \
  1785. F[6] * src[x + +3 * stride] + \
  1786. F[7] * src[x + +4 * stride] + 64) >> 7)
  1787. static av_always_inline void do_8tap_1d_c(uint8_t *_dst, ptrdiff_t dst_stride,
  1788. const uint8_t *_src, ptrdiff_t src_stride,
  1789. int w, int h, ptrdiff_t ds,
  1790. const int16_t *filter, int avg)
  1791. {
  1792. pixel *dst = (pixel *) _dst;
  1793. const pixel *src = (const pixel *) _src;
  1794. dst_stride /= sizeof(pixel);
  1795. src_stride /= sizeof(pixel);
  1796. do {
  1797. int x;
  1798. for (x = 0; x < w; x++)
  1799. if (avg) {
  1800. dst[x] = (dst[x] + FILTER_8TAP(src, x, filter, ds) + 1) >> 1;
  1801. } else {
  1802. dst[x] = FILTER_8TAP(src, x, filter, ds);
  1803. }
  1804. dst += dst_stride;
  1805. src += src_stride;
  1806. } while (--h);
  1807. }
  1808. #define filter_8tap_1d_fn(opn, opa, dir, ds) \
  1809. static av_noinline void opn##_8tap_1d_##dir##_c(uint8_t *dst, ptrdiff_t dst_stride, \
  1810. const uint8_t *src, ptrdiff_t src_stride, \
  1811. int w, int h, const int16_t *filter) \
  1812. { \
  1813. do_8tap_1d_c(dst, dst_stride, src, src_stride, w, h, ds, filter, opa); \
  1814. }
  1815. filter_8tap_1d_fn(put, 0, v, src_stride / sizeof(pixel))
  1816. filter_8tap_1d_fn(put, 0, h, 1)
  1817. filter_8tap_1d_fn(avg, 1, v, src_stride / sizeof(pixel))
  1818. filter_8tap_1d_fn(avg, 1, h, 1)
  1819. #undef filter_8tap_1d_fn
  1820. static av_always_inline void do_8tap_2d_c(uint8_t *_dst, ptrdiff_t dst_stride,
  1821. const uint8_t *_src, ptrdiff_t src_stride,
  1822. int w, int h, const int16_t *filterx,
  1823. const int16_t *filtery, int avg)
  1824. {
  1825. int tmp_h = h + 7;
  1826. pixel tmp[64 * 71], *tmp_ptr = tmp;
  1827. pixel *dst = (pixel *) _dst;
  1828. const pixel *src = (const pixel *) _src;
  1829. dst_stride /= sizeof(pixel);
  1830. src_stride /= sizeof(pixel);
  1831. src -= src_stride * 3;
  1832. do {
  1833. int x;
  1834. for (x = 0; x < w; x++)
  1835. tmp_ptr[x] = FILTER_8TAP(src, x, filterx, 1);
  1836. tmp_ptr += 64;
  1837. src += src_stride;
  1838. } while (--tmp_h);
  1839. tmp_ptr = tmp + 64 * 3;
  1840. do {
  1841. int x;
  1842. for (x = 0; x < w; x++)
  1843. if (avg) {
  1844. dst[x] = (dst[x] + FILTER_8TAP(tmp_ptr, x, filtery, 64) + 1) >> 1;
  1845. } else {
  1846. dst[x] = FILTER_8TAP(tmp_ptr, x, filtery, 64);
  1847. }
  1848. tmp_ptr += 64;
  1849. dst += dst_stride;
  1850. } while (--h);
  1851. }
  1852. #define filter_8tap_2d_fn(opn, opa) \
  1853. static av_noinline void opn##_8tap_2d_hv_c(uint8_t *dst, ptrdiff_t dst_stride, \
  1854. const uint8_t *src, ptrdiff_t src_stride, \
  1855. int w, int h, const int16_t *filterx, \
  1856. const int16_t *filtery) \
  1857. { \
  1858. do_8tap_2d_c(dst, dst_stride, src, src_stride, w, h, filterx, filtery, opa); \
  1859. }
  1860. filter_8tap_2d_fn(put, 0)
  1861. filter_8tap_2d_fn(avg, 1)
  1862. #undef filter_8tap_2d_fn
  1863. #define filter_fn_1d(sz, dir, dir_m, type, type_idx, avg) \
  1864. static void avg##_8tap_##type##_##sz##dir##_c(uint8_t *dst, ptrdiff_t dst_stride, \
  1865. const uint8_t *src, ptrdiff_t src_stride, \
  1866. int h, int mx, int my) \
  1867. { \
  1868. avg##_8tap_1d_##dir##_c(dst, dst_stride, src, src_stride, sz, h, \
  1869. ff_vp9_subpel_filters[type_idx][dir_m]); \
  1870. }
  1871. #define filter_fn_2d(sz, type, type_idx, avg) \
  1872. static void avg##_8tap_##type##_##sz##hv_c(uint8_t *dst, ptrdiff_t dst_stride, \
  1873. const uint8_t *src, ptrdiff_t src_stride, \
  1874. int h, int mx, int my) \
  1875. { \
  1876. avg##_8tap_2d_hv_c(dst, dst_stride, src, src_stride, sz, h, \
  1877. ff_vp9_subpel_filters[type_idx][mx], \
  1878. ff_vp9_subpel_filters[type_idx][my]); \
  1879. }
  1880. #if BIT_DEPTH != 12
  1881. #define FILTER_BILIN(src, x, mxy, stride) \
  1882. (src[x] + ((mxy * (src[x + stride] - src[x]) + 8) >> 4))
  1883. static av_always_inline void do_bilin_1d_c(uint8_t *_dst, ptrdiff_t dst_stride,
  1884. const uint8_t *_src, ptrdiff_t src_stride,
  1885. int w, int h, ptrdiff_t ds, int mxy, int avg)
  1886. {
  1887. pixel *dst = (pixel *) _dst;
  1888. const pixel *src = (const pixel *) _src;
  1889. dst_stride /= sizeof(pixel);
  1890. src_stride /= sizeof(pixel);
  1891. do {
  1892. int x;
  1893. for (x = 0; x < w; x++)
  1894. if (avg) {
  1895. dst[x] = (dst[x] + FILTER_BILIN(src, x, mxy, ds) + 1) >> 1;
  1896. } else {
  1897. dst[x] = FILTER_BILIN(src, x, mxy, ds);
  1898. }
  1899. dst += dst_stride;
  1900. src += src_stride;
  1901. } while (--h);
  1902. }
  1903. #define bilin_1d_fn(opn, opa, dir, ds) \
  1904. static av_noinline void opn##_bilin_1d_##dir##_c(uint8_t *dst, ptrdiff_t dst_stride, \
  1905. const uint8_t *src, ptrdiff_t src_stride, \
  1906. int w, int h, int mxy) \
  1907. { \
  1908. do_bilin_1d_c(dst, dst_stride, src, src_stride, w, h, ds, mxy, opa); \
  1909. }
  1910. bilin_1d_fn(put, 0, v, src_stride / sizeof(pixel))
  1911. bilin_1d_fn(put, 0, h, 1)
  1912. bilin_1d_fn(avg, 1, v, src_stride / sizeof(pixel))
  1913. bilin_1d_fn(avg, 1, h, 1)
  1914. #undef bilin_1d_fn
  1915. static av_always_inline void do_bilin_2d_c(uint8_t *_dst, ptrdiff_t dst_stride,
  1916. const uint8_t *_src, ptrdiff_t src_stride,
  1917. int w, int h, int mx, int my, int avg)
  1918. {
  1919. pixel tmp[64 * 65], *tmp_ptr = tmp;
  1920. int tmp_h = h + 1;
  1921. pixel *dst = (pixel *) _dst;
  1922. const pixel *src = (const pixel *) _src;
  1923. dst_stride /= sizeof(pixel);
  1924. src_stride /= sizeof(pixel);
  1925. do {
  1926. int x;
  1927. for (x = 0; x < w; x++)
  1928. tmp_ptr[x] = FILTER_BILIN(src, x, mx, 1);
  1929. tmp_ptr += 64;
  1930. src += src_stride;
  1931. } while (--tmp_h);
  1932. tmp_ptr = tmp;
  1933. do {
  1934. int x;
  1935. for (x = 0; x < w; x++)
  1936. if (avg) {
  1937. dst[x] = (dst[x] + FILTER_BILIN(tmp_ptr, x, my, 64) + 1) >> 1;
  1938. } else {
  1939. dst[x] = FILTER_BILIN(tmp_ptr, x, my, 64);
  1940. }
  1941. tmp_ptr += 64;
  1942. dst += dst_stride;
  1943. } while (--h);
  1944. }
  1945. #define bilin_2d_fn(opn, opa) \
  1946. static av_noinline void opn##_bilin_2d_hv_c(uint8_t *dst, ptrdiff_t dst_stride, \
  1947. const uint8_t *src, ptrdiff_t src_stride, \
  1948. int w, int h, int mx, int my) \
  1949. { \
  1950. do_bilin_2d_c(dst, dst_stride, src, src_stride, w, h, mx, my, opa); \
  1951. }
  1952. bilin_2d_fn(put, 0)
  1953. bilin_2d_fn(avg, 1)
  1954. #undef bilin_2d_fn
  1955. #define bilinf_fn_1d(sz, dir, dir_m, avg) \
  1956. static void avg##_bilin_##sz##dir##_c(uint8_t *dst, ptrdiff_t dst_stride, \
  1957. const uint8_t *src, ptrdiff_t src_stride, \
  1958. int h, int mx, int my) \
  1959. { \
  1960. avg##_bilin_1d_##dir##_c(dst, dst_stride, src, src_stride, sz, h, dir_m); \
  1961. }
  1962. #define bilinf_fn_2d(sz, avg) \
  1963. static void avg##_bilin_##sz##hv_c(uint8_t *dst, ptrdiff_t dst_stride, \
  1964. const uint8_t *src, ptrdiff_t src_stride, \
  1965. int h, int mx, int my) \
  1966. { \
  1967. avg##_bilin_2d_hv_c(dst, dst_stride, src, src_stride, sz, h, mx, my); \
  1968. }
  1969. #else
  1970. #define bilinf_fn_1d(a, b, c, d)
  1971. #define bilinf_fn_2d(a, b)
  1972. #endif
  1973. #define filter_fn(sz, avg) \
  1974. filter_fn_1d(sz, h, mx, regular, FILTER_8TAP_REGULAR, avg) \
  1975. filter_fn_1d(sz, v, my, regular, FILTER_8TAP_REGULAR, avg) \
  1976. filter_fn_2d(sz, regular, FILTER_8TAP_REGULAR, avg) \
  1977. filter_fn_1d(sz, h, mx, smooth, FILTER_8TAP_SMOOTH, avg) \
  1978. filter_fn_1d(sz, v, my, smooth, FILTER_8TAP_SMOOTH, avg) \
  1979. filter_fn_2d(sz, smooth, FILTER_8TAP_SMOOTH, avg) \
  1980. filter_fn_1d(sz, h, mx, sharp, FILTER_8TAP_SHARP, avg) \
  1981. filter_fn_1d(sz, v, my, sharp, FILTER_8TAP_SHARP, avg) \
  1982. filter_fn_2d(sz, sharp, FILTER_8TAP_SHARP, avg) \
  1983. bilinf_fn_1d(sz, h, mx, avg) \
  1984. bilinf_fn_1d(sz, v, my, avg) \
  1985. bilinf_fn_2d(sz, avg)
  1986. #define filter_fn_set(avg) \
  1987. filter_fn(64, avg) \
  1988. filter_fn(32, avg) \
  1989. filter_fn(16, avg) \
  1990. filter_fn(8, avg) \
  1991. filter_fn(4, avg)
  1992. filter_fn_set(put)
  1993. filter_fn_set(avg)
  1994. #undef filter_fn
  1995. #undef filter_fn_set
  1996. #undef filter_fn_1d
  1997. #undef filter_fn_2d
  1998. #undef bilinf_fn_1d
  1999. #undef bilinf_fn_2d
  2000. #if BIT_DEPTH != 8
  2001. void ff_vp9dsp_mc_init_10(VP9DSPContext *dsp);
  2002. #endif
  2003. #if BIT_DEPTH != 10
  2004. static
  2005. #endif
  2006. av_cold void FUNC(ff_vp9dsp_mc_init)(VP9DSPContext *dsp)
  2007. {
  2008. #if BIT_DEPTH == 12
  2009. ff_vp9dsp_mc_init_10(dsp);
  2010. #else /* BIT_DEPTH == 12 */
  2011. #define init_fpel(idx1, idx2, sz, type) \
  2012. dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][0][0] = type##sz##_c; \
  2013. dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][0][0] = type##sz##_c; \
  2014. dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][0][0] = type##sz##_c; \
  2015. dsp->mc[idx1][FILTER_BILINEAR ][idx2][0][0] = type##sz##_c
  2016. #define init_copy_avg(idx, sz) \
  2017. init_fpel(idx, 0, sz, copy); \
  2018. init_fpel(idx, 1, sz, avg)
  2019. init_copy_avg(0, 64);
  2020. init_copy_avg(1, 32);
  2021. init_copy_avg(2, 16);
  2022. init_copy_avg(3, 8);
  2023. init_copy_avg(4, 4);
  2024. #undef init_copy_avg
  2025. #undef init_fpel
  2026. #endif /* BIT_DEPTH == 12 */
  2027. #define init_subpel1_bd_aware(idx1, idx2, idxh, idxv, sz, dir, type) \
  2028. dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][idxh][idxv] = type##_8tap_smooth_##sz##dir##_c; \
  2029. dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][idxh][idxv] = type##_8tap_regular_##sz##dir##_c; \
  2030. dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][idxh][idxv] = type##_8tap_sharp_##sz##dir##_c
  2031. #if BIT_DEPTH == 12
  2032. #define init_subpel1 init_subpel1_bd_aware
  2033. #else
  2034. #define init_subpel1(idx1, idx2, idxh, idxv, sz, dir, type) \
  2035. init_subpel1_bd_aware(idx1, idx2, idxh, idxv, sz, dir, type); \
  2036. dsp->mc[idx1][FILTER_BILINEAR ][idx2][idxh][idxv] = type##_bilin_##sz##dir##_c
  2037. #endif
  2038. #define init_subpel2(idx, idxh, idxv, dir, type) \
  2039. init_subpel1(0, idx, idxh, idxv, 64, dir, type); \
  2040. init_subpel1(1, idx, idxh, idxv, 32, dir, type); \
  2041. init_subpel1(2, idx, idxh, idxv, 16, dir, type); \
  2042. init_subpel1(3, idx, idxh, idxv, 8, dir, type); \
  2043. init_subpel1(4, idx, idxh, idxv, 4, dir, type)
  2044. #define init_subpel3(idx, type) \
  2045. init_subpel2(idx, 1, 1, hv, type); \
  2046. init_subpel2(idx, 0, 1, v, type); \
  2047. init_subpel2(idx, 1, 0, h, type)
  2048. init_subpel3(0, put);
  2049. init_subpel3(1, avg);
  2050. #undef init_subpel1
  2051. #undef init_subpel2
  2052. #undef init_subpel3
  2053. #undef init_subpel1_bd_aware
  2054. }
  2055. static av_always_inline void do_scaled_8tap_c(uint8_t *_dst, ptrdiff_t dst_stride,
  2056. const uint8_t *_src, ptrdiff_t src_stride,
  2057. int w, int h, int mx, int my,
  2058. int dx, int dy, int avg,
  2059. const int16_t (*filters)[8])
  2060. {
  2061. int tmp_h = (((h - 1) * dy + my) >> 4) + 8;
  2062. pixel tmp[64 * 135], *tmp_ptr = tmp;
  2063. pixel *dst = (pixel *) _dst;
  2064. const pixel *src = (const pixel *) _src;
  2065. dst_stride /= sizeof(pixel);
  2066. src_stride /= sizeof(pixel);
  2067. src -= src_stride * 3;
  2068. do {
  2069. int x;
  2070. int imx = mx, ioff = 0;
  2071. for (x = 0; x < w; x++) {
  2072. tmp_ptr[x] = FILTER_8TAP(src, ioff, filters[imx], 1);
  2073. imx += dx;
  2074. ioff += imx >> 4;
  2075. imx &= 0xf;
  2076. }
  2077. tmp_ptr += 64;
  2078. src += src_stride;
  2079. } while (--tmp_h);
  2080. tmp_ptr = tmp + 64 * 3;
  2081. do {
  2082. int x;
  2083. const int16_t *filter = filters[my];
  2084. for (x = 0; x < w; x++)
  2085. if (avg) {
  2086. dst[x] = (dst[x] + FILTER_8TAP(tmp_ptr, x, filter, 64) + 1) >> 1;
  2087. } else {
  2088. dst[x] = FILTER_8TAP(tmp_ptr, x, filter, 64);
  2089. }
  2090. my += dy;
  2091. tmp_ptr += (my >> 4) * 64;
  2092. my &= 0xf;
  2093. dst += dst_stride;
  2094. } while (--h);
  2095. }
  2096. #define scaled_filter_8tap_fn(opn, opa) \
  2097. static av_noinline void opn##_scaled_8tap_c(uint8_t *dst, ptrdiff_t dst_stride, \
  2098. const uint8_t *src, ptrdiff_t src_stride, \
  2099. int w, int h, int mx, int my, int dx, int dy, \
  2100. const int16_t (*filters)[8]) \
  2101. { \
  2102. do_scaled_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
  2103. opa, filters); \
  2104. }
  2105. scaled_filter_8tap_fn(put, 0)
  2106. scaled_filter_8tap_fn(avg, 1)
  2107. #undef scaled_filter_8tap_fn
  2108. #undef FILTER_8TAP
  2109. #define scaled_filter_fn(sz, type, type_idx, avg) \
  2110. static void avg##_scaled_##type##_##sz##_c(uint8_t *dst, ptrdiff_t dst_stride, \
  2111. const uint8_t *src, ptrdiff_t src_stride, \
  2112. int h, int mx, int my, int dx, int dy) \
  2113. { \
  2114. avg##_scaled_8tap_c(dst, dst_stride, src, src_stride, sz, h, mx, my, dx, dy, \
  2115. ff_vp9_subpel_filters[type_idx]); \
  2116. }
  2117. #if BIT_DEPTH != 12
  2118. static av_always_inline void do_scaled_bilin_c(uint8_t *_dst, ptrdiff_t dst_stride,
  2119. const uint8_t *_src, ptrdiff_t src_stride,
  2120. int w, int h, int mx, int my,
  2121. int dx, int dy, int avg)
  2122. {
  2123. pixel tmp[64 * 129], *tmp_ptr = tmp;
  2124. int tmp_h = (((h - 1) * dy + my) >> 4) + 2;
  2125. pixel *dst = (pixel *) _dst;
  2126. const pixel *src = (const pixel *) _src;
  2127. dst_stride /= sizeof(pixel);
  2128. src_stride /= sizeof(pixel);
  2129. do {
  2130. int x;
  2131. int imx = mx, ioff = 0;
  2132. for (x = 0; x < w; x++) {
  2133. tmp_ptr[x] = FILTER_BILIN(src, ioff, imx, 1);
  2134. imx += dx;
  2135. ioff += imx >> 4;
  2136. imx &= 0xf;
  2137. }
  2138. tmp_ptr += 64;
  2139. src += src_stride;
  2140. } while (--tmp_h);
  2141. tmp_ptr = tmp;
  2142. do {
  2143. int x;
  2144. for (x = 0; x < w; x++)
  2145. if (avg) {
  2146. dst[x] = (dst[x] + FILTER_BILIN(tmp_ptr, x, my, 64) + 1) >> 1;
  2147. } else {
  2148. dst[x] = FILTER_BILIN(tmp_ptr, x, my, 64);
  2149. }
  2150. my += dy;
  2151. tmp_ptr += (my >> 4) * 64;
  2152. my &= 0xf;
  2153. dst += dst_stride;
  2154. } while (--h);
  2155. }
  2156. #define scaled_bilin_fn(opn, opa) \
  2157. static av_noinline void opn##_scaled_bilin_c(uint8_t *dst, ptrdiff_t dst_stride, \
  2158. const uint8_t *src, ptrdiff_t src_stride, \
  2159. int w, int h, int mx, int my, int dx, int dy) \
  2160. { \
  2161. do_scaled_bilin_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, opa); \
  2162. }
  2163. scaled_bilin_fn(put, 0)
  2164. scaled_bilin_fn(avg, 1)
  2165. #undef scaled_bilin_fn
  2166. #undef FILTER_BILIN
  2167. #define scaled_bilinf_fn(sz, avg) \
  2168. static void avg##_scaled_bilin_##sz##_c(uint8_t *dst, ptrdiff_t dst_stride, \
  2169. const uint8_t *src, ptrdiff_t src_stride, \
  2170. int h, int mx, int my, int dx, int dy) \
  2171. { \
  2172. avg##_scaled_bilin_c(dst, dst_stride, src, src_stride, sz, h, mx, my, dx, dy); \
  2173. }
  2174. #else
  2175. #define scaled_bilinf_fn(a, b)
  2176. #endif
  2177. #define scaled_filter_fns(sz, avg) \
  2178. scaled_filter_fn(sz, regular, FILTER_8TAP_REGULAR, avg) \
  2179. scaled_filter_fn(sz, smooth, FILTER_8TAP_SMOOTH, avg) \
  2180. scaled_filter_fn(sz, sharp, FILTER_8TAP_SHARP, avg) \
  2181. scaled_bilinf_fn(sz, avg)
  2182. #define scaled_filter_fn_set(avg) \
  2183. scaled_filter_fns(64, avg) \
  2184. scaled_filter_fns(32, avg) \
  2185. scaled_filter_fns(16, avg) \
  2186. scaled_filter_fns(8, avg) \
  2187. scaled_filter_fns(4, avg)
  2188. scaled_filter_fn_set(put)
  2189. scaled_filter_fn_set(avg)
  2190. #undef scaled_filter_fns
  2191. #undef scaled_filter_fn_set
  2192. #undef scaled_filter_fn
  2193. #undef scaled_bilinf_fn
  2194. #if BIT_DEPTH != 8
  2195. void ff_vp9dsp_scaled_mc_init_10(VP9DSPContext *dsp);
  2196. #endif
  2197. #if BIT_DEPTH != 10
  2198. static
  2199. #endif
  2200. av_cold void FUNC(ff_vp9dsp_scaled_mc_init)(VP9DSPContext *dsp)
  2201. {
  2202. #define init_scaled_bd_aware(idx1, idx2, sz, type) \
  2203. dsp->smc[idx1][FILTER_8TAP_SMOOTH ][idx2] = type##_scaled_smooth_##sz##_c; \
  2204. dsp->smc[idx1][FILTER_8TAP_REGULAR][idx2] = type##_scaled_regular_##sz##_c; \
  2205. dsp->smc[idx1][FILTER_8TAP_SHARP ][idx2] = type##_scaled_sharp_##sz##_c
  2206. #if BIT_DEPTH == 12
  2207. ff_vp9dsp_scaled_mc_init_10(dsp);
  2208. #define init_scaled(a,b,c,d) init_scaled_bd_aware(a,b,c,d)
  2209. #else
  2210. #define init_scaled(idx1, idx2, sz, type) \
  2211. init_scaled_bd_aware(idx1, idx2, sz, type); \
  2212. dsp->smc[idx1][FILTER_BILINEAR ][idx2] = type##_scaled_bilin_##sz##_c
  2213. #endif
  2214. #define init_scaled_put_avg(idx, sz) \
  2215. init_scaled(idx, 0, sz, put); \
  2216. init_scaled(idx, 1, sz, avg)
  2217. init_scaled_put_avg(0, 64);
  2218. init_scaled_put_avg(1, 32);
  2219. init_scaled_put_avg(2, 16);
  2220. init_scaled_put_avg(3, 8);
  2221. init_scaled_put_avg(4, 4);
  2222. #undef init_scaled_put_avg
  2223. #undef init_scaled
  2224. #undef init_scaled_bd_aware
  2225. }
  2226. av_cold void FUNC(ff_vp9dsp_init)(VP9DSPContext *dsp)
  2227. {
  2228. FUNC(ff_vp9dsp_intrapred_init)(dsp);
  2229. vp9dsp_itxfm_init(dsp);
  2230. vp9dsp_loopfilter_init(dsp);
  2231. FUNC(ff_vp9dsp_mc_init)(dsp);
  2232. FUNC(ff_vp9dsp_scaled_mc_init)(dsp);
  2233. }