intrapred_neon.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  1. /*
  2. * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <arm_neon.h>
  11. #include "./vpx_config.h"
  12. #include "./vpx_dsp_rtcd.h"
  13. #include "vpx/vpx_integer.h"
  14. //------------------------------------------------------------------------------
  15. // DC 4x4
  16. static INLINE uint16x4_t dc_sum_4(const uint8_t *ref) {
  17. const uint8x8_t ref_u8 = vld1_u8(ref);
  18. const uint16x4_t p0 = vpaddl_u8(ref_u8);
  19. return vpadd_u16(p0, p0);
  20. }
  21. static INLINE void dc_store_4x4(uint8_t *dst, ptrdiff_t stride,
  22. const uint8x8_t dc) {
  23. const uint8x8_t dc_dup = vdup_lane_u8(dc, 0);
  24. int i;
  25. for (i = 0; i < 4; ++i, dst += stride) {
  26. vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(dc_dup), 0);
  27. }
  28. }
  29. void vpx_dc_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
  30. const uint8_t *above, const uint8_t *left) {
  31. const uint8x8_t a = vld1_u8(above);
  32. const uint8x8_t l = vld1_u8(left);
  33. const uint16x8_t al = vaddl_u8(a, l);
  34. uint16x4_t sum;
  35. uint8x8_t dc;
  36. sum = vpadd_u16(vget_low_u16(al), vget_low_u16(al));
  37. sum = vpadd_u16(sum, sum);
  38. dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 3));
  39. dc_store_4x4(dst, stride, dc);
  40. }
  41. void vpx_dc_left_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
  42. const uint8_t *above, const uint8_t *left) {
  43. const uint16x4_t sum = dc_sum_4(left);
  44. const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 2));
  45. (void)above;
  46. dc_store_4x4(dst, stride, dc);
  47. }
  48. void vpx_dc_top_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
  49. const uint8_t *above, const uint8_t *left) {
  50. const uint16x4_t sum = dc_sum_4(above);
  51. const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 2));
  52. (void)left;
  53. dc_store_4x4(dst, stride, dc);
  54. }
  55. void vpx_dc_128_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
  56. const uint8_t *above, const uint8_t *left) {
  57. const uint8x8_t dc = vdup_n_u8(0x80);
  58. (void)above;
  59. (void)left;
  60. dc_store_4x4(dst, stride, dc);
  61. }
  62. //------------------------------------------------------------------------------
  63. // DC 8x8
  64. static INLINE uint16x4_t dc_sum_8(const uint8_t *ref) {
  65. const uint8x8_t ref_u8 = vld1_u8(ref);
  66. uint16x4_t sum = vpaddl_u8(ref_u8);
  67. sum = vpadd_u16(sum, sum);
  68. return vpadd_u16(sum, sum);
  69. }
  70. static INLINE void dc_store_8x8(uint8_t *dst, ptrdiff_t stride,
  71. const uint8x8_t dc) {
  72. const uint8x8_t dc_dup = vdup_lane_u8(dc, 0);
  73. int i;
  74. for (i = 0; i < 8; ++i, dst += stride) {
  75. vst1_u8(dst, dc_dup);
  76. }
  77. }
  78. void vpx_dc_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
  79. const uint8_t *above, const uint8_t *left) {
  80. const uint8x8_t above_u8 = vld1_u8(above);
  81. const uint8x8_t left_u8 = vld1_u8(left);
  82. const uint8x16_t above_and_left = vcombine_u8(above_u8, left_u8);
  83. const uint16x8_t p0 = vpaddlq_u8(above_and_left);
  84. uint16x4_t sum = vadd_u16(vget_low_u16(p0), vget_high_u16(p0));
  85. uint8x8_t dc;
  86. sum = vpadd_u16(sum, sum);
  87. sum = vpadd_u16(sum, sum);
  88. dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 4));
  89. dc_store_8x8(dst, stride, dc);
  90. }
  91. void vpx_dc_left_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
  92. const uint8_t *above, const uint8_t *left) {
  93. const uint16x4_t sum = dc_sum_8(left);
  94. const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 3));
  95. (void)above;
  96. dc_store_8x8(dst, stride, dc);
  97. }
  98. void vpx_dc_top_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
  99. const uint8_t *above, const uint8_t *left) {
  100. const uint16x4_t sum = dc_sum_8(above);
  101. const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 3));
  102. (void)left;
  103. dc_store_8x8(dst, stride, dc);
  104. }
  105. void vpx_dc_128_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
  106. const uint8_t *above, const uint8_t *left) {
  107. const uint8x8_t dc = vdup_n_u8(0x80);
  108. (void)above;
  109. (void)left;
  110. dc_store_8x8(dst, stride, dc);
  111. }
  112. //------------------------------------------------------------------------------
  113. // DC 16x16
  114. static INLINE uint16x4_t dc_sum_16(const uint8_t *ref) {
  115. const uint8x16_t ref_u8 = vld1q_u8(ref);
  116. const uint16x8_t p0 = vpaddlq_u8(ref_u8);
  117. uint16x4_t sum = vadd_u16(vget_low_u16(p0), vget_high_u16(p0));
  118. sum = vpadd_u16(sum, sum);
  119. return vpadd_u16(sum, sum);
  120. }
  121. static INLINE void dc_store_16x16(uint8_t *dst, ptrdiff_t stride,
  122. const uint8x8_t dc) {
  123. const uint8x16_t dc_dup = vdupq_lane_u8(dc, 0);
  124. int i;
  125. for (i = 0; i < 16; ++i, dst += stride) {
  126. vst1q_u8(dst, dc_dup);
  127. }
  128. }
  129. void vpx_dc_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
  130. const uint8_t *above, const uint8_t *left) {
  131. const uint8x16_t ref0 = vld1q_u8(above);
  132. const uint8x16_t ref1 = vld1q_u8(left);
  133. const uint16x8_t p0 = vpaddlq_u8(ref0);
  134. const uint16x8_t p1 = vpaddlq_u8(ref1);
  135. const uint16x8_t p2 = vaddq_u16(p0, p1);
  136. uint16x4_t sum = vadd_u16(vget_low_u16(p2), vget_high_u16(p2));
  137. uint8x8_t dc;
  138. sum = vpadd_u16(sum, sum);
  139. sum = vpadd_u16(sum, sum);
  140. dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 5));
  141. dc_store_16x16(dst, stride, dc);
  142. }
  143. void vpx_dc_left_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
  144. const uint8_t *above,
  145. const uint8_t *left) {
  146. const uint16x4_t sum = dc_sum_16(left);
  147. const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 4));
  148. (void)above;
  149. dc_store_16x16(dst, stride, dc);
  150. }
  151. void vpx_dc_top_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
  152. const uint8_t *above,
  153. const uint8_t *left) {
  154. const uint16x4_t sum = dc_sum_16(above);
  155. const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 4));
  156. (void)left;
  157. dc_store_16x16(dst, stride, dc);
  158. }
  159. void vpx_dc_128_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
  160. const uint8_t *above,
  161. const uint8_t *left) {
  162. const uint8x8_t dc = vdup_n_u8(0x80);
  163. (void)above;
  164. (void)left;
  165. dc_store_16x16(dst, stride, dc);
  166. }
  167. //------------------------------------------------------------------------------
  168. // DC 32x32
  169. static INLINE uint16x4_t dc_sum_32(const uint8_t *ref) {
  170. const uint8x16x2_t r = vld2q_u8(ref);
  171. const uint16x8_t p0 = vpaddlq_u8(r.val[0]);
  172. const uint16x8_t p1 = vpaddlq_u8(r.val[1]);
  173. const uint16x8_t p2 = vaddq_u16(p0, p1);
  174. uint16x4_t sum = vadd_u16(vget_low_u16(p2), vget_high_u16(p2));
  175. sum = vpadd_u16(sum, sum);
  176. return vpadd_u16(sum, sum);
  177. }
  178. static INLINE void dc_store_32x32(uint8_t *dst, ptrdiff_t stride,
  179. const uint8x8_t dc) {
  180. uint8x16x2_t dc_dup;
  181. int i;
  182. dc_dup.val[0] = dc_dup.val[1] = vdupq_lane_u8(dc, 0);
  183. for (i = 0; i < 32; ++i, dst += stride) {
  184. vst2q_u8(dst, dc_dup);
  185. }
  186. }
  187. void vpx_dc_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
  188. const uint8_t *above, const uint8_t *left) {
  189. const uint8x16x2_t a = vld2q_u8(above);
  190. const uint8x16x2_t l = vld2q_u8(left);
  191. const uint16x8_t pa0 = vpaddlq_u8(a.val[0]);
  192. const uint16x8_t pl0 = vpaddlq_u8(l.val[0]);
  193. const uint16x8_t pa1 = vpaddlq_u8(a.val[1]);
  194. const uint16x8_t pl1 = vpaddlq_u8(l.val[1]);
  195. const uint16x8_t pa = vaddq_u16(pa0, pa1);
  196. const uint16x8_t pl = vaddq_u16(pl0, pl1);
  197. const uint16x8_t pal = vaddq_u16(pa, pl);
  198. uint16x4_t sum = vadd_u16(vget_low_u16(pal), vget_high_u16(pal));
  199. uint8x8_t dc;
  200. sum = vpadd_u16(sum, sum);
  201. sum = vpadd_u16(sum, sum);
  202. dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 6));
  203. dc_store_32x32(dst, stride, dc);
  204. }
  205. void vpx_dc_left_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
  206. const uint8_t *above,
  207. const uint8_t *left) {
  208. const uint16x4_t sum = dc_sum_32(left);
  209. const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 5));
  210. (void)above;
  211. dc_store_32x32(dst, stride, dc);
  212. }
  213. void vpx_dc_top_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
  214. const uint8_t *above,
  215. const uint8_t *left) {
  216. const uint16x4_t sum = dc_sum_32(above);
  217. const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 5));
  218. (void)left;
  219. dc_store_32x32(dst, stride, dc);
  220. }
  221. void vpx_dc_128_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
  222. const uint8_t *above,
  223. const uint8_t *left) {
  224. const uint8x8_t dc = vdup_n_u8(0x80);
  225. (void)above;
  226. (void)left;
  227. dc_store_32x32(dst, stride, dc);
  228. }
  229. // -----------------------------------------------------------------------------
  230. void vpx_d45_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
  231. const uint8_t *above, const uint8_t *left) {
  232. const uint8x8_t ABCDEFGH = vld1_u8(above);
  233. const uint64x1_t A1 = vshr_n_u64(vreinterpret_u64_u8(ABCDEFGH), 8);
  234. const uint64x1_t A2 = vshr_n_u64(vreinterpret_u64_u8(ABCDEFGH), 16);
  235. const uint8x8_t BCDEFGH0 = vreinterpret_u8_u64(A1);
  236. const uint8x8_t CDEFGH00 = vreinterpret_u8_u64(A2);
  237. const uint8x8_t avg1 = vhadd_u8(ABCDEFGH, CDEFGH00);
  238. const uint8x8_t avg2 = vrhadd_u8(avg1, BCDEFGH0);
  239. const uint64x1_t avg2_u64 = vreinterpret_u64_u8(avg2);
  240. const uint32x2_t r0 = vreinterpret_u32_u8(avg2);
  241. const uint32x2_t r1 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 8));
  242. const uint32x2_t r2 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 16));
  243. const uint32x2_t r3 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 24));
  244. (void)left;
  245. vst1_lane_u32((uint32_t *)(dst + 0 * stride), r0, 0);
  246. vst1_lane_u32((uint32_t *)(dst + 1 * stride), r1, 0);
  247. vst1_lane_u32((uint32_t *)(dst + 2 * stride), r2, 0);
  248. vst1_lane_u32((uint32_t *)(dst + 3 * stride), r3, 0);
  249. vst1_lane_u8(dst + 3 * stride + 3, ABCDEFGH, 7);
  250. }
  251. static INLINE void d45_store_8(uint8_t **dst, const ptrdiff_t stride,
  252. const uint8x8_t above_right, uint8x8_t *row) {
  253. *row = vext_u8(*row, above_right, 1);
  254. vst1_u8(*dst, *row);
  255. *dst += stride;
  256. }
  257. void vpx_d45_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
  258. const uint8_t *above, const uint8_t *left) {
  259. const uint8x8_t A0 = vld1_u8(above);
  260. const uint8x8_t above_right = vdup_lane_u8(A0, 7);
  261. const uint8x8_t A1 = vext_u8(A0, above_right, 1);
  262. const uint8x8_t A2 = vext_u8(A0, above_right, 2);
  263. const uint8x8_t avg1 = vhadd_u8(A0, A2);
  264. uint8x8_t row = vrhadd_u8(avg1, A1);
  265. (void)left;
  266. vst1_u8(dst, row);
  267. dst += stride;
  268. d45_store_8(&dst, stride, above_right, &row);
  269. d45_store_8(&dst, stride, above_right, &row);
  270. d45_store_8(&dst, stride, above_right, &row);
  271. d45_store_8(&dst, stride, above_right, &row);
  272. d45_store_8(&dst, stride, above_right, &row);
  273. d45_store_8(&dst, stride, above_right, &row);
  274. vst1_u8(dst, above_right);
  275. }
  276. static INLINE void d45_store_16(uint8_t **dst, const ptrdiff_t stride,
  277. const uint8x16_t above_right, uint8x16_t *row) {
  278. *row = vextq_u8(*row, above_right, 1);
  279. vst1q_u8(*dst, *row);
  280. *dst += stride;
  281. }
  282. void vpx_d45_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
  283. const uint8_t *above, const uint8_t *left) {
  284. const uint8x16_t A0 = vld1q_u8(above);
  285. const uint8x16_t above_right = vdupq_lane_u8(vget_high_u8(A0), 7);
  286. const uint8x16_t A1 = vextq_u8(A0, above_right, 1);
  287. const uint8x16_t A2 = vextq_u8(A0, above_right, 2);
  288. const uint8x16_t avg1 = vhaddq_u8(A0, A2);
  289. uint8x16_t row = vrhaddq_u8(avg1, A1);
  290. (void)left;
  291. vst1q_u8(dst, row);
  292. dst += stride;
  293. d45_store_16(&dst, stride, above_right, &row);
  294. d45_store_16(&dst, stride, above_right, &row);
  295. d45_store_16(&dst, stride, above_right, &row);
  296. d45_store_16(&dst, stride, above_right, &row);
  297. d45_store_16(&dst, stride, above_right, &row);
  298. d45_store_16(&dst, stride, above_right, &row);
  299. d45_store_16(&dst, stride, above_right, &row);
  300. d45_store_16(&dst, stride, above_right, &row);
  301. d45_store_16(&dst, stride, above_right, &row);
  302. d45_store_16(&dst, stride, above_right, &row);
  303. d45_store_16(&dst, stride, above_right, &row);
  304. d45_store_16(&dst, stride, above_right, &row);
  305. d45_store_16(&dst, stride, above_right, &row);
  306. d45_store_16(&dst, stride, above_right, &row);
  307. vst1q_u8(dst, above_right);
  308. }
  309. void vpx_d45_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
  310. const uint8_t *above, const uint8_t *left) {
  311. const uint8x16_t A0_0 = vld1q_u8(above);
  312. const uint8x16_t A0_1 = vld1q_u8(above + 16);
  313. const uint8x16_t above_right = vdupq_lane_u8(vget_high_u8(A0_1), 7);
  314. const uint8x16_t A1_0 = vld1q_u8(above + 1);
  315. const uint8x16_t A1_1 = vld1q_u8(above + 17);
  316. const uint8x16_t A2_0 = vld1q_u8(above + 2);
  317. const uint8x16_t A2_1 = vld1q_u8(above + 18);
  318. const uint8x16_t avg_0 = vhaddq_u8(A0_0, A2_0);
  319. const uint8x16_t avg_1 = vhaddq_u8(A0_1, A2_1);
  320. uint8x16_t row_0 = vrhaddq_u8(avg_0, A1_0);
  321. uint8x16_t row_1 = vrhaddq_u8(avg_1, A1_1);
  322. int i;
  323. (void)left;
  324. vst1q_u8(dst, row_0);
  325. dst += 16;
  326. vst1q_u8(dst, row_1);
  327. dst += stride - 16;
  328. for (i = 0; i < 30; ++i) {
  329. row_0 = vextq_u8(row_0, row_1, 1);
  330. row_1 = vextq_u8(row_1, above_right, 1);
  331. vst1q_u8(dst, row_0);
  332. dst += 16;
  333. vst1q_u8(dst, row_1);
  334. dst += stride - 16;
  335. }
  336. vst1q_u8(dst, above_right);
  337. dst += 16;
  338. vst1q_u8(dst, row_1);
  339. }
  340. // -----------------------------------------------------------------------------
  341. void vpx_d135_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
  342. const uint8_t *above, const uint8_t *left) {
  343. const uint8x8_t XA0123 = vld1_u8(above - 1);
  344. const uint8x8_t L0123 = vld1_u8(left);
  345. const uint8x8_t L3210 = vrev64_u8(L0123);
  346. const uint8x8_t L3210XA012 = vext_u8(L3210, XA0123, 4);
  347. const uint8x8_t L210XA0123 = vext_u8(L3210, XA0123, 5);
  348. const uint8x8_t L10XA0123_ =
  349. vreinterpret_u8_u64(vshr_n_u64(vreinterpret_u64_u8(L210XA0123), 8));
  350. const uint8x8_t avg1 = vhadd_u8(L10XA0123_, L3210XA012);
  351. const uint8x8_t avg2 = vrhadd_u8(avg1, L210XA0123);
  352. const uint64x1_t avg2_u64 = vreinterpret_u64_u8(avg2);
  353. const uint32x2_t r3 = vreinterpret_u32_u8(avg2);
  354. const uint32x2_t r2 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 8));
  355. const uint32x2_t r1 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 16));
  356. const uint32x2_t r0 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 24));
  357. vst1_lane_u32((uint32_t *)dst, r0, 0);
  358. dst += stride;
  359. vst1_lane_u32((uint32_t *)dst, r1, 0);
  360. dst += stride;
  361. vst1_lane_u32((uint32_t *)dst, r2, 0);
  362. dst += stride;
  363. vst1_lane_u32((uint32_t *)dst, r3, 0);
  364. }
  365. void vpx_d135_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
  366. const uint8_t *above, const uint8_t *left) {
  367. const uint8x8_t XA0123456 = vld1_u8(above - 1);
  368. const uint8x8_t A01234567 = vld1_u8(above);
  369. const uint8x8_t A1234567_ = vld1_u8(above + 1);
  370. const uint8x8_t L01234567 = vld1_u8(left);
  371. const uint8x8_t L76543210 = vrev64_u8(L01234567);
  372. const uint8x8_t L6543210X = vext_u8(L76543210, XA0123456, 1);
  373. const uint8x8_t L543210XA0 = vext_u8(L76543210, XA0123456, 2);
  374. const uint8x16_t L76543210XA0123456 = vcombine_u8(L76543210, XA0123456);
  375. const uint8x16_t L6543210XA01234567 = vcombine_u8(L6543210X, A01234567);
  376. const uint8x16_t L543210XA01234567_ = vcombine_u8(L543210XA0, A1234567_);
  377. const uint8x16_t avg = vhaddq_u8(L76543210XA0123456, L543210XA01234567_);
  378. const uint8x16_t row = vrhaddq_u8(avg, L6543210XA01234567);
  379. const uint8x8_t row_0 = vget_low_u8(row);
  380. const uint8x8_t row_1 = vget_high_u8(row);
  381. const uint8x8_t r0 = vext_u8(row_0, row_1, 7);
  382. const uint8x8_t r1 = vext_u8(row_0, row_1, 6);
  383. const uint8x8_t r2 = vext_u8(row_0, row_1, 5);
  384. const uint8x8_t r3 = vext_u8(row_0, row_1, 4);
  385. const uint8x8_t r4 = vext_u8(row_0, row_1, 3);
  386. const uint8x8_t r5 = vext_u8(row_0, row_1, 2);
  387. const uint8x8_t r6 = vext_u8(row_0, row_1, 1);
  388. vst1_u8(dst, r0);
  389. dst += stride;
  390. vst1_u8(dst, r1);
  391. dst += stride;
  392. vst1_u8(dst, r2);
  393. dst += stride;
  394. vst1_u8(dst, r3);
  395. dst += stride;
  396. vst1_u8(dst, r4);
  397. dst += stride;
  398. vst1_u8(dst, r5);
  399. dst += stride;
  400. vst1_u8(dst, r6);
  401. dst += stride;
  402. vst1_u8(dst, row_0);
  403. }
  404. static INLINE void d135_store_16x8(
  405. uint8_t **dst, const ptrdiff_t stride, const uint8x16_t row_0,
  406. const uint8x16_t row_1, const uint8x16_t row_2, const uint8x16_t row_3,
  407. const uint8x16_t row_4, const uint8x16_t row_5, const uint8x16_t row_6,
  408. const uint8x16_t row_7) {
  409. vst1q_u8(*dst, row_0);
  410. *dst += stride;
  411. vst1q_u8(*dst, row_1);
  412. *dst += stride;
  413. vst1q_u8(*dst, row_2);
  414. *dst += stride;
  415. vst1q_u8(*dst, row_3);
  416. *dst += stride;
  417. vst1q_u8(*dst, row_4);
  418. *dst += stride;
  419. vst1q_u8(*dst, row_5);
  420. *dst += stride;
  421. vst1q_u8(*dst, row_6);
  422. *dst += stride;
  423. vst1q_u8(*dst, row_7);
  424. *dst += stride;
  425. }
  426. void vpx_d135_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
  427. const uint8_t *above, const uint8_t *left) {
  428. const uint8x16_t XA0123456789abcde = vld1q_u8(above - 1);
  429. const uint8x16_t A0123456789abcdef = vld1q_u8(above);
  430. const uint8x16_t A123456789abcdef_ = vld1q_u8(above + 1);
  431. const uint8x16_t L0123456789abcdef = vld1q_u8(left);
  432. const uint8x8_t L76543210 = vrev64_u8(vget_low_u8(L0123456789abcdef));
  433. const uint8x8_t Lfedcba98 = vrev64_u8(vget_high_u8(L0123456789abcdef));
  434. const uint8x16_t Lfedcba9876543210 = vcombine_u8(Lfedcba98, L76543210);
  435. const uint8x16_t Ledcba9876543210X =
  436. vextq_u8(Lfedcba9876543210, XA0123456789abcde, 1);
  437. const uint8x16_t Ldcba9876543210XA0 =
  438. vextq_u8(Lfedcba9876543210, XA0123456789abcde, 2);
  439. const uint8x16_t avg_0 = vhaddq_u8(Lfedcba9876543210, Ldcba9876543210XA0);
  440. const uint8x16_t avg_1 = vhaddq_u8(XA0123456789abcde, A123456789abcdef_);
  441. const uint8x16_t row_0 = vrhaddq_u8(avg_0, Ledcba9876543210X);
  442. const uint8x16_t row_1 = vrhaddq_u8(avg_1, A0123456789abcdef);
  443. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 15);
  444. const uint8x16_t r_1 = vextq_u8(row_0, row_1, 14);
  445. const uint8x16_t r_2 = vextq_u8(row_0, row_1, 13);
  446. const uint8x16_t r_3 = vextq_u8(row_0, row_1, 12);
  447. const uint8x16_t r_4 = vextq_u8(row_0, row_1, 11);
  448. const uint8x16_t r_5 = vextq_u8(row_0, row_1, 10);
  449. const uint8x16_t r_6 = vextq_u8(row_0, row_1, 9);
  450. const uint8x16_t r_7 = vcombine_u8(vget_high_u8(row_0), vget_low_u8(row_1));
  451. const uint8x16_t r_8 = vextq_u8(row_0, row_1, 7);
  452. const uint8x16_t r_9 = vextq_u8(row_0, row_1, 6);
  453. const uint8x16_t r_a = vextq_u8(row_0, row_1, 5);
  454. const uint8x16_t r_b = vextq_u8(row_0, row_1, 4);
  455. const uint8x16_t r_c = vextq_u8(row_0, row_1, 3);
  456. const uint8x16_t r_d = vextq_u8(row_0, row_1, 2);
  457. const uint8x16_t r_e = vextq_u8(row_0, row_1, 1);
  458. d135_store_16x8(&dst, stride, r_0, r_1, r_2, r_3, r_4, r_5, r_6, r_7);
  459. d135_store_16x8(&dst, stride, r_8, r_9, r_a, r_b, r_c, r_d, r_e, row_0);
  460. }
  461. static INLINE void d135_store_32x2(uint8_t **dst, const ptrdiff_t stride,
  462. const uint8x16_t row_0,
  463. const uint8x16_t row_1,
  464. const uint8x16_t row_2) {
  465. uint8_t *dst2 = *dst;
  466. vst1q_u8(dst2, row_1);
  467. dst2 += 16;
  468. vst1q_u8(dst2, row_2);
  469. dst2 += 16 * stride - 16;
  470. vst1q_u8(dst2, row_0);
  471. dst2 += 16;
  472. vst1q_u8(dst2, row_1);
  473. *dst += stride;
  474. }
  475. void vpx_d135_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
  476. const uint8_t *above, const uint8_t *left) {
  477. const uint8x16_t LL0123456789abcdef = vld1q_u8(left + 16);
  478. const uint8x16_t LU0123456789abcdef = vld1q_u8(left);
  479. const uint8x8_t LL76543210 = vrev64_u8(vget_low_u8(LL0123456789abcdef));
  480. const uint8x8_t LU76543210 = vrev64_u8(vget_low_u8(LU0123456789abcdef));
  481. const uint8x8_t LLfedcba98 = vrev64_u8(vget_high_u8(LL0123456789abcdef));
  482. const uint8x8_t LUfedcba98 = vrev64_u8(vget_high_u8(LU0123456789abcdef));
  483. const uint8x16_t LLfedcba9876543210 = vcombine_u8(LLfedcba98, LL76543210);
  484. const uint8x16_t LUfedcba9876543210 = vcombine_u8(LUfedcba98, LU76543210);
  485. const uint8x16_t LLedcba9876543210Uf =
  486. vextq_u8(LLfedcba9876543210, LUfedcba9876543210, 1);
  487. const uint8x16_t LLdcba9876543210Ufe =
  488. vextq_u8(LLfedcba9876543210, LUfedcba9876543210, 2);
  489. const uint8x16_t avg_0 = vhaddq_u8(LLfedcba9876543210, LLdcba9876543210Ufe);
  490. const uint8x16_t row_0 = vrhaddq_u8(avg_0, LLedcba9876543210Uf);
  491. const uint8x16_t XAL0123456789abcde = vld1q_u8(above - 1);
  492. const uint8x16_t LUedcba9876543210X =
  493. vextq_u8(LUfedcba9876543210, XAL0123456789abcde, 1);
  494. const uint8x16_t LUdcba9876543210XA0 =
  495. vextq_u8(LUfedcba9876543210, XAL0123456789abcde, 2);
  496. const uint8x16_t avg_1 = vhaddq_u8(LUfedcba9876543210, LUdcba9876543210XA0);
  497. const uint8x16_t row_1 = vrhaddq_u8(avg_1, LUedcba9876543210X);
  498. const uint8x16_t AL0123456789abcdef = vld1q_u8(above);
  499. const uint8x16_t AL123456789abcdefg = vld1q_u8(above + 1);
  500. const uint8x16_t ALfR0123456789abcde = vld1q_u8(above + 15);
  501. const uint8x16_t AR0123456789abcdef = vld1q_u8(above + 16);
  502. const uint8x16_t AR123456789abcdef_ = vld1q_u8(above + 17);
  503. const uint8x16_t avg_2 = vhaddq_u8(XAL0123456789abcde, AL123456789abcdefg);
  504. const uint8x16_t row_2 = vrhaddq_u8(avg_2, AL0123456789abcdef);
  505. const uint8x16_t avg_3 = vhaddq_u8(ALfR0123456789abcde, AR123456789abcdef_);
  506. const uint8x16_t row_3 = vrhaddq_u8(avg_3, AR0123456789abcdef);
  507. {
  508. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 15);
  509. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 15);
  510. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 15);
  511. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  512. }
  513. {
  514. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 14);
  515. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 14);
  516. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 14);
  517. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  518. }
  519. {
  520. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 13);
  521. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 13);
  522. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 13);
  523. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  524. }
  525. {
  526. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 12);
  527. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 12);
  528. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 12);
  529. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  530. }
  531. {
  532. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 11);
  533. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 11);
  534. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 11);
  535. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  536. }
  537. {
  538. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 10);
  539. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 10);
  540. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 10);
  541. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  542. }
  543. {
  544. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 9);
  545. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 9);
  546. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 9);
  547. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  548. }
  549. {
  550. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 8);
  551. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 8);
  552. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 8);
  553. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  554. }
  555. {
  556. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 7);
  557. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 7);
  558. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 7);
  559. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  560. }
  561. {
  562. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 6);
  563. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 6);
  564. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 6);
  565. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  566. }
  567. {
  568. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 5);
  569. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 5);
  570. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 5);
  571. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  572. }
  573. {
  574. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 4);
  575. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 4);
  576. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 4);
  577. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  578. }
  579. {
  580. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 3);
  581. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 3);
  582. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 3);
  583. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  584. }
  585. {
  586. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 2);
  587. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 2);
  588. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 2);
  589. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  590. }
  591. {
  592. const uint8x16_t r_0 = vextq_u8(row_0, row_1, 1);
  593. const uint8x16_t r_1 = vextq_u8(row_1, row_2, 1);
  594. const uint8x16_t r_2 = vextq_u8(row_2, row_3, 1);
  595. d135_store_32x2(&dst, stride, r_0, r_1, r_2);
  596. }
  597. d135_store_32x2(&dst, stride, row_0, row_1, row_2);
  598. }
  599. #if !HAVE_NEON_ASM
  600. void vpx_v_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
  601. const uint8_t *above, const uint8_t *left) {
  602. const uint32_t d = *(const uint32_t *)above;
  603. int i;
  604. (void)left;
  605. for (i = 0; i < 4; i++, dst += stride) {
  606. *(uint32_t *)dst = d;
  607. }
  608. }
  609. void vpx_v_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
  610. const uint8_t *above, const uint8_t *left) {
  611. const uint8x8_t d = vld1_u8(above);
  612. int i;
  613. (void)left;
  614. for (i = 0; i < 8; i++, dst += stride) {
  615. vst1_u8(dst, d);
  616. }
  617. }
  618. void vpx_v_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
  619. const uint8_t *above, const uint8_t *left) {
  620. const uint8x16_t d = vld1q_u8(above);
  621. int i;
  622. (void)left;
  623. for (i = 0; i < 16; i++, dst += stride) {
  624. vst1q_u8(dst, d);
  625. }
  626. }
  627. void vpx_v_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
  628. const uint8_t *above, const uint8_t *left) {
  629. const uint8x16_t d0 = vld1q_u8(above);
  630. const uint8x16_t d1 = vld1q_u8(above + 16);
  631. int i;
  632. (void)left;
  633. for (i = 0; i < 32; i++) {
  634. // Note: performance was worse using vst2q_u8 under gcc-4.9 & clang-3.8.
  635. // clang-3.8 unrolled the loop fully with no filler so the cause is likely
  636. // the latency of the instruction.
  637. vst1q_u8(dst, d0);
  638. dst += 16;
  639. vst1q_u8(dst, d1);
  640. dst += stride - 16;
  641. }
  642. }
  643. // -----------------------------------------------------------------------------
  644. void vpx_h_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
  645. const uint8_t *above, const uint8_t *left) {
  646. const uint32x2_t zero = vdup_n_u32(0);
  647. const uint8x8_t left_u8 =
  648. vreinterpret_u8_u32(vld1_lane_u32((const uint32_t *)left, zero, 0));
  649. uint8x8_t d;
  650. (void)above;
  651. d = vdup_lane_u8(left_u8, 0);
  652. vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d), 0);
  653. dst += stride;
  654. d = vdup_lane_u8(left_u8, 1);
  655. vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d), 0);
  656. dst += stride;
  657. d = vdup_lane_u8(left_u8, 2);
  658. vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d), 0);
  659. dst += stride;
  660. d = vdup_lane_u8(left_u8, 3);
  661. vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d), 0);
  662. }
  663. void vpx_h_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
  664. const uint8_t *above, const uint8_t *left) {
  665. const uint8x8_t left_u8 = vld1_u8(left);
  666. uint8x8_t d;
  667. (void)above;
  668. d = vdup_lane_u8(left_u8, 0);
  669. vst1_u8(dst, d);
  670. dst += stride;
  671. d = vdup_lane_u8(left_u8, 1);
  672. vst1_u8(dst, d);
  673. dst += stride;
  674. d = vdup_lane_u8(left_u8, 2);
  675. vst1_u8(dst, d);
  676. dst += stride;
  677. d = vdup_lane_u8(left_u8, 3);
  678. vst1_u8(dst, d);
  679. dst += stride;
  680. d = vdup_lane_u8(left_u8, 4);
  681. vst1_u8(dst, d);
  682. dst += stride;
  683. d = vdup_lane_u8(left_u8, 5);
  684. vst1_u8(dst, d);
  685. dst += stride;
  686. d = vdup_lane_u8(left_u8, 6);
  687. vst1_u8(dst, d);
  688. dst += stride;
  689. d = vdup_lane_u8(left_u8, 7);
  690. vst1_u8(dst, d);
  691. }
  692. static INLINE void h_store_16x8(uint8_t **dst, const ptrdiff_t stride,
  693. const uint8x8_t left) {
  694. const uint8x16_t row_0 = vdupq_lane_u8(left, 0);
  695. const uint8x16_t row_1 = vdupq_lane_u8(left, 1);
  696. const uint8x16_t row_2 = vdupq_lane_u8(left, 2);
  697. const uint8x16_t row_3 = vdupq_lane_u8(left, 3);
  698. const uint8x16_t row_4 = vdupq_lane_u8(left, 4);
  699. const uint8x16_t row_5 = vdupq_lane_u8(left, 5);
  700. const uint8x16_t row_6 = vdupq_lane_u8(left, 6);
  701. const uint8x16_t row_7 = vdupq_lane_u8(left, 7);
  702. vst1q_u8(*dst, row_0);
  703. *dst += stride;
  704. vst1q_u8(*dst, row_1);
  705. *dst += stride;
  706. vst1q_u8(*dst, row_2);
  707. *dst += stride;
  708. vst1q_u8(*dst, row_3);
  709. *dst += stride;
  710. vst1q_u8(*dst, row_4);
  711. *dst += stride;
  712. vst1q_u8(*dst, row_5);
  713. *dst += stride;
  714. vst1q_u8(*dst, row_6);
  715. *dst += stride;
  716. vst1q_u8(*dst, row_7);
  717. *dst += stride;
  718. }
  719. void vpx_h_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
  720. const uint8_t *above, const uint8_t *left) {
  721. const uint8x16_t left_u8q = vld1q_u8(left);
  722. (void)above;
  723. h_store_16x8(&dst, stride, vget_low_u8(left_u8q));
  724. h_store_16x8(&dst, stride, vget_high_u8(left_u8q));
  725. }
  726. static INLINE void h_store_32x8(uint8_t **dst, const ptrdiff_t stride,
  727. const uint8x8_t left) {
  728. const uint8x16_t row_0 = vdupq_lane_u8(left, 0);
  729. const uint8x16_t row_1 = vdupq_lane_u8(left, 1);
  730. const uint8x16_t row_2 = vdupq_lane_u8(left, 2);
  731. const uint8x16_t row_3 = vdupq_lane_u8(left, 3);
  732. const uint8x16_t row_4 = vdupq_lane_u8(left, 4);
  733. const uint8x16_t row_5 = vdupq_lane_u8(left, 5);
  734. const uint8x16_t row_6 = vdupq_lane_u8(left, 6);
  735. const uint8x16_t row_7 = vdupq_lane_u8(left, 7);
  736. vst1q_u8(*dst, row_0); // Note clang-3.8 produced poor code w/vst2q_u8
  737. *dst += 16;
  738. vst1q_u8(*dst, row_0);
  739. *dst += stride - 16;
  740. vst1q_u8(*dst, row_1);
  741. *dst += 16;
  742. vst1q_u8(*dst, row_1);
  743. *dst += stride - 16;
  744. vst1q_u8(*dst, row_2);
  745. *dst += 16;
  746. vst1q_u8(*dst, row_2);
  747. *dst += stride - 16;
  748. vst1q_u8(*dst, row_3);
  749. *dst += 16;
  750. vst1q_u8(*dst, row_3);
  751. *dst += stride - 16;
  752. vst1q_u8(*dst, row_4);
  753. *dst += 16;
  754. vst1q_u8(*dst, row_4);
  755. *dst += stride - 16;
  756. vst1q_u8(*dst, row_5);
  757. *dst += 16;
  758. vst1q_u8(*dst, row_5);
  759. *dst += stride - 16;
  760. vst1q_u8(*dst, row_6);
  761. *dst += 16;
  762. vst1q_u8(*dst, row_6);
  763. *dst += stride - 16;
  764. vst1q_u8(*dst, row_7);
  765. *dst += 16;
  766. vst1q_u8(*dst, row_7);
  767. *dst += stride - 16;
  768. }
  769. void vpx_h_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
  770. const uint8_t *above, const uint8_t *left) {
  771. int i;
  772. (void)above;
  773. for (i = 0; i < 2; i++, left += 16) {
  774. const uint8x16_t left_u8 = vld1q_u8(left);
  775. h_store_32x8(&dst, stride, vget_low_u8(left_u8));
  776. h_store_32x8(&dst, stride, vget_high_u8(left_u8));
  777. }
  778. }
  779. // -----------------------------------------------------------------------------
  780. static INLINE int16x8_t convert_u8_to_s16(uint8x8_t v) {
  781. return vreinterpretq_s16_u16(vmovl_u8(v));
  782. }
  783. void vpx_tm_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
  784. const uint8_t *above, const uint8_t *left) {
  785. const uint8x8_t top_left = vld1_dup_u8(above - 1);
  786. const uint8x8_t left_u8 = vld1_u8(left);
  787. const uint8x8_t above_u8 = vld1_u8(above);
  788. const int16x4_t left_s16 = vget_low_s16(convert_u8_to_s16(left_u8));
  789. int16x8_t sub, sum;
  790. uint32x2_t d;
  791. sub = vreinterpretq_s16_u16(vsubl_u8(above_u8, top_left));
  792. // Avoid vcombine_s16() which generates lots of redundant code with clang-3.8.
  793. sub = vreinterpretq_s16_s64(
  794. vdupq_lane_s64(vreinterpret_s64_s16(vget_low_s16(sub)), 0));
  795. sum = vcombine_s16(vdup_lane_s16(left_s16, 0), vdup_lane_s16(left_s16, 1));
  796. sum = vaddq_s16(sum, sub);
  797. d = vreinterpret_u32_u8(vqmovun_s16(sum));
  798. vst1_lane_u32((uint32_t *)dst, d, 0);
  799. dst += stride;
  800. vst1_lane_u32((uint32_t *)dst, d, 1);
  801. dst += stride;
  802. sum = vcombine_s16(vdup_lane_s16(left_s16, 2), vdup_lane_s16(left_s16, 3));
  803. sum = vaddq_s16(sum, sub);
  804. d = vreinterpret_u32_u8(vqmovun_s16(sum));
  805. vst1_lane_u32((uint32_t *)dst, d, 0);
  806. dst += stride;
  807. vst1_lane_u32((uint32_t *)dst, d, 1);
  808. }
  809. static INLINE void tm_8_kernel(uint8_t **dst, const ptrdiff_t stride,
  810. const int16x8_t left_dup, const int16x8_t sub) {
  811. const int16x8_t sum = vaddq_s16(left_dup, sub);
  812. const uint8x8_t d = vqmovun_s16(sum);
  813. vst1_u8(*dst, d);
  814. *dst += stride;
  815. }
  816. void vpx_tm_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
  817. const uint8_t *above, const uint8_t *left) {
  818. const uint8x8_t top_left = vld1_dup_u8(above - 1);
  819. const uint8x8_t above_u8 = vld1_u8(above);
  820. const uint8x8_t left_u8 = vld1_u8(left);
  821. const int16x8_t left_s16q = convert_u8_to_s16(left_u8);
  822. const int16x8_t sub = vreinterpretq_s16_u16(vsubl_u8(above_u8, top_left));
  823. int16x4_t left_s16d = vget_low_s16(left_s16q);
  824. int i;
  825. for (i = 0; i < 2; i++, left_s16d = vget_high_s16(left_s16q)) {
  826. int16x8_t left_dup;
  827. left_dup = vdupq_lane_s16(left_s16d, 0);
  828. tm_8_kernel(&dst, stride, left_dup, sub);
  829. left_dup = vdupq_lane_s16(left_s16d, 1);
  830. tm_8_kernel(&dst, stride, left_dup, sub);
  831. left_dup = vdupq_lane_s16(left_s16d, 2);
  832. tm_8_kernel(&dst, stride, left_dup, sub);
  833. left_dup = vdupq_lane_s16(left_s16d, 3);
  834. tm_8_kernel(&dst, stride, left_dup, sub);
  835. }
  836. }
  837. static INLINE void tm_16_kernel(uint8_t **dst, const ptrdiff_t stride,
  838. const int16x8_t left_dup, const int16x8_t sub0,
  839. const int16x8_t sub1) {
  840. const int16x8_t sum0 = vaddq_s16(left_dup, sub0);
  841. const int16x8_t sum1 = vaddq_s16(left_dup, sub1);
  842. const uint8x8_t d0 = vqmovun_s16(sum0);
  843. const uint8x8_t d1 = vqmovun_s16(sum1);
  844. vst1_u8(*dst, d0);
  845. *dst += 8;
  846. vst1_u8(*dst, d1);
  847. *dst += stride - 8;
  848. }
  849. void vpx_tm_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
  850. const uint8_t *above, const uint8_t *left) {
  851. const uint8x16_t top_left = vld1q_dup_u8(above - 1);
  852. const uint8x16_t above_u8 = vld1q_u8(above);
  853. const int16x8_t sub0 = vreinterpretq_s16_u16(
  854. vsubl_u8(vget_low_u8(above_u8), vget_low_u8(top_left)));
  855. const int16x8_t sub1 = vreinterpretq_s16_u16(
  856. vsubl_u8(vget_high_u8(above_u8), vget_high_u8(top_left)));
  857. int16x8_t left_dup;
  858. int i;
  859. for (i = 0; i < 2; i++, left += 8) {
  860. const uint8x8_t left_u8 = vld1_u8(left);
  861. const int16x8_t left_s16q = convert_u8_to_s16(left_u8);
  862. const int16x4_t left_low = vget_low_s16(left_s16q);
  863. const int16x4_t left_high = vget_high_s16(left_s16q);
  864. left_dup = vdupq_lane_s16(left_low, 0);
  865. tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
  866. left_dup = vdupq_lane_s16(left_low, 1);
  867. tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
  868. left_dup = vdupq_lane_s16(left_low, 2);
  869. tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
  870. left_dup = vdupq_lane_s16(left_low, 3);
  871. tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
  872. left_dup = vdupq_lane_s16(left_high, 0);
  873. tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
  874. left_dup = vdupq_lane_s16(left_high, 1);
  875. tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
  876. left_dup = vdupq_lane_s16(left_high, 2);
  877. tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
  878. left_dup = vdupq_lane_s16(left_high, 3);
  879. tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
  880. }
  881. }
  882. static INLINE void tm_32_kernel(uint8_t **dst, const ptrdiff_t stride,
  883. const int16x8_t left_dup, const int16x8_t sub0,
  884. const int16x8_t sub1, const int16x8_t sub2,
  885. const int16x8_t sub3) {
  886. const int16x8_t sum0 = vaddq_s16(left_dup, sub0);
  887. const int16x8_t sum1 = vaddq_s16(left_dup, sub1);
  888. const int16x8_t sum2 = vaddq_s16(left_dup, sub2);
  889. const int16x8_t sum3 = vaddq_s16(left_dup, sub3);
  890. const uint8x8_t d0 = vqmovun_s16(sum0);
  891. const uint8x8_t d1 = vqmovun_s16(sum1);
  892. const uint8x8_t d2 = vqmovun_s16(sum2);
  893. const uint8x8_t d3 = vqmovun_s16(sum3);
  894. vst1q_u8(*dst, vcombine_u8(d0, d1));
  895. *dst += 16;
  896. vst1q_u8(*dst, vcombine_u8(d2, d3));
  897. *dst += stride - 16;
  898. }
  899. void vpx_tm_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
  900. const uint8_t *above, const uint8_t *left) {
  901. const uint8x16_t top_left = vld1q_dup_u8(above - 1);
  902. const uint8x16_t above_low = vld1q_u8(above);
  903. const uint8x16_t above_high = vld1q_u8(above + 16);
  904. const int16x8_t sub0 = vreinterpretq_s16_u16(
  905. vsubl_u8(vget_low_u8(above_low), vget_low_u8(top_left)));
  906. const int16x8_t sub1 = vreinterpretq_s16_u16(
  907. vsubl_u8(vget_high_u8(above_low), vget_high_u8(top_left)));
  908. const int16x8_t sub2 = vreinterpretq_s16_u16(
  909. vsubl_u8(vget_low_u8(above_high), vget_low_u8(top_left)));
  910. const int16x8_t sub3 = vreinterpretq_s16_u16(
  911. vsubl_u8(vget_high_u8(above_high), vget_high_u8(top_left)));
  912. int16x8_t left_dup;
  913. int i, j;
  914. for (j = 0; j < 4; j++, left += 8) {
  915. const uint8x8_t left_u8 = vld1_u8(left);
  916. const int16x8_t left_s16q = convert_u8_to_s16(left_u8);
  917. int16x4_t left_s16d = vget_low_s16(left_s16q);
  918. for (i = 0; i < 2; i++, left_s16d = vget_high_s16(left_s16q)) {
  919. left_dup = vdupq_lane_s16(left_s16d, 0);
  920. tm_32_kernel(&dst, stride, left_dup, sub0, sub1, sub2, sub3);
  921. left_dup = vdupq_lane_s16(left_s16d, 1);
  922. tm_32_kernel(&dst, stride, left_dup, sub0, sub1, sub2, sub3);
  923. left_dup = vdupq_lane_s16(left_s16d, 2);
  924. tm_32_kernel(&dst, stride, left_dup, sub0, sub1, sub2, sub3);
  925. left_dup = vdupq_lane_s16(left_s16d, 3);
  926. tm_32_kernel(&dst, stride, left_dup, sub0, sub1, sub2, sub3);
  927. }
  928. }
  929. }
  930. #endif // !HAVE_NEON_ASM