vp9_dct_intrin_sse2.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  1. /*
  2. * Copyright (c) 2012 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 <assert.h>
  11. #include <emmintrin.h> // SSE2
  12. #include "./vp9_rtcd.h"
  13. #include "./vpx_dsp_rtcd.h"
  14. #include "vpx_dsp/txfm_common.h"
  15. #include "vpx_dsp/x86/bitdepth_conversion_sse2.h"
  16. #include "vpx_dsp/x86/fwd_txfm_sse2.h"
  17. #include "vpx_dsp/x86/transpose_sse2.h"
  18. #include "vpx_dsp/x86/txfm_common_sse2.h"
  19. #include "vpx_ports/mem.h"
  20. static INLINE void load_buffer_4x4(const int16_t *input, __m128i *in,
  21. int stride) {
  22. const __m128i k__nonzero_bias_a = _mm_setr_epi16(0, 1, 1, 1, 1, 1, 1, 1);
  23. const __m128i k__nonzero_bias_b = _mm_setr_epi16(1, 0, 0, 0, 0, 0, 0, 0);
  24. __m128i mask;
  25. in[0] = _mm_loadl_epi64((const __m128i *)(input + 0 * stride));
  26. in[1] = _mm_loadl_epi64((const __m128i *)(input + 1 * stride));
  27. in[2] = _mm_loadl_epi64((const __m128i *)(input + 2 * stride));
  28. in[3] = _mm_loadl_epi64((const __m128i *)(input + 3 * stride));
  29. in[0] = _mm_slli_epi16(in[0], 4);
  30. in[1] = _mm_slli_epi16(in[1], 4);
  31. in[2] = _mm_slli_epi16(in[2], 4);
  32. in[3] = _mm_slli_epi16(in[3], 4);
  33. mask = _mm_cmpeq_epi16(in[0], k__nonzero_bias_a);
  34. in[0] = _mm_add_epi16(in[0], mask);
  35. in[0] = _mm_add_epi16(in[0], k__nonzero_bias_b);
  36. }
  37. static INLINE void write_buffer_4x4(tran_low_t *output, __m128i *res) {
  38. const __m128i kOne = _mm_set1_epi16(1);
  39. __m128i in01 = _mm_unpacklo_epi64(res[0], res[1]);
  40. __m128i in23 = _mm_unpacklo_epi64(res[2], res[3]);
  41. __m128i out01 = _mm_add_epi16(in01, kOne);
  42. __m128i out23 = _mm_add_epi16(in23, kOne);
  43. out01 = _mm_srai_epi16(out01, 2);
  44. out23 = _mm_srai_epi16(out23, 2);
  45. store_output(&out01, (output + 0 * 8));
  46. store_output(&out23, (output + 1 * 8));
  47. }
  48. static INLINE void transpose_4x4(__m128i *res) {
  49. // Combine and transpose
  50. // 00 01 02 03 20 21 22 23
  51. // 10 11 12 13 30 31 32 33
  52. const __m128i tr0_0 = _mm_unpacklo_epi16(res[0], res[1]);
  53. const __m128i tr0_1 = _mm_unpackhi_epi16(res[0], res[1]);
  54. // 00 10 01 11 02 12 03 13
  55. // 20 30 21 31 22 32 23 33
  56. res[0] = _mm_unpacklo_epi32(tr0_0, tr0_1);
  57. res[2] = _mm_unpackhi_epi32(tr0_0, tr0_1);
  58. // 00 10 20 30 01 11 21 31
  59. // 02 12 22 32 03 13 23 33
  60. // only use the first 4 16-bit integers
  61. res[1] = _mm_unpackhi_epi64(res[0], res[0]);
  62. res[3] = _mm_unpackhi_epi64(res[2], res[2]);
  63. }
  64. static void fdct4_sse2(__m128i *in) {
  65. const __m128i k__cospi_p16_p16 = _mm_set1_epi16(cospi_16_64);
  66. const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
  67. const __m128i k__cospi_p08_p24 = pair_set_epi16(cospi_8_64, cospi_24_64);
  68. const __m128i k__cospi_p24_m08 = pair_set_epi16(cospi_24_64, -cospi_8_64);
  69. const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
  70. __m128i u[4], v[4];
  71. u[0] = _mm_unpacklo_epi16(in[0], in[1]);
  72. u[1] = _mm_unpacklo_epi16(in[3], in[2]);
  73. v[0] = _mm_add_epi16(u[0], u[1]);
  74. v[1] = _mm_sub_epi16(u[0], u[1]);
  75. u[0] = _mm_madd_epi16(v[0], k__cospi_p16_p16); // 0
  76. u[1] = _mm_madd_epi16(v[0], k__cospi_p16_m16); // 2
  77. u[2] = _mm_madd_epi16(v[1], k__cospi_p08_p24); // 1
  78. u[3] = _mm_madd_epi16(v[1], k__cospi_p24_m08); // 3
  79. v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
  80. v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
  81. v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
  82. v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
  83. u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
  84. u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
  85. u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
  86. u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
  87. in[0] = _mm_packs_epi32(u[0], u[1]);
  88. in[1] = _mm_packs_epi32(u[2], u[3]);
  89. transpose_4x4(in);
  90. }
  91. static void fadst4_sse2(__m128i *in) {
  92. const __m128i k__sinpi_p01_p02 = pair_set_epi16(sinpi_1_9, sinpi_2_9);
  93. const __m128i k__sinpi_p04_m01 = pair_set_epi16(sinpi_4_9, -sinpi_1_9);
  94. const __m128i k__sinpi_p03_p04 = pair_set_epi16(sinpi_3_9, sinpi_4_9);
  95. const __m128i k__sinpi_m03_p02 = pair_set_epi16(-sinpi_3_9, sinpi_2_9);
  96. const __m128i k__sinpi_p03_p03 = _mm_set1_epi16((int16_t)sinpi_3_9);
  97. const __m128i kZero = _mm_set1_epi16(0);
  98. const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
  99. __m128i u[8], v[8];
  100. __m128i in7 = _mm_add_epi16(in[0], in[1]);
  101. u[0] = _mm_unpacklo_epi16(in[0], in[1]);
  102. u[1] = _mm_unpacklo_epi16(in[2], in[3]);
  103. u[2] = _mm_unpacklo_epi16(in7, kZero);
  104. u[3] = _mm_unpacklo_epi16(in[2], kZero);
  105. u[4] = _mm_unpacklo_epi16(in[3], kZero);
  106. v[0] = _mm_madd_epi16(u[0], k__sinpi_p01_p02); // s0 + s2
  107. v[1] = _mm_madd_epi16(u[1], k__sinpi_p03_p04); // s4 + s5
  108. v[2] = _mm_madd_epi16(u[2], k__sinpi_p03_p03); // x1
  109. v[3] = _mm_madd_epi16(u[0], k__sinpi_p04_m01); // s1 - s3
  110. v[4] = _mm_madd_epi16(u[1], k__sinpi_m03_p02); // -s4 + s6
  111. v[5] = _mm_madd_epi16(u[3], k__sinpi_p03_p03); // s4
  112. v[6] = _mm_madd_epi16(u[4], k__sinpi_p03_p03);
  113. u[0] = _mm_add_epi32(v[0], v[1]);
  114. u[1] = _mm_sub_epi32(v[2], v[6]);
  115. u[2] = _mm_add_epi32(v[3], v[4]);
  116. u[3] = _mm_sub_epi32(u[2], u[0]);
  117. u[4] = _mm_slli_epi32(v[5], 2);
  118. u[5] = _mm_sub_epi32(u[4], v[5]);
  119. u[6] = _mm_add_epi32(u[3], u[5]);
  120. v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
  121. v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
  122. v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
  123. v[3] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
  124. u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
  125. u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
  126. u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
  127. u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
  128. in[0] = _mm_packs_epi32(u[0], u[2]);
  129. in[1] = _mm_packs_epi32(u[1], u[3]);
  130. transpose_4x4(in);
  131. }
  132. void vp9_fht4x4_sse2(const int16_t *input, tran_low_t *output, int stride,
  133. int tx_type) {
  134. __m128i in[4];
  135. switch (tx_type) {
  136. case DCT_DCT: vpx_fdct4x4_sse2(input, output, stride); break;
  137. case ADST_DCT:
  138. load_buffer_4x4(input, in, stride);
  139. fadst4_sse2(in);
  140. fdct4_sse2(in);
  141. write_buffer_4x4(output, in);
  142. break;
  143. case DCT_ADST:
  144. load_buffer_4x4(input, in, stride);
  145. fdct4_sse2(in);
  146. fadst4_sse2(in);
  147. write_buffer_4x4(output, in);
  148. break;
  149. default:
  150. assert(tx_type == ADST_ADST);
  151. load_buffer_4x4(input, in, stride);
  152. fadst4_sse2(in);
  153. fadst4_sse2(in);
  154. write_buffer_4x4(output, in);
  155. break;
  156. }
  157. }
  158. // load 8x8 array
  159. static INLINE void load_buffer_8x8(const int16_t *input, __m128i *in,
  160. int stride) {
  161. in[0] = _mm_load_si128((const __m128i *)(input + 0 * stride));
  162. in[1] = _mm_load_si128((const __m128i *)(input + 1 * stride));
  163. in[2] = _mm_load_si128((const __m128i *)(input + 2 * stride));
  164. in[3] = _mm_load_si128((const __m128i *)(input + 3 * stride));
  165. in[4] = _mm_load_si128((const __m128i *)(input + 4 * stride));
  166. in[5] = _mm_load_si128((const __m128i *)(input + 5 * stride));
  167. in[6] = _mm_load_si128((const __m128i *)(input + 6 * stride));
  168. in[7] = _mm_load_si128((const __m128i *)(input + 7 * stride));
  169. in[0] = _mm_slli_epi16(in[0], 2);
  170. in[1] = _mm_slli_epi16(in[1], 2);
  171. in[2] = _mm_slli_epi16(in[2], 2);
  172. in[3] = _mm_slli_epi16(in[3], 2);
  173. in[4] = _mm_slli_epi16(in[4], 2);
  174. in[5] = _mm_slli_epi16(in[5], 2);
  175. in[6] = _mm_slli_epi16(in[6], 2);
  176. in[7] = _mm_slli_epi16(in[7], 2);
  177. }
  178. // right shift and rounding
  179. static INLINE void right_shift_8x8(__m128i *res, const int bit) {
  180. __m128i sign0 = _mm_srai_epi16(res[0], 15);
  181. __m128i sign1 = _mm_srai_epi16(res[1], 15);
  182. __m128i sign2 = _mm_srai_epi16(res[2], 15);
  183. __m128i sign3 = _mm_srai_epi16(res[3], 15);
  184. __m128i sign4 = _mm_srai_epi16(res[4], 15);
  185. __m128i sign5 = _mm_srai_epi16(res[5], 15);
  186. __m128i sign6 = _mm_srai_epi16(res[6], 15);
  187. __m128i sign7 = _mm_srai_epi16(res[7], 15);
  188. if (bit == 2) {
  189. const __m128i const_rounding = _mm_set1_epi16(1);
  190. res[0] = _mm_add_epi16(res[0], const_rounding);
  191. res[1] = _mm_add_epi16(res[1], const_rounding);
  192. res[2] = _mm_add_epi16(res[2], const_rounding);
  193. res[3] = _mm_add_epi16(res[3], const_rounding);
  194. res[4] = _mm_add_epi16(res[4], const_rounding);
  195. res[5] = _mm_add_epi16(res[5], const_rounding);
  196. res[6] = _mm_add_epi16(res[6], const_rounding);
  197. res[7] = _mm_add_epi16(res[7], const_rounding);
  198. }
  199. res[0] = _mm_sub_epi16(res[0], sign0);
  200. res[1] = _mm_sub_epi16(res[1], sign1);
  201. res[2] = _mm_sub_epi16(res[2], sign2);
  202. res[3] = _mm_sub_epi16(res[3], sign3);
  203. res[4] = _mm_sub_epi16(res[4], sign4);
  204. res[5] = _mm_sub_epi16(res[5], sign5);
  205. res[6] = _mm_sub_epi16(res[6], sign6);
  206. res[7] = _mm_sub_epi16(res[7], sign7);
  207. if (bit == 1) {
  208. res[0] = _mm_srai_epi16(res[0], 1);
  209. res[1] = _mm_srai_epi16(res[1], 1);
  210. res[2] = _mm_srai_epi16(res[2], 1);
  211. res[3] = _mm_srai_epi16(res[3], 1);
  212. res[4] = _mm_srai_epi16(res[4], 1);
  213. res[5] = _mm_srai_epi16(res[5], 1);
  214. res[6] = _mm_srai_epi16(res[6], 1);
  215. res[7] = _mm_srai_epi16(res[7], 1);
  216. } else {
  217. res[0] = _mm_srai_epi16(res[0], 2);
  218. res[1] = _mm_srai_epi16(res[1], 2);
  219. res[2] = _mm_srai_epi16(res[2], 2);
  220. res[3] = _mm_srai_epi16(res[3], 2);
  221. res[4] = _mm_srai_epi16(res[4], 2);
  222. res[5] = _mm_srai_epi16(res[5], 2);
  223. res[6] = _mm_srai_epi16(res[6], 2);
  224. res[7] = _mm_srai_epi16(res[7], 2);
  225. }
  226. }
  227. // write 8x8 array
  228. static INLINE void write_buffer_8x8(tran_low_t *output, __m128i *res,
  229. int stride) {
  230. store_output(&res[0], (output + 0 * stride));
  231. store_output(&res[1], (output + 1 * stride));
  232. store_output(&res[2], (output + 2 * stride));
  233. store_output(&res[3], (output + 3 * stride));
  234. store_output(&res[4], (output + 4 * stride));
  235. store_output(&res[5], (output + 5 * stride));
  236. store_output(&res[6], (output + 6 * stride));
  237. store_output(&res[7], (output + 7 * stride));
  238. }
  239. static void fdct8_sse2(__m128i *in) {
  240. // constants
  241. const __m128i k__cospi_p16_p16 = _mm_set1_epi16(cospi_16_64);
  242. const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
  243. const __m128i k__cospi_p24_p08 = pair_set_epi16(cospi_24_64, cospi_8_64);
  244. const __m128i k__cospi_m08_p24 = pair_set_epi16(-cospi_8_64, cospi_24_64);
  245. const __m128i k__cospi_p28_p04 = pair_set_epi16(cospi_28_64, cospi_4_64);
  246. const __m128i k__cospi_m04_p28 = pair_set_epi16(-cospi_4_64, cospi_28_64);
  247. const __m128i k__cospi_p12_p20 = pair_set_epi16(cospi_12_64, cospi_20_64);
  248. const __m128i k__cospi_m20_p12 = pair_set_epi16(-cospi_20_64, cospi_12_64);
  249. const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
  250. __m128i u0, u1, u2, u3, u4, u5, u6, u7;
  251. __m128i v0, v1, v2, v3, v4, v5, v6, v7;
  252. __m128i s0, s1, s2, s3, s4, s5, s6, s7;
  253. // stage 1
  254. s0 = _mm_add_epi16(in[0], in[7]);
  255. s1 = _mm_add_epi16(in[1], in[6]);
  256. s2 = _mm_add_epi16(in[2], in[5]);
  257. s3 = _mm_add_epi16(in[3], in[4]);
  258. s4 = _mm_sub_epi16(in[3], in[4]);
  259. s5 = _mm_sub_epi16(in[2], in[5]);
  260. s6 = _mm_sub_epi16(in[1], in[6]);
  261. s7 = _mm_sub_epi16(in[0], in[7]);
  262. u0 = _mm_add_epi16(s0, s3);
  263. u1 = _mm_add_epi16(s1, s2);
  264. u2 = _mm_sub_epi16(s1, s2);
  265. u3 = _mm_sub_epi16(s0, s3);
  266. // interleave and perform butterfly multiplication/addition
  267. v0 = _mm_unpacklo_epi16(u0, u1);
  268. v1 = _mm_unpackhi_epi16(u0, u1);
  269. v2 = _mm_unpacklo_epi16(u2, u3);
  270. v3 = _mm_unpackhi_epi16(u2, u3);
  271. u0 = _mm_madd_epi16(v0, k__cospi_p16_p16);
  272. u1 = _mm_madd_epi16(v1, k__cospi_p16_p16);
  273. u2 = _mm_madd_epi16(v0, k__cospi_p16_m16);
  274. u3 = _mm_madd_epi16(v1, k__cospi_p16_m16);
  275. u4 = _mm_madd_epi16(v2, k__cospi_p24_p08);
  276. u5 = _mm_madd_epi16(v3, k__cospi_p24_p08);
  277. u6 = _mm_madd_epi16(v2, k__cospi_m08_p24);
  278. u7 = _mm_madd_epi16(v3, k__cospi_m08_p24);
  279. // shift and rounding
  280. v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING);
  281. v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING);
  282. v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING);
  283. v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING);
  284. v4 = _mm_add_epi32(u4, k__DCT_CONST_ROUNDING);
  285. v5 = _mm_add_epi32(u5, k__DCT_CONST_ROUNDING);
  286. v6 = _mm_add_epi32(u6, k__DCT_CONST_ROUNDING);
  287. v7 = _mm_add_epi32(u7, k__DCT_CONST_ROUNDING);
  288. u0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
  289. u1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
  290. u2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
  291. u3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
  292. u4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
  293. u5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
  294. u6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
  295. u7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
  296. in[0] = _mm_packs_epi32(u0, u1);
  297. in[2] = _mm_packs_epi32(u4, u5);
  298. in[4] = _mm_packs_epi32(u2, u3);
  299. in[6] = _mm_packs_epi32(u6, u7);
  300. // stage 2
  301. // interleave and perform butterfly multiplication/addition
  302. u0 = _mm_unpacklo_epi16(s6, s5);
  303. u1 = _mm_unpackhi_epi16(s6, s5);
  304. v0 = _mm_madd_epi16(u0, k__cospi_p16_m16);
  305. v1 = _mm_madd_epi16(u1, k__cospi_p16_m16);
  306. v2 = _mm_madd_epi16(u0, k__cospi_p16_p16);
  307. v3 = _mm_madd_epi16(u1, k__cospi_p16_p16);
  308. // shift and rounding
  309. u0 = _mm_add_epi32(v0, k__DCT_CONST_ROUNDING);
  310. u1 = _mm_add_epi32(v1, k__DCT_CONST_ROUNDING);
  311. u2 = _mm_add_epi32(v2, k__DCT_CONST_ROUNDING);
  312. u3 = _mm_add_epi32(v3, k__DCT_CONST_ROUNDING);
  313. v0 = _mm_srai_epi32(u0, DCT_CONST_BITS);
  314. v1 = _mm_srai_epi32(u1, DCT_CONST_BITS);
  315. v2 = _mm_srai_epi32(u2, DCT_CONST_BITS);
  316. v3 = _mm_srai_epi32(u3, DCT_CONST_BITS);
  317. u0 = _mm_packs_epi32(v0, v1);
  318. u1 = _mm_packs_epi32(v2, v3);
  319. // stage 3
  320. s0 = _mm_add_epi16(s4, u0);
  321. s1 = _mm_sub_epi16(s4, u0);
  322. s2 = _mm_sub_epi16(s7, u1);
  323. s3 = _mm_add_epi16(s7, u1);
  324. // stage 4
  325. u0 = _mm_unpacklo_epi16(s0, s3);
  326. u1 = _mm_unpackhi_epi16(s0, s3);
  327. u2 = _mm_unpacklo_epi16(s1, s2);
  328. u3 = _mm_unpackhi_epi16(s1, s2);
  329. v0 = _mm_madd_epi16(u0, k__cospi_p28_p04);
  330. v1 = _mm_madd_epi16(u1, k__cospi_p28_p04);
  331. v2 = _mm_madd_epi16(u2, k__cospi_p12_p20);
  332. v3 = _mm_madd_epi16(u3, k__cospi_p12_p20);
  333. v4 = _mm_madd_epi16(u2, k__cospi_m20_p12);
  334. v5 = _mm_madd_epi16(u3, k__cospi_m20_p12);
  335. v6 = _mm_madd_epi16(u0, k__cospi_m04_p28);
  336. v7 = _mm_madd_epi16(u1, k__cospi_m04_p28);
  337. // shift and rounding
  338. u0 = _mm_add_epi32(v0, k__DCT_CONST_ROUNDING);
  339. u1 = _mm_add_epi32(v1, k__DCT_CONST_ROUNDING);
  340. u2 = _mm_add_epi32(v2, k__DCT_CONST_ROUNDING);
  341. u3 = _mm_add_epi32(v3, k__DCT_CONST_ROUNDING);
  342. u4 = _mm_add_epi32(v4, k__DCT_CONST_ROUNDING);
  343. u5 = _mm_add_epi32(v5, k__DCT_CONST_ROUNDING);
  344. u6 = _mm_add_epi32(v6, k__DCT_CONST_ROUNDING);
  345. u7 = _mm_add_epi32(v7, k__DCT_CONST_ROUNDING);
  346. v0 = _mm_srai_epi32(u0, DCT_CONST_BITS);
  347. v1 = _mm_srai_epi32(u1, DCT_CONST_BITS);
  348. v2 = _mm_srai_epi32(u2, DCT_CONST_BITS);
  349. v3 = _mm_srai_epi32(u3, DCT_CONST_BITS);
  350. v4 = _mm_srai_epi32(u4, DCT_CONST_BITS);
  351. v5 = _mm_srai_epi32(u5, DCT_CONST_BITS);
  352. v6 = _mm_srai_epi32(u6, DCT_CONST_BITS);
  353. v7 = _mm_srai_epi32(u7, DCT_CONST_BITS);
  354. in[1] = _mm_packs_epi32(v0, v1);
  355. in[3] = _mm_packs_epi32(v4, v5);
  356. in[5] = _mm_packs_epi32(v2, v3);
  357. in[7] = _mm_packs_epi32(v6, v7);
  358. // transpose
  359. transpose_16bit_8x8(in, in);
  360. }
  361. static void fadst8_sse2(__m128i *in) {
  362. // Constants
  363. const __m128i k__cospi_p02_p30 = pair_set_epi16(cospi_2_64, cospi_30_64);
  364. const __m128i k__cospi_p30_m02 = pair_set_epi16(cospi_30_64, -cospi_2_64);
  365. const __m128i k__cospi_p10_p22 = pair_set_epi16(cospi_10_64, cospi_22_64);
  366. const __m128i k__cospi_p22_m10 = pair_set_epi16(cospi_22_64, -cospi_10_64);
  367. const __m128i k__cospi_p18_p14 = pair_set_epi16(cospi_18_64, cospi_14_64);
  368. const __m128i k__cospi_p14_m18 = pair_set_epi16(cospi_14_64, -cospi_18_64);
  369. const __m128i k__cospi_p26_p06 = pair_set_epi16(cospi_26_64, cospi_6_64);
  370. const __m128i k__cospi_p06_m26 = pair_set_epi16(cospi_6_64, -cospi_26_64);
  371. const __m128i k__cospi_p08_p24 = pair_set_epi16(cospi_8_64, cospi_24_64);
  372. const __m128i k__cospi_p24_m08 = pair_set_epi16(cospi_24_64, -cospi_8_64);
  373. const __m128i k__cospi_m24_p08 = pair_set_epi16(-cospi_24_64, cospi_8_64);
  374. const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
  375. const __m128i k__cospi_p16_p16 = _mm_set1_epi16(cospi_16_64);
  376. const __m128i k__const_0 = _mm_set1_epi16(0);
  377. const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
  378. __m128i u0, u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, u11, u12, u13, u14, u15;
  379. __m128i v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15;
  380. __m128i w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15;
  381. __m128i s0, s1, s2, s3, s4, s5, s6, s7;
  382. __m128i in0, in1, in2, in3, in4, in5, in6, in7;
  383. // properly aligned for butterfly input
  384. in0 = in[7];
  385. in1 = in[0];
  386. in2 = in[5];
  387. in3 = in[2];
  388. in4 = in[3];
  389. in5 = in[4];
  390. in6 = in[1];
  391. in7 = in[6];
  392. // column transformation
  393. // stage 1
  394. // interleave and multiply/add into 32-bit integer
  395. s0 = _mm_unpacklo_epi16(in0, in1);
  396. s1 = _mm_unpackhi_epi16(in0, in1);
  397. s2 = _mm_unpacklo_epi16(in2, in3);
  398. s3 = _mm_unpackhi_epi16(in2, in3);
  399. s4 = _mm_unpacklo_epi16(in4, in5);
  400. s5 = _mm_unpackhi_epi16(in4, in5);
  401. s6 = _mm_unpacklo_epi16(in6, in7);
  402. s7 = _mm_unpackhi_epi16(in6, in7);
  403. u0 = _mm_madd_epi16(s0, k__cospi_p02_p30);
  404. u1 = _mm_madd_epi16(s1, k__cospi_p02_p30);
  405. u2 = _mm_madd_epi16(s0, k__cospi_p30_m02);
  406. u3 = _mm_madd_epi16(s1, k__cospi_p30_m02);
  407. u4 = _mm_madd_epi16(s2, k__cospi_p10_p22);
  408. u5 = _mm_madd_epi16(s3, k__cospi_p10_p22);
  409. u6 = _mm_madd_epi16(s2, k__cospi_p22_m10);
  410. u7 = _mm_madd_epi16(s3, k__cospi_p22_m10);
  411. u8 = _mm_madd_epi16(s4, k__cospi_p18_p14);
  412. u9 = _mm_madd_epi16(s5, k__cospi_p18_p14);
  413. u10 = _mm_madd_epi16(s4, k__cospi_p14_m18);
  414. u11 = _mm_madd_epi16(s5, k__cospi_p14_m18);
  415. u12 = _mm_madd_epi16(s6, k__cospi_p26_p06);
  416. u13 = _mm_madd_epi16(s7, k__cospi_p26_p06);
  417. u14 = _mm_madd_epi16(s6, k__cospi_p06_m26);
  418. u15 = _mm_madd_epi16(s7, k__cospi_p06_m26);
  419. // addition
  420. w0 = _mm_add_epi32(u0, u8);
  421. w1 = _mm_add_epi32(u1, u9);
  422. w2 = _mm_add_epi32(u2, u10);
  423. w3 = _mm_add_epi32(u3, u11);
  424. w4 = _mm_add_epi32(u4, u12);
  425. w5 = _mm_add_epi32(u5, u13);
  426. w6 = _mm_add_epi32(u6, u14);
  427. w7 = _mm_add_epi32(u7, u15);
  428. w8 = _mm_sub_epi32(u0, u8);
  429. w9 = _mm_sub_epi32(u1, u9);
  430. w10 = _mm_sub_epi32(u2, u10);
  431. w11 = _mm_sub_epi32(u3, u11);
  432. w12 = _mm_sub_epi32(u4, u12);
  433. w13 = _mm_sub_epi32(u5, u13);
  434. w14 = _mm_sub_epi32(u6, u14);
  435. w15 = _mm_sub_epi32(u7, u15);
  436. // shift and rounding
  437. v0 = _mm_add_epi32(w0, k__DCT_CONST_ROUNDING);
  438. v1 = _mm_add_epi32(w1, k__DCT_CONST_ROUNDING);
  439. v2 = _mm_add_epi32(w2, k__DCT_CONST_ROUNDING);
  440. v3 = _mm_add_epi32(w3, k__DCT_CONST_ROUNDING);
  441. v4 = _mm_add_epi32(w4, k__DCT_CONST_ROUNDING);
  442. v5 = _mm_add_epi32(w5, k__DCT_CONST_ROUNDING);
  443. v6 = _mm_add_epi32(w6, k__DCT_CONST_ROUNDING);
  444. v7 = _mm_add_epi32(w7, k__DCT_CONST_ROUNDING);
  445. v8 = _mm_add_epi32(w8, k__DCT_CONST_ROUNDING);
  446. v9 = _mm_add_epi32(w9, k__DCT_CONST_ROUNDING);
  447. v10 = _mm_add_epi32(w10, k__DCT_CONST_ROUNDING);
  448. v11 = _mm_add_epi32(w11, k__DCT_CONST_ROUNDING);
  449. v12 = _mm_add_epi32(w12, k__DCT_CONST_ROUNDING);
  450. v13 = _mm_add_epi32(w13, k__DCT_CONST_ROUNDING);
  451. v14 = _mm_add_epi32(w14, k__DCT_CONST_ROUNDING);
  452. v15 = _mm_add_epi32(w15, k__DCT_CONST_ROUNDING);
  453. u0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
  454. u1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
  455. u2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
  456. u3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
  457. u4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
  458. u5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
  459. u6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
  460. u7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
  461. u8 = _mm_srai_epi32(v8, DCT_CONST_BITS);
  462. u9 = _mm_srai_epi32(v9, DCT_CONST_BITS);
  463. u10 = _mm_srai_epi32(v10, DCT_CONST_BITS);
  464. u11 = _mm_srai_epi32(v11, DCT_CONST_BITS);
  465. u12 = _mm_srai_epi32(v12, DCT_CONST_BITS);
  466. u13 = _mm_srai_epi32(v13, DCT_CONST_BITS);
  467. u14 = _mm_srai_epi32(v14, DCT_CONST_BITS);
  468. u15 = _mm_srai_epi32(v15, DCT_CONST_BITS);
  469. // back to 16-bit and pack 8 integers into __m128i
  470. in[0] = _mm_packs_epi32(u0, u1);
  471. in[1] = _mm_packs_epi32(u2, u3);
  472. in[2] = _mm_packs_epi32(u4, u5);
  473. in[3] = _mm_packs_epi32(u6, u7);
  474. in[4] = _mm_packs_epi32(u8, u9);
  475. in[5] = _mm_packs_epi32(u10, u11);
  476. in[6] = _mm_packs_epi32(u12, u13);
  477. in[7] = _mm_packs_epi32(u14, u15);
  478. // stage 2
  479. s0 = _mm_add_epi16(in[0], in[2]);
  480. s1 = _mm_add_epi16(in[1], in[3]);
  481. s2 = _mm_sub_epi16(in[0], in[2]);
  482. s3 = _mm_sub_epi16(in[1], in[3]);
  483. u0 = _mm_unpacklo_epi16(in[4], in[5]);
  484. u1 = _mm_unpackhi_epi16(in[4], in[5]);
  485. u2 = _mm_unpacklo_epi16(in[6], in[7]);
  486. u3 = _mm_unpackhi_epi16(in[6], in[7]);
  487. v0 = _mm_madd_epi16(u0, k__cospi_p08_p24);
  488. v1 = _mm_madd_epi16(u1, k__cospi_p08_p24);
  489. v2 = _mm_madd_epi16(u0, k__cospi_p24_m08);
  490. v3 = _mm_madd_epi16(u1, k__cospi_p24_m08);
  491. v4 = _mm_madd_epi16(u2, k__cospi_m24_p08);
  492. v5 = _mm_madd_epi16(u3, k__cospi_m24_p08);
  493. v6 = _mm_madd_epi16(u2, k__cospi_p08_p24);
  494. v7 = _mm_madd_epi16(u3, k__cospi_p08_p24);
  495. w0 = _mm_add_epi32(v0, v4);
  496. w1 = _mm_add_epi32(v1, v5);
  497. w2 = _mm_add_epi32(v2, v6);
  498. w3 = _mm_add_epi32(v3, v7);
  499. w4 = _mm_sub_epi32(v0, v4);
  500. w5 = _mm_sub_epi32(v1, v5);
  501. w6 = _mm_sub_epi32(v2, v6);
  502. w7 = _mm_sub_epi32(v3, v7);
  503. v0 = _mm_add_epi32(w0, k__DCT_CONST_ROUNDING);
  504. v1 = _mm_add_epi32(w1, k__DCT_CONST_ROUNDING);
  505. v2 = _mm_add_epi32(w2, k__DCT_CONST_ROUNDING);
  506. v3 = _mm_add_epi32(w3, k__DCT_CONST_ROUNDING);
  507. v4 = _mm_add_epi32(w4, k__DCT_CONST_ROUNDING);
  508. v5 = _mm_add_epi32(w5, k__DCT_CONST_ROUNDING);
  509. v6 = _mm_add_epi32(w6, k__DCT_CONST_ROUNDING);
  510. v7 = _mm_add_epi32(w7, k__DCT_CONST_ROUNDING);
  511. u0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
  512. u1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
  513. u2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
  514. u3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
  515. u4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
  516. u5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
  517. u6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
  518. u7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
  519. // back to 16-bit intergers
  520. s4 = _mm_packs_epi32(u0, u1);
  521. s5 = _mm_packs_epi32(u2, u3);
  522. s6 = _mm_packs_epi32(u4, u5);
  523. s7 = _mm_packs_epi32(u6, u7);
  524. // stage 3
  525. u0 = _mm_unpacklo_epi16(s2, s3);
  526. u1 = _mm_unpackhi_epi16(s2, s3);
  527. u2 = _mm_unpacklo_epi16(s6, s7);
  528. u3 = _mm_unpackhi_epi16(s6, s7);
  529. v0 = _mm_madd_epi16(u0, k__cospi_p16_p16);
  530. v1 = _mm_madd_epi16(u1, k__cospi_p16_p16);
  531. v2 = _mm_madd_epi16(u0, k__cospi_p16_m16);
  532. v3 = _mm_madd_epi16(u1, k__cospi_p16_m16);
  533. v4 = _mm_madd_epi16(u2, k__cospi_p16_p16);
  534. v5 = _mm_madd_epi16(u3, k__cospi_p16_p16);
  535. v6 = _mm_madd_epi16(u2, k__cospi_p16_m16);
  536. v7 = _mm_madd_epi16(u3, k__cospi_p16_m16);
  537. u0 = _mm_add_epi32(v0, k__DCT_CONST_ROUNDING);
  538. u1 = _mm_add_epi32(v1, k__DCT_CONST_ROUNDING);
  539. u2 = _mm_add_epi32(v2, k__DCT_CONST_ROUNDING);
  540. u3 = _mm_add_epi32(v3, k__DCT_CONST_ROUNDING);
  541. u4 = _mm_add_epi32(v4, k__DCT_CONST_ROUNDING);
  542. u5 = _mm_add_epi32(v5, k__DCT_CONST_ROUNDING);
  543. u6 = _mm_add_epi32(v6, k__DCT_CONST_ROUNDING);
  544. u7 = _mm_add_epi32(v7, k__DCT_CONST_ROUNDING);
  545. v0 = _mm_srai_epi32(u0, DCT_CONST_BITS);
  546. v1 = _mm_srai_epi32(u1, DCT_CONST_BITS);
  547. v2 = _mm_srai_epi32(u2, DCT_CONST_BITS);
  548. v3 = _mm_srai_epi32(u3, DCT_CONST_BITS);
  549. v4 = _mm_srai_epi32(u4, DCT_CONST_BITS);
  550. v5 = _mm_srai_epi32(u5, DCT_CONST_BITS);
  551. v6 = _mm_srai_epi32(u6, DCT_CONST_BITS);
  552. v7 = _mm_srai_epi32(u7, DCT_CONST_BITS);
  553. s2 = _mm_packs_epi32(v0, v1);
  554. s3 = _mm_packs_epi32(v2, v3);
  555. s6 = _mm_packs_epi32(v4, v5);
  556. s7 = _mm_packs_epi32(v6, v7);
  557. // FIXME(jingning): do subtract using bit inversion?
  558. in[0] = s0;
  559. in[1] = _mm_sub_epi16(k__const_0, s4);
  560. in[2] = s6;
  561. in[3] = _mm_sub_epi16(k__const_0, s2);
  562. in[4] = s3;
  563. in[5] = _mm_sub_epi16(k__const_0, s7);
  564. in[6] = s5;
  565. in[7] = _mm_sub_epi16(k__const_0, s1);
  566. // transpose
  567. transpose_16bit_8x8(in, in);
  568. }
  569. void vp9_fht8x8_sse2(const int16_t *input, tran_low_t *output, int stride,
  570. int tx_type) {
  571. __m128i in[8];
  572. switch (tx_type) {
  573. case DCT_DCT: vpx_fdct8x8_sse2(input, output, stride); break;
  574. case ADST_DCT:
  575. load_buffer_8x8(input, in, stride);
  576. fadst8_sse2(in);
  577. fdct8_sse2(in);
  578. right_shift_8x8(in, 1);
  579. write_buffer_8x8(output, in, 8);
  580. break;
  581. case DCT_ADST:
  582. load_buffer_8x8(input, in, stride);
  583. fdct8_sse2(in);
  584. fadst8_sse2(in);
  585. right_shift_8x8(in, 1);
  586. write_buffer_8x8(output, in, 8);
  587. break;
  588. default:
  589. assert(tx_type == ADST_ADST);
  590. load_buffer_8x8(input, in, stride);
  591. fadst8_sse2(in);
  592. fadst8_sse2(in);
  593. right_shift_8x8(in, 1);
  594. write_buffer_8x8(output, in, 8);
  595. break;
  596. }
  597. }
  598. static INLINE void load_buffer_16x16(const int16_t *input, __m128i *in0,
  599. __m128i *in1, int stride) {
  600. // load first 8 columns
  601. load_buffer_8x8(input, in0, stride);
  602. load_buffer_8x8(input + 8 * stride, in0 + 8, stride);
  603. input += 8;
  604. // load second 8 columns
  605. load_buffer_8x8(input, in1, stride);
  606. load_buffer_8x8(input + 8 * stride, in1 + 8, stride);
  607. }
  608. static INLINE void write_buffer_16x16(tran_low_t *output, __m128i *in0,
  609. __m128i *in1, int stride) {
  610. // write first 8 columns
  611. write_buffer_8x8(output, in0, stride);
  612. write_buffer_8x8(output + 8 * stride, in0 + 8, stride);
  613. // write second 8 columns
  614. output += 8;
  615. write_buffer_8x8(output, in1, stride);
  616. write_buffer_8x8(output + 8 * stride, in1 + 8, stride);
  617. }
  618. static INLINE void right_shift_16x16(__m128i *res0, __m128i *res1) {
  619. // perform rounding operations
  620. right_shift_8x8(res0, 2);
  621. right_shift_8x8(res0 + 8, 2);
  622. right_shift_8x8(res1, 2);
  623. right_shift_8x8(res1 + 8, 2);
  624. }
  625. static void fdct16_8col(__m128i *in) {
  626. // perform 16x16 1-D DCT for 8 columns
  627. __m128i i[8], s[8], p[8], t[8], u[16], v[16];
  628. const __m128i k__cospi_p16_p16 = _mm_set1_epi16(cospi_16_64);
  629. const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
  630. const __m128i k__cospi_m16_p16 = pair_set_epi16(-cospi_16_64, cospi_16_64);
  631. const __m128i k__cospi_p24_p08 = pair_set_epi16(cospi_24_64, cospi_8_64);
  632. const __m128i k__cospi_p08_m24 = pair_set_epi16(cospi_8_64, -cospi_24_64);
  633. const __m128i k__cospi_m08_p24 = pair_set_epi16(-cospi_8_64, cospi_24_64);
  634. const __m128i k__cospi_p28_p04 = pair_set_epi16(cospi_28_64, cospi_4_64);
  635. const __m128i k__cospi_m04_p28 = pair_set_epi16(-cospi_4_64, cospi_28_64);
  636. const __m128i k__cospi_p12_p20 = pair_set_epi16(cospi_12_64, cospi_20_64);
  637. const __m128i k__cospi_m20_p12 = pair_set_epi16(-cospi_20_64, cospi_12_64);
  638. const __m128i k__cospi_p30_p02 = pair_set_epi16(cospi_30_64, cospi_2_64);
  639. const __m128i k__cospi_p14_p18 = pair_set_epi16(cospi_14_64, cospi_18_64);
  640. const __m128i k__cospi_m02_p30 = pair_set_epi16(-cospi_2_64, cospi_30_64);
  641. const __m128i k__cospi_m18_p14 = pair_set_epi16(-cospi_18_64, cospi_14_64);
  642. const __m128i k__cospi_p22_p10 = pair_set_epi16(cospi_22_64, cospi_10_64);
  643. const __m128i k__cospi_p06_p26 = pair_set_epi16(cospi_6_64, cospi_26_64);
  644. const __m128i k__cospi_m10_p22 = pair_set_epi16(-cospi_10_64, cospi_22_64);
  645. const __m128i k__cospi_m26_p06 = pair_set_epi16(-cospi_26_64, cospi_6_64);
  646. const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
  647. // stage 1
  648. i[0] = _mm_add_epi16(in[0], in[15]);
  649. i[1] = _mm_add_epi16(in[1], in[14]);
  650. i[2] = _mm_add_epi16(in[2], in[13]);
  651. i[3] = _mm_add_epi16(in[3], in[12]);
  652. i[4] = _mm_add_epi16(in[4], in[11]);
  653. i[5] = _mm_add_epi16(in[5], in[10]);
  654. i[6] = _mm_add_epi16(in[6], in[9]);
  655. i[7] = _mm_add_epi16(in[7], in[8]);
  656. s[0] = _mm_sub_epi16(in[7], in[8]);
  657. s[1] = _mm_sub_epi16(in[6], in[9]);
  658. s[2] = _mm_sub_epi16(in[5], in[10]);
  659. s[3] = _mm_sub_epi16(in[4], in[11]);
  660. s[4] = _mm_sub_epi16(in[3], in[12]);
  661. s[5] = _mm_sub_epi16(in[2], in[13]);
  662. s[6] = _mm_sub_epi16(in[1], in[14]);
  663. s[7] = _mm_sub_epi16(in[0], in[15]);
  664. p[0] = _mm_add_epi16(i[0], i[7]);
  665. p[1] = _mm_add_epi16(i[1], i[6]);
  666. p[2] = _mm_add_epi16(i[2], i[5]);
  667. p[3] = _mm_add_epi16(i[3], i[4]);
  668. p[4] = _mm_sub_epi16(i[3], i[4]);
  669. p[5] = _mm_sub_epi16(i[2], i[5]);
  670. p[6] = _mm_sub_epi16(i[1], i[6]);
  671. p[7] = _mm_sub_epi16(i[0], i[7]);
  672. u[0] = _mm_add_epi16(p[0], p[3]);
  673. u[1] = _mm_add_epi16(p[1], p[2]);
  674. u[2] = _mm_sub_epi16(p[1], p[2]);
  675. u[3] = _mm_sub_epi16(p[0], p[3]);
  676. v[0] = _mm_unpacklo_epi16(u[0], u[1]);
  677. v[1] = _mm_unpackhi_epi16(u[0], u[1]);
  678. v[2] = _mm_unpacklo_epi16(u[2], u[3]);
  679. v[3] = _mm_unpackhi_epi16(u[2], u[3]);
  680. u[0] = _mm_madd_epi16(v[0], k__cospi_p16_p16);
  681. u[1] = _mm_madd_epi16(v[1], k__cospi_p16_p16);
  682. u[2] = _mm_madd_epi16(v[0], k__cospi_p16_m16);
  683. u[3] = _mm_madd_epi16(v[1], k__cospi_p16_m16);
  684. u[4] = _mm_madd_epi16(v[2], k__cospi_p24_p08);
  685. u[5] = _mm_madd_epi16(v[3], k__cospi_p24_p08);
  686. u[6] = _mm_madd_epi16(v[2], k__cospi_m08_p24);
  687. u[7] = _mm_madd_epi16(v[3], k__cospi_m08_p24);
  688. v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
  689. v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
  690. v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
  691. v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
  692. v[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
  693. v[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
  694. v[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
  695. v[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
  696. u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
  697. u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
  698. u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
  699. u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
  700. u[4] = _mm_srai_epi32(v[4], DCT_CONST_BITS);
  701. u[5] = _mm_srai_epi32(v[5], DCT_CONST_BITS);
  702. u[6] = _mm_srai_epi32(v[6], DCT_CONST_BITS);
  703. u[7] = _mm_srai_epi32(v[7], DCT_CONST_BITS);
  704. in[0] = _mm_packs_epi32(u[0], u[1]);
  705. in[4] = _mm_packs_epi32(u[4], u[5]);
  706. in[8] = _mm_packs_epi32(u[2], u[3]);
  707. in[12] = _mm_packs_epi32(u[6], u[7]);
  708. u[0] = _mm_unpacklo_epi16(p[5], p[6]);
  709. u[1] = _mm_unpackhi_epi16(p[5], p[6]);
  710. v[0] = _mm_madd_epi16(u[0], k__cospi_m16_p16);
  711. v[1] = _mm_madd_epi16(u[1], k__cospi_m16_p16);
  712. v[2] = _mm_madd_epi16(u[0], k__cospi_p16_p16);
  713. v[3] = _mm_madd_epi16(u[1], k__cospi_p16_p16);
  714. u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
  715. u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
  716. u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
  717. u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
  718. v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
  719. v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
  720. v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
  721. v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
  722. u[0] = _mm_packs_epi32(v[0], v[1]);
  723. u[1] = _mm_packs_epi32(v[2], v[3]);
  724. t[0] = _mm_add_epi16(p[4], u[0]);
  725. t[1] = _mm_sub_epi16(p[4], u[0]);
  726. t[2] = _mm_sub_epi16(p[7], u[1]);
  727. t[3] = _mm_add_epi16(p[7], u[1]);
  728. u[0] = _mm_unpacklo_epi16(t[0], t[3]);
  729. u[1] = _mm_unpackhi_epi16(t[0], t[3]);
  730. u[2] = _mm_unpacklo_epi16(t[1], t[2]);
  731. u[3] = _mm_unpackhi_epi16(t[1], t[2]);
  732. v[0] = _mm_madd_epi16(u[0], k__cospi_p28_p04);
  733. v[1] = _mm_madd_epi16(u[1], k__cospi_p28_p04);
  734. v[2] = _mm_madd_epi16(u[2], k__cospi_p12_p20);
  735. v[3] = _mm_madd_epi16(u[3], k__cospi_p12_p20);
  736. v[4] = _mm_madd_epi16(u[2], k__cospi_m20_p12);
  737. v[5] = _mm_madd_epi16(u[3], k__cospi_m20_p12);
  738. v[6] = _mm_madd_epi16(u[0], k__cospi_m04_p28);
  739. v[7] = _mm_madd_epi16(u[1], k__cospi_m04_p28);
  740. u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
  741. u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
  742. u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
  743. u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
  744. u[4] = _mm_add_epi32(v[4], k__DCT_CONST_ROUNDING);
  745. u[5] = _mm_add_epi32(v[5], k__DCT_CONST_ROUNDING);
  746. u[6] = _mm_add_epi32(v[6], k__DCT_CONST_ROUNDING);
  747. u[7] = _mm_add_epi32(v[7], k__DCT_CONST_ROUNDING);
  748. v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
  749. v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
  750. v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
  751. v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
  752. v[4] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
  753. v[5] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
  754. v[6] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
  755. v[7] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
  756. in[2] = _mm_packs_epi32(v[0], v[1]);
  757. in[6] = _mm_packs_epi32(v[4], v[5]);
  758. in[10] = _mm_packs_epi32(v[2], v[3]);
  759. in[14] = _mm_packs_epi32(v[6], v[7]);
  760. // stage 2
  761. u[0] = _mm_unpacklo_epi16(s[2], s[5]);
  762. u[1] = _mm_unpackhi_epi16(s[2], s[5]);
  763. u[2] = _mm_unpacklo_epi16(s[3], s[4]);
  764. u[3] = _mm_unpackhi_epi16(s[3], s[4]);
  765. v[0] = _mm_madd_epi16(u[0], k__cospi_m16_p16);
  766. v[1] = _mm_madd_epi16(u[1], k__cospi_m16_p16);
  767. v[2] = _mm_madd_epi16(u[2], k__cospi_m16_p16);
  768. v[3] = _mm_madd_epi16(u[3], k__cospi_m16_p16);
  769. v[4] = _mm_madd_epi16(u[2], k__cospi_p16_p16);
  770. v[5] = _mm_madd_epi16(u[3], k__cospi_p16_p16);
  771. v[6] = _mm_madd_epi16(u[0], k__cospi_p16_p16);
  772. v[7] = _mm_madd_epi16(u[1], k__cospi_p16_p16);
  773. u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
  774. u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
  775. u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
  776. u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
  777. u[4] = _mm_add_epi32(v[4], k__DCT_CONST_ROUNDING);
  778. u[5] = _mm_add_epi32(v[5], k__DCT_CONST_ROUNDING);
  779. u[6] = _mm_add_epi32(v[6], k__DCT_CONST_ROUNDING);
  780. u[7] = _mm_add_epi32(v[7], k__DCT_CONST_ROUNDING);
  781. v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
  782. v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
  783. v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
  784. v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
  785. v[4] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
  786. v[5] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
  787. v[6] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
  788. v[7] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
  789. t[2] = _mm_packs_epi32(v[0], v[1]);
  790. t[3] = _mm_packs_epi32(v[2], v[3]);
  791. t[4] = _mm_packs_epi32(v[4], v[5]);
  792. t[5] = _mm_packs_epi32(v[6], v[7]);
  793. // stage 3
  794. p[0] = _mm_add_epi16(s[0], t[3]);
  795. p[1] = _mm_add_epi16(s[1], t[2]);
  796. p[2] = _mm_sub_epi16(s[1], t[2]);
  797. p[3] = _mm_sub_epi16(s[0], t[3]);
  798. p[4] = _mm_sub_epi16(s[7], t[4]);
  799. p[5] = _mm_sub_epi16(s[6], t[5]);
  800. p[6] = _mm_add_epi16(s[6], t[5]);
  801. p[7] = _mm_add_epi16(s[7], t[4]);
  802. // stage 4
  803. u[0] = _mm_unpacklo_epi16(p[1], p[6]);
  804. u[1] = _mm_unpackhi_epi16(p[1], p[6]);
  805. u[2] = _mm_unpacklo_epi16(p[2], p[5]);
  806. u[3] = _mm_unpackhi_epi16(p[2], p[5]);
  807. v[0] = _mm_madd_epi16(u[0], k__cospi_m08_p24);
  808. v[1] = _mm_madd_epi16(u[1], k__cospi_m08_p24);
  809. v[2] = _mm_madd_epi16(u[2], k__cospi_p24_p08);
  810. v[3] = _mm_madd_epi16(u[3], k__cospi_p24_p08);
  811. v[4] = _mm_madd_epi16(u[2], k__cospi_p08_m24);
  812. v[5] = _mm_madd_epi16(u[3], k__cospi_p08_m24);
  813. v[6] = _mm_madd_epi16(u[0], k__cospi_p24_p08);
  814. v[7] = _mm_madd_epi16(u[1], k__cospi_p24_p08);
  815. u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
  816. u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
  817. u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
  818. u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
  819. u[4] = _mm_add_epi32(v[4], k__DCT_CONST_ROUNDING);
  820. u[5] = _mm_add_epi32(v[5], k__DCT_CONST_ROUNDING);
  821. u[6] = _mm_add_epi32(v[6], k__DCT_CONST_ROUNDING);
  822. u[7] = _mm_add_epi32(v[7], k__DCT_CONST_ROUNDING);
  823. v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
  824. v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
  825. v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
  826. v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
  827. v[4] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
  828. v[5] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
  829. v[6] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
  830. v[7] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
  831. t[1] = _mm_packs_epi32(v[0], v[1]);
  832. t[2] = _mm_packs_epi32(v[2], v[3]);
  833. t[5] = _mm_packs_epi32(v[4], v[5]);
  834. t[6] = _mm_packs_epi32(v[6], v[7]);
  835. // stage 5
  836. s[0] = _mm_add_epi16(p[0], t[1]);
  837. s[1] = _mm_sub_epi16(p[0], t[1]);
  838. s[2] = _mm_add_epi16(p[3], t[2]);
  839. s[3] = _mm_sub_epi16(p[3], t[2]);
  840. s[4] = _mm_sub_epi16(p[4], t[5]);
  841. s[5] = _mm_add_epi16(p[4], t[5]);
  842. s[6] = _mm_sub_epi16(p[7], t[6]);
  843. s[7] = _mm_add_epi16(p[7], t[6]);
  844. // stage 6
  845. u[0] = _mm_unpacklo_epi16(s[0], s[7]);
  846. u[1] = _mm_unpackhi_epi16(s[0], s[7]);
  847. u[2] = _mm_unpacklo_epi16(s[1], s[6]);
  848. u[3] = _mm_unpackhi_epi16(s[1], s[6]);
  849. u[4] = _mm_unpacklo_epi16(s[2], s[5]);
  850. u[5] = _mm_unpackhi_epi16(s[2], s[5]);
  851. u[6] = _mm_unpacklo_epi16(s[3], s[4]);
  852. u[7] = _mm_unpackhi_epi16(s[3], s[4]);
  853. v[0] = _mm_madd_epi16(u[0], k__cospi_p30_p02);
  854. v[1] = _mm_madd_epi16(u[1], k__cospi_p30_p02);
  855. v[2] = _mm_madd_epi16(u[2], k__cospi_p14_p18);
  856. v[3] = _mm_madd_epi16(u[3], k__cospi_p14_p18);
  857. v[4] = _mm_madd_epi16(u[4], k__cospi_p22_p10);
  858. v[5] = _mm_madd_epi16(u[5], k__cospi_p22_p10);
  859. v[6] = _mm_madd_epi16(u[6], k__cospi_p06_p26);
  860. v[7] = _mm_madd_epi16(u[7], k__cospi_p06_p26);
  861. v[8] = _mm_madd_epi16(u[6], k__cospi_m26_p06);
  862. v[9] = _mm_madd_epi16(u[7], k__cospi_m26_p06);
  863. v[10] = _mm_madd_epi16(u[4], k__cospi_m10_p22);
  864. v[11] = _mm_madd_epi16(u[5], k__cospi_m10_p22);
  865. v[12] = _mm_madd_epi16(u[2], k__cospi_m18_p14);
  866. v[13] = _mm_madd_epi16(u[3], k__cospi_m18_p14);
  867. v[14] = _mm_madd_epi16(u[0], k__cospi_m02_p30);
  868. v[15] = _mm_madd_epi16(u[1], k__cospi_m02_p30);
  869. u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
  870. u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
  871. u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
  872. u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
  873. u[4] = _mm_add_epi32(v[4], k__DCT_CONST_ROUNDING);
  874. u[5] = _mm_add_epi32(v[5], k__DCT_CONST_ROUNDING);
  875. u[6] = _mm_add_epi32(v[6], k__DCT_CONST_ROUNDING);
  876. u[7] = _mm_add_epi32(v[7], k__DCT_CONST_ROUNDING);
  877. u[8] = _mm_add_epi32(v[8], k__DCT_CONST_ROUNDING);
  878. u[9] = _mm_add_epi32(v[9], k__DCT_CONST_ROUNDING);
  879. u[10] = _mm_add_epi32(v[10], k__DCT_CONST_ROUNDING);
  880. u[11] = _mm_add_epi32(v[11], k__DCT_CONST_ROUNDING);
  881. u[12] = _mm_add_epi32(v[12], k__DCT_CONST_ROUNDING);
  882. u[13] = _mm_add_epi32(v[13], k__DCT_CONST_ROUNDING);
  883. u[14] = _mm_add_epi32(v[14], k__DCT_CONST_ROUNDING);
  884. u[15] = _mm_add_epi32(v[15], k__DCT_CONST_ROUNDING);
  885. v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
  886. v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
  887. v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
  888. v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
  889. v[4] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
  890. v[5] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
  891. v[6] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
  892. v[7] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
  893. v[8] = _mm_srai_epi32(u[8], DCT_CONST_BITS);
  894. v[9] = _mm_srai_epi32(u[9], DCT_CONST_BITS);
  895. v[10] = _mm_srai_epi32(u[10], DCT_CONST_BITS);
  896. v[11] = _mm_srai_epi32(u[11], DCT_CONST_BITS);
  897. v[12] = _mm_srai_epi32(u[12], DCT_CONST_BITS);
  898. v[13] = _mm_srai_epi32(u[13], DCT_CONST_BITS);
  899. v[14] = _mm_srai_epi32(u[14], DCT_CONST_BITS);
  900. v[15] = _mm_srai_epi32(u[15], DCT_CONST_BITS);
  901. in[1] = _mm_packs_epi32(v[0], v[1]);
  902. in[9] = _mm_packs_epi32(v[2], v[3]);
  903. in[5] = _mm_packs_epi32(v[4], v[5]);
  904. in[13] = _mm_packs_epi32(v[6], v[7]);
  905. in[3] = _mm_packs_epi32(v[8], v[9]);
  906. in[11] = _mm_packs_epi32(v[10], v[11]);
  907. in[7] = _mm_packs_epi32(v[12], v[13]);
  908. in[15] = _mm_packs_epi32(v[14], v[15]);
  909. }
  910. static void fadst16_8col(__m128i *in) {
  911. // perform 16x16 1-D ADST for 8 columns
  912. __m128i s[16], x[16], u[32], v[32];
  913. const __m128i k__cospi_p01_p31 = pair_set_epi16(cospi_1_64, cospi_31_64);
  914. const __m128i k__cospi_p31_m01 = pair_set_epi16(cospi_31_64, -cospi_1_64);
  915. const __m128i k__cospi_p05_p27 = pair_set_epi16(cospi_5_64, cospi_27_64);
  916. const __m128i k__cospi_p27_m05 = pair_set_epi16(cospi_27_64, -cospi_5_64);
  917. const __m128i k__cospi_p09_p23 = pair_set_epi16(cospi_9_64, cospi_23_64);
  918. const __m128i k__cospi_p23_m09 = pair_set_epi16(cospi_23_64, -cospi_9_64);
  919. const __m128i k__cospi_p13_p19 = pair_set_epi16(cospi_13_64, cospi_19_64);
  920. const __m128i k__cospi_p19_m13 = pair_set_epi16(cospi_19_64, -cospi_13_64);
  921. const __m128i k__cospi_p17_p15 = pair_set_epi16(cospi_17_64, cospi_15_64);
  922. const __m128i k__cospi_p15_m17 = pair_set_epi16(cospi_15_64, -cospi_17_64);
  923. const __m128i k__cospi_p21_p11 = pair_set_epi16(cospi_21_64, cospi_11_64);
  924. const __m128i k__cospi_p11_m21 = pair_set_epi16(cospi_11_64, -cospi_21_64);
  925. const __m128i k__cospi_p25_p07 = pair_set_epi16(cospi_25_64, cospi_7_64);
  926. const __m128i k__cospi_p07_m25 = pair_set_epi16(cospi_7_64, -cospi_25_64);
  927. const __m128i k__cospi_p29_p03 = pair_set_epi16(cospi_29_64, cospi_3_64);
  928. const __m128i k__cospi_p03_m29 = pair_set_epi16(cospi_3_64, -cospi_29_64);
  929. const __m128i k__cospi_p04_p28 = pair_set_epi16(cospi_4_64, cospi_28_64);
  930. const __m128i k__cospi_p28_m04 = pair_set_epi16(cospi_28_64, -cospi_4_64);
  931. const __m128i k__cospi_p20_p12 = pair_set_epi16(cospi_20_64, cospi_12_64);
  932. const __m128i k__cospi_p12_m20 = pair_set_epi16(cospi_12_64, -cospi_20_64);
  933. const __m128i k__cospi_m28_p04 = pair_set_epi16(-cospi_28_64, cospi_4_64);
  934. const __m128i k__cospi_m12_p20 = pair_set_epi16(-cospi_12_64, cospi_20_64);
  935. const __m128i k__cospi_p08_p24 = pair_set_epi16(cospi_8_64, cospi_24_64);
  936. const __m128i k__cospi_p24_m08 = pair_set_epi16(cospi_24_64, -cospi_8_64);
  937. const __m128i k__cospi_m24_p08 = pair_set_epi16(-cospi_24_64, cospi_8_64);
  938. const __m128i k__cospi_m16_m16 = _mm_set1_epi16(-cospi_16_64);
  939. const __m128i k__cospi_p16_p16 = _mm_set1_epi16(cospi_16_64);
  940. const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
  941. const __m128i k__cospi_m16_p16 = pair_set_epi16(-cospi_16_64, cospi_16_64);
  942. const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
  943. const __m128i kZero = _mm_set1_epi16(0);
  944. u[0] = _mm_unpacklo_epi16(in[15], in[0]);
  945. u[1] = _mm_unpackhi_epi16(in[15], in[0]);
  946. u[2] = _mm_unpacklo_epi16(in[13], in[2]);
  947. u[3] = _mm_unpackhi_epi16(in[13], in[2]);
  948. u[4] = _mm_unpacklo_epi16(in[11], in[4]);
  949. u[5] = _mm_unpackhi_epi16(in[11], in[4]);
  950. u[6] = _mm_unpacklo_epi16(in[9], in[6]);
  951. u[7] = _mm_unpackhi_epi16(in[9], in[6]);
  952. u[8] = _mm_unpacklo_epi16(in[7], in[8]);
  953. u[9] = _mm_unpackhi_epi16(in[7], in[8]);
  954. u[10] = _mm_unpacklo_epi16(in[5], in[10]);
  955. u[11] = _mm_unpackhi_epi16(in[5], in[10]);
  956. u[12] = _mm_unpacklo_epi16(in[3], in[12]);
  957. u[13] = _mm_unpackhi_epi16(in[3], in[12]);
  958. u[14] = _mm_unpacklo_epi16(in[1], in[14]);
  959. u[15] = _mm_unpackhi_epi16(in[1], in[14]);
  960. v[0] = _mm_madd_epi16(u[0], k__cospi_p01_p31);
  961. v[1] = _mm_madd_epi16(u[1], k__cospi_p01_p31);
  962. v[2] = _mm_madd_epi16(u[0], k__cospi_p31_m01);
  963. v[3] = _mm_madd_epi16(u[1], k__cospi_p31_m01);
  964. v[4] = _mm_madd_epi16(u[2], k__cospi_p05_p27);
  965. v[5] = _mm_madd_epi16(u[3], k__cospi_p05_p27);
  966. v[6] = _mm_madd_epi16(u[2], k__cospi_p27_m05);
  967. v[7] = _mm_madd_epi16(u[3], k__cospi_p27_m05);
  968. v[8] = _mm_madd_epi16(u[4], k__cospi_p09_p23);
  969. v[9] = _mm_madd_epi16(u[5], k__cospi_p09_p23);
  970. v[10] = _mm_madd_epi16(u[4], k__cospi_p23_m09);
  971. v[11] = _mm_madd_epi16(u[5], k__cospi_p23_m09);
  972. v[12] = _mm_madd_epi16(u[6], k__cospi_p13_p19);
  973. v[13] = _mm_madd_epi16(u[7], k__cospi_p13_p19);
  974. v[14] = _mm_madd_epi16(u[6], k__cospi_p19_m13);
  975. v[15] = _mm_madd_epi16(u[7], k__cospi_p19_m13);
  976. v[16] = _mm_madd_epi16(u[8], k__cospi_p17_p15);
  977. v[17] = _mm_madd_epi16(u[9], k__cospi_p17_p15);
  978. v[18] = _mm_madd_epi16(u[8], k__cospi_p15_m17);
  979. v[19] = _mm_madd_epi16(u[9], k__cospi_p15_m17);
  980. v[20] = _mm_madd_epi16(u[10], k__cospi_p21_p11);
  981. v[21] = _mm_madd_epi16(u[11], k__cospi_p21_p11);
  982. v[22] = _mm_madd_epi16(u[10], k__cospi_p11_m21);
  983. v[23] = _mm_madd_epi16(u[11], k__cospi_p11_m21);
  984. v[24] = _mm_madd_epi16(u[12], k__cospi_p25_p07);
  985. v[25] = _mm_madd_epi16(u[13], k__cospi_p25_p07);
  986. v[26] = _mm_madd_epi16(u[12], k__cospi_p07_m25);
  987. v[27] = _mm_madd_epi16(u[13], k__cospi_p07_m25);
  988. v[28] = _mm_madd_epi16(u[14], k__cospi_p29_p03);
  989. v[29] = _mm_madd_epi16(u[15], k__cospi_p29_p03);
  990. v[30] = _mm_madd_epi16(u[14], k__cospi_p03_m29);
  991. v[31] = _mm_madd_epi16(u[15], k__cospi_p03_m29);
  992. u[0] = _mm_add_epi32(v[0], v[16]);
  993. u[1] = _mm_add_epi32(v[1], v[17]);
  994. u[2] = _mm_add_epi32(v[2], v[18]);
  995. u[3] = _mm_add_epi32(v[3], v[19]);
  996. u[4] = _mm_add_epi32(v[4], v[20]);
  997. u[5] = _mm_add_epi32(v[5], v[21]);
  998. u[6] = _mm_add_epi32(v[6], v[22]);
  999. u[7] = _mm_add_epi32(v[7], v[23]);
  1000. u[8] = _mm_add_epi32(v[8], v[24]);
  1001. u[9] = _mm_add_epi32(v[9], v[25]);
  1002. u[10] = _mm_add_epi32(v[10], v[26]);
  1003. u[11] = _mm_add_epi32(v[11], v[27]);
  1004. u[12] = _mm_add_epi32(v[12], v[28]);
  1005. u[13] = _mm_add_epi32(v[13], v[29]);
  1006. u[14] = _mm_add_epi32(v[14], v[30]);
  1007. u[15] = _mm_add_epi32(v[15], v[31]);
  1008. u[16] = _mm_sub_epi32(v[0], v[16]);
  1009. u[17] = _mm_sub_epi32(v[1], v[17]);
  1010. u[18] = _mm_sub_epi32(v[2], v[18]);
  1011. u[19] = _mm_sub_epi32(v[3], v[19]);
  1012. u[20] = _mm_sub_epi32(v[4], v[20]);
  1013. u[21] = _mm_sub_epi32(v[5], v[21]);
  1014. u[22] = _mm_sub_epi32(v[6], v[22]);
  1015. u[23] = _mm_sub_epi32(v[7], v[23]);
  1016. u[24] = _mm_sub_epi32(v[8], v[24]);
  1017. u[25] = _mm_sub_epi32(v[9], v[25]);
  1018. u[26] = _mm_sub_epi32(v[10], v[26]);
  1019. u[27] = _mm_sub_epi32(v[11], v[27]);
  1020. u[28] = _mm_sub_epi32(v[12], v[28]);
  1021. u[29] = _mm_sub_epi32(v[13], v[29]);
  1022. u[30] = _mm_sub_epi32(v[14], v[30]);
  1023. u[31] = _mm_sub_epi32(v[15], v[31]);
  1024. v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
  1025. v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
  1026. v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
  1027. v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
  1028. v[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
  1029. v[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
  1030. v[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
  1031. v[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
  1032. v[8] = _mm_add_epi32(u[8], k__DCT_CONST_ROUNDING);
  1033. v[9] = _mm_add_epi32(u[9], k__DCT_CONST_ROUNDING);
  1034. v[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
  1035. v[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
  1036. v[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
  1037. v[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
  1038. v[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
  1039. v[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
  1040. v[16] = _mm_add_epi32(u[16], k__DCT_CONST_ROUNDING);
  1041. v[17] = _mm_add_epi32(u[17], k__DCT_CONST_ROUNDING);
  1042. v[18] = _mm_add_epi32(u[18], k__DCT_CONST_ROUNDING);
  1043. v[19] = _mm_add_epi32(u[19], k__DCT_CONST_ROUNDING);
  1044. v[20] = _mm_add_epi32(u[20], k__DCT_CONST_ROUNDING);
  1045. v[21] = _mm_add_epi32(u[21], k__DCT_CONST_ROUNDING);
  1046. v[22] = _mm_add_epi32(u[22], k__DCT_CONST_ROUNDING);
  1047. v[23] = _mm_add_epi32(u[23], k__DCT_CONST_ROUNDING);
  1048. v[24] = _mm_add_epi32(u[24], k__DCT_CONST_ROUNDING);
  1049. v[25] = _mm_add_epi32(u[25], k__DCT_CONST_ROUNDING);
  1050. v[26] = _mm_add_epi32(u[26], k__DCT_CONST_ROUNDING);
  1051. v[27] = _mm_add_epi32(u[27], k__DCT_CONST_ROUNDING);
  1052. v[28] = _mm_add_epi32(u[28], k__DCT_CONST_ROUNDING);
  1053. v[29] = _mm_add_epi32(u[29], k__DCT_CONST_ROUNDING);
  1054. v[30] = _mm_add_epi32(u[30], k__DCT_CONST_ROUNDING);
  1055. v[31] = _mm_add_epi32(u[31], k__DCT_CONST_ROUNDING);
  1056. u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
  1057. u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
  1058. u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
  1059. u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
  1060. u[4] = _mm_srai_epi32(v[4], DCT_CONST_BITS);
  1061. u[5] = _mm_srai_epi32(v[5], DCT_CONST_BITS);
  1062. u[6] = _mm_srai_epi32(v[6], DCT_CONST_BITS);
  1063. u[7] = _mm_srai_epi32(v[7], DCT_CONST_BITS);
  1064. u[8] = _mm_srai_epi32(v[8], DCT_CONST_BITS);
  1065. u[9] = _mm_srai_epi32(v[9], DCT_CONST_BITS);
  1066. u[10] = _mm_srai_epi32(v[10], DCT_CONST_BITS);
  1067. u[11] = _mm_srai_epi32(v[11], DCT_CONST_BITS);
  1068. u[12] = _mm_srai_epi32(v[12], DCT_CONST_BITS);
  1069. u[13] = _mm_srai_epi32(v[13], DCT_CONST_BITS);
  1070. u[14] = _mm_srai_epi32(v[14], DCT_CONST_BITS);
  1071. u[15] = _mm_srai_epi32(v[15], DCT_CONST_BITS);
  1072. u[16] = _mm_srai_epi32(v[16], DCT_CONST_BITS);
  1073. u[17] = _mm_srai_epi32(v[17], DCT_CONST_BITS);
  1074. u[18] = _mm_srai_epi32(v[18], DCT_CONST_BITS);
  1075. u[19] = _mm_srai_epi32(v[19], DCT_CONST_BITS);
  1076. u[20] = _mm_srai_epi32(v[20], DCT_CONST_BITS);
  1077. u[21] = _mm_srai_epi32(v[21], DCT_CONST_BITS);
  1078. u[22] = _mm_srai_epi32(v[22], DCT_CONST_BITS);
  1079. u[23] = _mm_srai_epi32(v[23], DCT_CONST_BITS);
  1080. u[24] = _mm_srai_epi32(v[24], DCT_CONST_BITS);
  1081. u[25] = _mm_srai_epi32(v[25], DCT_CONST_BITS);
  1082. u[26] = _mm_srai_epi32(v[26], DCT_CONST_BITS);
  1083. u[27] = _mm_srai_epi32(v[27], DCT_CONST_BITS);
  1084. u[28] = _mm_srai_epi32(v[28], DCT_CONST_BITS);
  1085. u[29] = _mm_srai_epi32(v[29], DCT_CONST_BITS);
  1086. u[30] = _mm_srai_epi32(v[30], DCT_CONST_BITS);
  1087. u[31] = _mm_srai_epi32(v[31], DCT_CONST_BITS);
  1088. s[0] = _mm_packs_epi32(u[0], u[1]);
  1089. s[1] = _mm_packs_epi32(u[2], u[3]);
  1090. s[2] = _mm_packs_epi32(u[4], u[5]);
  1091. s[3] = _mm_packs_epi32(u[6], u[7]);
  1092. s[4] = _mm_packs_epi32(u[8], u[9]);
  1093. s[5] = _mm_packs_epi32(u[10], u[11]);
  1094. s[6] = _mm_packs_epi32(u[12], u[13]);
  1095. s[7] = _mm_packs_epi32(u[14], u[15]);
  1096. s[8] = _mm_packs_epi32(u[16], u[17]);
  1097. s[9] = _mm_packs_epi32(u[18], u[19]);
  1098. s[10] = _mm_packs_epi32(u[20], u[21]);
  1099. s[11] = _mm_packs_epi32(u[22], u[23]);
  1100. s[12] = _mm_packs_epi32(u[24], u[25]);
  1101. s[13] = _mm_packs_epi32(u[26], u[27]);
  1102. s[14] = _mm_packs_epi32(u[28], u[29]);
  1103. s[15] = _mm_packs_epi32(u[30], u[31]);
  1104. // stage 2
  1105. u[0] = _mm_unpacklo_epi16(s[8], s[9]);
  1106. u[1] = _mm_unpackhi_epi16(s[8], s[9]);
  1107. u[2] = _mm_unpacklo_epi16(s[10], s[11]);
  1108. u[3] = _mm_unpackhi_epi16(s[10], s[11]);
  1109. u[4] = _mm_unpacklo_epi16(s[12], s[13]);
  1110. u[5] = _mm_unpackhi_epi16(s[12], s[13]);
  1111. u[6] = _mm_unpacklo_epi16(s[14], s[15]);
  1112. u[7] = _mm_unpackhi_epi16(s[14], s[15]);
  1113. v[0] = _mm_madd_epi16(u[0], k__cospi_p04_p28);
  1114. v[1] = _mm_madd_epi16(u[1], k__cospi_p04_p28);
  1115. v[2] = _mm_madd_epi16(u[0], k__cospi_p28_m04);
  1116. v[3] = _mm_madd_epi16(u[1], k__cospi_p28_m04);
  1117. v[4] = _mm_madd_epi16(u[2], k__cospi_p20_p12);
  1118. v[5] = _mm_madd_epi16(u[3], k__cospi_p20_p12);
  1119. v[6] = _mm_madd_epi16(u[2], k__cospi_p12_m20);
  1120. v[7] = _mm_madd_epi16(u[3], k__cospi_p12_m20);
  1121. v[8] = _mm_madd_epi16(u[4], k__cospi_m28_p04);
  1122. v[9] = _mm_madd_epi16(u[5], k__cospi_m28_p04);
  1123. v[10] = _mm_madd_epi16(u[4], k__cospi_p04_p28);
  1124. v[11] = _mm_madd_epi16(u[5], k__cospi_p04_p28);
  1125. v[12] = _mm_madd_epi16(u[6], k__cospi_m12_p20);
  1126. v[13] = _mm_madd_epi16(u[7], k__cospi_m12_p20);
  1127. v[14] = _mm_madd_epi16(u[6], k__cospi_p20_p12);
  1128. v[15] = _mm_madd_epi16(u[7], k__cospi_p20_p12);
  1129. u[0] = _mm_add_epi32(v[0], v[8]);
  1130. u[1] = _mm_add_epi32(v[1], v[9]);
  1131. u[2] = _mm_add_epi32(v[2], v[10]);
  1132. u[3] = _mm_add_epi32(v[3], v[11]);
  1133. u[4] = _mm_add_epi32(v[4], v[12]);
  1134. u[5] = _mm_add_epi32(v[5], v[13]);
  1135. u[6] = _mm_add_epi32(v[6], v[14]);
  1136. u[7] = _mm_add_epi32(v[7], v[15]);
  1137. u[8] = _mm_sub_epi32(v[0], v[8]);
  1138. u[9] = _mm_sub_epi32(v[1], v[9]);
  1139. u[10] = _mm_sub_epi32(v[2], v[10]);
  1140. u[11] = _mm_sub_epi32(v[3], v[11]);
  1141. u[12] = _mm_sub_epi32(v[4], v[12]);
  1142. u[13] = _mm_sub_epi32(v[5], v[13]);
  1143. u[14] = _mm_sub_epi32(v[6], v[14]);
  1144. u[15] = _mm_sub_epi32(v[7], v[15]);
  1145. v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
  1146. v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
  1147. v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
  1148. v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
  1149. v[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
  1150. v[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
  1151. v[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
  1152. v[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
  1153. v[8] = _mm_add_epi32(u[8], k__DCT_CONST_ROUNDING);
  1154. v[9] = _mm_add_epi32(u[9], k__DCT_CONST_ROUNDING);
  1155. v[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
  1156. v[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
  1157. v[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
  1158. v[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
  1159. v[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
  1160. v[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
  1161. u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
  1162. u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
  1163. u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
  1164. u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
  1165. u[4] = _mm_srai_epi32(v[4], DCT_CONST_BITS);
  1166. u[5] = _mm_srai_epi32(v[5], DCT_CONST_BITS);
  1167. u[6] = _mm_srai_epi32(v[6], DCT_CONST_BITS);
  1168. u[7] = _mm_srai_epi32(v[7], DCT_CONST_BITS);
  1169. u[8] = _mm_srai_epi32(v[8], DCT_CONST_BITS);
  1170. u[9] = _mm_srai_epi32(v[9], DCT_CONST_BITS);
  1171. u[10] = _mm_srai_epi32(v[10], DCT_CONST_BITS);
  1172. u[11] = _mm_srai_epi32(v[11], DCT_CONST_BITS);
  1173. u[12] = _mm_srai_epi32(v[12], DCT_CONST_BITS);
  1174. u[13] = _mm_srai_epi32(v[13], DCT_CONST_BITS);
  1175. u[14] = _mm_srai_epi32(v[14], DCT_CONST_BITS);
  1176. u[15] = _mm_srai_epi32(v[15], DCT_CONST_BITS);
  1177. x[0] = _mm_add_epi16(s[0], s[4]);
  1178. x[1] = _mm_add_epi16(s[1], s[5]);
  1179. x[2] = _mm_add_epi16(s[2], s[6]);
  1180. x[3] = _mm_add_epi16(s[3], s[7]);
  1181. x[4] = _mm_sub_epi16(s[0], s[4]);
  1182. x[5] = _mm_sub_epi16(s[1], s[5]);
  1183. x[6] = _mm_sub_epi16(s[2], s[6]);
  1184. x[7] = _mm_sub_epi16(s[3], s[7]);
  1185. x[8] = _mm_packs_epi32(u[0], u[1]);
  1186. x[9] = _mm_packs_epi32(u[2], u[3]);
  1187. x[10] = _mm_packs_epi32(u[4], u[5]);
  1188. x[11] = _mm_packs_epi32(u[6], u[7]);
  1189. x[12] = _mm_packs_epi32(u[8], u[9]);
  1190. x[13] = _mm_packs_epi32(u[10], u[11]);
  1191. x[14] = _mm_packs_epi32(u[12], u[13]);
  1192. x[15] = _mm_packs_epi32(u[14], u[15]);
  1193. // stage 3
  1194. u[0] = _mm_unpacklo_epi16(x[4], x[5]);
  1195. u[1] = _mm_unpackhi_epi16(x[4], x[5]);
  1196. u[2] = _mm_unpacklo_epi16(x[6], x[7]);
  1197. u[3] = _mm_unpackhi_epi16(x[6], x[7]);
  1198. u[4] = _mm_unpacklo_epi16(x[12], x[13]);
  1199. u[5] = _mm_unpackhi_epi16(x[12], x[13]);
  1200. u[6] = _mm_unpacklo_epi16(x[14], x[15]);
  1201. u[7] = _mm_unpackhi_epi16(x[14], x[15]);
  1202. v[0] = _mm_madd_epi16(u[0], k__cospi_p08_p24);
  1203. v[1] = _mm_madd_epi16(u[1], k__cospi_p08_p24);
  1204. v[2] = _mm_madd_epi16(u[0], k__cospi_p24_m08);
  1205. v[3] = _mm_madd_epi16(u[1], k__cospi_p24_m08);
  1206. v[4] = _mm_madd_epi16(u[2], k__cospi_m24_p08);
  1207. v[5] = _mm_madd_epi16(u[3], k__cospi_m24_p08);
  1208. v[6] = _mm_madd_epi16(u[2], k__cospi_p08_p24);
  1209. v[7] = _mm_madd_epi16(u[3], k__cospi_p08_p24);
  1210. v[8] = _mm_madd_epi16(u[4], k__cospi_p08_p24);
  1211. v[9] = _mm_madd_epi16(u[5], k__cospi_p08_p24);
  1212. v[10] = _mm_madd_epi16(u[4], k__cospi_p24_m08);
  1213. v[11] = _mm_madd_epi16(u[5], k__cospi_p24_m08);
  1214. v[12] = _mm_madd_epi16(u[6], k__cospi_m24_p08);
  1215. v[13] = _mm_madd_epi16(u[7], k__cospi_m24_p08);
  1216. v[14] = _mm_madd_epi16(u[6], k__cospi_p08_p24);
  1217. v[15] = _mm_madd_epi16(u[7], k__cospi_p08_p24);
  1218. u[0] = _mm_add_epi32(v[0], v[4]);
  1219. u[1] = _mm_add_epi32(v[1], v[5]);
  1220. u[2] = _mm_add_epi32(v[2], v[6]);
  1221. u[3] = _mm_add_epi32(v[3], v[7]);
  1222. u[4] = _mm_sub_epi32(v[0], v[4]);
  1223. u[5] = _mm_sub_epi32(v[1], v[5]);
  1224. u[6] = _mm_sub_epi32(v[2], v[6]);
  1225. u[7] = _mm_sub_epi32(v[3], v[7]);
  1226. u[8] = _mm_add_epi32(v[8], v[12]);
  1227. u[9] = _mm_add_epi32(v[9], v[13]);
  1228. u[10] = _mm_add_epi32(v[10], v[14]);
  1229. u[11] = _mm_add_epi32(v[11], v[15]);
  1230. u[12] = _mm_sub_epi32(v[8], v[12]);
  1231. u[13] = _mm_sub_epi32(v[9], v[13]);
  1232. u[14] = _mm_sub_epi32(v[10], v[14]);
  1233. u[15] = _mm_sub_epi32(v[11], v[15]);
  1234. u[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
  1235. u[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
  1236. u[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
  1237. u[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
  1238. u[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
  1239. u[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
  1240. u[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
  1241. u[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
  1242. u[8] = _mm_add_epi32(u[8], k__DCT_CONST_ROUNDING);
  1243. u[9] = _mm_add_epi32(u[9], k__DCT_CONST_ROUNDING);
  1244. u[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
  1245. u[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
  1246. u[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
  1247. u[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
  1248. u[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
  1249. u[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
  1250. v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
  1251. v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
  1252. v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
  1253. v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
  1254. v[4] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
  1255. v[5] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
  1256. v[6] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
  1257. v[7] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
  1258. v[8] = _mm_srai_epi32(u[8], DCT_CONST_BITS);
  1259. v[9] = _mm_srai_epi32(u[9], DCT_CONST_BITS);
  1260. v[10] = _mm_srai_epi32(u[10], DCT_CONST_BITS);
  1261. v[11] = _mm_srai_epi32(u[11], DCT_CONST_BITS);
  1262. v[12] = _mm_srai_epi32(u[12], DCT_CONST_BITS);
  1263. v[13] = _mm_srai_epi32(u[13], DCT_CONST_BITS);
  1264. v[14] = _mm_srai_epi32(u[14], DCT_CONST_BITS);
  1265. v[15] = _mm_srai_epi32(u[15], DCT_CONST_BITS);
  1266. s[0] = _mm_add_epi16(x[0], x[2]);
  1267. s[1] = _mm_add_epi16(x[1], x[3]);
  1268. s[2] = _mm_sub_epi16(x[0], x[2]);
  1269. s[3] = _mm_sub_epi16(x[1], x[3]);
  1270. s[4] = _mm_packs_epi32(v[0], v[1]);
  1271. s[5] = _mm_packs_epi32(v[2], v[3]);
  1272. s[6] = _mm_packs_epi32(v[4], v[5]);
  1273. s[7] = _mm_packs_epi32(v[6], v[7]);
  1274. s[8] = _mm_add_epi16(x[8], x[10]);
  1275. s[9] = _mm_add_epi16(x[9], x[11]);
  1276. s[10] = _mm_sub_epi16(x[8], x[10]);
  1277. s[11] = _mm_sub_epi16(x[9], x[11]);
  1278. s[12] = _mm_packs_epi32(v[8], v[9]);
  1279. s[13] = _mm_packs_epi32(v[10], v[11]);
  1280. s[14] = _mm_packs_epi32(v[12], v[13]);
  1281. s[15] = _mm_packs_epi32(v[14], v[15]);
  1282. // stage 4
  1283. u[0] = _mm_unpacklo_epi16(s[2], s[3]);
  1284. u[1] = _mm_unpackhi_epi16(s[2], s[3]);
  1285. u[2] = _mm_unpacklo_epi16(s[6], s[7]);
  1286. u[3] = _mm_unpackhi_epi16(s[6], s[7]);
  1287. u[4] = _mm_unpacklo_epi16(s[10], s[11]);
  1288. u[5] = _mm_unpackhi_epi16(s[10], s[11]);
  1289. u[6] = _mm_unpacklo_epi16(s[14], s[15]);
  1290. u[7] = _mm_unpackhi_epi16(s[14], s[15]);
  1291. v[0] = _mm_madd_epi16(u[0], k__cospi_m16_m16);
  1292. v[1] = _mm_madd_epi16(u[1], k__cospi_m16_m16);
  1293. v[2] = _mm_madd_epi16(u[0], k__cospi_p16_m16);
  1294. v[3] = _mm_madd_epi16(u[1], k__cospi_p16_m16);
  1295. v[4] = _mm_madd_epi16(u[2], k__cospi_p16_p16);
  1296. v[5] = _mm_madd_epi16(u[3], k__cospi_p16_p16);
  1297. v[6] = _mm_madd_epi16(u[2], k__cospi_m16_p16);
  1298. v[7] = _mm_madd_epi16(u[3], k__cospi_m16_p16);
  1299. v[8] = _mm_madd_epi16(u[4], k__cospi_p16_p16);
  1300. v[9] = _mm_madd_epi16(u[5], k__cospi_p16_p16);
  1301. v[10] = _mm_madd_epi16(u[4], k__cospi_m16_p16);
  1302. v[11] = _mm_madd_epi16(u[5], k__cospi_m16_p16);
  1303. v[12] = _mm_madd_epi16(u[6], k__cospi_m16_m16);
  1304. v[13] = _mm_madd_epi16(u[7], k__cospi_m16_m16);
  1305. v[14] = _mm_madd_epi16(u[6], k__cospi_p16_m16);
  1306. v[15] = _mm_madd_epi16(u[7], k__cospi_p16_m16);
  1307. u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
  1308. u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
  1309. u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
  1310. u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
  1311. u[4] = _mm_add_epi32(v[4], k__DCT_CONST_ROUNDING);
  1312. u[5] = _mm_add_epi32(v[5], k__DCT_CONST_ROUNDING);
  1313. u[6] = _mm_add_epi32(v[6], k__DCT_CONST_ROUNDING);
  1314. u[7] = _mm_add_epi32(v[7], k__DCT_CONST_ROUNDING);
  1315. u[8] = _mm_add_epi32(v[8], k__DCT_CONST_ROUNDING);
  1316. u[9] = _mm_add_epi32(v[9], k__DCT_CONST_ROUNDING);
  1317. u[10] = _mm_add_epi32(v[10], k__DCT_CONST_ROUNDING);
  1318. u[11] = _mm_add_epi32(v[11], k__DCT_CONST_ROUNDING);
  1319. u[12] = _mm_add_epi32(v[12], k__DCT_CONST_ROUNDING);
  1320. u[13] = _mm_add_epi32(v[13], k__DCT_CONST_ROUNDING);
  1321. u[14] = _mm_add_epi32(v[14], k__DCT_CONST_ROUNDING);
  1322. u[15] = _mm_add_epi32(v[15], k__DCT_CONST_ROUNDING);
  1323. v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
  1324. v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
  1325. v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
  1326. v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
  1327. v[4] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
  1328. v[5] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
  1329. v[6] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
  1330. v[7] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
  1331. v[8] = _mm_srai_epi32(u[8], DCT_CONST_BITS);
  1332. v[9] = _mm_srai_epi32(u[9], DCT_CONST_BITS);
  1333. v[10] = _mm_srai_epi32(u[10], DCT_CONST_BITS);
  1334. v[11] = _mm_srai_epi32(u[11], DCT_CONST_BITS);
  1335. v[12] = _mm_srai_epi32(u[12], DCT_CONST_BITS);
  1336. v[13] = _mm_srai_epi32(u[13], DCT_CONST_BITS);
  1337. v[14] = _mm_srai_epi32(u[14], DCT_CONST_BITS);
  1338. v[15] = _mm_srai_epi32(u[15], DCT_CONST_BITS);
  1339. in[0] = s[0];
  1340. in[1] = _mm_sub_epi16(kZero, s[8]);
  1341. in[2] = s[12];
  1342. in[3] = _mm_sub_epi16(kZero, s[4]);
  1343. in[4] = _mm_packs_epi32(v[4], v[5]);
  1344. in[5] = _mm_packs_epi32(v[12], v[13]);
  1345. in[6] = _mm_packs_epi32(v[8], v[9]);
  1346. in[7] = _mm_packs_epi32(v[0], v[1]);
  1347. in[8] = _mm_packs_epi32(v[2], v[3]);
  1348. in[9] = _mm_packs_epi32(v[10], v[11]);
  1349. in[10] = _mm_packs_epi32(v[14], v[15]);
  1350. in[11] = _mm_packs_epi32(v[6], v[7]);
  1351. in[12] = s[5];
  1352. in[13] = _mm_sub_epi16(kZero, s[13]);
  1353. in[14] = s[9];
  1354. in[15] = _mm_sub_epi16(kZero, s[1]);
  1355. }
  1356. static void fdct16_sse2(__m128i *in0, __m128i *in1) {
  1357. fdct16_8col(in0);
  1358. fdct16_8col(in1);
  1359. transpose_16bit_16x16(in0, in1);
  1360. }
  1361. static void fadst16_sse2(__m128i *in0, __m128i *in1) {
  1362. fadst16_8col(in0);
  1363. fadst16_8col(in1);
  1364. transpose_16bit_16x16(in0, in1);
  1365. }
  1366. void vp9_fht16x16_sse2(const int16_t *input, tran_low_t *output, int stride,
  1367. int tx_type) {
  1368. __m128i in0[16], in1[16];
  1369. switch (tx_type) {
  1370. case DCT_DCT: vpx_fdct16x16_sse2(input, output, stride); break;
  1371. case ADST_DCT:
  1372. load_buffer_16x16(input, in0, in1, stride);
  1373. fadst16_sse2(in0, in1);
  1374. right_shift_16x16(in0, in1);
  1375. fdct16_sse2(in0, in1);
  1376. write_buffer_16x16(output, in0, in1, 16);
  1377. break;
  1378. case DCT_ADST:
  1379. load_buffer_16x16(input, in0, in1, stride);
  1380. fdct16_sse2(in0, in1);
  1381. right_shift_16x16(in0, in1);
  1382. fadst16_sse2(in0, in1);
  1383. write_buffer_16x16(output, in0, in1, 16);
  1384. break;
  1385. default:
  1386. assert(tx_type == ADST_ADST);
  1387. load_buffer_16x16(input, in0, in1, stride);
  1388. fadst16_sse2(in0, in1);
  1389. right_shift_16x16(in0, in1);
  1390. fadst16_sse2(in0, in1);
  1391. write_buffer_16x16(output, in0, in1, 16);
  1392. break;
  1393. }
  1394. }