2
0

highbd_idct16x16_add_sse4.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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/transpose_sse2.h"
  16. #include "vpx_dsp/x86/txfm_common_sse2.h"
  17. static INLINE void highbd_idct16_4col_stage5(const __m128i *const in,
  18. __m128i *const out) {
  19. // stage 5
  20. out[0] = _mm_add_epi32(in[0], in[3]);
  21. out[1] = _mm_add_epi32(in[1], in[2]);
  22. out[2] = _mm_sub_epi32(in[1], in[2]);
  23. out[3] = _mm_sub_epi32(in[0], in[3]);
  24. highbd_butterfly_cospi16_sse4_1(in[6], in[5], &out[6], &out[5]);
  25. out[8] = _mm_add_epi32(in[8], in[11]);
  26. out[9] = _mm_add_epi32(in[9], in[10]);
  27. out[10] = _mm_sub_epi32(in[9], in[10]);
  28. out[11] = _mm_sub_epi32(in[8], in[11]);
  29. out[12] = _mm_sub_epi32(in[15], in[12]);
  30. out[13] = _mm_sub_epi32(in[14], in[13]);
  31. out[14] = _mm_add_epi32(in[14], in[13]);
  32. out[15] = _mm_add_epi32(in[15], in[12]);
  33. }
  34. static INLINE void highbd_idct16_4col_stage6(const __m128i *const in,
  35. __m128i *const out) {
  36. out[0] = _mm_add_epi32(in[0], in[7]);
  37. out[1] = _mm_add_epi32(in[1], in[6]);
  38. out[2] = _mm_add_epi32(in[2], in[5]);
  39. out[3] = _mm_add_epi32(in[3], in[4]);
  40. out[4] = _mm_sub_epi32(in[3], in[4]);
  41. out[5] = _mm_sub_epi32(in[2], in[5]);
  42. out[6] = _mm_sub_epi32(in[1], in[6]);
  43. out[7] = _mm_sub_epi32(in[0], in[7]);
  44. out[8] = in[8];
  45. out[9] = in[9];
  46. highbd_butterfly_cospi16_sse4_1(in[13], in[10], &out[13], &out[10]);
  47. highbd_butterfly_cospi16_sse4_1(in[12], in[11], &out[12], &out[11]);
  48. out[14] = in[14];
  49. out[15] = in[15];
  50. }
  51. void vpx_highbd_idct16_4col_sse4_1(__m128i *const io /*io[16]*/) {
  52. __m128i step1[16], step2[16];
  53. // stage 2
  54. highbd_butterfly_sse4_1(io[1], io[15], cospi_30_64, cospi_2_64, &step2[8],
  55. &step2[15]);
  56. highbd_butterfly_sse4_1(io[9], io[7], cospi_14_64, cospi_18_64, &step2[9],
  57. &step2[14]);
  58. highbd_butterfly_sse4_1(io[5], io[11], cospi_22_64, cospi_10_64, &step2[10],
  59. &step2[13]);
  60. highbd_butterfly_sse4_1(io[13], io[3], cospi_6_64, cospi_26_64, &step2[11],
  61. &step2[12]);
  62. // stage 3
  63. highbd_butterfly_sse4_1(io[2], io[14], cospi_28_64, cospi_4_64, &step1[4],
  64. &step1[7]);
  65. highbd_butterfly_sse4_1(io[10], io[6], cospi_12_64, cospi_20_64, &step1[5],
  66. &step1[6]);
  67. step1[8] = _mm_add_epi32(step2[8], step2[9]);
  68. step1[9] = _mm_sub_epi32(step2[8], step2[9]);
  69. step1[10] = _mm_sub_epi32(step2[11], step2[10]);
  70. step1[11] = _mm_add_epi32(step2[11], step2[10]);
  71. step1[12] = _mm_add_epi32(step2[12], step2[13]);
  72. step1[13] = _mm_sub_epi32(step2[12], step2[13]);
  73. step1[14] = _mm_sub_epi32(step2[15], step2[14]);
  74. step1[15] = _mm_add_epi32(step2[15], step2[14]);
  75. // stage 4
  76. highbd_butterfly_cospi16_sse4_1(io[0], io[8], &step2[0], &step2[1]);
  77. highbd_butterfly_sse4_1(io[4], io[12], cospi_24_64, cospi_8_64, &step2[2],
  78. &step2[3]);
  79. highbd_butterfly_sse4_1(step1[14], step1[9], cospi_24_64, cospi_8_64,
  80. &step2[9], &step2[14]);
  81. highbd_butterfly_sse4_1(step1[10], step1[13], -cospi_8_64, -cospi_24_64,
  82. &step2[13], &step2[10]);
  83. step2[5] = _mm_sub_epi32(step1[4], step1[5]);
  84. step1[4] = _mm_add_epi32(step1[4], step1[5]);
  85. step2[6] = _mm_sub_epi32(step1[7], step1[6]);
  86. step1[7] = _mm_add_epi32(step1[7], step1[6]);
  87. step2[8] = step1[8];
  88. step2[11] = step1[11];
  89. step2[12] = step1[12];
  90. step2[15] = step1[15];
  91. highbd_idct16_4col_stage5(step2, step1);
  92. highbd_idct16_4col_stage6(step1, step2);
  93. highbd_idct16_4col_stage7(step2, io);
  94. }
  95. static INLINE void highbd_idct16x16_38_4col(__m128i *const io /*io[16]*/) {
  96. __m128i step1[16], step2[16];
  97. __m128i temp1[2];
  98. // stage 2
  99. highbd_partial_butterfly_sse4_1(io[1], cospi_30_64, cospi_2_64, &step2[8],
  100. &step2[15]);
  101. highbd_partial_butterfly_sse4_1(io[7], -cospi_18_64, cospi_14_64, &step2[9],
  102. &step2[14]);
  103. highbd_partial_butterfly_sse4_1(io[5], cospi_22_64, cospi_10_64, &step2[10],
  104. &step2[13]);
  105. highbd_partial_butterfly_sse4_1(io[3], -cospi_26_64, cospi_6_64, &step2[11],
  106. &step2[12]);
  107. // stage 3
  108. highbd_partial_butterfly_sse4_1(io[2], cospi_28_64, cospi_4_64, &step1[4],
  109. &step1[7]);
  110. highbd_partial_butterfly_sse4_1(io[6], -cospi_20_64, cospi_12_64, &step1[5],
  111. &step1[6]);
  112. step1[8] = _mm_add_epi32(step2[8], step2[9]);
  113. step1[9] = _mm_sub_epi32(step2[8], step2[9]);
  114. step1[10] = _mm_sub_epi32(step2[11], step2[10]);
  115. step1[11] = _mm_add_epi32(step2[11], step2[10]);
  116. step1[12] = _mm_add_epi32(step2[12], step2[13]);
  117. step1[13] = _mm_sub_epi32(step2[12], step2[13]);
  118. step1[14] = _mm_sub_epi32(step2[15], step2[14]);
  119. step1[15] = _mm_add_epi32(step2[15], step2[14]);
  120. // stage 4
  121. extend_64bit(io[0], temp1);
  122. step2[0] = multiplication_round_shift_sse4_1(temp1, cospi_16_64);
  123. step2[1] = step2[0];
  124. highbd_partial_butterfly_sse4_1(io[4], cospi_24_64, cospi_8_64, &step2[2],
  125. &step2[3]);
  126. highbd_butterfly_sse4_1(step1[14], step1[9], cospi_24_64, cospi_8_64,
  127. &step2[9], &step2[14]);
  128. highbd_butterfly_sse4_1(step1[10], step1[13], -cospi_8_64, -cospi_24_64,
  129. &step2[13], &step2[10]);
  130. step2[5] = _mm_sub_epi32(step1[4], step1[5]);
  131. step1[4] = _mm_add_epi32(step1[4], step1[5]);
  132. step2[6] = _mm_sub_epi32(step1[7], step1[6]);
  133. step1[7] = _mm_add_epi32(step1[7], step1[6]);
  134. step2[8] = step1[8];
  135. step2[11] = step1[11];
  136. step2[12] = step1[12];
  137. step2[15] = step1[15];
  138. highbd_idct16_4col_stage5(step2, step1);
  139. highbd_idct16_4col_stage6(step1, step2);
  140. highbd_idct16_4col_stage7(step2, io);
  141. }
  142. static INLINE void highbd_idct16x16_10_4col(__m128i *const io /*io[16]*/) {
  143. __m128i step1[16], step2[16];
  144. __m128i temp[2];
  145. // stage 2
  146. highbd_partial_butterfly_sse4_1(io[1], cospi_30_64, cospi_2_64, &step2[8],
  147. &step2[15]);
  148. highbd_partial_butterfly_sse4_1(io[3], -cospi_26_64, cospi_6_64, &step2[11],
  149. &step2[12]);
  150. // stage 3
  151. highbd_partial_butterfly_sse4_1(io[2], cospi_28_64, cospi_4_64, &step1[4],
  152. &step1[7]);
  153. step1[8] = step2[8];
  154. step1[9] = step2[8];
  155. step1[10] = step2[11];
  156. step1[11] = step2[11];
  157. step1[12] = step2[12];
  158. step1[13] = step2[12];
  159. step1[14] = step2[15];
  160. step1[15] = step2[15];
  161. // stage 4
  162. extend_64bit(io[0], temp);
  163. step2[0] = multiplication_round_shift_sse4_1(temp, cospi_16_64);
  164. step2[1] = step2[0];
  165. step2[2] = _mm_setzero_si128();
  166. step2[3] = _mm_setzero_si128();
  167. highbd_butterfly_sse4_1(step1[14], step1[9], cospi_24_64, cospi_8_64,
  168. &step2[9], &step2[14]);
  169. highbd_butterfly_sse4_1(step1[10], step1[13], -cospi_8_64, -cospi_24_64,
  170. &step2[13], &step2[10]);
  171. step2[5] = step1[4];
  172. step2[6] = step1[7];
  173. step2[8] = step1[8];
  174. step2[11] = step1[11];
  175. step2[12] = step1[12];
  176. step2[15] = step1[15];
  177. highbd_idct16_4col_stage5(step2, step1);
  178. highbd_idct16_4col_stage6(step1, step2);
  179. highbd_idct16_4col_stage7(step2, io);
  180. }
  181. void vpx_highbd_idct16x16_256_add_sse4_1(const tran_low_t *input,
  182. uint16_t *dest, int stride, int bd) {
  183. int i;
  184. __m128i out[16], *in;
  185. if (bd == 8) {
  186. __m128i l[16], r[16];
  187. in = l;
  188. for (i = 0; i < 2; i++) {
  189. highbd_load_pack_transpose_32bit_8x8(&input[0], 16, &in[0]);
  190. highbd_load_pack_transpose_32bit_8x8(&input[8], 16, &in[8]);
  191. idct16_8col(in, in);
  192. in = r;
  193. input += 128;
  194. }
  195. for (i = 0; i < 16; i += 8) {
  196. int j;
  197. transpose_16bit_8x8(l + i, out);
  198. transpose_16bit_8x8(r + i, out + 8);
  199. idct16_8col(out, out);
  200. for (j = 0; j < 16; ++j) {
  201. highbd_write_buffer_8(dest + j * stride, out[j], bd);
  202. }
  203. dest += 8;
  204. }
  205. } else {
  206. __m128i all[4][16];
  207. for (i = 0; i < 4; i++) {
  208. in = all[i];
  209. highbd_load_transpose_32bit_8x4(&input[0], 16, &in[0]);
  210. highbd_load_transpose_32bit_8x4(&input[8], 16, &in[8]);
  211. vpx_highbd_idct16_4col_sse4_1(in);
  212. input += 4 * 16;
  213. }
  214. for (i = 0; i < 16; i += 4) {
  215. int j;
  216. transpose_32bit_4x4(all[0] + i, out + 0);
  217. transpose_32bit_4x4(all[1] + i, out + 4);
  218. transpose_32bit_4x4(all[2] + i, out + 8);
  219. transpose_32bit_4x4(all[3] + i, out + 12);
  220. vpx_highbd_idct16_4col_sse4_1(out);
  221. for (j = 0; j < 16; ++j) {
  222. highbd_write_buffer_4(dest + j * stride, out[j], bd);
  223. }
  224. dest += 4;
  225. }
  226. }
  227. }
  228. void vpx_highbd_idct16x16_38_add_sse4_1(const tran_low_t *input, uint16_t *dest,
  229. int stride, int bd) {
  230. int i;
  231. __m128i out[16];
  232. if (bd == 8) {
  233. __m128i in[16], temp[16];
  234. highbd_load_pack_transpose_32bit_8x8(&input[0], 16, &in[0]);
  235. for (i = 8; i < 16; i++) {
  236. in[i] = _mm_setzero_si128();
  237. }
  238. idct16_8col(in, temp);
  239. for (i = 0; i < 16; i += 8) {
  240. int j;
  241. transpose_16bit_8x8(temp + i, in);
  242. idct16_8col(in, out);
  243. for (j = 0; j < 16; ++j) {
  244. highbd_write_buffer_8(dest + j * stride, out[j], bd);
  245. }
  246. dest += 8;
  247. }
  248. } else {
  249. __m128i all[2][16], *in;
  250. for (i = 0; i < 2; i++) {
  251. in = all[i];
  252. highbd_load_transpose_32bit_8x4(input, 16, in);
  253. highbd_idct16x16_38_4col(in);
  254. input += 4 * 16;
  255. }
  256. for (i = 0; i < 16; i += 4) {
  257. int j;
  258. transpose_32bit_4x4(all[0] + i, out + 0);
  259. transpose_32bit_4x4(all[1] + i, out + 4);
  260. highbd_idct16x16_38_4col(out);
  261. for (j = 0; j < 16; ++j) {
  262. highbd_write_buffer_4(dest + j * stride, out[j], bd);
  263. }
  264. dest += 4;
  265. }
  266. }
  267. }
  268. void vpx_highbd_idct16x16_10_add_sse4_1(const tran_low_t *input, uint16_t *dest,
  269. int stride, int bd) {
  270. int i;
  271. __m128i out[16];
  272. if (bd == 8) {
  273. __m128i in[16], l[16];
  274. in[0] = load_pack_8_32bit(input + 0 * 16);
  275. in[1] = load_pack_8_32bit(input + 1 * 16);
  276. in[2] = load_pack_8_32bit(input + 2 * 16);
  277. in[3] = load_pack_8_32bit(input + 3 * 16);
  278. idct16x16_10_pass1(in, l);
  279. for (i = 0; i < 16; i += 8) {
  280. int j;
  281. idct16x16_10_pass2(l + i, in);
  282. for (j = 0; j < 16; ++j) {
  283. highbd_write_buffer_8(dest + j * stride, in[j], bd);
  284. }
  285. dest += 8;
  286. }
  287. } else {
  288. __m128i all[2][16], *in;
  289. for (i = 0; i < 2; i++) {
  290. in = all[i];
  291. highbd_load_transpose_32bit_4x4(input, 16, in);
  292. highbd_idct16x16_10_4col(in);
  293. input += 4 * 16;
  294. }
  295. for (i = 0; i < 16; i += 4) {
  296. int j;
  297. transpose_32bit_4x4(&all[0][i], out);
  298. highbd_idct16x16_10_4col(out);
  299. for (j = 0; j < 16; ++j) {
  300. highbd_write_buffer_4(dest + j * stride, out[j], bd);
  301. }
  302. dest += 4;
  303. }
  304. }
  305. }