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.

2518 lines
86KB

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