idct_neon.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. /*
  2. * Copyright (c) 2016 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. #ifndef VPX_VPX_DSP_ARM_IDCT_NEON_H_
  11. #define VPX_VPX_DSP_ARM_IDCT_NEON_H_
  12. #include <arm_neon.h>
  13. #include "./vpx_config.h"
  14. #include "vpx_dsp/arm/transpose_neon.h"
  15. #include "vpx_dsp/txfm_common.h"
  16. #include "vpx_dsp/vpx_dsp_common.h"
  17. static const int16_t kCospi[16] = {
  18. 16384 /* cospi_0_64 */, 15137 /* cospi_8_64 */,
  19. 11585 /* cospi_16_64 */, 6270 /* cospi_24_64 */,
  20. 16069 /* cospi_4_64 */, 13623 /* cospi_12_64 */,
  21. -9102 /* -cospi_20_64 */, 3196 /* cospi_28_64 */,
  22. 16305 /* cospi_2_64 */, 1606 /* cospi_30_64 */,
  23. 14449 /* cospi_10_64 */, 7723 /* cospi_22_64 */,
  24. 15679 /* cospi_6_64 */, -4756 /* -cospi_26_64 */,
  25. 12665 /* cospi_14_64 */, -10394 /* -cospi_18_64 */
  26. };
  27. static const int32_t kCospi32[16] = {
  28. 16384 /* cospi_0_64 */, 15137 /* cospi_8_64 */,
  29. 11585 /* cospi_16_64 */, 6270 /* cospi_24_64 */,
  30. 16069 /* cospi_4_64 */, 13623 /* cospi_12_64 */,
  31. -9102 /* -cospi_20_64 */, 3196 /* cospi_28_64 */,
  32. 16305 /* cospi_2_64 */, 1606 /* cospi_30_64 */,
  33. 14449 /* cospi_10_64 */, 7723 /* cospi_22_64 */,
  34. 15679 /* cospi_6_64 */, -4756 /* -cospi_26_64 */,
  35. 12665 /* cospi_14_64 */, -10394 /* -cospi_18_64 */
  36. };
  37. //------------------------------------------------------------------------------
  38. // Use saturating add/sub to avoid overflow in 2nd pass in high bit-depth
  39. static INLINE int16x8_t final_add(const int16x8_t a, const int16x8_t b) {
  40. #if CONFIG_VP9_HIGHBITDEPTH
  41. return vqaddq_s16(a, b);
  42. #else
  43. return vaddq_s16(a, b);
  44. #endif
  45. }
  46. static INLINE int16x8_t final_sub(const int16x8_t a, const int16x8_t b) {
  47. #if CONFIG_VP9_HIGHBITDEPTH
  48. return vqsubq_s16(a, b);
  49. #else
  50. return vsubq_s16(a, b);
  51. #endif
  52. }
  53. //------------------------------------------------------------------------------
  54. static INLINE int32x4x2_t highbd_idct_add_dual(const int32x4x2_t s0,
  55. const int32x4x2_t s1) {
  56. int32x4x2_t t;
  57. t.val[0] = vaddq_s32(s0.val[0], s1.val[0]);
  58. t.val[1] = vaddq_s32(s0.val[1], s1.val[1]);
  59. return t;
  60. }
  61. static INLINE int32x4x2_t highbd_idct_sub_dual(const int32x4x2_t s0,
  62. const int32x4x2_t s1) {
  63. int32x4x2_t t;
  64. t.val[0] = vsubq_s32(s0.val[0], s1.val[0]);
  65. t.val[1] = vsubq_s32(s0.val[1], s1.val[1]);
  66. return t;
  67. }
  68. //------------------------------------------------------------------------------
  69. static INLINE int16x8_t dct_const_round_shift_low_8(const int32x4_t *const in) {
  70. return vcombine_s16(vrshrn_n_s32(in[0], DCT_CONST_BITS),
  71. vrshrn_n_s32(in[1], DCT_CONST_BITS));
  72. }
  73. static INLINE void dct_const_round_shift_low_8_dual(const int32x4_t *const t32,
  74. int16x8_t *const d0,
  75. int16x8_t *const d1) {
  76. *d0 = dct_const_round_shift_low_8(t32 + 0);
  77. *d1 = dct_const_round_shift_low_8(t32 + 2);
  78. }
  79. static INLINE int32x4x2_t
  80. dct_const_round_shift_high_4x2(const int64x2_t *const in) {
  81. int32x4x2_t out;
  82. out.val[0] = vcombine_s32(vrshrn_n_s64(in[0], DCT_CONST_BITS),
  83. vrshrn_n_s64(in[1], DCT_CONST_BITS));
  84. out.val[1] = vcombine_s32(vrshrn_n_s64(in[2], DCT_CONST_BITS),
  85. vrshrn_n_s64(in[3], DCT_CONST_BITS));
  86. return out;
  87. }
  88. // Multiply a by a_const. Saturate, shift and narrow by DCT_CONST_BITS.
  89. static INLINE int16x8_t multiply_shift_and_narrow_s16(const int16x8_t a,
  90. const int16_t a_const) {
  91. // Shift by DCT_CONST_BITS + rounding will be within 16 bits for well formed
  92. // streams. See WRAPLOW and dct_const_round_shift for details.
  93. // This instruction doubles the result and returns the high half, essentially
  94. // resulting in a right shift by 15. By multiplying the constant first that
  95. // becomes a right shift by DCT_CONST_BITS.
  96. // The largest possible value used here is
  97. // vpx_dsp/txfm_common.h:cospi_1_64 = 16364 (* 2 = 32728) a which falls *just*
  98. // within the range of int16_t (+32767 / -32768) even when negated.
  99. return vqrdmulhq_n_s16(a, a_const * 2);
  100. }
  101. // Add a and b, then multiply by ab_const. Shift and narrow by DCT_CONST_BITS.
  102. static INLINE int16x8_t add_multiply_shift_and_narrow_s16(
  103. const int16x8_t a, const int16x8_t b, const int16_t ab_const) {
  104. // In both add_ and it's pair, sub_, the input for well-formed streams will be
  105. // well within 16 bits (input to the idct is the difference between two frames
  106. // and will be within -255 to 255, or 9 bits)
  107. // However, for inputs over about 25,000 (valid for int16_t, but not for idct
  108. // input) this function can not use vaddq_s16.
  109. // In order to match existing behavior and intentionally out of range tests,
  110. // expand the addition up to 32 bits to prevent truncation.
  111. int32x4_t t[2];
  112. t[0] = vaddl_s16(vget_low_s16(a), vget_low_s16(b));
  113. t[1] = vaddl_s16(vget_high_s16(a), vget_high_s16(b));
  114. t[0] = vmulq_n_s32(t[0], ab_const);
  115. t[1] = vmulq_n_s32(t[1], ab_const);
  116. return dct_const_round_shift_low_8(t);
  117. }
  118. // Subtract b from a, then multiply by ab_const. Shift and narrow by
  119. // DCT_CONST_BITS.
  120. static INLINE int16x8_t sub_multiply_shift_and_narrow_s16(
  121. const int16x8_t a, const int16x8_t b, const int16_t ab_const) {
  122. int32x4_t t[2];
  123. t[0] = vsubl_s16(vget_low_s16(a), vget_low_s16(b));
  124. t[1] = vsubl_s16(vget_high_s16(a), vget_high_s16(b));
  125. t[0] = vmulq_n_s32(t[0], ab_const);
  126. t[1] = vmulq_n_s32(t[1], ab_const);
  127. return dct_const_round_shift_low_8(t);
  128. }
  129. // Multiply a by a_const and b by b_const, then accumulate. Shift and narrow by
  130. // DCT_CONST_BITS.
  131. static INLINE int16x8_t multiply_accumulate_shift_and_narrow_s16(
  132. const int16x8_t a, const int16_t a_const, const int16x8_t b,
  133. const int16_t b_const) {
  134. int32x4_t t[2];
  135. t[0] = vmull_n_s16(vget_low_s16(a), a_const);
  136. t[1] = vmull_n_s16(vget_high_s16(a), a_const);
  137. t[0] = vmlal_n_s16(t[0], vget_low_s16(b), b_const);
  138. t[1] = vmlal_n_s16(t[1], vget_high_s16(b), b_const);
  139. return dct_const_round_shift_low_8(t);
  140. }
  141. //------------------------------------------------------------------------------
  142. // Note: The following 4 functions could use 32-bit operations for bit-depth 10.
  143. // However, although it's 20% faster with gcc, it's 20% slower with clang.
  144. // Use 64-bit operations for now.
  145. // Multiply a by a_const. Saturate, shift and narrow by DCT_CONST_BITS.
  146. static INLINE int32x4x2_t
  147. multiply_shift_and_narrow_s32_dual(const int32x4x2_t a, const int32_t a_const) {
  148. int64x2_t b[4];
  149. b[0] = vmull_n_s32(vget_low_s32(a.val[0]), a_const);
  150. b[1] = vmull_n_s32(vget_high_s32(a.val[0]), a_const);
  151. b[2] = vmull_n_s32(vget_low_s32(a.val[1]), a_const);
  152. b[3] = vmull_n_s32(vget_high_s32(a.val[1]), a_const);
  153. return dct_const_round_shift_high_4x2(b);
  154. }
  155. // Add a and b, then multiply by ab_const. Shift and narrow by DCT_CONST_BITS.
  156. static INLINE int32x4x2_t add_multiply_shift_and_narrow_s32_dual(
  157. const int32x4x2_t a, const int32x4x2_t b, const int32_t ab_const) {
  158. int32x4_t t[2];
  159. int64x2_t c[4];
  160. t[0] = vaddq_s32(a.val[0], b.val[0]);
  161. t[1] = vaddq_s32(a.val[1], b.val[1]);
  162. c[0] = vmull_n_s32(vget_low_s32(t[0]), ab_const);
  163. c[1] = vmull_n_s32(vget_high_s32(t[0]), ab_const);
  164. c[2] = vmull_n_s32(vget_low_s32(t[1]), ab_const);
  165. c[3] = vmull_n_s32(vget_high_s32(t[1]), ab_const);
  166. return dct_const_round_shift_high_4x2(c);
  167. }
  168. // Subtract b from a, then multiply by ab_const. Shift and narrow by
  169. // DCT_CONST_BITS.
  170. static INLINE int32x4x2_t sub_multiply_shift_and_narrow_s32_dual(
  171. const int32x4x2_t a, const int32x4x2_t b, const int32_t ab_const) {
  172. int32x4_t t[2];
  173. int64x2_t c[4];
  174. t[0] = vsubq_s32(a.val[0], b.val[0]);
  175. t[1] = vsubq_s32(a.val[1], b.val[1]);
  176. c[0] = vmull_n_s32(vget_low_s32(t[0]), ab_const);
  177. c[1] = vmull_n_s32(vget_high_s32(t[0]), ab_const);
  178. c[2] = vmull_n_s32(vget_low_s32(t[1]), ab_const);
  179. c[3] = vmull_n_s32(vget_high_s32(t[1]), ab_const);
  180. return dct_const_round_shift_high_4x2(c);
  181. }
  182. // Multiply a by a_const and b by b_const, then accumulate. Shift and narrow by
  183. // DCT_CONST_BITS.
  184. static INLINE int32x4x2_t multiply_accumulate_shift_and_narrow_s32_dual(
  185. const int32x4x2_t a, const int32_t a_const, const int32x4x2_t b,
  186. const int32_t b_const) {
  187. int64x2_t c[4];
  188. c[0] = vmull_n_s32(vget_low_s32(a.val[0]), a_const);
  189. c[1] = vmull_n_s32(vget_high_s32(a.val[0]), a_const);
  190. c[2] = vmull_n_s32(vget_low_s32(a.val[1]), a_const);
  191. c[3] = vmull_n_s32(vget_high_s32(a.val[1]), a_const);
  192. c[0] = vmlal_n_s32(c[0], vget_low_s32(b.val[0]), b_const);
  193. c[1] = vmlal_n_s32(c[1], vget_high_s32(b.val[0]), b_const);
  194. c[2] = vmlal_n_s32(c[2], vget_low_s32(b.val[1]), b_const);
  195. c[3] = vmlal_n_s32(c[3], vget_high_s32(b.val[1]), b_const);
  196. return dct_const_round_shift_high_4x2(c);
  197. }
  198. // Shift the output down by 6 and add it to the destination buffer.
  199. static INLINE void add_and_store_u8_s16(const int16x8_t *const a, uint8_t *d,
  200. const int stride) {
  201. uint8x8_t b[8];
  202. int16x8_t c[8];
  203. b[0] = vld1_u8(d);
  204. d += stride;
  205. b[1] = vld1_u8(d);
  206. d += stride;
  207. b[2] = vld1_u8(d);
  208. d += stride;
  209. b[3] = vld1_u8(d);
  210. d += stride;
  211. b[4] = vld1_u8(d);
  212. d += stride;
  213. b[5] = vld1_u8(d);
  214. d += stride;
  215. b[6] = vld1_u8(d);
  216. d += stride;
  217. b[7] = vld1_u8(d);
  218. d -= (7 * stride);
  219. // c = b + (a >> 6)
  220. c[0] = vrsraq_n_s16(vreinterpretq_s16_u16(vmovl_u8(b[0])), a[0], 6);
  221. c[1] = vrsraq_n_s16(vreinterpretq_s16_u16(vmovl_u8(b[1])), a[1], 6);
  222. c[2] = vrsraq_n_s16(vreinterpretq_s16_u16(vmovl_u8(b[2])), a[2], 6);
  223. c[3] = vrsraq_n_s16(vreinterpretq_s16_u16(vmovl_u8(b[3])), a[3], 6);
  224. c[4] = vrsraq_n_s16(vreinterpretq_s16_u16(vmovl_u8(b[4])), a[4], 6);
  225. c[5] = vrsraq_n_s16(vreinterpretq_s16_u16(vmovl_u8(b[5])), a[5], 6);
  226. c[6] = vrsraq_n_s16(vreinterpretq_s16_u16(vmovl_u8(b[6])), a[6], 6);
  227. c[7] = vrsraq_n_s16(vreinterpretq_s16_u16(vmovl_u8(b[7])), a[7], 6);
  228. b[0] = vqmovun_s16(c[0]);
  229. b[1] = vqmovun_s16(c[1]);
  230. b[2] = vqmovun_s16(c[2]);
  231. b[3] = vqmovun_s16(c[3]);
  232. b[4] = vqmovun_s16(c[4]);
  233. b[5] = vqmovun_s16(c[5]);
  234. b[6] = vqmovun_s16(c[6]);
  235. b[7] = vqmovun_s16(c[7]);
  236. vst1_u8(d, b[0]);
  237. d += stride;
  238. vst1_u8(d, b[1]);
  239. d += stride;
  240. vst1_u8(d, b[2]);
  241. d += stride;
  242. vst1_u8(d, b[3]);
  243. d += stride;
  244. vst1_u8(d, b[4]);
  245. d += stride;
  246. vst1_u8(d, b[5]);
  247. d += stride;
  248. vst1_u8(d, b[6]);
  249. d += stride;
  250. vst1_u8(d, b[7]);
  251. }
  252. static INLINE uint8x16_t create_dcq(const int16_t dc) {
  253. // Clip both sides and gcc may compile to assembly 'usat'.
  254. const int16_t t = (dc < 0) ? 0 : ((dc > 255) ? 255 : dc);
  255. return vdupq_n_u8((uint8_t)t);
  256. }
  257. static INLINE void idct4x4_16_kernel_bd8(int16x8_t *const a) {
  258. const int16x4_t cospis = vld1_s16(kCospi);
  259. int16x4_t b[4];
  260. int32x4_t c[4];
  261. int16x8_t d[2];
  262. b[0] = vget_low_s16(a[0]);
  263. b[1] = vget_high_s16(a[0]);
  264. b[2] = vget_low_s16(a[1]);
  265. b[3] = vget_high_s16(a[1]);
  266. c[0] = vmull_lane_s16(b[0], cospis, 2);
  267. c[2] = vmull_lane_s16(b[1], cospis, 2);
  268. c[1] = vsubq_s32(c[0], c[2]);
  269. c[0] = vaddq_s32(c[0], c[2]);
  270. c[3] = vmull_lane_s16(b[2], cospis, 3);
  271. c[2] = vmull_lane_s16(b[2], cospis, 1);
  272. c[3] = vmlsl_lane_s16(c[3], b[3], cospis, 1);
  273. c[2] = vmlal_lane_s16(c[2], b[3], cospis, 3);
  274. dct_const_round_shift_low_8_dual(c, &d[0], &d[1]);
  275. a[0] = vaddq_s16(d[0], d[1]);
  276. a[1] = vsubq_s16(d[0], d[1]);
  277. }
  278. static INLINE void transpose_idct4x4_16_bd8(int16x8_t *const a) {
  279. transpose_s16_4x4q(&a[0], &a[1]);
  280. idct4x4_16_kernel_bd8(a);
  281. }
  282. static INLINE void idct8x8_12_pass1_bd8(const int16x4_t cospis0,
  283. const int16x4_t cospisd0,
  284. const int16x4_t cospisd1,
  285. int16x4_t *const io) {
  286. int16x4_t step1[8], step2[8];
  287. int32x4_t t32[2];
  288. transpose_s16_4x4d(&io[0], &io[1], &io[2], &io[3]);
  289. // stage 1
  290. step1[4] = vqrdmulh_lane_s16(io[1], cospisd1, 3);
  291. step1[5] = vqrdmulh_lane_s16(io[3], cospisd1, 2);
  292. step1[6] = vqrdmulh_lane_s16(io[3], cospisd1, 1);
  293. step1[7] = vqrdmulh_lane_s16(io[1], cospisd1, 0);
  294. // stage 2
  295. step2[1] = vqrdmulh_lane_s16(io[0], cospisd0, 2);
  296. step2[2] = vqrdmulh_lane_s16(io[2], cospisd0, 3);
  297. step2[3] = vqrdmulh_lane_s16(io[2], cospisd0, 1);
  298. step2[4] = vadd_s16(step1[4], step1[5]);
  299. step2[5] = vsub_s16(step1[4], step1[5]);
  300. step2[6] = vsub_s16(step1[7], step1[6]);
  301. step2[7] = vadd_s16(step1[7], step1[6]);
  302. // stage 3
  303. step1[0] = vadd_s16(step2[1], step2[3]);
  304. step1[1] = vadd_s16(step2[1], step2[2]);
  305. step1[2] = vsub_s16(step2[1], step2[2]);
  306. step1[3] = vsub_s16(step2[1], step2[3]);
  307. t32[1] = vmull_lane_s16(step2[6], cospis0, 2);
  308. t32[0] = vmlsl_lane_s16(t32[1], step2[5], cospis0, 2);
  309. t32[1] = vmlal_lane_s16(t32[1], step2[5], cospis0, 2);
  310. step1[5] = vrshrn_n_s32(t32[0], DCT_CONST_BITS);
  311. step1[6] = vrshrn_n_s32(t32[1], DCT_CONST_BITS);
  312. // stage 4
  313. io[0] = vadd_s16(step1[0], step2[7]);
  314. io[1] = vadd_s16(step1[1], step1[6]);
  315. io[2] = vadd_s16(step1[2], step1[5]);
  316. io[3] = vadd_s16(step1[3], step2[4]);
  317. io[4] = vsub_s16(step1[3], step2[4]);
  318. io[5] = vsub_s16(step1[2], step1[5]);
  319. io[6] = vsub_s16(step1[1], step1[6]);
  320. io[7] = vsub_s16(step1[0], step2[7]);
  321. }
  322. static INLINE void idct8x8_12_pass2_bd8(const int16x4_t cospis0,
  323. const int16x4_t cospisd0,
  324. const int16x4_t cospisd1,
  325. const int16x4_t *const input,
  326. int16x8_t *const output) {
  327. int16x8_t in[4];
  328. int16x8_t step1[8], step2[8];
  329. int32x4_t t32[8];
  330. transpose_s16_4x8(input[0], input[1], input[2], input[3], input[4], input[5],
  331. input[6], input[7], &in[0], &in[1], &in[2], &in[3]);
  332. // stage 1
  333. step1[4] = vqrdmulhq_lane_s16(in[1], cospisd1, 3);
  334. step1[5] = vqrdmulhq_lane_s16(in[3], cospisd1, 2);
  335. step1[6] = vqrdmulhq_lane_s16(in[3], cospisd1, 1);
  336. step1[7] = vqrdmulhq_lane_s16(in[1], cospisd1, 0);
  337. // stage 2
  338. step2[1] = vqrdmulhq_lane_s16(in[0], cospisd0, 2);
  339. step2[2] = vqrdmulhq_lane_s16(in[2], cospisd0, 3);
  340. step2[3] = vqrdmulhq_lane_s16(in[2], cospisd0, 1);
  341. step2[4] = vaddq_s16(step1[4], step1[5]);
  342. step2[5] = vsubq_s16(step1[4], step1[5]);
  343. step2[6] = vsubq_s16(step1[7], step1[6]);
  344. step2[7] = vaddq_s16(step1[7], step1[6]);
  345. // stage 3
  346. step1[0] = vaddq_s16(step2[1], step2[3]);
  347. step1[1] = vaddq_s16(step2[1], step2[2]);
  348. step1[2] = vsubq_s16(step2[1], step2[2]);
  349. step1[3] = vsubq_s16(step2[1], step2[3]);
  350. t32[2] = vmull_lane_s16(vget_low_s16(step2[6]), cospis0, 2);
  351. t32[3] = vmull_lane_s16(vget_high_s16(step2[6]), cospis0, 2);
  352. t32[0] = vmlsl_lane_s16(t32[2], vget_low_s16(step2[5]), cospis0, 2);
  353. t32[1] = vmlsl_lane_s16(t32[3], vget_high_s16(step2[5]), cospis0, 2);
  354. t32[2] = vmlal_lane_s16(t32[2], vget_low_s16(step2[5]), cospis0, 2);
  355. t32[3] = vmlal_lane_s16(t32[3], vget_high_s16(step2[5]), cospis0, 2);
  356. dct_const_round_shift_low_8_dual(t32, &step1[5], &step1[6]);
  357. // stage 4
  358. output[0] = vaddq_s16(step1[0], step2[7]);
  359. output[1] = vaddq_s16(step1[1], step1[6]);
  360. output[2] = vaddq_s16(step1[2], step1[5]);
  361. output[3] = vaddq_s16(step1[3], step2[4]);
  362. output[4] = vsubq_s16(step1[3], step2[4]);
  363. output[5] = vsubq_s16(step1[2], step1[5]);
  364. output[6] = vsubq_s16(step1[1], step1[6]);
  365. output[7] = vsubq_s16(step1[0], step2[7]);
  366. }
  367. static INLINE void idct8x8_64_1d_bd8_kernel(const int16x4_t cospis0,
  368. const int16x4_t cospis1,
  369. int16x8_t *const io) {
  370. int16x4_t input1l, input1h, input3l, input3h, input5l, input5h, input7l,
  371. input7h;
  372. int16x4_t step1l[4], step1h[4];
  373. int16x8_t step1[8], step2[8];
  374. int32x4_t t32[8];
  375. // stage 1
  376. input1l = vget_low_s16(io[1]);
  377. input1h = vget_high_s16(io[1]);
  378. input3l = vget_low_s16(io[3]);
  379. input3h = vget_high_s16(io[3]);
  380. input5l = vget_low_s16(io[5]);
  381. input5h = vget_high_s16(io[5]);
  382. input7l = vget_low_s16(io[7]);
  383. input7h = vget_high_s16(io[7]);
  384. step1l[0] = vget_low_s16(io[0]);
  385. step1h[0] = vget_high_s16(io[0]);
  386. step1l[1] = vget_low_s16(io[2]);
  387. step1h[1] = vget_high_s16(io[2]);
  388. step1l[2] = vget_low_s16(io[4]);
  389. step1h[2] = vget_high_s16(io[4]);
  390. step1l[3] = vget_low_s16(io[6]);
  391. step1h[3] = vget_high_s16(io[6]);
  392. t32[0] = vmull_lane_s16(input1l, cospis1, 3);
  393. t32[1] = vmull_lane_s16(input1h, cospis1, 3);
  394. t32[2] = vmull_lane_s16(input3l, cospis1, 2);
  395. t32[3] = vmull_lane_s16(input3h, cospis1, 2);
  396. t32[4] = vmull_lane_s16(input3l, cospis1, 1);
  397. t32[5] = vmull_lane_s16(input3h, cospis1, 1);
  398. t32[6] = vmull_lane_s16(input1l, cospis1, 0);
  399. t32[7] = vmull_lane_s16(input1h, cospis1, 0);
  400. t32[0] = vmlsl_lane_s16(t32[0], input7l, cospis1, 0);
  401. t32[1] = vmlsl_lane_s16(t32[1], input7h, cospis1, 0);
  402. t32[2] = vmlal_lane_s16(t32[2], input5l, cospis1, 1);
  403. t32[3] = vmlal_lane_s16(t32[3], input5h, cospis1, 1);
  404. t32[4] = vmlsl_lane_s16(t32[4], input5l, cospis1, 2);
  405. t32[5] = vmlsl_lane_s16(t32[5], input5h, cospis1, 2);
  406. t32[6] = vmlal_lane_s16(t32[6], input7l, cospis1, 3);
  407. t32[7] = vmlal_lane_s16(t32[7], input7h, cospis1, 3);
  408. dct_const_round_shift_low_8_dual(&t32[0], &step1[4], &step1[5]);
  409. dct_const_round_shift_low_8_dual(&t32[4], &step1[6], &step1[7]);
  410. // stage 2
  411. t32[2] = vmull_lane_s16(step1l[0], cospis0, 2);
  412. t32[3] = vmull_lane_s16(step1h[0], cospis0, 2);
  413. t32[4] = vmull_lane_s16(step1l[1], cospis0, 3);
  414. t32[5] = vmull_lane_s16(step1h[1], cospis0, 3);
  415. t32[6] = vmull_lane_s16(step1l[1], cospis0, 1);
  416. t32[7] = vmull_lane_s16(step1h[1], cospis0, 1);
  417. t32[0] = vmlal_lane_s16(t32[2], step1l[2], cospis0, 2);
  418. t32[1] = vmlal_lane_s16(t32[3], step1h[2], cospis0, 2);
  419. t32[2] = vmlsl_lane_s16(t32[2], step1l[2], cospis0, 2);
  420. t32[3] = vmlsl_lane_s16(t32[3], step1h[2], cospis0, 2);
  421. t32[4] = vmlsl_lane_s16(t32[4], step1l[3], cospis0, 1);
  422. t32[5] = vmlsl_lane_s16(t32[5], step1h[3], cospis0, 1);
  423. t32[6] = vmlal_lane_s16(t32[6], step1l[3], cospis0, 3);
  424. t32[7] = vmlal_lane_s16(t32[7], step1h[3], cospis0, 3);
  425. dct_const_round_shift_low_8_dual(&t32[0], &step2[0], &step2[1]);
  426. dct_const_round_shift_low_8_dual(&t32[4], &step2[2], &step2[3]);
  427. step2[4] = vaddq_s16(step1[4], step1[5]);
  428. step2[5] = vsubq_s16(step1[4], step1[5]);
  429. step2[6] = vsubq_s16(step1[7], step1[6]);
  430. step2[7] = vaddq_s16(step1[7], step1[6]);
  431. // stage 3
  432. step1[0] = vaddq_s16(step2[0], step2[3]);
  433. step1[1] = vaddq_s16(step2[1], step2[2]);
  434. step1[2] = vsubq_s16(step2[1], step2[2]);
  435. step1[3] = vsubq_s16(step2[0], step2[3]);
  436. t32[2] = vmull_lane_s16(vget_low_s16(step2[6]), cospis0, 2);
  437. t32[3] = vmull_lane_s16(vget_high_s16(step2[6]), cospis0, 2);
  438. t32[0] = vmlsl_lane_s16(t32[2], vget_low_s16(step2[5]), cospis0, 2);
  439. t32[1] = vmlsl_lane_s16(t32[3], vget_high_s16(step2[5]), cospis0, 2);
  440. t32[2] = vmlal_lane_s16(t32[2], vget_low_s16(step2[5]), cospis0, 2);
  441. t32[3] = vmlal_lane_s16(t32[3], vget_high_s16(step2[5]), cospis0, 2);
  442. dct_const_round_shift_low_8_dual(t32, &step1[5], &step1[6]);
  443. // stage 4
  444. io[0] = vaddq_s16(step1[0], step2[7]);
  445. io[1] = vaddq_s16(step1[1], step1[6]);
  446. io[2] = vaddq_s16(step1[2], step1[5]);
  447. io[3] = vaddq_s16(step1[3], step2[4]);
  448. io[4] = vsubq_s16(step1[3], step2[4]);
  449. io[5] = vsubq_s16(step1[2], step1[5]);
  450. io[6] = vsubq_s16(step1[1], step1[6]);
  451. io[7] = vsubq_s16(step1[0], step2[7]);
  452. }
  453. static INLINE void idct8x8_64_1d_bd8(const int16x4_t cospis0,
  454. const int16x4_t cospis1,
  455. int16x8_t *const io) {
  456. transpose_s16_8x8(&io[0], &io[1], &io[2], &io[3], &io[4], &io[5], &io[6],
  457. &io[7]);
  458. idct8x8_64_1d_bd8_kernel(cospis0, cospis1, io);
  459. }
  460. static INLINE void idct_cospi_8_24_q_kernel(const int16x8_t s0,
  461. const int16x8_t s1,
  462. const int16x4_t cospi_0_8_16_24,
  463. int32x4_t *const t32) {
  464. t32[0] = vmull_lane_s16(vget_low_s16(s0), cospi_0_8_16_24, 3);
  465. t32[1] = vmull_lane_s16(vget_high_s16(s0), cospi_0_8_16_24, 3);
  466. t32[2] = vmull_lane_s16(vget_low_s16(s1), cospi_0_8_16_24, 3);
  467. t32[3] = vmull_lane_s16(vget_high_s16(s1), cospi_0_8_16_24, 3);
  468. t32[0] = vmlsl_lane_s16(t32[0], vget_low_s16(s1), cospi_0_8_16_24, 1);
  469. t32[1] = vmlsl_lane_s16(t32[1], vget_high_s16(s1), cospi_0_8_16_24, 1);
  470. t32[2] = vmlal_lane_s16(t32[2], vget_low_s16(s0), cospi_0_8_16_24, 1);
  471. t32[3] = vmlal_lane_s16(t32[3], vget_high_s16(s0), cospi_0_8_16_24, 1);
  472. }
  473. static INLINE void idct_cospi_8_24_q(const int16x8_t s0, const int16x8_t s1,
  474. const int16x4_t cospi_0_8_16_24,
  475. int16x8_t *const d0, int16x8_t *const d1) {
  476. int32x4_t t32[4];
  477. idct_cospi_8_24_q_kernel(s0, s1, cospi_0_8_16_24, t32);
  478. dct_const_round_shift_low_8_dual(t32, d0, d1);
  479. }
  480. static INLINE void idct_cospi_8_24_neg_q(const int16x8_t s0, const int16x8_t s1,
  481. const int16x4_t cospi_0_8_16_24,
  482. int16x8_t *const d0,
  483. int16x8_t *const d1) {
  484. int32x4_t t32[4];
  485. idct_cospi_8_24_q_kernel(s0, s1, cospi_0_8_16_24, t32);
  486. t32[2] = vnegq_s32(t32[2]);
  487. t32[3] = vnegq_s32(t32[3]);
  488. dct_const_round_shift_low_8_dual(t32, d0, d1);
  489. }
  490. static INLINE void idct_cospi_16_16_q(const int16x8_t s0, const int16x8_t s1,
  491. const int16x4_t cospi_0_8_16_24,
  492. int16x8_t *const d0,
  493. int16x8_t *const d1) {
  494. int32x4_t t32[6];
  495. t32[4] = vmull_lane_s16(vget_low_s16(s1), cospi_0_8_16_24, 2);
  496. t32[5] = vmull_lane_s16(vget_high_s16(s1), cospi_0_8_16_24, 2);
  497. t32[0] = vmlsl_lane_s16(t32[4], vget_low_s16(s0), cospi_0_8_16_24, 2);
  498. t32[1] = vmlsl_lane_s16(t32[5], vget_high_s16(s0), cospi_0_8_16_24, 2);
  499. t32[2] = vmlal_lane_s16(t32[4], vget_low_s16(s0), cospi_0_8_16_24, 2);
  500. t32[3] = vmlal_lane_s16(t32[5], vget_high_s16(s0), cospi_0_8_16_24, 2);
  501. dct_const_round_shift_low_8_dual(t32, d0, d1);
  502. }
  503. static INLINE void idct_cospi_2_30(const int16x8_t s0, const int16x8_t s1,
  504. const int16x4_t cospi_2_30_10_22,
  505. int16x8_t *const d0, int16x8_t *const d1) {
  506. int32x4_t t32[4];
  507. t32[0] = vmull_lane_s16(vget_low_s16(s0), cospi_2_30_10_22, 1);
  508. t32[1] = vmull_lane_s16(vget_high_s16(s0), cospi_2_30_10_22, 1);
  509. t32[2] = vmull_lane_s16(vget_low_s16(s1), cospi_2_30_10_22, 1);
  510. t32[3] = vmull_lane_s16(vget_high_s16(s1), cospi_2_30_10_22, 1);
  511. t32[0] = vmlsl_lane_s16(t32[0], vget_low_s16(s1), cospi_2_30_10_22, 0);
  512. t32[1] = vmlsl_lane_s16(t32[1], vget_high_s16(s1), cospi_2_30_10_22, 0);
  513. t32[2] = vmlal_lane_s16(t32[2], vget_low_s16(s0), cospi_2_30_10_22, 0);
  514. t32[3] = vmlal_lane_s16(t32[3], vget_high_s16(s0), cospi_2_30_10_22, 0);
  515. dct_const_round_shift_low_8_dual(t32, d0, d1);
  516. }
  517. static INLINE void idct_cospi_4_28(const int16x8_t s0, const int16x8_t s1,
  518. const int16x4_t cospi_4_12_20N_28,
  519. int16x8_t *const d0, int16x8_t *const d1) {
  520. int32x4_t t32[4];
  521. t32[0] = vmull_lane_s16(vget_low_s16(s0), cospi_4_12_20N_28, 3);
  522. t32[1] = vmull_lane_s16(vget_high_s16(s0), cospi_4_12_20N_28, 3);
  523. t32[2] = vmull_lane_s16(vget_low_s16(s1), cospi_4_12_20N_28, 3);
  524. t32[3] = vmull_lane_s16(vget_high_s16(s1), cospi_4_12_20N_28, 3);
  525. t32[0] = vmlsl_lane_s16(t32[0], vget_low_s16(s1), cospi_4_12_20N_28, 0);
  526. t32[1] = vmlsl_lane_s16(t32[1], vget_high_s16(s1), cospi_4_12_20N_28, 0);
  527. t32[2] = vmlal_lane_s16(t32[2], vget_low_s16(s0), cospi_4_12_20N_28, 0);
  528. t32[3] = vmlal_lane_s16(t32[3], vget_high_s16(s0), cospi_4_12_20N_28, 0);
  529. dct_const_round_shift_low_8_dual(t32, d0, d1);
  530. }
  531. static INLINE void idct_cospi_6_26(const int16x8_t s0, const int16x8_t s1,
  532. const int16x4_t cospi_6_26N_14_18N,
  533. int16x8_t *const d0, int16x8_t *const d1) {
  534. int32x4_t t32[4];
  535. t32[0] = vmull_lane_s16(vget_low_s16(s0), cospi_6_26N_14_18N, 0);
  536. t32[1] = vmull_lane_s16(vget_high_s16(s0), cospi_6_26N_14_18N, 0);
  537. t32[2] = vmull_lane_s16(vget_low_s16(s1), cospi_6_26N_14_18N, 0);
  538. t32[3] = vmull_lane_s16(vget_high_s16(s1), cospi_6_26N_14_18N, 0);
  539. t32[0] = vmlal_lane_s16(t32[0], vget_low_s16(s1), cospi_6_26N_14_18N, 1);
  540. t32[1] = vmlal_lane_s16(t32[1], vget_high_s16(s1), cospi_6_26N_14_18N, 1);
  541. t32[2] = vmlsl_lane_s16(t32[2], vget_low_s16(s0), cospi_6_26N_14_18N, 1);
  542. t32[3] = vmlsl_lane_s16(t32[3], vget_high_s16(s0), cospi_6_26N_14_18N, 1);
  543. dct_const_round_shift_low_8_dual(t32, d0, d1);
  544. }
  545. static INLINE void idct_cospi_10_22(const int16x8_t s0, const int16x8_t s1,
  546. const int16x4_t cospi_2_30_10_22,
  547. int16x8_t *const d0, int16x8_t *const d1) {
  548. int32x4_t t32[4];
  549. t32[0] = vmull_lane_s16(vget_low_s16(s0), cospi_2_30_10_22, 3);
  550. t32[1] = vmull_lane_s16(vget_high_s16(s0), cospi_2_30_10_22, 3);
  551. t32[2] = vmull_lane_s16(vget_low_s16(s1), cospi_2_30_10_22, 3);
  552. t32[3] = vmull_lane_s16(vget_high_s16(s1), cospi_2_30_10_22, 3);
  553. t32[0] = vmlsl_lane_s16(t32[0], vget_low_s16(s1), cospi_2_30_10_22, 2);
  554. t32[1] = vmlsl_lane_s16(t32[1], vget_high_s16(s1), cospi_2_30_10_22, 2);
  555. t32[2] = vmlal_lane_s16(t32[2], vget_low_s16(s0), cospi_2_30_10_22, 2);
  556. t32[3] = vmlal_lane_s16(t32[3], vget_high_s16(s0), cospi_2_30_10_22, 2);
  557. dct_const_round_shift_low_8_dual(t32, d0, d1);
  558. }
  559. static INLINE void idct_cospi_12_20(const int16x8_t s0, const int16x8_t s1,
  560. const int16x4_t cospi_4_12_20N_28,
  561. int16x8_t *const d0, int16x8_t *const d1) {
  562. int32x4_t t32[4];
  563. t32[0] = vmull_lane_s16(vget_low_s16(s0), cospi_4_12_20N_28, 1);
  564. t32[1] = vmull_lane_s16(vget_high_s16(s0), cospi_4_12_20N_28, 1);
  565. t32[2] = vmull_lane_s16(vget_low_s16(s1), cospi_4_12_20N_28, 1);
  566. t32[3] = vmull_lane_s16(vget_high_s16(s1), cospi_4_12_20N_28, 1);
  567. t32[0] = vmlal_lane_s16(t32[0], vget_low_s16(s1), cospi_4_12_20N_28, 2);
  568. t32[1] = vmlal_lane_s16(t32[1], vget_high_s16(s1), cospi_4_12_20N_28, 2);
  569. t32[2] = vmlsl_lane_s16(t32[2], vget_low_s16(s0), cospi_4_12_20N_28, 2);
  570. t32[3] = vmlsl_lane_s16(t32[3], vget_high_s16(s0), cospi_4_12_20N_28, 2);
  571. dct_const_round_shift_low_8_dual(t32, d0, d1);
  572. }
  573. static INLINE void idct_cospi_14_18(const int16x8_t s0, const int16x8_t s1,
  574. const int16x4_t cospi_6_26N_14_18N,
  575. int16x8_t *const d0, int16x8_t *const d1) {
  576. int32x4_t t32[4];
  577. t32[0] = vmull_lane_s16(vget_low_s16(s0), cospi_6_26N_14_18N, 2);
  578. t32[1] = vmull_lane_s16(vget_high_s16(s0), cospi_6_26N_14_18N, 2);
  579. t32[2] = vmull_lane_s16(vget_low_s16(s1), cospi_6_26N_14_18N, 2);
  580. t32[3] = vmull_lane_s16(vget_high_s16(s1), cospi_6_26N_14_18N, 2);
  581. t32[0] = vmlal_lane_s16(t32[0], vget_low_s16(s1), cospi_6_26N_14_18N, 3);
  582. t32[1] = vmlal_lane_s16(t32[1], vget_high_s16(s1), cospi_6_26N_14_18N, 3);
  583. t32[2] = vmlsl_lane_s16(t32[2], vget_low_s16(s0), cospi_6_26N_14_18N, 3);
  584. t32[3] = vmlsl_lane_s16(t32[3], vget_high_s16(s0), cospi_6_26N_14_18N, 3);
  585. dct_const_round_shift_low_8_dual(t32, d0, d1);
  586. }
  587. static INLINE void idct16x16_add_stage7(const int16x8_t *const step2,
  588. int16x8_t *const out) {
  589. #if CONFIG_VP9_HIGHBITDEPTH
  590. // Use saturating add/sub to avoid overflow in 2nd pass
  591. out[0] = vqaddq_s16(step2[0], step2[15]);
  592. out[1] = vqaddq_s16(step2[1], step2[14]);
  593. out[2] = vqaddq_s16(step2[2], step2[13]);
  594. out[3] = vqaddq_s16(step2[3], step2[12]);
  595. out[4] = vqaddq_s16(step2[4], step2[11]);
  596. out[5] = vqaddq_s16(step2[5], step2[10]);
  597. out[6] = vqaddq_s16(step2[6], step2[9]);
  598. out[7] = vqaddq_s16(step2[7], step2[8]);
  599. out[8] = vqsubq_s16(step2[7], step2[8]);
  600. out[9] = vqsubq_s16(step2[6], step2[9]);
  601. out[10] = vqsubq_s16(step2[5], step2[10]);
  602. out[11] = vqsubq_s16(step2[4], step2[11]);
  603. out[12] = vqsubq_s16(step2[3], step2[12]);
  604. out[13] = vqsubq_s16(step2[2], step2[13]);
  605. out[14] = vqsubq_s16(step2[1], step2[14]);
  606. out[15] = vqsubq_s16(step2[0], step2[15]);
  607. #else
  608. out[0] = vaddq_s16(step2[0], step2[15]);
  609. out[1] = vaddq_s16(step2[1], step2[14]);
  610. out[2] = vaddq_s16(step2[2], step2[13]);
  611. out[3] = vaddq_s16(step2[3], step2[12]);
  612. out[4] = vaddq_s16(step2[4], step2[11]);
  613. out[5] = vaddq_s16(step2[5], step2[10]);
  614. out[6] = vaddq_s16(step2[6], step2[9]);
  615. out[7] = vaddq_s16(step2[7], step2[8]);
  616. out[8] = vsubq_s16(step2[7], step2[8]);
  617. out[9] = vsubq_s16(step2[6], step2[9]);
  618. out[10] = vsubq_s16(step2[5], step2[10]);
  619. out[11] = vsubq_s16(step2[4], step2[11]);
  620. out[12] = vsubq_s16(step2[3], step2[12]);
  621. out[13] = vsubq_s16(step2[2], step2[13]);
  622. out[14] = vsubq_s16(step2[1], step2[14]);
  623. out[15] = vsubq_s16(step2[0], step2[15]);
  624. #endif
  625. }
  626. static INLINE void idct16x16_store_pass1(const int16x8_t *const out,
  627. int16_t *output) {
  628. // Save the result into output
  629. vst1q_s16(output, out[0]);
  630. output += 16;
  631. vst1q_s16(output, out[1]);
  632. output += 16;
  633. vst1q_s16(output, out[2]);
  634. output += 16;
  635. vst1q_s16(output, out[3]);
  636. output += 16;
  637. vst1q_s16(output, out[4]);
  638. output += 16;
  639. vst1q_s16(output, out[5]);
  640. output += 16;
  641. vst1q_s16(output, out[6]);
  642. output += 16;
  643. vst1q_s16(output, out[7]);
  644. output += 16;
  645. vst1q_s16(output, out[8]);
  646. output += 16;
  647. vst1q_s16(output, out[9]);
  648. output += 16;
  649. vst1q_s16(output, out[10]);
  650. output += 16;
  651. vst1q_s16(output, out[11]);
  652. output += 16;
  653. vst1q_s16(output, out[12]);
  654. output += 16;
  655. vst1q_s16(output, out[13]);
  656. output += 16;
  657. vst1q_s16(output, out[14]);
  658. output += 16;
  659. vst1q_s16(output, out[15]);
  660. }
  661. static INLINE void idct8x8_add8x1(const int16x8_t a, uint8_t **const dest,
  662. const int stride) {
  663. const uint8x8_t s = vld1_u8(*dest);
  664. const int16x8_t res = vrshrq_n_s16(a, 5);
  665. const uint16x8_t q = vaddw_u8(vreinterpretq_u16_s16(res), s);
  666. const uint8x8_t d = vqmovun_s16(vreinterpretq_s16_u16(q));
  667. vst1_u8(*dest, d);
  668. *dest += stride;
  669. }
  670. static INLINE void idct8x8_add8x8_neon(int16x8_t *const out, uint8_t *dest,
  671. const int stride) {
  672. idct8x8_add8x1(out[0], &dest, stride);
  673. idct8x8_add8x1(out[1], &dest, stride);
  674. idct8x8_add8x1(out[2], &dest, stride);
  675. idct8x8_add8x1(out[3], &dest, stride);
  676. idct8x8_add8x1(out[4], &dest, stride);
  677. idct8x8_add8x1(out[5], &dest, stride);
  678. idct8x8_add8x1(out[6], &dest, stride);
  679. idct8x8_add8x1(out[7], &dest, stride);
  680. }
  681. static INLINE void idct16x16_add8x1(const int16x8_t a, uint8_t **const dest,
  682. const int stride) {
  683. const uint8x8_t s = vld1_u8(*dest);
  684. const int16x8_t res = vrshrq_n_s16(a, 6);
  685. const uint16x8_t q = vaddw_u8(vreinterpretq_u16_s16(res), s);
  686. const uint8x8_t d = vqmovun_s16(vreinterpretq_s16_u16(q));
  687. vst1_u8(*dest, d);
  688. *dest += stride;
  689. }
  690. static INLINE void idct16x16_add_store(const int16x8_t *const out,
  691. uint8_t *dest, const int stride) {
  692. // Add the result to dest
  693. idct16x16_add8x1(out[0], &dest, stride);
  694. idct16x16_add8x1(out[1], &dest, stride);
  695. idct16x16_add8x1(out[2], &dest, stride);
  696. idct16x16_add8x1(out[3], &dest, stride);
  697. idct16x16_add8x1(out[4], &dest, stride);
  698. idct16x16_add8x1(out[5], &dest, stride);
  699. idct16x16_add8x1(out[6], &dest, stride);
  700. idct16x16_add8x1(out[7], &dest, stride);
  701. idct16x16_add8x1(out[8], &dest, stride);
  702. idct16x16_add8x1(out[9], &dest, stride);
  703. idct16x16_add8x1(out[10], &dest, stride);
  704. idct16x16_add8x1(out[11], &dest, stride);
  705. idct16x16_add8x1(out[12], &dest, stride);
  706. idct16x16_add8x1(out[13], &dest, stride);
  707. idct16x16_add8x1(out[14], &dest, stride);
  708. idct16x16_add8x1(out[15], &dest, stride);
  709. }
  710. static INLINE void highbd_idct16x16_add8x1(const int16x8_t a,
  711. const int16x8_t max,
  712. uint16_t **const dest,
  713. const int stride) {
  714. const uint16x8_t s = vld1q_u16(*dest);
  715. const int16x8_t res0 = vqaddq_s16(a, vreinterpretq_s16_u16(s));
  716. const int16x8_t res1 = vminq_s16(res0, max);
  717. const uint16x8_t d = vqshluq_n_s16(res1, 0);
  718. vst1q_u16(*dest, d);
  719. *dest += stride;
  720. }
  721. static INLINE void idct16x16_add_store_bd8(int16x8_t *const out, uint16_t *dest,
  722. const int stride) {
  723. // Add the result to dest
  724. const int16x8_t max = vdupq_n_s16((1 << 8) - 1);
  725. out[0] = vrshrq_n_s16(out[0], 6);
  726. out[1] = vrshrq_n_s16(out[1], 6);
  727. out[2] = vrshrq_n_s16(out[2], 6);
  728. out[3] = vrshrq_n_s16(out[3], 6);
  729. out[4] = vrshrq_n_s16(out[4], 6);
  730. out[5] = vrshrq_n_s16(out[5], 6);
  731. out[6] = vrshrq_n_s16(out[6], 6);
  732. out[7] = vrshrq_n_s16(out[7], 6);
  733. out[8] = vrshrq_n_s16(out[8], 6);
  734. out[9] = vrshrq_n_s16(out[9], 6);
  735. out[10] = vrshrq_n_s16(out[10], 6);
  736. out[11] = vrshrq_n_s16(out[11], 6);
  737. out[12] = vrshrq_n_s16(out[12], 6);
  738. out[13] = vrshrq_n_s16(out[13], 6);
  739. out[14] = vrshrq_n_s16(out[14], 6);
  740. out[15] = vrshrq_n_s16(out[15], 6);
  741. highbd_idct16x16_add8x1(out[0], max, &dest, stride);
  742. highbd_idct16x16_add8x1(out[1], max, &dest, stride);
  743. highbd_idct16x16_add8x1(out[2], max, &dest, stride);
  744. highbd_idct16x16_add8x1(out[3], max, &dest, stride);
  745. highbd_idct16x16_add8x1(out[4], max, &dest, stride);
  746. highbd_idct16x16_add8x1(out[5], max, &dest, stride);
  747. highbd_idct16x16_add8x1(out[6], max, &dest, stride);
  748. highbd_idct16x16_add8x1(out[7], max, &dest, stride);
  749. highbd_idct16x16_add8x1(out[8], max, &dest, stride);
  750. highbd_idct16x16_add8x1(out[9], max, &dest, stride);
  751. highbd_idct16x16_add8x1(out[10], max, &dest, stride);
  752. highbd_idct16x16_add8x1(out[11], max, &dest, stride);
  753. highbd_idct16x16_add8x1(out[12], max, &dest, stride);
  754. highbd_idct16x16_add8x1(out[13], max, &dest, stride);
  755. highbd_idct16x16_add8x1(out[14], max, &dest, stride);
  756. highbd_idct16x16_add8x1(out[15], max, &dest, stride);
  757. }
  758. static INLINE void highbd_idct16x16_add8x1_bd8(const int16x8_t a,
  759. uint16_t **const dest,
  760. const int stride) {
  761. const uint16x8_t s = vld1q_u16(*dest);
  762. const int16x8_t res = vrsraq_n_s16(vreinterpretq_s16_u16(s), a, 6);
  763. const uint16x8_t d = vmovl_u8(vqmovun_s16(res));
  764. vst1q_u16(*dest, d);
  765. *dest += stride;
  766. }
  767. static INLINE void highbd_add_and_store_bd8(const int16x8_t *const a,
  768. uint16_t *out, const int stride) {
  769. highbd_idct16x16_add8x1_bd8(a[0], &out, stride);
  770. highbd_idct16x16_add8x1_bd8(a[1], &out, stride);
  771. highbd_idct16x16_add8x1_bd8(a[2], &out, stride);
  772. highbd_idct16x16_add8x1_bd8(a[3], &out, stride);
  773. highbd_idct16x16_add8x1_bd8(a[4], &out, stride);
  774. highbd_idct16x16_add8x1_bd8(a[5], &out, stride);
  775. highbd_idct16x16_add8x1_bd8(a[6], &out, stride);
  776. highbd_idct16x16_add8x1_bd8(a[7], &out, stride);
  777. highbd_idct16x16_add8x1_bd8(a[8], &out, stride);
  778. highbd_idct16x16_add8x1_bd8(a[9], &out, stride);
  779. highbd_idct16x16_add8x1_bd8(a[10], &out, stride);
  780. highbd_idct16x16_add8x1_bd8(a[11], &out, stride);
  781. highbd_idct16x16_add8x1_bd8(a[12], &out, stride);
  782. highbd_idct16x16_add8x1_bd8(a[13], &out, stride);
  783. highbd_idct16x16_add8x1_bd8(a[14], &out, stride);
  784. highbd_idct16x16_add8x1_bd8(a[15], &out, stride);
  785. highbd_idct16x16_add8x1_bd8(a[16], &out, stride);
  786. highbd_idct16x16_add8x1_bd8(a[17], &out, stride);
  787. highbd_idct16x16_add8x1_bd8(a[18], &out, stride);
  788. highbd_idct16x16_add8x1_bd8(a[19], &out, stride);
  789. highbd_idct16x16_add8x1_bd8(a[20], &out, stride);
  790. highbd_idct16x16_add8x1_bd8(a[21], &out, stride);
  791. highbd_idct16x16_add8x1_bd8(a[22], &out, stride);
  792. highbd_idct16x16_add8x1_bd8(a[23], &out, stride);
  793. highbd_idct16x16_add8x1_bd8(a[24], &out, stride);
  794. highbd_idct16x16_add8x1_bd8(a[25], &out, stride);
  795. highbd_idct16x16_add8x1_bd8(a[26], &out, stride);
  796. highbd_idct16x16_add8x1_bd8(a[27], &out, stride);
  797. highbd_idct16x16_add8x1_bd8(a[28], &out, stride);
  798. highbd_idct16x16_add8x1_bd8(a[29], &out, stride);
  799. highbd_idct16x16_add8x1_bd8(a[30], &out, stride);
  800. highbd_idct16x16_add8x1_bd8(a[31], &out, stride);
  801. }
  802. void vpx_idct16x16_256_add_half1d(const void *const input, int16_t *output,
  803. void *const dest, const int stride,
  804. const int highbd_flag);
  805. void vpx_idct16x16_38_add_half1d(const void *const input, int16_t *const output,
  806. void *const dest, const int stride,
  807. const int highbd_flag);
  808. void vpx_idct16x16_10_add_half1d_pass1(const tran_low_t *input,
  809. int16_t *output);
  810. void vpx_idct16x16_10_add_half1d_pass2(const int16_t *input,
  811. int16_t *const output, void *const dest,
  812. const int stride, const int highbd_flag);
  813. void vpx_idct32_32_neon(const tran_low_t *input, uint8_t *dest,
  814. const int stride, const int highbd_flag);
  815. void vpx_idct32_12_neon(const tran_low_t *const input, int16_t *output);
  816. void vpx_idct32_16_neon(const int16_t *const input, void *const output,
  817. const int stride, const int highbd_flag);
  818. void vpx_idct32_6_neon(const tran_low_t *input, int16_t *output);
  819. void vpx_idct32_8_neon(const int16_t *input, void *const output, int stride,
  820. const int highbd_flag);
  821. #endif // VPX_VPX_DSP_ARM_IDCT_NEON_H_