highbd_idct32x32_add_sse2.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /*
  2. * Copyright (c) 2015 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 "./vpx_dsp_rtcd.h"
  11. #include "vpx_dsp/x86/highbd_inv_txfm_sse2.h"
  12. #include "vpx_dsp/x86/inv_txfm_sse2.h"
  13. #include "vpx_dsp/x86/transpose_sse2.h"
  14. #include "vpx_dsp/x86/txfm_common_sse2.h"
  15. static INLINE void highbd_idct32_4x32_quarter_2_stage_4_to_6(
  16. __m128i *const step1 /*step1[16]*/, __m128i *const out /*out[16]*/) {
  17. __m128i step2[32];
  18. // stage 4
  19. step2[8] = step1[8];
  20. step2[15] = step1[15];
  21. highbd_butterfly_sse2(step1[14], step1[9], cospi_24_64, cospi_8_64, &step2[9],
  22. &step2[14]);
  23. highbd_butterfly_sse2(step1[10], step1[13], cospi_8_64, cospi_24_64,
  24. &step2[13], &step2[10]);
  25. step2[11] = step1[11];
  26. step2[12] = step1[12];
  27. // stage 5
  28. step1[8] = _mm_add_epi32(step2[8], step2[11]);
  29. step1[9] = _mm_add_epi32(step2[9], step2[10]);
  30. step1[10] = _mm_sub_epi32(step2[9], step2[10]);
  31. step1[11] = _mm_sub_epi32(step2[8], step2[11]);
  32. step1[12] = _mm_sub_epi32(step2[15], step2[12]);
  33. step1[13] = _mm_sub_epi32(step2[14], step2[13]);
  34. step1[14] = _mm_add_epi32(step2[14], step2[13]);
  35. step1[15] = _mm_add_epi32(step2[15], step2[12]);
  36. // stage 6
  37. out[8] = step1[8];
  38. out[9] = step1[9];
  39. highbd_butterfly_sse2(step1[13], step1[10], cospi_16_64, cospi_16_64,
  40. &out[10], &out[13]);
  41. highbd_butterfly_sse2(step1[12], step1[11], cospi_16_64, cospi_16_64,
  42. &out[11], &out[12]);
  43. out[14] = step1[14];
  44. out[15] = step1[15];
  45. }
  46. static INLINE void highbd_idct32_4x32_quarter_3_4_stage_4_to_7(
  47. __m128i *const step1 /*step1[32]*/, __m128i *const out /*out[32]*/) {
  48. __m128i step2[32];
  49. // stage 4
  50. step2[16] = _mm_add_epi32(step1[16], step1[19]);
  51. step2[17] = _mm_add_epi32(step1[17], step1[18]);
  52. step2[18] = _mm_sub_epi32(step1[17], step1[18]);
  53. step2[19] = _mm_sub_epi32(step1[16], step1[19]);
  54. step2[20] = _mm_sub_epi32(step1[20], step1[23]); // step2[20] = -step2[20]
  55. step2[21] = _mm_sub_epi32(step1[21], step1[22]); // step2[21] = -step2[21]
  56. step2[22] = _mm_add_epi32(step1[21], step1[22]);
  57. step2[23] = _mm_add_epi32(step1[20], step1[23]);
  58. step2[24] = _mm_add_epi32(step1[27], step1[24]);
  59. step2[25] = _mm_add_epi32(step1[26], step1[25]);
  60. step2[26] = _mm_sub_epi32(step1[26], step1[25]); // step2[26] = -step2[26]
  61. step2[27] = _mm_sub_epi32(step1[27], step1[24]); // step2[27] = -step2[27]
  62. step2[28] = _mm_sub_epi32(step1[31], step1[28]);
  63. step2[29] = _mm_sub_epi32(step1[30], step1[29]);
  64. step2[30] = _mm_add_epi32(step1[29], step1[30]);
  65. step2[31] = _mm_add_epi32(step1[28], step1[31]);
  66. // stage 5
  67. step1[16] = step2[16];
  68. step1[17] = step2[17];
  69. highbd_butterfly_sse2(step2[29], step2[18], cospi_24_64, cospi_8_64,
  70. &step1[18], &step1[29]);
  71. highbd_butterfly_sse2(step2[28], step2[19], cospi_24_64, cospi_8_64,
  72. &step1[19], &step1[28]);
  73. highbd_butterfly_sse2(step2[20], step2[27], cospi_8_64, cospi_24_64,
  74. &step1[27], &step1[20]);
  75. highbd_butterfly_sse2(step2[21], step2[26], cospi_8_64, cospi_24_64,
  76. &step1[26], &step1[21]);
  77. step1[22] = step2[22];
  78. step1[23] = step2[23];
  79. step1[24] = step2[24];
  80. step1[25] = step2[25];
  81. step1[30] = step2[30];
  82. step1[31] = step2[31];
  83. // stage 6
  84. step2[16] = _mm_add_epi32(step1[16], step1[23]);
  85. step2[17] = _mm_add_epi32(step1[17], step1[22]);
  86. step2[18] = _mm_add_epi32(step1[18], step1[21]);
  87. step2[19] = _mm_add_epi32(step1[19], step1[20]);
  88. step2[20] = _mm_sub_epi32(step1[19], step1[20]);
  89. step2[21] = _mm_sub_epi32(step1[18], step1[21]);
  90. step2[22] = _mm_sub_epi32(step1[17], step1[22]);
  91. step2[23] = _mm_sub_epi32(step1[16], step1[23]);
  92. step2[24] = _mm_sub_epi32(step1[31], step1[24]);
  93. step2[25] = _mm_sub_epi32(step1[30], step1[25]);
  94. step2[26] = _mm_sub_epi32(step1[29], step1[26]);
  95. step2[27] = _mm_sub_epi32(step1[28], step1[27]);
  96. step2[28] = _mm_add_epi32(step1[27], step1[28]);
  97. step2[29] = _mm_add_epi32(step1[26], step1[29]);
  98. step2[30] = _mm_add_epi32(step1[25], step1[30]);
  99. step2[31] = _mm_add_epi32(step1[24], step1[31]);
  100. // stage 7
  101. out[16] = step2[16];
  102. out[17] = step2[17];
  103. out[18] = step2[18];
  104. out[19] = step2[19];
  105. highbd_butterfly_sse2(step2[27], step2[20], cospi_16_64, cospi_16_64,
  106. &out[20], &out[27]);
  107. highbd_butterfly_sse2(step2[26], step2[21], cospi_16_64, cospi_16_64,
  108. &out[21], &out[26]);
  109. highbd_butterfly_sse2(step2[25], step2[22], cospi_16_64, cospi_16_64,
  110. &out[22], &out[25]);
  111. highbd_butterfly_sse2(step2[24], step2[23], cospi_16_64, cospi_16_64,
  112. &out[23], &out[24]);
  113. out[28] = step2[28];
  114. out[29] = step2[29];
  115. out[30] = step2[30];
  116. out[31] = step2[31];
  117. }
  118. // Group the coefficient calculation into smaller functions to prevent stack
  119. // spillover in 32x32 idct optimizations:
  120. // quarter_1: 0-7
  121. // quarter_2: 8-15
  122. // quarter_3_4: 16-23, 24-31
  123. // For each 4x32 block __m128i in[32],
  124. // Input with index, 0, 4, 8, 12, 16, 20, 24, 28
  125. // output pixels: 0-7 in __m128i out[32]
  126. static INLINE void highbd_idct32_1024_4x32_quarter_1(
  127. const __m128i *const in /*in[32]*/, __m128i *const out /*out[8]*/) {
  128. __m128i step1[8], step2[8];
  129. // stage 3
  130. highbd_butterfly_sse2(in[4], in[28], cospi_28_64, cospi_4_64, &step1[4],
  131. &step1[7]);
  132. highbd_butterfly_sse2(in[20], in[12], cospi_12_64, cospi_20_64, &step1[5],
  133. &step1[6]);
  134. // stage 4
  135. highbd_butterfly_sse2(in[0], in[16], cospi_16_64, cospi_16_64, &step2[1],
  136. &step2[0]);
  137. highbd_butterfly_sse2(in[8], in[24], cospi_24_64, cospi_8_64, &step2[2],
  138. &step2[3]);
  139. step2[4] = _mm_add_epi32(step1[4], step1[5]);
  140. step2[5] = _mm_sub_epi32(step1[4], step1[5]);
  141. step2[6] = _mm_sub_epi32(step1[7], step1[6]);
  142. step2[7] = _mm_add_epi32(step1[7], step1[6]);
  143. // stage 5
  144. step1[0] = _mm_add_epi32(step2[0], step2[3]);
  145. step1[1] = _mm_add_epi32(step2[1], step2[2]);
  146. step1[2] = _mm_sub_epi32(step2[1], step2[2]);
  147. step1[3] = _mm_sub_epi32(step2[0], step2[3]);
  148. step1[4] = step2[4];
  149. highbd_butterfly_sse2(step2[6], step2[5], cospi_16_64, cospi_16_64, &step1[5],
  150. &step1[6]);
  151. step1[7] = step2[7];
  152. // stage 6
  153. out[0] = _mm_add_epi32(step1[0], step1[7]);
  154. out[1] = _mm_add_epi32(step1[1], step1[6]);
  155. out[2] = _mm_add_epi32(step1[2], step1[5]);
  156. out[3] = _mm_add_epi32(step1[3], step1[4]);
  157. out[4] = _mm_sub_epi32(step1[3], step1[4]);
  158. out[5] = _mm_sub_epi32(step1[2], step1[5]);
  159. out[6] = _mm_sub_epi32(step1[1], step1[6]);
  160. out[7] = _mm_sub_epi32(step1[0], step1[7]);
  161. }
  162. // For each 4x32 block __m128i in[32],
  163. // Input with index, 2, 6, 10, 14, 18, 22, 26, 30
  164. // output pixels: 8-15 in __m128i out[32]
  165. static INLINE void highbd_idct32_1024_4x32_quarter_2(
  166. const __m128i *in /*in[32]*/, __m128i *out /*out[16]*/) {
  167. __m128i step1[32], step2[32];
  168. // stage 2
  169. highbd_butterfly_sse2(in[2], in[30], cospi_30_64, cospi_2_64, &step2[8],
  170. &step2[15]);
  171. highbd_butterfly_sse2(in[18], in[14], cospi_14_64, cospi_18_64, &step2[9],
  172. &step2[14]);
  173. highbd_butterfly_sse2(in[10], in[22], cospi_22_64, cospi_10_64, &step2[10],
  174. &step2[13]);
  175. highbd_butterfly_sse2(in[26], in[6], cospi_6_64, cospi_26_64, &step2[11],
  176. &step2[12]);
  177. // stage 3
  178. step1[8] = _mm_add_epi32(step2[8], step2[9]);
  179. step1[9] = _mm_sub_epi32(step2[8], step2[9]);
  180. step1[14] = _mm_sub_epi32(step2[15], step2[14]);
  181. step1[15] = _mm_add_epi32(step2[15], step2[14]);
  182. step1[10] = _mm_sub_epi32(step2[10], step2[11]); // step1[10] = -step1[10]
  183. step1[11] = _mm_add_epi32(step2[10], step2[11]);
  184. step1[12] = _mm_add_epi32(step2[13], step2[12]);
  185. step1[13] = _mm_sub_epi32(step2[13], step2[12]); // step1[13] = -step1[13]
  186. highbd_idct32_4x32_quarter_2_stage_4_to_6(step1, out);
  187. }
  188. static INLINE void highbd_idct32_1024_4x32_quarter_1_2(
  189. const __m128i *const in /*in[32]*/, __m128i *const out /*out[32]*/) {
  190. __m128i temp[16];
  191. highbd_idct32_1024_4x32_quarter_1(in, temp);
  192. highbd_idct32_1024_4x32_quarter_2(in, temp);
  193. // stage 7
  194. highbd_add_sub_butterfly(temp, out, 16);
  195. }
  196. // For each 4x32 block __m128i in[32],
  197. // Input with odd index,
  198. // 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31
  199. // output pixels: 16-23, 24-31 in __m128i out[32]
  200. static INLINE void highbd_idct32_1024_4x32_quarter_3_4(
  201. const __m128i *const in /*in[32]*/, __m128i *const out /*out[32]*/) {
  202. __m128i step1[32], step2[32];
  203. // stage 1
  204. highbd_butterfly_sse2(in[1], in[31], cospi_31_64, cospi_1_64, &step1[16],
  205. &step1[31]);
  206. highbd_butterfly_sse2(in[17], in[15], cospi_15_64, cospi_17_64, &step1[17],
  207. &step1[30]);
  208. highbd_butterfly_sse2(in[9], in[23], cospi_23_64, cospi_9_64, &step1[18],
  209. &step1[29]);
  210. highbd_butterfly_sse2(in[25], in[7], cospi_7_64, cospi_25_64, &step1[19],
  211. &step1[28]);
  212. highbd_butterfly_sse2(in[5], in[27], cospi_27_64, cospi_5_64, &step1[20],
  213. &step1[27]);
  214. highbd_butterfly_sse2(in[21], in[11], cospi_11_64, cospi_21_64, &step1[21],
  215. &step1[26]);
  216. highbd_butterfly_sse2(in[13], in[19], cospi_19_64, cospi_13_64, &step1[22],
  217. &step1[25]);
  218. highbd_butterfly_sse2(in[29], in[3], cospi_3_64, cospi_29_64, &step1[23],
  219. &step1[24]);
  220. // stage 2
  221. step2[16] = _mm_add_epi32(step1[16], step1[17]);
  222. step2[17] = _mm_sub_epi32(step1[16], step1[17]);
  223. step2[18] = _mm_sub_epi32(step1[18], step1[19]); // step2[18] = -step2[18]
  224. step2[19] = _mm_add_epi32(step1[18], step1[19]);
  225. step2[20] = _mm_add_epi32(step1[20], step1[21]);
  226. step2[21] = _mm_sub_epi32(step1[20], step1[21]);
  227. step2[22] = _mm_sub_epi32(step1[22], step1[23]); // step2[22] = -step2[22]
  228. step2[23] = _mm_add_epi32(step1[22], step1[23]);
  229. step2[24] = _mm_add_epi32(step1[25], step1[24]);
  230. step2[25] = _mm_sub_epi32(step1[25], step1[24]); // step2[25] = -step2[25]
  231. step2[26] = _mm_sub_epi32(step1[27], step1[26]);
  232. step2[27] = _mm_add_epi32(step1[27], step1[26]);
  233. step2[28] = _mm_add_epi32(step1[29], step1[28]);
  234. step2[29] = _mm_sub_epi32(step1[29], step1[28]); // step2[29] = -step2[29]
  235. step2[30] = _mm_sub_epi32(step1[31], step1[30]);
  236. step2[31] = _mm_add_epi32(step1[31], step1[30]);
  237. // stage 3
  238. step1[16] = step2[16];
  239. step1[31] = step2[31];
  240. highbd_butterfly_sse2(step2[30], step2[17], cospi_28_64, cospi_4_64,
  241. &step1[17], &step1[30]);
  242. highbd_butterfly_sse2(step2[18], step2[29], cospi_4_64, cospi_28_64,
  243. &step1[29], &step1[18]);
  244. step1[19] = step2[19];
  245. step1[20] = step2[20];
  246. highbd_butterfly_sse2(step2[26], step2[21], cospi_12_64, cospi_20_64,
  247. &step1[21], &step1[26]);
  248. highbd_butterfly_sse2(step2[22], step2[25], cospi_20_64, cospi_12_64,
  249. &step1[25], &step1[22]);
  250. step1[23] = step2[23];
  251. step1[24] = step2[24];
  252. step1[27] = step2[27];
  253. step1[28] = step2[28];
  254. highbd_idct32_4x32_quarter_3_4_stage_4_to_7(step1, out);
  255. }
  256. static void highbd_idct32_1024_4x32(__m128i *const io /*io[32]*/) {
  257. __m128i temp[32];
  258. highbd_idct32_1024_4x32_quarter_1_2(io, temp);
  259. highbd_idct32_1024_4x32_quarter_3_4(io, temp);
  260. // final stage
  261. highbd_add_sub_butterfly(temp, io, 32);
  262. }
  263. void vpx_highbd_idct32x32_1024_add_sse2(const tran_low_t *input, uint16_t *dest,
  264. int stride, int bd) {
  265. int i, j;
  266. if (bd == 8) {
  267. __m128i col[4][32], io[32];
  268. // rows
  269. for (i = 0; i < 4; i++) {
  270. highbd_load_pack_transpose_32bit_8x8(&input[0], 32, &io[0]);
  271. highbd_load_pack_transpose_32bit_8x8(&input[8], 32, &io[8]);
  272. highbd_load_pack_transpose_32bit_8x8(&input[16], 32, &io[16]);
  273. highbd_load_pack_transpose_32bit_8x8(&input[24], 32, &io[24]);
  274. idct32_1024_8x32(io, col[i]);
  275. input += 32 << 3;
  276. }
  277. // columns
  278. for (i = 0; i < 32; i += 8) {
  279. // Transpose 32x8 block to 8x32 block
  280. transpose_16bit_8x8(col[0] + i, io);
  281. transpose_16bit_8x8(col[1] + i, io + 8);
  282. transpose_16bit_8x8(col[2] + i, io + 16);
  283. transpose_16bit_8x8(col[3] + i, io + 24);
  284. idct32_1024_8x32(io, io);
  285. for (j = 0; j < 32; ++j) {
  286. highbd_write_buffer_8(dest + j * stride, io[j], bd);
  287. }
  288. dest += 8;
  289. }
  290. } else {
  291. __m128i all[8][32], out[32], *in;
  292. for (i = 0; i < 8; i++) {
  293. in = all[i];
  294. highbd_load_transpose_32bit_8x4(&input[0], 32, &in[0]);
  295. highbd_load_transpose_32bit_8x4(&input[8], 32, &in[8]);
  296. highbd_load_transpose_32bit_8x4(&input[16], 32, &in[16]);
  297. highbd_load_transpose_32bit_8x4(&input[24], 32, &in[24]);
  298. highbd_idct32_1024_4x32(in);
  299. input += 4 * 32;
  300. }
  301. for (i = 0; i < 32; i += 4) {
  302. transpose_32bit_4x4(all[0] + i, out + 0);
  303. transpose_32bit_4x4(all[1] + i, out + 4);
  304. transpose_32bit_4x4(all[2] + i, out + 8);
  305. transpose_32bit_4x4(all[3] + i, out + 12);
  306. transpose_32bit_4x4(all[4] + i, out + 16);
  307. transpose_32bit_4x4(all[5] + i, out + 20);
  308. transpose_32bit_4x4(all[6] + i, out + 24);
  309. transpose_32bit_4x4(all[7] + i, out + 28);
  310. highbd_idct32_1024_4x32(out);
  311. for (j = 0; j < 32; ++j) {
  312. highbd_write_buffer_4(dest + j * stride, out[j], bd);
  313. }
  314. dest += 4;
  315. }
  316. }
  317. }
  318. // -----------------------------------------------------------------------------
  319. // For each 4x32 block __m128i in[32],
  320. // Input with index, 0, 4, 8, 12
  321. // output pixels: 0-7 in __m128i out[32]
  322. static INLINE void highbd_idct32_135_4x32_quarter_1(
  323. const __m128i *const in /*in[32]*/, __m128i *const out /*out[8]*/) {
  324. __m128i step1[8], step2[8];
  325. // stage 3
  326. highbd_partial_butterfly_sse2(in[4], cospi_28_64, cospi_4_64, &step1[4],
  327. &step1[7]);
  328. highbd_partial_butterfly_neg_sse2(in[12], cospi_12_64, cospi_20_64, &step1[5],
  329. &step1[6]);
  330. // stage 4
  331. highbd_partial_butterfly_sse2(in[0], cospi_16_64, cospi_16_64, &step2[1],
  332. &step2[0]);
  333. highbd_partial_butterfly_sse2(in[8], cospi_24_64, cospi_8_64, &step2[2],
  334. &step2[3]);
  335. step2[4] = _mm_add_epi32(step1[4], step1[5]);
  336. step2[5] = _mm_sub_epi32(step1[4], step1[5]);
  337. step2[6] = _mm_sub_epi32(step1[7], step1[6]);
  338. step2[7] = _mm_add_epi32(step1[7], step1[6]);
  339. // stage 5
  340. step1[0] = _mm_add_epi32(step2[0], step2[3]);
  341. step1[1] = _mm_add_epi32(step2[1], step2[2]);
  342. step1[2] = _mm_sub_epi32(step2[1], step2[2]);
  343. step1[3] = _mm_sub_epi32(step2[0], step2[3]);
  344. step1[4] = step2[4];
  345. highbd_butterfly_sse2(step2[6], step2[5], cospi_16_64, cospi_16_64, &step1[5],
  346. &step1[6]);
  347. step1[7] = step2[7];
  348. // stage 6
  349. out[0] = _mm_add_epi32(step1[0], step1[7]);
  350. out[1] = _mm_add_epi32(step1[1], step1[6]);
  351. out[2] = _mm_add_epi32(step1[2], step1[5]);
  352. out[3] = _mm_add_epi32(step1[3], step1[4]);
  353. out[4] = _mm_sub_epi32(step1[3], step1[4]);
  354. out[5] = _mm_sub_epi32(step1[2], step1[5]);
  355. out[6] = _mm_sub_epi32(step1[1], step1[6]);
  356. out[7] = _mm_sub_epi32(step1[0], step1[7]);
  357. }
  358. // For each 4x32 block __m128i in[32],
  359. // Input with index, 2, 6, 10, 14
  360. // output pixels: 8-15 in __m128i out[32]
  361. static INLINE void highbd_idct32_135_4x32_quarter_2(
  362. const __m128i *in /*in[32]*/, __m128i *out /*out[16]*/) {
  363. __m128i step1[32], step2[32];
  364. // stage 2
  365. highbd_partial_butterfly_sse2(in[2], cospi_30_64, cospi_2_64, &step2[8],
  366. &step2[15]);
  367. highbd_partial_butterfly_neg_sse2(in[14], cospi_14_64, cospi_18_64, &step2[9],
  368. &step2[14]);
  369. highbd_partial_butterfly_sse2(in[10], cospi_22_64, cospi_10_64, &step2[10],
  370. &step2[13]);
  371. highbd_partial_butterfly_neg_sse2(in[6], cospi_6_64, cospi_26_64, &step2[11],
  372. &step2[12]);
  373. // stage 3
  374. step1[8] = _mm_add_epi32(step2[8], step2[9]);
  375. step1[9] = _mm_sub_epi32(step2[8], step2[9]);
  376. step1[14] = _mm_sub_epi32(step2[15], step2[14]);
  377. step1[15] = _mm_add_epi32(step2[15], step2[14]);
  378. step1[10] = _mm_sub_epi32(step2[10], step2[11]); // step1[10] = -step1[10]
  379. step1[11] = _mm_add_epi32(step2[10], step2[11]);
  380. step1[12] = _mm_add_epi32(step2[13], step2[12]);
  381. step1[13] = _mm_sub_epi32(step2[13], step2[12]); // step1[13] = -step1[13]
  382. highbd_idct32_4x32_quarter_2_stage_4_to_6(step1, out);
  383. }
  384. static INLINE void highbd_idct32_135_4x32_quarter_1_2(
  385. const __m128i *const in /*in[32]*/, __m128i *const out /*out[32]*/) {
  386. __m128i temp[16];
  387. highbd_idct32_135_4x32_quarter_1(in, temp);
  388. highbd_idct32_135_4x32_quarter_2(in, temp);
  389. // stage 7
  390. highbd_add_sub_butterfly(temp, out, 16);
  391. }
  392. // For each 4x32 block __m128i in[32],
  393. // Input with odd index,
  394. // 1, 3, 5, 7, 9, 11, 13, 15
  395. // output pixels: 16-23, 24-31 in __m128i out[32]
  396. static INLINE void highbd_idct32_135_4x32_quarter_3_4(
  397. const __m128i *const in /*in[32]*/, __m128i *const out /*out[32]*/) {
  398. __m128i step1[32], step2[32];
  399. // stage 1
  400. highbd_partial_butterfly_sse2(in[1], cospi_31_64, cospi_1_64, &step1[16],
  401. &step1[31]);
  402. highbd_partial_butterfly_neg_sse2(in[15], cospi_15_64, cospi_17_64,
  403. &step1[17], &step1[30]);
  404. highbd_partial_butterfly_sse2(in[9], cospi_23_64, cospi_9_64, &step1[18],
  405. &step1[29]);
  406. highbd_partial_butterfly_neg_sse2(in[7], cospi_7_64, cospi_25_64, &step1[19],
  407. &step1[28]);
  408. highbd_partial_butterfly_sse2(in[5], cospi_27_64, cospi_5_64, &step1[20],
  409. &step1[27]);
  410. highbd_partial_butterfly_neg_sse2(in[11], cospi_11_64, cospi_21_64,
  411. &step1[21], &step1[26]);
  412. highbd_partial_butterfly_sse2(in[13], cospi_19_64, cospi_13_64, &step1[22],
  413. &step1[25]);
  414. highbd_partial_butterfly_neg_sse2(in[3], cospi_3_64, cospi_29_64, &step1[23],
  415. &step1[24]);
  416. // stage 2
  417. step2[16] = _mm_add_epi32(step1[16], step1[17]);
  418. step2[17] = _mm_sub_epi32(step1[16], step1[17]);
  419. step2[18] = _mm_sub_epi32(step1[18], step1[19]); // step2[18] = -step2[18]
  420. step2[19] = _mm_add_epi32(step1[18], step1[19]);
  421. step2[20] = _mm_add_epi32(step1[20], step1[21]);
  422. step2[21] = _mm_sub_epi32(step1[20], step1[21]);
  423. step2[22] = _mm_sub_epi32(step1[22], step1[23]); // step2[22] = -step2[22]
  424. step2[23] = _mm_add_epi32(step1[22], step1[23]);
  425. step2[24] = _mm_add_epi32(step1[25], step1[24]);
  426. step2[25] = _mm_sub_epi32(step1[25], step1[24]); // step2[25] = -step2[25]
  427. step2[26] = _mm_sub_epi32(step1[27], step1[26]);
  428. step2[27] = _mm_add_epi32(step1[27], step1[26]);
  429. step2[28] = _mm_add_epi32(step1[29], step1[28]);
  430. step2[29] = _mm_sub_epi32(step1[29], step1[28]); // step2[29] = -step2[29]
  431. step2[30] = _mm_sub_epi32(step1[31], step1[30]);
  432. step2[31] = _mm_add_epi32(step1[31], step1[30]);
  433. // stage 3
  434. step1[16] = step2[16];
  435. step1[31] = step2[31];
  436. highbd_butterfly_sse2(step2[30], step2[17], cospi_28_64, cospi_4_64,
  437. &step1[17], &step1[30]);
  438. highbd_butterfly_sse2(step2[18], step2[29], cospi_4_64, cospi_28_64,
  439. &step1[29], &step1[18]);
  440. step1[19] = step2[19];
  441. step1[20] = step2[20];
  442. highbd_butterfly_sse2(step2[26], step2[21], cospi_12_64, cospi_20_64,
  443. &step1[21], &step1[26]);
  444. highbd_butterfly_sse2(step2[22], step2[25], cospi_20_64, cospi_12_64,
  445. &step1[25], &step1[22]);
  446. step1[23] = step2[23];
  447. step1[24] = step2[24];
  448. step1[27] = step2[27];
  449. step1[28] = step2[28];
  450. highbd_idct32_4x32_quarter_3_4_stage_4_to_7(step1, out);
  451. }
  452. static void highbd_idct32_135_4x32(__m128i *const io /*io[32]*/) {
  453. __m128i temp[32];
  454. highbd_idct32_135_4x32_quarter_1_2(io, temp);
  455. highbd_idct32_135_4x32_quarter_3_4(io, temp);
  456. // final stage
  457. highbd_add_sub_butterfly(temp, io, 32);
  458. }
  459. void vpx_highbd_idct32x32_135_add_sse2(const tran_low_t *input, uint16_t *dest,
  460. int stride, int bd) {
  461. int i, j;
  462. if (bd == 8) {
  463. __m128i col[2][32], in[32], out[32];
  464. for (i = 16; i < 32; i++) {
  465. in[i] = _mm_setzero_si128();
  466. }
  467. // rows
  468. for (i = 0; i < 2; i++) {
  469. highbd_load_pack_transpose_32bit_8x8(&input[0], 32, &in[0]);
  470. highbd_load_pack_transpose_32bit_8x8(&input[8], 32, &in[8]);
  471. idct32_1024_8x32(in, col[i]);
  472. input += 32 << 3;
  473. }
  474. // columns
  475. for (i = 0; i < 32; i += 8) {
  476. transpose_16bit_8x8(col[0] + i, in);
  477. transpose_16bit_8x8(col[1] + i, in + 8);
  478. idct32_1024_8x32(in, out);
  479. for (j = 0; j < 32; ++j) {
  480. highbd_write_buffer_8(dest + j * stride, out[j], bd);
  481. }
  482. dest += 8;
  483. }
  484. } else {
  485. __m128i all[8][32], out[32], *in;
  486. for (i = 0; i < 4; i++) {
  487. in = all[i];
  488. highbd_load_transpose_32bit_8x4(&input[0], 32, &in[0]);
  489. highbd_load_transpose_32bit_8x4(&input[8], 32, &in[8]);
  490. highbd_idct32_135_4x32(in);
  491. input += 4 * 32;
  492. }
  493. for (i = 0; i < 32; i += 4) {
  494. transpose_32bit_4x4(all[0] + i, out + 0);
  495. transpose_32bit_4x4(all[1] + i, out + 4);
  496. transpose_32bit_4x4(all[2] + i, out + 8);
  497. transpose_32bit_4x4(all[3] + i, out + 12);
  498. highbd_idct32_135_4x32(out);
  499. for (j = 0; j < 32; ++j) {
  500. highbd_write_buffer_4(dest + j * stride, out[j], bd);
  501. }
  502. dest += 4;
  503. }
  504. }
  505. }
  506. // -----------------------------------------------------------------------------
  507. // For each 4x32 block __m128i in[32],
  508. // Input with index, 0, 4
  509. // output pixels: 0-7 in __m128i out[32]
  510. static INLINE void highbd_idct32_34_4x32_quarter_1(
  511. const __m128i *const in /*in[32]*/, __m128i *const out /*out[8]*/) {
  512. __m128i step1[8], step2[8];
  513. // stage 3
  514. highbd_partial_butterfly_sse2(in[4], cospi_28_64, cospi_4_64, &step1[4],
  515. &step1[7]);
  516. // stage 4
  517. highbd_partial_butterfly_sse2(in[0], cospi_16_64, cospi_16_64, &step2[1],
  518. &step2[0]);
  519. step2[4] = step1[4];
  520. step2[5] = step1[4];
  521. step2[6] = step1[7];
  522. step2[7] = step1[7];
  523. // stage 5
  524. step1[0] = step2[0];
  525. step1[1] = step2[1];
  526. step1[2] = step2[1];
  527. step1[3] = step2[0];
  528. step1[4] = step2[4];
  529. highbd_butterfly_sse2(step2[6], step2[5], cospi_16_64, cospi_16_64, &step1[5],
  530. &step1[6]);
  531. step1[7] = step2[7];
  532. // stage 6
  533. out[0] = _mm_add_epi32(step1[0], step1[7]);
  534. out[1] = _mm_add_epi32(step1[1], step1[6]);
  535. out[2] = _mm_add_epi32(step1[2], step1[5]);
  536. out[3] = _mm_add_epi32(step1[3], step1[4]);
  537. out[4] = _mm_sub_epi32(step1[3], step1[4]);
  538. out[5] = _mm_sub_epi32(step1[2], step1[5]);
  539. out[6] = _mm_sub_epi32(step1[1], step1[6]);
  540. out[7] = _mm_sub_epi32(step1[0], step1[7]);
  541. }
  542. // For each 4x32 block __m128i in[32],
  543. // Input with index, 2, 6
  544. // output pixels: 8-15 in __m128i out[32]
  545. static INLINE void highbd_idct32_34_4x32_quarter_2(const __m128i *in /*in[32]*/,
  546. __m128i *out /*out[16]*/) {
  547. __m128i step1[32], step2[32];
  548. // stage 2
  549. highbd_partial_butterfly_sse2(in[2], cospi_30_64, cospi_2_64, &step2[8],
  550. &step2[15]);
  551. highbd_partial_butterfly_neg_sse2(in[6], cospi_6_64, cospi_26_64, &step2[11],
  552. &step2[12]);
  553. // stage 3
  554. step1[8] = step2[8];
  555. step1[9] = step2[8];
  556. step1[14] = step2[15];
  557. step1[15] = step2[15];
  558. step1[10] = step2[11];
  559. step1[11] = step2[11];
  560. step1[12] = step2[12];
  561. step1[13] = step2[12];
  562. step1[10] =
  563. _mm_sub_epi32(_mm_setzero_si128(), step1[10]); // step1[10] = -step1[10]
  564. step1[13] =
  565. _mm_sub_epi32(_mm_setzero_si128(), step1[13]); // step1[13] = -step1[13]
  566. highbd_idct32_4x32_quarter_2_stage_4_to_6(step1, out);
  567. }
  568. static INLINE void highbd_idct32_34_4x32_quarter_1_2(
  569. const __m128i *const in /*in[32]*/, __m128i *const out /*out[32]*/) {
  570. __m128i temp[16];
  571. highbd_idct32_34_4x32_quarter_1(in, temp);
  572. highbd_idct32_34_4x32_quarter_2(in, temp);
  573. // stage 7
  574. highbd_add_sub_butterfly(temp, out, 16);
  575. }
  576. // For each 4x32 block __m128i in[32],
  577. // Input with odd index,
  578. // 1, 3, 5, 7
  579. // output pixels: 16-23, 24-31 in __m128i out[32]
  580. static INLINE void highbd_idct32_34_4x32_quarter_3_4(
  581. const __m128i *const in /*in[32]*/, __m128i *const out /*out[32]*/) {
  582. __m128i step1[32], step2[32];
  583. // stage 1
  584. highbd_partial_butterfly_sse2(in[1], cospi_31_64, cospi_1_64, &step1[16],
  585. &step1[31]);
  586. highbd_partial_butterfly_neg_sse2(in[7], cospi_7_64, cospi_25_64, &step1[19],
  587. &step1[28]);
  588. highbd_partial_butterfly_sse2(in[5], cospi_27_64, cospi_5_64, &step1[20],
  589. &step1[27]);
  590. highbd_partial_butterfly_neg_sse2(in[3], cospi_3_64, cospi_29_64, &step1[23],
  591. &step1[24]);
  592. // stage 2
  593. step2[16] = step1[16];
  594. step2[17] = step1[16];
  595. step2[18] = step1[19];
  596. step2[19] = step1[19];
  597. step2[20] = step1[20];
  598. step2[21] = step1[20];
  599. step2[22] = step1[23];
  600. step2[23] = step1[23];
  601. step2[24] = step1[24];
  602. step2[25] = step1[24];
  603. step2[26] = step1[27];
  604. step2[27] = step1[27];
  605. step2[28] = step1[28];
  606. step2[29] = step1[28];
  607. step2[30] = step1[31];
  608. step2[31] = step1[31];
  609. // stage 3
  610. step2[18] =
  611. _mm_sub_epi32(_mm_setzero_si128(), step2[18]); // step2[18] = -step2[18]
  612. step2[22] =
  613. _mm_sub_epi32(_mm_setzero_si128(), step2[22]); // step2[22] = -step2[22]
  614. step2[25] =
  615. _mm_sub_epi32(_mm_setzero_si128(), step2[25]); // step2[25] = -step2[25]
  616. step2[29] =
  617. _mm_sub_epi32(_mm_setzero_si128(), step2[29]); // step2[29] = -step2[29]
  618. step1[16] = step2[16];
  619. step1[31] = step2[31];
  620. highbd_butterfly_sse2(step2[30], step2[17], cospi_28_64, cospi_4_64,
  621. &step1[17], &step1[30]);
  622. highbd_butterfly_sse2(step2[18], step2[29], cospi_4_64, cospi_28_64,
  623. &step1[29], &step1[18]);
  624. step1[19] = step2[19];
  625. step1[20] = step2[20];
  626. highbd_butterfly_sse2(step2[26], step2[21], cospi_12_64, cospi_20_64,
  627. &step1[21], &step1[26]);
  628. highbd_butterfly_sse2(step2[22], step2[25], cospi_20_64, cospi_12_64,
  629. &step1[25], &step1[22]);
  630. step1[23] = step2[23];
  631. step1[24] = step2[24];
  632. step1[27] = step2[27];
  633. step1[28] = step2[28];
  634. highbd_idct32_4x32_quarter_3_4_stage_4_to_7(step1, out);
  635. }
  636. static void highbd_idct32_34_4x32(__m128i *const io /*io[32]*/) {
  637. __m128i temp[32];
  638. highbd_idct32_34_4x32_quarter_1_2(io, temp);
  639. highbd_idct32_34_4x32_quarter_3_4(io, temp);
  640. // final stage
  641. highbd_add_sub_butterfly(temp, io, 32);
  642. }
  643. void vpx_highbd_idct32x32_34_add_sse2(const tran_low_t *input, uint16_t *dest,
  644. int stride, int bd) {
  645. int i, j;
  646. if (bd == 8) {
  647. __m128i col[32], in[32], out[32];
  648. // rows
  649. highbd_load_pack_transpose_32bit_8x8(&input[0], 32, &in[0]);
  650. idct32_34_8x32_sse2(in, col);
  651. // columns
  652. for (i = 0; i < 32; i += 8) {
  653. transpose_16bit_8x8(col + i, in);
  654. idct32_34_8x32_sse2(in, out);
  655. for (j = 0; j < 32; ++j) {
  656. highbd_write_buffer_8(dest + j * stride, out[j], bd);
  657. }
  658. dest += 8;
  659. }
  660. } else {
  661. __m128i all[8][32], out[32], *in;
  662. for (i = 0; i < 4; i++) {
  663. in = all[i];
  664. highbd_load_transpose_32bit_8x4(&input[0], 32, &in[0]);
  665. highbd_load_transpose_32bit_8x4(&input[8], 32, &in[8]);
  666. highbd_idct32_34_4x32(in);
  667. input += 4 * 32;
  668. }
  669. for (i = 0; i < 32; i += 4) {
  670. transpose_32bit_4x4(all[0] + i, out + 0);
  671. transpose_32bit_4x4(all[1] + i, out + 4);
  672. transpose_32bit_4x4(all[2] + i, out + 8);
  673. transpose_32bit_4x4(all[3] + i, out + 12);
  674. highbd_idct32_34_4x32(out);
  675. for (j = 0; j < 32; ++j) {
  676. highbd_write_buffer_4(dest + j * stride, out[j], bd);
  677. }
  678. dest += 4;
  679. }
  680. }
  681. }
  682. void vpx_highbd_idct32x32_1_add_sse2(const tran_low_t *input, uint16_t *dest,
  683. int stride, int bd) {
  684. highbd_idct_1_add_kernel(input, dest, stride, bd, 32);
  685. }