highbd_idct32x32_add_sse4.c 27 KB

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