idct.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. /*
  2. * Copyright (c) 2024 Zhao Zhili
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavcodec/wasm/hevc/idct.h"
  21. #include <wasm_simd128.h>
  22. #include "libavutil/mem_internal.h"
  23. static const int8_t transform[] = {
  24. 64, 83, 64, 36, 89, 75, 50, 18,
  25. 90, 87, 80, 70, 57, 43, 25, 9,
  26. 90, 90, 88, 85, 82, 78, 73, 67,
  27. 61, 54, 46, 38, 31, 22, 13, 4,
  28. };
  29. static inline void transpose_4x8h(v128_t *src)
  30. {
  31. v128_t t0 = wasm_i16x8_shuffle(src[0], src[1], 0, 8, 2, 10, 4, 12, 6, 14);
  32. v128_t t1 = wasm_i16x8_shuffle(src[0], src[1], 1, 9, 3, 11, 5, 13, 7, 15);
  33. v128_t t2 = wasm_i16x8_shuffle(src[2], src[3], 0, 8, 2, 10, 4, 12, 6, 14);
  34. v128_t t3 = wasm_i16x8_shuffle(src[2], src[3], 1, 9, 3, 11, 5, 13, 7, 15);
  35. src[0] = wasm_i32x4_shuffle(t0, t2, 0, 4, 2, 6);
  36. src[2] = wasm_i32x4_shuffle(t0, t2, 1, 5, 3, 7);
  37. src[1] = wasm_i32x4_shuffle(t1, t3, 0, 4, 2, 6);
  38. src[3] = wasm_i32x4_shuffle(t1, t3, 1, 5, 3, 7);
  39. }
  40. static inline void transpose_8x8h(v128_t *src)
  41. {
  42. transpose_4x8h(src);
  43. transpose_4x8h(&src[4]);
  44. }
  45. static inline void tr_4x4(v128_t *src, v128_t *trans, int shift)
  46. {
  47. v128_t tmp[4];
  48. v128_t add = wasm_i32x4_splat(1 << (shift - 1));
  49. v128_t e0 = wasm_i32x4_extmul_low_i16x8(src[0], trans[0]);
  50. v128_t e1 = wasm_i32x4_extmul_low_i16x8(src[0], trans[0]);
  51. v128_t o0 = wasm_i32x4_extmul_low_i16x8(src[1], trans[1]);
  52. v128_t o1 = wasm_i32x4_extmul_low_i16x8(src[1], trans[3]);
  53. tmp[0] = wasm_i32x4_extmul_low_i16x8(src[2], trans[0]);
  54. tmp[1] = wasm_i32x4_extmul_low_i16x8(src[2], trans[0]);
  55. tmp[2] = wasm_i32x4_extmul_low_i16x8(src[3], trans[3]);
  56. tmp[3] = wasm_i32x4_extmul_low_i16x8(src[3], trans[1]);
  57. e0 = wasm_i32x4_add(e0, tmp[0]);
  58. e1 = wasm_i32x4_sub(e1, tmp[1]);
  59. o0 = wasm_i32x4_add(o0, tmp[2]);
  60. o1 = wasm_i32x4_sub(o1, tmp[3]);
  61. tmp[0] = wasm_i32x4_add(e0, o0);
  62. tmp[1] = wasm_i32x4_sub(e0, o0);
  63. tmp[2] = wasm_i32x4_add(e1, o1);
  64. tmp[3] = wasm_i32x4_sub(e1, o1);
  65. tmp[0] = wasm_i32x4_add(tmp[0], add);
  66. tmp[1] = wasm_i32x4_add(tmp[1], add);
  67. tmp[2] = wasm_i32x4_add(tmp[2], add);
  68. tmp[3] = wasm_i32x4_add(tmp[3], add);
  69. tmp[0] = wasm_i32x4_shr(tmp[0], shift);
  70. tmp[1] = wasm_i32x4_shr(tmp[1], shift);
  71. tmp[2] = wasm_i32x4_shr(tmp[2], shift);
  72. tmp[3] = wasm_i32x4_shr(tmp[3], shift);
  73. src[0] = wasm_i16x8_narrow_i32x4(tmp[0], tmp[0]);
  74. src[3] = wasm_i16x8_narrow_i32x4(tmp[1], tmp[1]);
  75. src[1] = wasm_i16x8_narrow_i32x4(tmp[2], tmp[2]);
  76. src[2] = wasm_i16x8_narrow_i32x4(tmp[3], tmp[3]);
  77. }
  78. static void idct_4x4(int16_t *coeffs, int bit_depth)
  79. {
  80. v128_t src[4];
  81. v128_t trans[4];
  82. src[0] = wasm_v128_load64_zero(&coeffs[0]);
  83. src[1] = wasm_v128_load64_zero(&coeffs[4]);
  84. src[2] = wasm_v128_load64_zero(&coeffs[8]);
  85. src[3] = wasm_v128_load64_zero(&coeffs[12]);
  86. trans[0] = wasm_i16x8_const_splat(transform[0]);
  87. trans[1] = wasm_i16x8_const_splat(transform[1]);
  88. trans[2] = wasm_i16x8_const_splat(transform[2]);
  89. trans[3] = wasm_i16x8_const_splat(transform[3]);
  90. tr_4x4(src, trans, 7);
  91. transpose_4x8h(src);
  92. tr_4x4(src, trans, 20 - bit_depth);
  93. transpose_4x8h(src);
  94. src[0] = wasm_i64x2_shuffle(src[0], src[1], 0, 2);
  95. src[2] = wasm_i64x2_shuffle(src[2], src[3], 0, 2);
  96. wasm_v128_store(&coeffs[0], src[0]);
  97. wasm_v128_store(&coeffs[8], src[2]);
  98. }
  99. void ff_hevc_idct_4x4_8_simd128(int16_t *coeffs, int col_limit)
  100. {
  101. idct_4x4(coeffs, 8);
  102. }
  103. void ff_hevc_idct_4x4_10_simd128(int16_t *coeffs, int col_limit)
  104. {
  105. idct_4x4(coeffs, 10);
  106. }
  107. static inline void shift_narrow_low(v128_t src, v128_t *dst, v128_t add, int shift)
  108. {
  109. src = wasm_i32x4_add(src, add);
  110. src = wasm_i32x4_shr(src, shift);
  111. *dst = wasm_i64x2_shuffle(wasm_i16x8_narrow_i32x4(src, src), *dst, 0, 3);
  112. }
  113. static inline void shift_narrow_high(v128_t src, v128_t *dst, v128_t add, int shift)
  114. {
  115. src = wasm_i32x4_add(src, add);
  116. src = wasm_i32x4_shr(src, shift);
  117. *dst = wasm_i64x2_shuffle(wasm_i16x8_narrow_i32x4(src, src), *dst, 2, 0);
  118. }
  119. #define tr_4x4_8(in0, in1, in2, in3, dst0, dst1, dst2, dst3, trans, half0, half1) \
  120. do { \
  121. v128_t e0, e1, o0, o1; \
  122. v128_t tmp[4]; \
  123. \
  124. e0 = wasm_i32x4_extmul_ ## half0 ## _i16x8(in0, trans[0]); \
  125. e1 = e0; \
  126. o0 = wasm_i32x4_extmul_ ## half0 ## _i16x8(in1, trans[1]); \
  127. o1 = wasm_i32x4_extmul_ ## half0 ## _i16x8(in1, trans[3]); \
  128. \
  129. tmp[0] = wasm_i32x4_extmul_ ## half1 ## _i16x8(in2, trans[0]); \
  130. tmp[1] = wasm_i32x4_extmul_ ## half1 ## _i16x8(in2, trans[0]); \
  131. tmp[2] = wasm_i32x4_extmul_ ## half1 ## _i16x8(in3, trans[3]); \
  132. tmp[3] = wasm_i32x4_extmul_ ## half1 ## _i16x8(in3, trans[1]); \
  133. e0 = wasm_i32x4_add(e0, tmp[0]); \
  134. e1 = wasm_i32x4_sub(e1, tmp[1]); \
  135. o0 = wasm_i32x4_add(o0, tmp[2]); \
  136. o1 = wasm_i32x4_sub(o1, tmp[3]); \
  137. dst0 = wasm_i32x4_add(e0, o0); \
  138. dst1 = wasm_i32x4_add(e1, o1); \
  139. dst2 = wasm_i32x4_sub(e1, o1); \
  140. dst3 = wasm_i32x4_sub(e0, o0); \
  141. } while (0)
  142. #define tr_8x4(src0, src1, half0, half1, trans, shift) \
  143. do { \
  144. v128_t v24, v25, v26, v27, v28, v29, v30, v31; \
  145. v128_t add = wasm_i32x4_splat(1 << (shift - 1)); \
  146. \
  147. tr_4x4_8(src0[0], src0[2], src1[0], src1[2], v24, v25, v26, v27, trans, half0, half1); \
  148. \
  149. v30 = wasm_i32x4_extmul_ ## half0 ## _i16x8(src0[1], trans[6]); \
  150. v28 = wasm_i32x4_extmul_ ## half0 ## _i16x8(src0[1], trans[4]); \
  151. v29 = wasm_i32x4_extmul_ ## half0 ## _i16x8(src0[1], trans[5]); \
  152. v30 = wasm_i32x4_sub(v30, wasm_i32x4_extmul_ ## half0 ## _i16x8(src0[3], trans[4])); \
  153. v28 = wasm_i32x4_add(v28, wasm_i32x4_extmul_ ## half0 ## _i16x8(src0[3], trans[5])); \
  154. v29 = wasm_i32x4_sub(v29, wasm_i32x4_extmul_ ## half0 ## _i16x8(src0[3], trans[7])); \
  155. \
  156. v30 = wasm_i32x4_add(v30, wasm_i32x4_extmul_ ## half1 ## _i16x8(src1[1], trans[7])); \
  157. v28 = wasm_i32x4_add(v28, wasm_i32x4_extmul_ ## half1 ## _i16x8(src1[1], trans[6])); \
  158. v29 = wasm_i32x4_sub(v29, wasm_i32x4_extmul_ ## half1 ## _i16x8(src1[1], trans[4])); \
  159. \
  160. v30 = wasm_i32x4_add(v30, wasm_i32x4_extmul_ ## half1 ## _i16x8(src1[3], trans[5])); \
  161. v28 = wasm_i32x4_add(v28, wasm_i32x4_extmul_ ## half1 ## _i16x8(src1[3], trans[7])); \
  162. v29 = wasm_i32x4_sub(v29, wasm_i32x4_extmul_ ## half1 ## _i16x8(src1[3], trans[6])); \
  163. \
  164. v31 = wasm_i32x4_add(v26, v30); \
  165. v26 = wasm_i32x4_sub(v26, v30); \
  166. shift_narrow_ ## half0 (v31, &src0[2], add, shift); \
  167. v31 = wasm_i32x4_extmul_ ## half0 ## _i16x8(src0[1], trans[7]); \
  168. v31 = wasm_i32x4_sub(v31, wasm_i32x4_extmul_ ## half0 ## _i16x8(src0[3], trans[6])); \
  169. v31 = wasm_i32x4_add(v31, wasm_i32x4_extmul_ ## half1 ## _i16x8(src1[1], trans[5])); \
  170. v31 = wasm_i32x4_sub(v31, wasm_i32x4_extmul_ ## half1 ## _i16x8(src1[3], trans[4])); \
  171. shift_narrow_ ## half1 (v26, &src1[1], add, shift); \
  172. v26 = wasm_i32x4_add(v24, v28); \
  173. v24 = wasm_i32x4_sub(v24, v28); \
  174. v28 = wasm_i32x4_add(v25, v29); \
  175. v25 = wasm_i32x4_sub(v25, v29); \
  176. v30 = wasm_i32x4_add(v27, v31); \
  177. v27 = wasm_i32x4_sub(v27, v31); \
  178. shift_narrow_ ## half0 (v26, &src0[0], add, shift); \
  179. shift_narrow_ ## half1 (v24, &src1[3], add, shift); \
  180. shift_narrow_ ## half0 (v28, &src0[1], add, shift); \
  181. shift_narrow_ ## half1 (v25, &src1[2], add, shift); \
  182. shift_narrow_ ## half0 (v30, &src0[3], add, shift); \
  183. shift_narrow_ ## half1 (v27, &src1[0], add, shift); \
  184. } while (0)
  185. static void idct_8x8(int16_t *coeffs, int bit_depth)
  186. {
  187. v128_t src[8];
  188. v128_t trans[8];
  189. v128_t *src1;
  190. int shift1 = 7;
  191. int shift2 = 20 - bit_depth;
  192. src[0] = wasm_v128_load(coeffs + 0 * 8);
  193. src[1] = wasm_v128_load(coeffs + 1 * 8);
  194. src[2] = wasm_v128_load(coeffs + 2 * 8);
  195. src[3] = wasm_v128_load(coeffs + 3 * 8);
  196. src[4] = wasm_v128_load(coeffs + 4 * 8);
  197. src[5] = wasm_v128_load(coeffs + 5 * 8);
  198. src[6] = wasm_v128_load(coeffs + 6 * 8);
  199. src[7] = wasm_v128_load(coeffs + 7 * 8);
  200. trans[0] = wasm_i16x8_const_splat(transform[0]);
  201. trans[1] = wasm_i16x8_const_splat(transform[1]);
  202. trans[2] = wasm_i16x8_const_splat(transform[2]);
  203. trans[3] = wasm_i16x8_const_splat(transform[3]);
  204. trans[4] = wasm_i16x8_const_splat(transform[4]);
  205. trans[5] = wasm_i16x8_const_splat(transform[5]);
  206. trans[6] = wasm_i16x8_const_splat(transform[6]);
  207. trans[7] = wasm_i16x8_const_splat(transform[7]);
  208. src1 = &src[4];
  209. tr_8x4(src, src1, low, low, trans, shift1);
  210. tr_8x4(src, src1, high, high, trans, shift1);
  211. transpose_8x8h(src);
  212. tr_8x4(src, src, low, high, trans, shift2);
  213. tr_8x4(src1, src1, low, high, trans, shift2);
  214. transpose_8x8h(src);
  215. wasm_v128_store(&coeffs[0 * 8], src[0]);
  216. wasm_v128_store(&coeffs[1 * 8], src[1]);
  217. wasm_v128_store(&coeffs[2 * 8], src[2]);
  218. wasm_v128_store(&coeffs[3 * 8], src[3]);
  219. wasm_v128_store(&coeffs[4 * 8], src[4]);
  220. wasm_v128_store(&coeffs[5 * 8], src[5]);
  221. wasm_v128_store(&coeffs[6 * 8], src[6]);
  222. wasm_v128_store(&coeffs[7 * 8], src[7]);
  223. }
  224. void ff_hevc_idct_8x8_8_simd128(int16_t *coeffs, int col_limit)
  225. {
  226. idct_8x8(coeffs, 8);
  227. }
  228. void ff_hevc_idct_8x8_10_simd128(int16_t *coeffs, int col_limit)
  229. {
  230. idct_8x8(coeffs, 10);
  231. }
  232. #define load16(x1, x3, x2, in0, in1, in2, in3) \
  233. in0 = wasm_v128_load64_zero(x1); \
  234. in0 = wasm_v128_load64_lane(x3, in0, 1); \
  235. x1 += x2; \
  236. x3 += x2; \
  237. in1 = wasm_v128_load64_zero(x1); \
  238. in1 = wasm_v128_load64_lane(x3, in1, 1); \
  239. x1 += x2; \
  240. x3 += x2; \
  241. in2 = wasm_v128_load64_zero(x1); \
  242. in2 = wasm_v128_load64_lane(x3, in2, 1); \
  243. x1 += x2; \
  244. x3 += x2; \
  245. in3 = wasm_v128_load64_zero(x1); \
  246. in3 = wasm_v128_load64_lane(x3, in3, 1); \
  247. x1 += x2; \
  248. x3 += x2; \
  249. #define bufferfly(e, o, p, m) \
  250. p = wasm_i32x4_add(e, o); \
  251. m = wasm_i32x4_sub(e, o); \
  252. static void tr16_8x4(v128_t in0, v128_t in1, v128_t in2, v128_t in3,
  253. const v128_t *trans, char *sp, int offset)
  254. {
  255. v128_t v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31;
  256. tr_4x4_8(in0, in1, in2, in3, v24, v25, v26, v27, trans, low, low);
  257. v28 = wasm_i32x4_extmul_high_i16x8(in0, trans[4]);
  258. v29 = wasm_i32x4_extmul_high_i16x8(in0, trans[5]);
  259. v30 = wasm_i32x4_extmul_high_i16x8(in0, trans[6]);
  260. v31 = wasm_i32x4_extmul_high_i16x8(in0, trans[7]);
  261. v28 = wasm_i32x4_add(v28, wasm_i32x4_extmul_high_i16x8(in1, trans[5]));
  262. v29 = wasm_i32x4_sub(v29, wasm_i32x4_extmul_high_i16x8(in1, trans[7]));
  263. v30 = wasm_i32x4_sub(v30, wasm_i32x4_extmul_high_i16x8(in1, trans[4]));
  264. v31 = wasm_i32x4_sub(v31, wasm_i32x4_extmul_high_i16x8(in1, trans[6]));
  265. v28 = wasm_i32x4_add(v28, wasm_i32x4_extmul_high_i16x8(in2, trans[6]));
  266. v29 = wasm_i32x4_sub(v29, wasm_i32x4_extmul_high_i16x8(in2, trans[4]));
  267. v30 = wasm_i32x4_add(v30, wasm_i32x4_extmul_high_i16x8(in2, trans[7]));
  268. v31 = wasm_i32x4_add(v31, wasm_i32x4_extmul_high_i16x8(in2, trans[5]));
  269. v28 = wasm_i32x4_add(v28, wasm_i32x4_extmul_high_i16x8(in3, trans[7]));
  270. v29 = wasm_i32x4_sub(v29, wasm_i32x4_extmul_high_i16x8(in3, trans[6]));
  271. v30 = wasm_i32x4_add(v30, wasm_i32x4_extmul_high_i16x8(in3, trans[5]));
  272. v31 = wasm_i32x4_sub(v31, wasm_i32x4_extmul_high_i16x8(in3, trans[4]));
  273. bufferfly(v24, v28, v16, v23);
  274. bufferfly(v25, v29, v17, v22);
  275. bufferfly(v26, v30, v18, v21);
  276. bufferfly(v27, v31, v19, v20);
  277. sp += offset;
  278. wasm_v128_store(sp, v16); sp += 16;
  279. wasm_v128_store(sp, v17); sp += 16;
  280. wasm_v128_store(sp, v18); sp += 16;
  281. wasm_v128_store(sp, v19); sp += 16;
  282. wasm_v128_store(sp, v20); sp += 16;
  283. wasm_v128_store(sp, v21); sp += 16;
  284. wasm_v128_store(sp, v22); sp += 16;
  285. wasm_v128_store(sp, v23);
  286. }
  287. static void scale(v128_t *out0, v128_t *out1, v128_t *out2, v128_t *out3,
  288. v128_t in0, v128_t in1, v128_t in2, v128_t in3,
  289. v128_t in4, v128_t in5, v128_t in6, v128_t in7,
  290. int shift)
  291. {
  292. v128_t add = wasm_i32x4_splat(1 << (shift - 1));
  293. in0 = wasm_i32x4_add(in0, add);
  294. in1 = wasm_i32x4_add(in1, add);
  295. in2 = wasm_i32x4_add(in2, add);
  296. in3 = wasm_i32x4_add(in3, add);
  297. in4 = wasm_i32x4_add(in4, add);
  298. in5 = wasm_i32x4_add(in5, add);
  299. in6 = wasm_i32x4_add(in6, add);
  300. in7 = wasm_i32x4_add(in7, add);
  301. in0 = wasm_i32x4_shr(in0, shift);
  302. in1 = wasm_i32x4_shr(in1, shift);
  303. in2 = wasm_i32x4_shr(in2, shift);
  304. in3 = wasm_i32x4_shr(in3, shift);
  305. in4 = wasm_i32x4_shr(in4, shift);
  306. in5 = wasm_i32x4_shr(in5, shift);
  307. in6 = wasm_i32x4_shr(in6, shift);
  308. in7 = wasm_i32x4_shr(in7, shift);
  309. *out0 = wasm_i16x8_narrow_i32x4(in0, in1);
  310. *out1 = wasm_i16x8_narrow_i32x4(in2, in3);
  311. *out2 = wasm_i16x8_narrow_i32x4(in4, in5);
  312. *out3 = wasm_i16x8_narrow_i32x4(in6, in7);
  313. }
  314. static void transpose16_4x4_2(v128_t *r0, v128_t *r1, v128_t *r2, v128_t *r3)
  315. {
  316. v128_t t0, t1, t2, t3, t4, t5;
  317. t0 = wasm_i16x8_shuffle(*r0, *r1, 0, 8, 2, 10, 4, 12, 6, 14);
  318. t1 = wasm_i16x8_shuffle(*r0, *r1, 1, 9, 3, 11, 5, 13, 7, 15);
  319. t2 = wasm_i16x8_shuffle(*r2, *r3, 0, 8, 2, 10, 4, 12, 6, 14);
  320. t3 = wasm_i16x8_shuffle(*r2, *r3, 1, 9, 3, 11, 5, 13, 7, 15);
  321. t4 = wasm_i32x4_shuffle(t0, t2, 0, 4, 2, 6);
  322. t5 = wasm_i32x4_shuffle(t0, t2, 1, 5, 3, 7);
  323. t0 = wasm_i32x4_shuffle(t1, t3, 0, 4, 2, 6);
  324. t2 = wasm_i32x4_shuffle(t1, t3, 1, 5, 3, 7);
  325. *r0 = wasm_i64x2_shuffle(t4, *r0, 0, 3);
  326. *r2 = wasm_i64x2_shuffle(t5, *r2, 0, 3);
  327. *r1 = wasm_i64x2_shuffle(t0, *r1, 0, 3);
  328. *r3 = wasm_i64x2_shuffle(t2, *r3, 0, 3);
  329. t0 = wasm_i16x8_shuffle(*r3, *r2, 0, 8, 2, 10, 4, 12, 6, 14);
  330. t1 = wasm_i16x8_shuffle(*r3, *r2, 1, 9, 3, 11, 5, 13, 7, 15);
  331. t2 = wasm_i16x8_shuffle(*r1, *r0, 0, 8, 2, 10, 4, 12, 6, 14);
  332. t3 = wasm_i16x8_shuffle(*r1, *r0, 1, 9, 3, 11, 5, 13, 7, 15);
  333. t4 = wasm_i32x4_shuffle(t0, t2, 0, 4, 2, 6);
  334. t5 = wasm_i32x4_shuffle(t0, t2, 1, 5, 3, 7);
  335. t0 = wasm_i32x4_shuffle(t1, t3, 0, 4, 2, 6);
  336. t2 = wasm_i32x4_shuffle(t1, t3, 1, 5, 3, 7);
  337. *r3 = wasm_i64x2_shuffle(*r3, t4, 0, 3);
  338. *r1 = wasm_i64x2_shuffle(*r1, t5, 0, 3);
  339. *r2 = wasm_i64x2_shuffle(*r2, t0, 0, 3);
  340. *r0 = wasm_i64x2_shuffle(*r0, t2, 0, 3);
  341. }
  342. static void store16(v128_t in0, v128_t in1, v128_t in2, v128_t in3,
  343. char *x1, char *x3, int x1_step, int x3_step)
  344. {
  345. wasm_v128_store64_lane(x1, in0, 0);
  346. wasm_v128_store64_lane(x3, in0, 1);
  347. x1 += x1_step;
  348. x3 += x3_step;
  349. wasm_v128_store64_lane(x1, in1, 0);
  350. wasm_v128_store64_lane(x3, in1, 1);
  351. x1 += x1_step;
  352. x3 += x3_step;
  353. wasm_v128_store64_lane(x1, in2, 0);
  354. wasm_v128_store64_lane(x3, in2, 1);
  355. x1 += x1_step;
  356. x3 += x3_step;
  357. wasm_v128_store64_lane(x1, in3, 0);
  358. wasm_v128_store64_lane(x3, in3, 1);
  359. }
  360. static void store_to_stack(char *sp, int off1, int off2,
  361. v128_t in0, v128_t in2, v128_t in4, v128_t in6,
  362. v128_t in7, v128_t in5, v128_t in3, v128_t in1)
  363. {
  364. char *x1 = sp + off1;
  365. char *x3 = sp + off2;
  366. wasm_v128_store(x1, in0);
  367. wasm_v128_store(x3, in1);
  368. x1 += 16;
  369. x3 -= 16;
  370. wasm_v128_store(x1, in2);
  371. wasm_v128_store(x3, in3);
  372. x1 += 16;
  373. x3 -= 16;
  374. wasm_v128_store(x1, in4);
  375. wasm_v128_store(x3, in5);
  376. x1 += 16;
  377. x3 -= 16;
  378. wasm_v128_store(x1, in6);
  379. wasm_v128_store(x3, in7);
  380. }
  381. #define sum_sub(out, in0, in1, operation, half) \
  382. out = wasm_i32x4_ ## operation (out, wasm_i32x4_extmul_ ## half ## _i16x8(in0, in1));
  383. #define add_member(in, t0, t1, t2, t3, t4, t5, t6, t7, op0, op1, op2, op3, op4, op5, op6, op7, half) \
  384. do { \
  385. sum_sub(v21, in, t0, op0, half) \
  386. sum_sub(v22, in, t1, op1, half) \
  387. sum_sub(v23, in, t2, op2, half) \
  388. sum_sub(v24, in, t3, op3, half) \
  389. sum_sub(v25, in, t4, op4, half) \
  390. sum_sub(v26, in, t5, op5, half) \
  391. sum_sub(v27, in, t6, op6, half) \
  392. sum_sub(v28, in, t7, op7, half) \
  393. } while (0)
  394. #define butterfly16(in0, in1, in2, in3, in4, in5, in6, in7) \
  395. do { \
  396. v20 = wasm_i32x4_add(in0, in1); \
  397. in0 = wasm_i32x4_sub(in0, in1); \
  398. in1 = wasm_i32x4_add(in2, in3); \
  399. in2 = wasm_i32x4_sub(in2, in3); \
  400. in3 = wasm_i32x4_add(in4, in5); \
  401. in4 = wasm_i32x4_sub(in4, in5); \
  402. in5 = wasm_i32x4_add(in6, in7); \
  403. in6 = wasm_i32x4_sub(in6, in7); \
  404. } while (0)
  405. static void tr_16x4(char *src, char *buf, char *sp,
  406. int shift, int offset, int step)
  407. {
  408. char *x1, *x3, *x4;
  409. int x2;
  410. v128_t trans[8];
  411. v128_t v16, v17, v18, v19, v20, v21, v22, v23,
  412. v24, v25, v26, v27, v28, v29, v30, v31;
  413. trans[0] = wasm_i16x8_const_splat(transform[0]);
  414. trans[1] = wasm_i16x8_const_splat(transform[1]);
  415. trans[2] = wasm_i16x8_const_splat(transform[2]);
  416. trans[3] = wasm_i16x8_const_splat(transform[3]);
  417. trans[4] = wasm_i16x8_const_splat(transform[4]);
  418. trans[5] = wasm_i16x8_const_splat(transform[5]);
  419. trans[6] = wasm_i16x8_const_splat(transform[6]);
  420. trans[7] = wasm_i16x8_const_splat(transform[7]);
  421. x1 = src;
  422. x3 = src + step * 64;
  423. x2 = step * 128;
  424. load16(x1, x3, x2, v16, v17, v18, v19);
  425. tr16_8x4(v16, v17, v18, v19, trans, sp, offset);
  426. x1 = src + step * 32;
  427. x3 = src + step * 3 * 32;
  428. x2 = step * 128;
  429. load16(x1, x3, x2, v20, v17, v18, v19);
  430. trans[0] = wasm_i16x8_const_splat(transform[0 + 8]);
  431. trans[1] = wasm_i16x8_const_splat(transform[1 + 8]);
  432. trans[2] = wasm_i16x8_const_splat(transform[2 + 8]);
  433. trans[3] = wasm_i16x8_const_splat(transform[3 + 8]);
  434. trans[4] = wasm_i16x8_const_splat(transform[4 + 8]);
  435. trans[5] = wasm_i16x8_const_splat(transform[5 + 8]);
  436. trans[6] = wasm_i16x8_const_splat(transform[6 + 8]);
  437. trans[7] = wasm_i16x8_const_splat(transform[7 + 8]);
  438. v21 = wasm_i32x4_extmul_low_i16x8(v20, trans[0]);
  439. v22 = wasm_i32x4_extmul_low_i16x8(v20, trans[1]);
  440. v23 = wasm_i32x4_extmul_low_i16x8(v20, trans[2]);
  441. v24 = wasm_i32x4_extmul_low_i16x8(v20, trans[3]);
  442. v25 = wasm_i32x4_extmul_low_i16x8(v20, trans[4]);
  443. v26 = wasm_i32x4_extmul_low_i16x8(v20, trans[5]);
  444. v27 = wasm_i32x4_extmul_low_i16x8(v20, trans[6]);
  445. v28 = wasm_i32x4_extmul_low_i16x8(v20, trans[7]);
  446. add_member(v20, trans[1], trans[4], trans[7], trans[5],
  447. trans[2], trans[0], trans[3], trans[6],
  448. add, add, add, sub, sub, sub, sub, sub, high);
  449. add_member(v17, trans[2], trans[7], trans[3], trans[1],
  450. trans[6], trans[4], trans[0], trans[5],
  451. add, add, sub, sub, sub, add, add, add, low);
  452. add_member(v17, trans[3], trans[5], trans[1], trans[7],
  453. trans[0], trans[6], trans[2], trans[4],
  454. add, sub, sub, add, add, add, sub, sub, high);
  455. add_member(v18, trans[4], trans[2], trans[6], trans[0],
  456. trans[7], trans[1], trans[5], trans[3],
  457. add, sub, sub, add, sub, sub, add, add, low);
  458. add_member(v18, trans[5], trans[0], trans[4], trans[6],
  459. trans[1], trans[3], trans[7], trans[2],
  460. add, sub, add, add, sub, add, add, sub, high);
  461. add_member(v19, trans[6], trans[3], trans[0], trans[2],
  462. trans[5], trans[7], trans[4], trans[1],
  463. add, sub, add, sub, add, add, sub, add, low);
  464. add_member(v19, trans[7], trans[6], trans[5], trans[4],
  465. trans[3], trans[2], trans[1], trans[0],
  466. add, sub, add, sub, add, sub, add, sub, high);
  467. x4 = &sp[offset];
  468. v16 = wasm_v128_load(x4);
  469. x4 += 16;
  470. v17 = wasm_v128_load(x4);
  471. x4 += 16;
  472. v18 = wasm_v128_load(x4);
  473. x4 += 16;
  474. v19 = wasm_v128_load(x4);
  475. butterfly16(v16, v21, v17, v22, v18, v23, v19, v24);
  476. if (shift > 0) {
  477. scale(&v29, &v30, &v31, &v24,
  478. v20, v16, v21, v17, v22, v18, v23, v19,
  479. shift);
  480. transpose16_4x4_2(&v29, &v30, &v31, &v24);
  481. x1 = buf;
  482. x3 = &buf[24 + 3 * 32];
  483. store16(v29, v30, v31, v24, x1, x3, 32, -32);
  484. } else {
  485. store_to_stack(sp, offset, offset + 240,
  486. v20, v21, v22, v23, v19, v18, v17, v16);
  487. }
  488. x4 = &sp[offset + 64];
  489. v16 = wasm_v128_load(x4);
  490. x4 += 16;
  491. v17 = wasm_v128_load(x4);
  492. x4 += 16;
  493. v18 = wasm_v128_load(x4);
  494. x4 += 16;
  495. v19 = wasm_v128_load(x4);
  496. butterfly16(v16, v25, v17, v26, v18, v27, v19, v28);
  497. if (shift > 0) {
  498. scale(&v29, &v30, &v31, &v20,
  499. v20, v16, v25, v17, v26, v18, v27, v19,
  500. shift);
  501. transpose16_4x4_2(&v29, &v30, &v31, &v20);
  502. x1 = &buf[8];
  503. x3 = &buf[16 + 3 * 32];
  504. store16(v29, v30, v31, v20, x1, x3, 32, -32);
  505. } else {
  506. store_to_stack(sp, offset + 64, offset + 176,
  507. v20, v25, v26, v27, v19, v18, v17, v16);
  508. }
  509. }
  510. static void idct_16x16(char *coeffs, int bit_depth)
  511. {
  512. DECLARE_ALIGNED(16, char, sp)[640];
  513. for (int i = 0; i < 4; i++) {
  514. char *x5 = &coeffs[8 * i];
  515. char *x6 = &sp[8 * i * 16];
  516. tr_16x4(x5, x6, sp, 7, 512, 1);
  517. }
  518. for (int i = 0; i < 4; i++) {
  519. char *x5 = &sp[8 * i];
  520. char *x6 = &coeffs[8 * i * 16];
  521. tr_16x4(x5, x6, sp, 20 - bit_depth, 512, 1);
  522. }
  523. }
  524. void ff_hevc_idct_16x16_8_simd128(int16_t *coeffs, int col_limit)
  525. {
  526. idct_16x16((char *)coeffs, 8);
  527. }
  528. void ff_hevc_idct_16x16_10_simd128(int16_t *coeffs, int col_limit)
  529. {
  530. idct_16x16((char *)coeffs, 10);
  531. }
  532. #define add_member32(in, t0, t1, t2, t3, op0, op1, op2, op3, half) \
  533. do { \
  534. sum_sub(v24, in, t0, op0, half) \
  535. sum_sub(v25, in, t1, op1, half) \
  536. sum_sub(v26, in, t2, op2, half) \
  537. sum_sub(v27, in, t3, op3, half) \
  538. } while (0)
  539. #define butterfly32(in0, in1, in2, in3, out) \
  540. do { \
  541. out = wasm_i32x4_add(in0, in1); \
  542. in0 = wasm_i32x4_sub(in0, in1); \
  543. in1 = wasm_i32x4_add(in2, in3); \
  544. in2 = wasm_i32x4_sub(in2, in3); \
  545. } while (0)
  546. static void tr_32x4(char *x5, char *x11, char *sp, int shift)
  547. {
  548. char *x1, *x3, *x4;
  549. // transform in v0 - v4
  550. v128_t v0[4];
  551. v128_t v1[4];
  552. v128_t v2[4];
  553. v128_t v3[4];
  554. v128_t v4, v5, v6, v7, v16, v17, v18, v19,
  555. v20, v21, v22, v23, v24, v25, v26, v27,
  556. v28, v29, v30, v31, v32, v33;
  557. tr_16x4(x5, x11, sp, 0, 2048, 4);
  558. // load32
  559. x1 = &x5[64];
  560. x3 = &x1[128];
  561. v4 = wasm_v128_load64_zero(x1);
  562. v4 = wasm_v128_load64_lane(x3, v4, 1);
  563. x1 += 256;
  564. x3 += 256;
  565. v5 = wasm_v128_load64_zero(x1);
  566. v5 = wasm_v128_load64_lane(x3, v5, 1);
  567. x1 += 256;
  568. x3 += 256;
  569. v6 = wasm_v128_load64_zero(x1);
  570. v6 = wasm_v128_load64_lane(x3, v6, 1);
  571. x1 += 256;
  572. x3 += 256;
  573. v7 = wasm_v128_load64_zero(x1);
  574. v7 = wasm_v128_load64_lane(x3, v7, 1);
  575. x1 += 256;
  576. x3 += 256;
  577. v16 = wasm_v128_load64_zero(x1);
  578. v16 = wasm_v128_load64_lane(x3, v16, 1);
  579. x1 += 256;
  580. x3 += 256;
  581. v17 = wasm_v128_load64_zero(x1);
  582. v17 = wasm_v128_load64_lane(x3, v17, 1);
  583. x1 += 256;
  584. x3 += 256;
  585. v18 = wasm_v128_load64_zero(x1);
  586. v18 = wasm_v128_load64_lane(x3, v18, 1);
  587. x1 += 256;
  588. x3 += 256;
  589. v19 = wasm_v128_load64_zero(x1);
  590. v19 = wasm_v128_load64_lane(x3, v19, 1);
  591. // load transform
  592. v0[0] = wasm_i16x8_const_splat(transform[16 + 0]);
  593. v0[1] = wasm_i16x8_const_splat(transform[16 + 1]);
  594. v0[2] = wasm_i16x8_const_splat(transform[16 + 2]);
  595. v0[3] = wasm_i16x8_const_splat(transform[16 + 3]);
  596. v1[0] = wasm_i16x8_const_splat(transform[16 + 4]);
  597. v1[1] = wasm_i16x8_const_splat(transform[16 + 5]);
  598. v1[2] = wasm_i16x8_const_splat(transform[16 + 6]);
  599. v1[3] = wasm_i16x8_const_splat(transform[16 + 7]);
  600. v2[0] = wasm_i16x8_const_splat(transform[16 + 8]);
  601. v2[1] = wasm_i16x8_const_splat(transform[16 + 9]);
  602. v2[2] = wasm_i16x8_const_splat(transform[16 + 10]);
  603. v2[3] = wasm_i16x8_const_splat(transform[16 + 11]);
  604. v3[0] = wasm_i16x8_const_splat(transform[16 + 12]);
  605. v3[1] = wasm_i16x8_const_splat(transform[16 + 13]);
  606. v3[2] = wasm_i16x8_const_splat(transform[16 + 14]);
  607. v3[3] = wasm_i16x8_const_splat(transform[16 + 15]);
  608. // tr_block1
  609. v24 = wasm_i32x4_extmul_low_i16x8(v4, v0[0]);
  610. v25 = wasm_i32x4_extmul_low_i16x8(v4, v0[1]);
  611. v26 = wasm_i32x4_extmul_low_i16x8(v4, v0[2]);
  612. v27 = wasm_i32x4_extmul_low_i16x8(v4, v0[3]);
  613. add_member32(v4, v0[1], v1[0], v1[3], v2[2], add, add, add, add, high);
  614. add_member32(v5, v0[2], v1[3], v3[0], v3[2], add, add, add, sub, low);
  615. add_member32(v5, v0[3], v2[2], v3[2], v1[3], add, add, sub, sub, high);
  616. add_member32(v6, v1[0], v3[1], v2[1], v0[0], add, add, sub, sub, low);
  617. add_member32(v6, v1[1], v3[3], v1[0], v1[2], add, sub, sub, sub, high);
  618. add_member32(v7, v1[2], v3[0], v0[0], v3[1], add, sub, sub, sub, low);
  619. add_member32(v7, v1[3], v2[1], v1[1], v2[3], add, sub, sub, add, high);
  620. add_member32(v16, v2[0], v1[2], v2[2], v1[0], add, sub, sub, add, low);
  621. add_member32(v16, v2[1], v0[3], v3[3], v0[2], add, sub, sub, add, high);
  622. add_member32(v17, v2[2], v0[1], v2[3], v2[1], add, sub, add, add, low);
  623. add_member32(v17, v2[3], v0[2], v1[2], v3[3], add, sub, add, sub, high);
  624. add_member32(v18, v3[0], v1[1], v0[1], v2[0], add, sub, add, sub, low);
  625. add_member32(v18, v3[1], v2[0], v0[3], v0[1], add, sub, add, sub, high);
  626. add_member32(v19, v3[2], v2[3], v2[0], v1[1], add, sub, add, sub, low);
  627. add_member32(v19, v3[3], v3[2], v3[1], v3[0], add, sub, add, sub, high);
  628. x4 = &sp[2048];
  629. // scale_store
  630. v28 = wasm_v128_load(x4);
  631. x4 += 16;
  632. v29 = wasm_v128_load(x4);
  633. x4 += 16;
  634. v30 = wasm_v128_load(x4);
  635. x4 += 16;
  636. v31 = wasm_v128_load(x4);
  637. x4 += 16;
  638. butterfly32(v28, v24, v29, v25, v32);
  639. butterfly32(v30, v26, v31, v27, v33);
  640. scale(&v20, &v21, &v22, &v23, v32, v28, v24, v29, v33, v30, v26, v31, shift);
  641. transpose16_4x4_2(&v20, &v21, &v22, &v23);
  642. x1 = x11;
  643. x3 = &x11[56 + 3 * 64];
  644. store16(v20, v21, v22, v23, x1, x3, 64, -64);
  645. // tr_block2
  646. v24 = wasm_i32x4_extmul_low_i16x8(v4, v1[0]);
  647. v25 = wasm_i32x4_extmul_low_i16x8(v4, v1[1]);
  648. v26 = wasm_i32x4_extmul_low_i16x8(v4, v1[2]);
  649. v27 = wasm_i32x4_extmul_low_i16x8(v4, v1[3]);
  650. add_member32(v4, v3[1], v3[3], v3[0], v2[1], add, sub, sub, sub, high);
  651. add_member32(v5, v2[1], v1[0], v0[0], v1[1], sub, sub, sub, sub, low);
  652. add_member32(v5, v0[0], v1[2], v3[1], v2[3], sub, sub, sub, add, high);
  653. add_member32(v6, v2[0], v3[2], v1[1], v0[3], sub, add, add, add, low);
  654. add_member32(v6, v3[2], v0[3], v1[3], v3[1], add, add, add, sub, high);
  655. add_member32(v7, v1[1], v1[3], v2[3], v0[0], add, add, sub, sub, low);
  656. add_member32(v7, v0[3], v3[1], v0[1], v3[3], add, sub, sub, add, high);
  657. add_member32(v16, v3[0], v0[2], v3[2], v0[1], add, sub, sub, add, low);
  658. add_member32(v16, v2[2], v2[0], v1[0], v3[2], sub, sub, add, add, high);
  659. add_member32(v17, v0[1], v3[0], v2[0], v0[2], sub, add, add, sub, low);
  660. add_member32(v17, v1[3], v0[1], v2[2], v3[0], sub, add, sub, sub, high);
  661. add_member32(v18, v3[3], v2[1], v0[2], v1[0], add, add, sub, add, low);
  662. add_member32(v18, v1[2], v2[3], v3[3], v2[2], add, sub, sub, add, high);
  663. add_member32(v19, v0[2], v0[1], v0[3], v1[2], add, sub, add, sub, low);
  664. add_member32(v19, v2[3], v2[2], v2[1], v2[0], add, sub, add, sub, high);
  665. // scale_store
  666. v28 = wasm_v128_load(x4);
  667. x4 += 16;
  668. v29 = wasm_v128_load(x4);
  669. x4 += 16;
  670. v30 = wasm_v128_load(x4);
  671. x4 += 16;
  672. v31 = wasm_v128_load(x4);
  673. x4 += 16;
  674. butterfly32(v28, v24, v29, v25, v32);
  675. butterfly32(v30, v26, v31, v27, v33);
  676. scale(&v20, &v21, &v22, &v23, v32, v28, v24, v29, v33, v30, v26, v31, shift);
  677. transpose16_4x4_2(&v20, &v21, &v22, &v23);
  678. x1 = &x11[8];
  679. x3 = &x11[48 + 3 * 64];
  680. store16(v20, v21, v22, v23, x1, x3, 64, -64);
  681. // tr_block3
  682. v24 = wasm_i32x4_extmul_low_i16x8(v4, v2[0]);
  683. v25 = wasm_i32x4_extmul_low_i16x8(v4, v2[1]);
  684. v26 = wasm_i32x4_extmul_low_i16x8(v4, v2[2]);
  685. v27 = wasm_i32x4_extmul_low_i16x8(v4, v2[3]);
  686. add_member32(v4, v1[2], v0[3], v0[0], v0[2], sub, sub, sub, sub, high);
  687. add_member32(v5, v2[2], v3[3], v2[3], v1[2], sub, sub, add, add, low);
  688. add_member32(v5, v1[0], v0[2], v2[1], v3[3], add, add, add, sub, high);
  689. add_member32(v6, v3[0], v2[2], v0[1], v1[3], add, sub, sub, sub, low);
  690. add_member32(v6, v0[2], v2[0], v3[0], v0[0], sub, sub, add, add, high);
  691. add_member32(v7, v3[2], v1[0], v2[0], v2[2], sub, add, add, sub, low);
  692. add_member32(v7, v0[0], v3[2], v0[2], v3[0], add, add, sub, sub, high);
  693. add_member32(v16, v3[3], v0[1], v3[1], v0[3], sub, sub, add, add, low);
  694. add_member32(v16, v0[1], v2[3], v1[3], v1[1], sub, add, add, sub, high);
  695. add_member32(v17, v3[1], v1[3], v0[3], v3[2], add, add, sub, add, low);
  696. add_member32(v17, v0[3], v1[1], v3[2], v2[0], add, sub, add, add, high);
  697. add_member32(v18, v2[3], v3[1], v1[2], v0[1], sub, sub, add, sub, low);
  698. add_member32(v18, v1[1], v0[0], v1[0], v2[1], sub, add, sub, add, high);
  699. add_member32(v19, v2[1], v3[0], v3[3], v3[1], add, sub, add, add, low);
  700. add_member32(v19, v1[3], v1[2], v1[1], v1[0], add, sub, add, sub, high);
  701. // scale_store
  702. v28 = wasm_v128_load(x4);
  703. x4 += 16;
  704. v29 = wasm_v128_load(x4);
  705. x4 += 16;
  706. v30 = wasm_v128_load(x4);
  707. x4 += 16;
  708. v31 = wasm_v128_load(x4);
  709. x4 += 16;
  710. butterfly32(v28, v24, v29, v25, v32);
  711. butterfly32(v30, v26, v31, v27, v33);
  712. scale(&v20, &v21, &v22, &v23, v32, v28, v24, v29, v33, v30, v26, v31, shift);
  713. transpose16_4x4_2(&v20, &v21, &v22, &v23);
  714. x1 = &x11[16];
  715. x3 = &x11[40 + 3 * 64];
  716. store16(v20, v21, v22, v23, x1, x3, 64, -64);
  717. // try_block4
  718. v24 = wasm_i32x4_extmul_low_i16x8(v4, v3[0]);
  719. v25 = wasm_i32x4_extmul_low_i16x8(v4, v3[1]);
  720. v26 = wasm_i32x4_extmul_low_i16x8(v4, v3[2]);
  721. v27 = wasm_i32x4_extmul_low_i16x8(v4, v3[3]);
  722. add_member32(v4, v1[1], v2[0], v2[3], v3[2], sub, sub, sub, sub, high);
  723. add_member32(v5, v0[0], v0[3], v2[0], v3[1], add, add, add, add, low);
  724. add_member32(v5, v2[0], v0[0], v1[1], v3[0], sub, sub, sub, sub, high);
  725. add_member32(v6, v3[3], v1[2], v0[2], v2[3], add, add, add, add, low);
  726. add_member32(v6, v2[1], v2[3], v0[0], v2[2], add, sub, sub, sub, high);
  727. add_member32(v7, v0[2], v3[3], v0[3], v2[1], sub, sub, add, add, low);
  728. add_member32(v7, v1[0], v2[2], v1[2], v2[0], add, add, sub, sub, high);
  729. add_member32(v16, v2[3], v1[1], v2[1], v1[3], sub, sub, add, add, low);
  730. add_member32(v16, v3[1], v0[1], v3[0], v1[2], sub, add, sub, sub, high);
  731. add_member32(v17, v1[2], v1[0], v3[3], v1[1], add, sub, add, add, low);
  732. add_member32(v17, v0[1], v2[1], v3[1], v1[0], sub, add, add, sub, high);
  733. add_member32(v18, v1[3], v3[2], v2[2], v0[3], add, sub, sub, add, low);
  734. add_member32(v18, v3[2], v3[0], v1[3], v0[2], sub, sub, add, sub, high);
  735. add_member32(v19, v2[2], v1[3], v1[0], v0[1], sub, add, sub, add, low);
  736. add_member32(v19, v0[3], v0[2], v0[1], v0[0], add, sub, add, sub, high);
  737. // scale_store
  738. v28 = wasm_v128_load(x4);
  739. x4 += 16;
  740. v29 = wasm_v128_load(x4);
  741. x4 += 16;
  742. v30 = wasm_v128_load(x4);
  743. x4 += 16;
  744. v31 = wasm_v128_load(x4);
  745. butterfly32(v28, v24, v29, v25, v32);
  746. butterfly32(v30, v26, v31, v27, v33);
  747. scale(&v20, &v21, &v22, &v23, v32, v28, v24, v29, v33, v30, v26, v31, shift);
  748. transpose16_4x4_2(&v20, &v21, &v22, &v23);
  749. x1 = &x11[24];
  750. x3 = &x11[32 + 3 * 64];
  751. store16(v20, v21, v22, v23, x1, x3, 64, -64);
  752. }
  753. static void idct_32x32(char *coeffs, int bit_depth)
  754. {
  755. DECLARE_ALIGNED(16, char, sp)[2432];
  756. char *x5, *x11;
  757. for (int i = 0; i < 8; i++) {
  758. x5 = &coeffs[8 * i];
  759. x11 = &sp[8 * i * 32];
  760. tr_32x4(x5, x11, sp, 7);
  761. }
  762. for (int i = 0; i < 8; i++) {
  763. x5 = &sp[8 * i];
  764. x11 = &coeffs[8 * i * 32];
  765. tr_32x4(x5, x11, sp, 20 - bit_depth);
  766. }
  767. }
  768. void ff_hevc_idct_32x32_8_simd128(int16_t *coeffs, int col_limit)
  769. {
  770. idct_32x32((char *)coeffs, 8);
  771. }
  772. void ff_hevc_idct_32x32_10_simd128(int16_t *coeffs, int col_limit)
  773. {
  774. idct_32x32((char *)coeffs, 10);
  775. }