1 /*
2  * Copyright (c) 2018, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #include "av1/common/x86/av1_txfm_sse2.h"
13 #include "av1/encoder/av1_fwd_txfm1d_cfg.h"
14 #include "av1/encoder/x86/av1_fwd_txfm_sse2.h"
15 
16 // TODO(linfengz): refine fdct4x8 and fadst4x8 optimization (if possible).
17 
fdct4x4_new_sse2(const __m128i * input,__m128i * output,int8_t cos_bit)18 static void fdct4x4_new_sse2(const __m128i *input, __m128i *output,
19                              int8_t cos_bit) {
20   const int32_t *cospi = cospi_arr(cos_bit);
21   const __m128i cospi_p32_p32 = pair_set_epi16(cospi[32], cospi[32]);
22   const __m128i cospi_p32_m32 = pair_set_epi16(cospi[32], -cospi[32]);
23   const __m128i cospi_p16_p48 = pair_set_epi16(cospi[16], cospi[48]);
24   const __m128i cospi_p48_m16 = pair_set_epi16(cospi[48], -cospi[16]);
25   const __m128i __rounding = _mm_set1_epi32(1 << (cos_bit - 1));
26   __m128i u[4], v[4];
27 
28   u[0] = _mm_unpacklo_epi16(input[0], input[1]);
29   u[1] = _mm_unpacklo_epi16(input[3], input[2]);
30 
31   v[0] = _mm_add_epi16(u[0], u[1]);
32   v[1] = _mm_sub_epi16(u[0], u[1]);
33 
34   u[0] = _mm_madd_epi16(v[0], cospi_p32_p32);  // 0
35   u[1] = _mm_madd_epi16(v[0], cospi_p32_m32);  // 2
36   u[2] = _mm_madd_epi16(v[1], cospi_p16_p48);  // 1
37   u[3] = _mm_madd_epi16(v[1], cospi_p48_m16);  // 3
38 
39   v[0] = _mm_add_epi32(u[0], __rounding);
40   v[1] = _mm_add_epi32(u[1], __rounding);
41   v[2] = _mm_add_epi32(u[2], __rounding);
42   v[3] = _mm_add_epi32(u[3], __rounding);
43   u[0] = _mm_srai_epi32(v[0], cos_bit);
44   u[1] = _mm_srai_epi32(v[1], cos_bit);
45   u[2] = _mm_srai_epi32(v[2], cos_bit);
46   u[3] = _mm_srai_epi32(v[3], cos_bit);
47 
48   output[0] = _mm_packs_epi32(u[0], u[1]);
49   output[1] = _mm_packs_epi32(u[2], u[3]);
50   output[2] = _mm_srli_si128(output[0], 8);
51   output[3] = _mm_srli_si128(output[1], 8);
52 }
53 
fdct8x4_new_sse2(const __m128i * input,__m128i * output,int8_t cos_bit)54 static void fdct8x4_new_sse2(const __m128i *input, __m128i *output,
55                              int8_t cos_bit) {
56   const int32_t *cospi = cospi_arr(cos_bit);
57   const __m128i __rounding = _mm_set1_epi32(1 << (cos_bit - 1));
58 
59   __m128i cospi_p32_p32 = pair_set_epi16(cospi[32], cospi[32]);
60   __m128i cospi_p32_m32 = pair_set_epi16(cospi[32], -cospi[32]);
61   __m128i cospi_p48_p16 = pair_set_epi16(cospi[48], cospi[16]);
62   __m128i cospi_m16_p48 = pair_set_epi16(-cospi[16], cospi[48]);
63 
64   // stage 1
65   __m128i x1[4];
66   x1[0] = _mm_adds_epi16(input[0], input[3]);
67   x1[3] = _mm_subs_epi16(input[0], input[3]);
68   x1[1] = _mm_adds_epi16(input[1], input[2]);
69   x1[2] = _mm_subs_epi16(input[1], input[2]);
70 
71   // stage 2
72   __m128i x2[4];
73   btf_16_sse2(cospi_p32_p32, cospi_p32_m32, x1[0], x1[1], x2[0], x2[1]);
74   btf_16_sse2(cospi_p48_p16, cospi_m16_p48, x1[2], x1[3], x2[2], x2[3]);
75 
76   // stage 3
77   output[0] = x2[0];
78   output[1] = x2[2];
79   output[2] = x2[1];
80   output[3] = x2[3];
81 }
82 
fdct4x8_new_sse2(const __m128i * input,__m128i * output,int8_t cos_bit)83 static void fdct4x8_new_sse2(const __m128i *input, __m128i *output,
84                              int8_t cos_bit) {
85   const int32_t *cospi = cospi_arr(cos_bit);
86   const __m128i __rounding = _mm_set1_epi32(1 << (cos_bit - 1));
87 
88   __m128i cospi_m32_p32 = pair_set_epi16(-cospi[32], cospi[32]);
89   __m128i cospi_p32_p32 = pair_set_epi16(cospi[32], cospi[32]);
90   __m128i cospi_p32_m32 = pair_set_epi16(cospi[32], -cospi[32]);
91   __m128i cospi_p48_p16 = pair_set_epi16(cospi[48], cospi[16]);
92   __m128i cospi_m16_p48 = pair_set_epi16(-cospi[16], cospi[48]);
93   __m128i cospi_p56_p08 = pair_set_epi16(cospi[56], cospi[8]);
94   __m128i cospi_m08_p56 = pair_set_epi16(-cospi[8], cospi[56]);
95   __m128i cospi_p24_p40 = pair_set_epi16(cospi[24], cospi[40]);
96   __m128i cospi_m40_p24 = pair_set_epi16(-cospi[40], cospi[24]);
97 
98   // stage 1
99   __m128i x1[8];
100   x1[0] = _mm_adds_epi16(input[0], input[7]);
101   x1[7] = _mm_subs_epi16(input[0], input[7]);
102   x1[1] = _mm_adds_epi16(input[1], input[6]);
103   x1[6] = _mm_subs_epi16(input[1], input[6]);
104   x1[2] = _mm_adds_epi16(input[2], input[5]);
105   x1[5] = _mm_subs_epi16(input[2], input[5]);
106   x1[3] = _mm_adds_epi16(input[3], input[4]);
107   x1[4] = _mm_subs_epi16(input[3], input[4]);
108 
109   // stage 2
110   __m128i x2[8];
111   x2[0] = _mm_adds_epi16(x1[0], x1[3]);
112   x2[3] = _mm_subs_epi16(x1[0], x1[3]);
113   x2[1] = _mm_adds_epi16(x1[1], x1[2]);
114   x2[2] = _mm_subs_epi16(x1[1], x1[2]);
115   x2[4] = x1[4];
116   btf_16_w4_sse2(&cospi_m32_p32, &cospi_p32_p32, __rounding, cos_bit, &x1[5],
117                  &x1[6], &x2[5], &x2[6]);
118   x2[7] = x1[7];
119 
120   // stage 3
121   __m128i x3[8];
122   btf_16_w4_sse2(&cospi_p32_p32, &cospi_p32_m32, __rounding, cos_bit, &x2[0],
123                  &x2[1], &x3[0], &x3[1]);
124   btf_16_w4_sse2(&cospi_p48_p16, &cospi_m16_p48, __rounding, cos_bit, &x2[2],
125                  &x2[3], &x3[2], &x3[3]);
126   x3[4] = _mm_adds_epi16(x2[4], x2[5]);
127   x3[5] = _mm_subs_epi16(x2[4], x2[5]);
128   x3[6] = _mm_subs_epi16(x2[7], x2[6]);
129   x3[7] = _mm_adds_epi16(x2[7], x2[6]);
130 
131   // stage 4
132   __m128i x4[8];
133   x4[0] = x3[0];
134   x4[1] = x3[1];
135   x4[2] = x3[2];
136   x4[3] = x3[3];
137   btf_16_w4_sse2(&cospi_p56_p08, &cospi_m08_p56, __rounding, cos_bit, &x3[4],
138                  &x3[7], &x4[4], &x4[7]);
139   btf_16_w4_sse2(&cospi_p24_p40, &cospi_m40_p24, __rounding, cos_bit, &x3[5],
140                  &x3[6], &x4[5], &x4[6]);
141 
142   // stage 5
143   output[0] = x4[0];
144   output[1] = x4[4];
145   output[2] = x4[2];
146   output[3] = x4[6];
147   output[4] = x4[1];
148   output[5] = x4[5];
149   output[6] = x4[3];
150   output[7] = x4[7];
151 }
152 
fdct8x8_new_sse2(const __m128i * input,__m128i * output,int8_t cos_bit)153 static void fdct8x8_new_sse2(const __m128i *input, __m128i *output,
154                              int8_t cos_bit) {
155   const int32_t *cospi = cospi_arr(cos_bit);
156   const __m128i __rounding = _mm_set1_epi32(1 << (cos_bit - 1));
157 
158   __m128i cospi_m32_p32 = pair_set_epi16(-cospi[32], cospi[32]);
159   __m128i cospi_p32_p32 = pair_set_epi16(cospi[32], cospi[32]);
160   __m128i cospi_p32_m32 = pair_set_epi16(cospi[32], -cospi[32]);
161   __m128i cospi_p48_p16 = pair_set_epi16(cospi[48], cospi[16]);
162   __m128i cospi_m16_p48 = pair_set_epi16(-cospi[16], cospi[48]);
163   __m128i cospi_p56_p08 = pair_set_epi16(cospi[56], cospi[8]);
164   __m128i cospi_m08_p56 = pair_set_epi16(-cospi[8], cospi[56]);
165   __m128i cospi_p24_p40 = pair_set_epi16(cospi[24], cospi[40]);
166   __m128i cospi_m40_p24 = pair_set_epi16(-cospi[40], cospi[24]);
167 
168   // stage 1
169   __m128i x1[8];
170   x1[0] = _mm_adds_epi16(input[0], input[7]);
171   x1[7] = _mm_subs_epi16(input[0], input[7]);
172   x1[1] = _mm_adds_epi16(input[1], input[6]);
173   x1[6] = _mm_subs_epi16(input[1], input[6]);
174   x1[2] = _mm_adds_epi16(input[2], input[5]);
175   x1[5] = _mm_subs_epi16(input[2], input[5]);
176   x1[3] = _mm_adds_epi16(input[3], input[4]);
177   x1[4] = _mm_subs_epi16(input[3], input[4]);
178 
179   // stage 2
180   __m128i x2[8];
181   x2[0] = _mm_adds_epi16(x1[0], x1[3]);
182   x2[3] = _mm_subs_epi16(x1[0], x1[3]);
183   x2[1] = _mm_adds_epi16(x1[1], x1[2]);
184   x2[2] = _mm_subs_epi16(x1[1], x1[2]);
185   x2[4] = x1[4];
186   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[5], x1[6], x2[5], x2[6]);
187   x2[7] = x1[7];
188 
189   // stage 3
190   __m128i x3[8];
191   btf_16_sse2(cospi_p32_p32, cospi_p32_m32, x2[0], x2[1], x3[0], x3[1]);
192   btf_16_sse2(cospi_p48_p16, cospi_m16_p48, x2[2], x2[3], x3[2], x3[3]);
193   x3[4] = _mm_adds_epi16(x2[4], x2[5]);
194   x3[5] = _mm_subs_epi16(x2[4], x2[5]);
195   x3[6] = _mm_subs_epi16(x2[7], x2[6]);
196   x3[7] = _mm_adds_epi16(x2[7], x2[6]);
197 
198   // stage 4
199   __m128i x4[8];
200   x4[0] = x3[0];
201   x4[1] = x3[1];
202   x4[2] = x3[2];
203   x4[3] = x3[3];
204   btf_16_sse2(cospi_p56_p08, cospi_m08_p56, x3[4], x3[7], x4[4], x4[7]);
205   btf_16_sse2(cospi_p24_p40, cospi_m40_p24, x3[5], x3[6], x4[5], x4[6]);
206 
207   // stage 5
208   output[0] = x4[0];
209   output[1] = x4[4];
210   output[2] = x4[2];
211   output[3] = x4[6];
212   output[4] = x4[1];
213   output[5] = x4[5];
214   output[6] = x4[3];
215   output[7] = x4[7];
216 }
217 
fdct8x16_new_sse2(const __m128i * input,__m128i * output,int8_t cos_bit)218 static void fdct8x16_new_sse2(const __m128i *input, __m128i *output,
219                               int8_t cos_bit) {
220   const int32_t *cospi = cospi_arr(cos_bit);
221   const __m128i __rounding = _mm_set1_epi32(1 << (cos_bit - 1));
222 
223   __m128i cospi_m32_p32 = pair_set_epi16(-cospi[32], cospi[32]);
224   __m128i cospi_p32_p32 = pair_set_epi16(cospi[32], cospi[32]);
225   __m128i cospi_p32_m32 = pair_set_epi16(cospi[32], -cospi[32]);
226   __m128i cospi_p48_p16 = pair_set_epi16(cospi[48], cospi[16]);
227   __m128i cospi_m16_p48 = pair_set_epi16(-cospi[16], cospi[48]);
228   __m128i cospi_m48_m16 = pair_set_epi16(-cospi[48], -cospi[16]);
229   __m128i cospi_p56_p08 = pair_set_epi16(cospi[56], cospi[8]);
230   __m128i cospi_m08_p56 = pair_set_epi16(-cospi[8], cospi[56]);
231   __m128i cospi_p24_p40 = pair_set_epi16(cospi[24], cospi[40]);
232   __m128i cospi_m40_p24 = pair_set_epi16(-cospi[40], cospi[24]);
233   __m128i cospi_p60_p04 = pair_set_epi16(cospi[60], cospi[4]);
234   __m128i cospi_m04_p60 = pair_set_epi16(-cospi[4], cospi[60]);
235   __m128i cospi_p28_p36 = pair_set_epi16(cospi[28], cospi[36]);
236   __m128i cospi_m36_p28 = pair_set_epi16(-cospi[36], cospi[28]);
237   __m128i cospi_p44_p20 = pair_set_epi16(cospi[44], cospi[20]);
238   __m128i cospi_m20_p44 = pair_set_epi16(-cospi[20], cospi[44]);
239   __m128i cospi_p12_p52 = pair_set_epi16(cospi[12], cospi[52]);
240   __m128i cospi_m52_p12 = pair_set_epi16(-cospi[52], cospi[12]);
241 
242   // stage 1
243   __m128i x1[16];
244   x1[0] = _mm_adds_epi16(input[0], input[15]);
245   x1[15] = _mm_subs_epi16(input[0], input[15]);
246   x1[1] = _mm_adds_epi16(input[1], input[14]);
247   x1[14] = _mm_subs_epi16(input[1], input[14]);
248   x1[2] = _mm_adds_epi16(input[2], input[13]);
249   x1[13] = _mm_subs_epi16(input[2], input[13]);
250   x1[3] = _mm_adds_epi16(input[3], input[12]);
251   x1[12] = _mm_subs_epi16(input[3], input[12]);
252   x1[4] = _mm_adds_epi16(input[4], input[11]);
253   x1[11] = _mm_subs_epi16(input[4], input[11]);
254   x1[5] = _mm_adds_epi16(input[5], input[10]);
255   x1[10] = _mm_subs_epi16(input[5], input[10]);
256   x1[6] = _mm_adds_epi16(input[6], input[9]);
257   x1[9] = _mm_subs_epi16(input[6], input[9]);
258   x1[7] = _mm_adds_epi16(input[7], input[8]);
259   x1[8] = _mm_subs_epi16(input[7], input[8]);
260 
261   // stage 2
262   __m128i x2[16];
263   x2[0] = _mm_adds_epi16(x1[0], x1[7]);
264   x2[7] = _mm_subs_epi16(x1[0], x1[7]);
265   x2[1] = _mm_adds_epi16(x1[1], x1[6]);
266   x2[6] = _mm_subs_epi16(x1[1], x1[6]);
267   x2[2] = _mm_adds_epi16(x1[2], x1[5]);
268   x2[5] = _mm_subs_epi16(x1[2], x1[5]);
269   x2[3] = _mm_adds_epi16(x1[3], x1[4]);
270   x2[4] = _mm_subs_epi16(x1[3], x1[4]);
271   x2[8] = x1[8];
272   x2[9] = x1[9];
273   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[10], x1[13], x2[10], x2[13]);
274   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[11], x1[12], x2[11], x2[12]);
275   x2[14] = x1[14];
276   x2[15] = x1[15];
277 
278   // stage 3
279   __m128i x3[16];
280   x3[0] = _mm_adds_epi16(x2[0], x2[3]);
281   x3[3] = _mm_subs_epi16(x2[0], x2[3]);
282   x3[1] = _mm_adds_epi16(x2[1], x2[2]);
283   x3[2] = _mm_subs_epi16(x2[1], x2[2]);
284   x3[4] = x2[4];
285   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x2[5], x2[6], x3[5], x3[6]);
286   x3[7] = x2[7];
287   x3[8] = _mm_adds_epi16(x2[8], x2[11]);
288   x3[11] = _mm_subs_epi16(x2[8], x2[11]);
289   x3[9] = _mm_adds_epi16(x2[9], x2[10]);
290   x3[10] = _mm_subs_epi16(x2[9], x2[10]);
291   x3[12] = _mm_subs_epi16(x2[15], x2[12]);
292   x3[15] = _mm_adds_epi16(x2[15], x2[12]);
293   x3[13] = _mm_subs_epi16(x2[14], x2[13]);
294   x3[14] = _mm_adds_epi16(x2[14], x2[13]);
295 
296   // stage 4
297   __m128i x4[16];
298   btf_16_sse2(cospi_p32_p32, cospi_p32_m32, x3[0], x3[1], x4[0], x4[1]);
299   btf_16_sse2(cospi_p48_p16, cospi_m16_p48, x3[2], x3[3], x4[2], x4[3]);
300   x4[4] = _mm_adds_epi16(x3[4], x3[5]);
301   x4[5] = _mm_subs_epi16(x3[4], x3[5]);
302   x4[6] = _mm_subs_epi16(x3[7], x3[6]);
303   x4[7] = _mm_adds_epi16(x3[7], x3[6]);
304   x4[8] = x3[8];
305   btf_16_sse2(cospi_m16_p48, cospi_p48_p16, x3[9], x3[14], x4[9], x4[14]);
306   btf_16_sse2(cospi_m48_m16, cospi_m16_p48, x3[10], x3[13], x4[10], x4[13]);
307   x4[11] = x3[11];
308   x4[12] = x3[12];
309   x4[15] = x3[15];
310 
311   // stage 5
312   __m128i x5[16];
313   x5[0] = x4[0];
314   x5[1] = x4[1];
315   x5[2] = x4[2];
316   x5[3] = x4[3];
317   btf_16_sse2(cospi_p56_p08, cospi_m08_p56, x4[4], x4[7], x5[4], x5[7]);
318   btf_16_sse2(cospi_p24_p40, cospi_m40_p24, x4[5], x4[6], x5[5], x5[6]);
319   x5[8] = _mm_adds_epi16(x4[8], x4[9]);
320   x5[9] = _mm_subs_epi16(x4[8], x4[9]);
321   x5[10] = _mm_subs_epi16(x4[11], x4[10]);
322   x5[11] = _mm_adds_epi16(x4[11], x4[10]);
323   x5[12] = _mm_adds_epi16(x4[12], x4[13]);
324   x5[13] = _mm_subs_epi16(x4[12], x4[13]);
325   x5[14] = _mm_subs_epi16(x4[15], x4[14]);
326   x5[15] = _mm_adds_epi16(x4[15], x4[14]);
327 
328   // stage 6
329   __m128i x6[16];
330   x6[0] = x5[0];
331   x6[1] = x5[1];
332   x6[2] = x5[2];
333   x6[3] = x5[3];
334   x6[4] = x5[4];
335   x6[5] = x5[5];
336   x6[6] = x5[6];
337   x6[7] = x5[7];
338   btf_16_sse2(cospi_p60_p04, cospi_m04_p60, x5[8], x5[15], x6[8], x6[15]);
339   btf_16_sse2(cospi_p28_p36, cospi_m36_p28, x5[9], x5[14], x6[9], x6[14]);
340   btf_16_sse2(cospi_p44_p20, cospi_m20_p44, x5[10], x5[13], x6[10], x6[13]);
341   btf_16_sse2(cospi_p12_p52, cospi_m52_p12, x5[11], x5[12], x6[11], x6[12]);
342 
343   // stage 7
344   output[0] = x6[0];
345   output[1] = x6[8];
346   output[2] = x6[4];
347   output[3] = x6[12];
348   output[4] = x6[2];
349   output[5] = x6[10];
350   output[6] = x6[6];
351   output[7] = x6[14];
352   output[8] = x6[1];
353   output[9] = x6[9];
354   output[10] = x6[5];
355   output[11] = x6[13];
356   output[12] = x6[3];
357   output[13] = x6[11];
358   output[14] = x6[7];
359   output[15] = x6[15];
360 }
361 
av1_fdct8x32_new_sse2(const __m128i * input,__m128i * output,int8_t cos_bit)362 void av1_fdct8x32_new_sse2(const __m128i *input, __m128i *output,
363                            int8_t cos_bit) {
364   const int32_t *cospi = cospi_arr(cos_bit);
365   const __m128i __rounding = _mm_set1_epi32(1 << (cos_bit - 1));
366 
367   __m128i cospi_m32_p32 = pair_set_epi16(-cospi[32], cospi[32]);
368   __m128i cospi_p32_p32 = pair_set_epi16(cospi[32], cospi[32]);
369   __m128i cospi_m16_p48 = pair_set_epi16(-cospi[16], cospi[48]);
370   __m128i cospi_p48_p16 = pair_set_epi16(cospi[48], cospi[16]);
371   __m128i cospi_m48_m16 = pair_set_epi16(-cospi[48], -cospi[16]);
372   __m128i cospi_p32_m32 = pair_set_epi16(cospi[32], -cospi[32]);
373   __m128i cospi_p56_p08 = pair_set_epi16(cospi[56], cospi[8]);
374   __m128i cospi_m08_p56 = pair_set_epi16(-cospi[8], cospi[56]);
375   __m128i cospi_p24_p40 = pair_set_epi16(cospi[24], cospi[40]);
376   __m128i cospi_m40_p24 = pair_set_epi16(-cospi[40], cospi[24]);
377   __m128i cospi_m56_m08 = pair_set_epi16(-cospi[56], -cospi[8]);
378   __m128i cospi_m24_m40 = pair_set_epi16(-cospi[24], -cospi[40]);
379   __m128i cospi_p60_p04 = pair_set_epi16(cospi[60], cospi[4]);
380   __m128i cospi_m04_p60 = pair_set_epi16(-cospi[4], cospi[60]);
381   __m128i cospi_p28_p36 = pair_set_epi16(cospi[28], cospi[36]);
382   __m128i cospi_m36_p28 = pair_set_epi16(-cospi[36], cospi[28]);
383   __m128i cospi_p44_p20 = pair_set_epi16(cospi[44], cospi[20]);
384   __m128i cospi_m20_p44 = pair_set_epi16(-cospi[20], cospi[44]);
385   __m128i cospi_p12_p52 = pair_set_epi16(cospi[12], cospi[52]);
386   __m128i cospi_m52_p12 = pair_set_epi16(-cospi[52], cospi[12]);
387   __m128i cospi_p62_p02 = pair_set_epi16(cospi[62], cospi[2]);
388   __m128i cospi_m02_p62 = pair_set_epi16(-cospi[2], cospi[62]);
389   __m128i cospi_p30_p34 = pair_set_epi16(cospi[30], cospi[34]);
390   __m128i cospi_m34_p30 = pair_set_epi16(-cospi[34], cospi[30]);
391   __m128i cospi_p46_p18 = pair_set_epi16(cospi[46], cospi[18]);
392   __m128i cospi_m18_p46 = pair_set_epi16(-cospi[18], cospi[46]);
393   __m128i cospi_p14_p50 = pair_set_epi16(cospi[14], cospi[50]);
394   __m128i cospi_m50_p14 = pair_set_epi16(-cospi[50], cospi[14]);
395   __m128i cospi_p54_p10 = pair_set_epi16(cospi[54], cospi[10]);
396   __m128i cospi_m10_p54 = pair_set_epi16(-cospi[10], cospi[54]);
397   __m128i cospi_p22_p42 = pair_set_epi16(cospi[22], cospi[42]);
398   __m128i cospi_m42_p22 = pair_set_epi16(-cospi[42], cospi[22]);
399   __m128i cospi_p38_p26 = pair_set_epi16(cospi[38], cospi[26]);
400   __m128i cospi_m26_p38 = pair_set_epi16(-cospi[26], cospi[38]);
401   __m128i cospi_p06_p58 = pair_set_epi16(cospi[6], cospi[58]);
402   __m128i cospi_m58_p06 = pair_set_epi16(-cospi[58], cospi[6]);
403 
404   // stage 1
405   __m128i x1[32];
406   x1[0] = _mm_adds_epi16(input[0], input[31]);
407   x1[31] = _mm_subs_epi16(input[0], input[31]);
408   x1[1] = _mm_adds_epi16(input[1], input[30]);
409   x1[30] = _mm_subs_epi16(input[1], input[30]);
410   x1[2] = _mm_adds_epi16(input[2], input[29]);
411   x1[29] = _mm_subs_epi16(input[2], input[29]);
412   x1[3] = _mm_adds_epi16(input[3], input[28]);
413   x1[28] = _mm_subs_epi16(input[3], input[28]);
414   x1[4] = _mm_adds_epi16(input[4], input[27]);
415   x1[27] = _mm_subs_epi16(input[4], input[27]);
416   x1[5] = _mm_adds_epi16(input[5], input[26]);
417   x1[26] = _mm_subs_epi16(input[5], input[26]);
418   x1[6] = _mm_adds_epi16(input[6], input[25]);
419   x1[25] = _mm_subs_epi16(input[6], input[25]);
420   x1[7] = _mm_adds_epi16(input[7], input[24]);
421   x1[24] = _mm_subs_epi16(input[7], input[24]);
422   x1[8] = _mm_adds_epi16(input[8], input[23]);
423   x1[23] = _mm_subs_epi16(input[8], input[23]);
424   x1[9] = _mm_adds_epi16(input[9], input[22]);
425   x1[22] = _mm_subs_epi16(input[9], input[22]);
426   x1[10] = _mm_adds_epi16(input[10], input[21]);
427   x1[21] = _mm_subs_epi16(input[10], input[21]);
428   x1[11] = _mm_adds_epi16(input[11], input[20]);
429   x1[20] = _mm_subs_epi16(input[11], input[20]);
430   x1[12] = _mm_adds_epi16(input[12], input[19]);
431   x1[19] = _mm_subs_epi16(input[12], input[19]);
432   x1[13] = _mm_adds_epi16(input[13], input[18]);
433   x1[18] = _mm_subs_epi16(input[13], input[18]);
434   x1[14] = _mm_adds_epi16(input[14], input[17]);
435   x1[17] = _mm_subs_epi16(input[14], input[17]);
436   x1[15] = _mm_adds_epi16(input[15], input[16]);
437   x1[16] = _mm_subs_epi16(input[15], input[16]);
438 
439   // stage 2
440   __m128i x2[32];
441   x2[0] = _mm_adds_epi16(x1[0], x1[15]);
442   x2[15] = _mm_subs_epi16(x1[0], x1[15]);
443   x2[1] = _mm_adds_epi16(x1[1], x1[14]);
444   x2[14] = _mm_subs_epi16(x1[1], x1[14]);
445   x2[2] = _mm_adds_epi16(x1[2], x1[13]);
446   x2[13] = _mm_subs_epi16(x1[2], x1[13]);
447   x2[3] = _mm_adds_epi16(x1[3], x1[12]);
448   x2[12] = _mm_subs_epi16(x1[3], x1[12]);
449   x2[4] = _mm_adds_epi16(x1[4], x1[11]);
450   x2[11] = _mm_subs_epi16(x1[4], x1[11]);
451   x2[5] = _mm_adds_epi16(x1[5], x1[10]);
452   x2[10] = _mm_subs_epi16(x1[5], x1[10]);
453   x2[6] = _mm_adds_epi16(x1[6], x1[9]);
454   x2[9] = _mm_subs_epi16(x1[6], x1[9]);
455   x2[7] = _mm_adds_epi16(x1[7], x1[8]);
456   x2[8] = _mm_subs_epi16(x1[7], x1[8]);
457   x2[16] = x1[16];
458   x2[17] = x1[17];
459   x2[18] = x1[18];
460   x2[19] = x1[19];
461   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[20], x1[27], x2[20], x2[27]);
462   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[21], x1[26], x2[21], x2[26]);
463   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[22], x1[25], x2[22], x2[25]);
464   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[23], x1[24], x2[23], x2[24]);
465   x2[28] = x1[28];
466   x2[29] = x1[29];
467   x2[30] = x1[30];
468   x2[31] = x1[31];
469 
470   // stage 3
471   __m128i x3[32];
472   x3[0] = _mm_adds_epi16(x2[0], x2[7]);
473   x3[7] = _mm_subs_epi16(x2[0], x2[7]);
474   x3[1] = _mm_adds_epi16(x2[1], x2[6]);
475   x3[6] = _mm_subs_epi16(x2[1], x2[6]);
476   x3[2] = _mm_adds_epi16(x2[2], x2[5]);
477   x3[5] = _mm_subs_epi16(x2[2], x2[5]);
478   x3[3] = _mm_adds_epi16(x2[3], x2[4]);
479   x3[4] = _mm_subs_epi16(x2[3], x2[4]);
480   x3[8] = x2[8];
481   x3[9] = x2[9];
482   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x2[10], x2[13], x3[10], x3[13]);
483   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x2[11], x2[12], x3[11], x3[12]);
484   x3[14] = x2[14];
485   x3[15] = x2[15];
486   x3[16] = _mm_adds_epi16(x2[16], x2[23]);
487   x3[23] = _mm_subs_epi16(x2[16], x2[23]);
488   x3[17] = _mm_adds_epi16(x2[17], x2[22]);
489   x3[22] = _mm_subs_epi16(x2[17], x2[22]);
490   x3[18] = _mm_adds_epi16(x2[18], x2[21]);
491   x3[21] = _mm_subs_epi16(x2[18], x2[21]);
492   x3[19] = _mm_adds_epi16(x2[19], x2[20]);
493   x3[20] = _mm_subs_epi16(x2[19], x2[20]);
494   x3[24] = _mm_subs_epi16(x2[31], x2[24]);
495   x3[31] = _mm_adds_epi16(x2[31], x2[24]);
496   x3[25] = _mm_subs_epi16(x2[30], x2[25]);
497   x3[30] = _mm_adds_epi16(x2[30], x2[25]);
498   x3[26] = _mm_subs_epi16(x2[29], x2[26]);
499   x3[29] = _mm_adds_epi16(x2[29], x2[26]);
500   x3[27] = _mm_subs_epi16(x2[28], x2[27]);
501   x3[28] = _mm_adds_epi16(x2[28], x2[27]);
502 
503   // stage 4
504   __m128i x4[32];
505   x4[0] = _mm_adds_epi16(x3[0], x3[3]);
506   x4[3] = _mm_subs_epi16(x3[0], x3[3]);
507   x4[1] = _mm_adds_epi16(x3[1], x3[2]);
508   x4[2] = _mm_subs_epi16(x3[1], x3[2]);
509   x4[4] = x3[4];
510   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x3[5], x3[6], x4[5], x4[6]);
511   x4[7] = x3[7];
512   x4[8] = _mm_adds_epi16(x3[8], x3[11]);
513   x4[11] = _mm_subs_epi16(x3[8], x3[11]);
514   x4[9] = _mm_adds_epi16(x3[9], x3[10]);
515   x4[10] = _mm_subs_epi16(x3[9], x3[10]);
516   x4[12] = _mm_subs_epi16(x3[15], x3[12]);
517   x4[15] = _mm_adds_epi16(x3[15], x3[12]);
518   x4[13] = _mm_subs_epi16(x3[14], x3[13]);
519   x4[14] = _mm_adds_epi16(x3[14], x3[13]);
520   x4[16] = x3[16];
521   x4[17] = x3[17];
522   btf_16_sse2(cospi_m16_p48, cospi_p48_p16, x3[18], x3[29], x4[18], x4[29]);
523   btf_16_sse2(cospi_m16_p48, cospi_p48_p16, x3[19], x3[28], x4[19], x4[28]);
524   btf_16_sse2(cospi_m48_m16, cospi_m16_p48, x3[20], x3[27], x4[20], x4[27]);
525   btf_16_sse2(cospi_m48_m16, cospi_m16_p48, x3[21], x3[26], x4[21], x4[26]);
526   x4[22] = x3[22];
527   x4[23] = x3[23];
528   x4[24] = x3[24];
529   x4[25] = x3[25];
530   x4[30] = x3[30];
531   x4[31] = x3[31];
532 
533   // stage 5
534   __m128i x5[32];
535   btf_16_sse2(cospi_p32_p32, cospi_p32_m32, x4[0], x4[1], x5[0], x5[1]);
536   btf_16_sse2(cospi_p48_p16, cospi_m16_p48, x4[2], x4[3], x5[2], x5[3]);
537   x5[4] = _mm_adds_epi16(x4[4], x4[5]);
538   x5[5] = _mm_subs_epi16(x4[4], x4[5]);
539   x5[6] = _mm_subs_epi16(x4[7], x4[6]);
540   x5[7] = _mm_adds_epi16(x4[7], x4[6]);
541   x5[8] = x4[8];
542   btf_16_sse2(cospi_m16_p48, cospi_p48_p16, x4[9], x4[14], x5[9], x5[14]);
543   btf_16_sse2(cospi_m48_m16, cospi_m16_p48, x4[10], x4[13], x5[10], x5[13]);
544   x5[11] = x4[11];
545   x5[12] = x4[12];
546   x5[15] = x4[15];
547   x5[16] = _mm_adds_epi16(x4[16], x4[19]);
548   x5[19] = _mm_subs_epi16(x4[16], x4[19]);
549   x5[17] = _mm_adds_epi16(x4[17], x4[18]);
550   x5[18] = _mm_subs_epi16(x4[17], x4[18]);
551   x5[20] = _mm_subs_epi16(x4[23], x4[20]);
552   x5[23] = _mm_adds_epi16(x4[23], x4[20]);
553   x5[21] = _mm_subs_epi16(x4[22], x4[21]);
554   x5[22] = _mm_adds_epi16(x4[22], x4[21]);
555   x5[24] = _mm_adds_epi16(x4[24], x4[27]);
556   x5[27] = _mm_subs_epi16(x4[24], x4[27]);
557   x5[25] = _mm_adds_epi16(x4[25], x4[26]);
558   x5[26] = _mm_subs_epi16(x4[25], x4[26]);
559   x5[28] = _mm_subs_epi16(x4[31], x4[28]);
560   x5[31] = _mm_adds_epi16(x4[31], x4[28]);
561   x5[29] = _mm_subs_epi16(x4[30], x4[29]);
562   x5[30] = _mm_adds_epi16(x4[30], x4[29]);
563 
564   // stage 6
565   __m128i x6[32];
566   x6[0] = x5[0];
567   x6[1] = x5[1];
568   x6[2] = x5[2];
569   x6[3] = x5[3];
570   btf_16_sse2(cospi_p56_p08, cospi_m08_p56, x5[4], x5[7], x6[4], x6[7]);
571   btf_16_sse2(cospi_p24_p40, cospi_m40_p24, x5[5], x5[6], x6[5], x6[6]);
572   x6[8] = _mm_adds_epi16(x5[8], x5[9]);
573   x6[9] = _mm_subs_epi16(x5[8], x5[9]);
574   x6[10] = _mm_subs_epi16(x5[11], x5[10]);
575   x6[11] = _mm_adds_epi16(x5[11], x5[10]);
576   x6[12] = _mm_adds_epi16(x5[12], x5[13]);
577   x6[13] = _mm_subs_epi16(x5[12], x5[13]);
578   x6[14] = _mm_subs_epi16(x5[15], x5[14]);
579   x6[15] = _mm_adds_epi16(x5[15], x5[14]);
580   x6[16] = x5[16];
581   btf_16_sse2(cospi_m08_p56, cospi_p56_p08, x5[17], x5[30], x6[17], x6[30]);
582   btf_16_sse2(cospi_m56_m08, cospi_m08_p56, x5[18], x5[29], x6[18], x6[29]);
583   x6[19] = x5[19];
584   x6[20] = x5[20];
585   btf_16_sse2(cospi_m40_p24, cospi_p24_p40, x5[21], x5[26], x6[21], x6[26]);
586   btf_16_sse2(cospi_m24_m40, cospi_m40_p24, x5[22], x5[25], x6[22], x6[25]);
587   x6[23] = x5[23];
588   x6[24] = x5[24];
589   x6[27] = x5[27];
590   x6[28] = x5[28];
591   x6[31] = x5[31];
592 
593   // stage 7
594   __m128i x7[32];
595   x7[0] = x6[0];
596   x7[1] = x6[1];
597   x7[2] = x6[2];
598   x7[3] = x6[3];
599   x7[4] = x6[4];
600   x7[5] = x6[5];
601   x7[6] = x6[6];
602   x7[7] = x6[7];
603   btf_16_sse2(cospi_p60_p04, cospi_m04_p60, x6[8], x6[15], x7[8], x7[15]);
604   btf_16_sse2(cospi_p28_p36, cospi_m36_p28, x6[9], x6[14], x7[9], x7[14]);
605   btf_16_sse2(cospi_p44_p20, cospi_m20_p44, x6[10], x6[13], x7[10], x7[13]);
606   btf_16_sse2(cospi_p12_p52, cospi_m52_p12, x6[11], x6[12], x7[11], x7[12]);
607   x7[16] = _mm_adds_epi16(x6[16], x6[17]);
608   x7[17] = _mm_subs_epi16(x6[16], x6[17]);
609   x7[18] = _mm_subs_epi16(x6[19], x6[18]);
610   x7[19] = _mm_adds_epi16(x6[19], x6[18]);
611   x7[20] = _mm_adds_epi16(x6[20], x6[21]);
612   x7[21] = _mm_subs_epi16(x6[20], x6[21]);
613   x7[22] = _mm_subs_epi16(x6[23], x6[22]);
614   x7[23] = _mm_adds_epi16(x6[23], x6[22]);
615   x7[24] = _mm_adds_epi16(x6[24], x6[25]);
616   x7[25] = _mm_subs_epi16(x6[24], x6[25]);
617   x7[26] = _mm_subs_epi16(x6[27], x6[26]);
618   x7[27] = _mm_adds_epi16(x6[27], x6[26]);
619   x7[28] = _mm_adds_epi16(x6[28], x6[29]);
620   x7[29] = _mm_subs_epi16(x6[28], x6[29]);
621   x7[30] = _mm_subs_epi16(x6[31], x6[30]);
622   x7[31] = _mm_adds_epi16(x6[31], x6[30]);
623 
624   // stage 8
625   __m128i x8[32];
626   x8[0] = x7[0];
627   x8[1] = x7[1];
628   x8[2] = x7[2];
629   x8[3] = x7[3];
630   x8[4] = x7[4];
631   x8[5] = x7[5];
632   x8[6] = x7[6];
633   x8[7] = x7[7];
634   x8[8] = x7[8];
635   x8[9] = x7[9];
636   x8[10] = x7[10];
637   x8[11] = x7[11];
638   x8[12] = x7[12];
639   x8[13] = x7[13];
640   x8[14] = x7[14];
641   x8[15] = x7[15];
642   btf_16_sse2(cospi_p62_p02, cospi_m02_p62, x7[16], x7[31], x8[16], x8[31]);
643   btf_16_sse2(cospi_p30_p34, cospi_m34_p30, x7[17], x7[30], x8[17], x8[30]);
644   btf_16_sse2(cospi_p46_p18, cospi_m18_p46, x7[18], x7[29], x8[18], x8[29]);
645   btf_16_sse2(cospi_p14_p50, cospi_m50_p14, x7[19], x7[28], x8[19], x8[28]);
646   btf_16_sse2(cospi_p54_p10, cospi_m10_p54, x7[20], x7[27], x8[20], x8[27]);
647   btf_16_sse2(cospi_p22_p42, cospi_m42_p22, x7[21], x7[26], x8[21], x8[26]);
648   btf_16_sse2(cospi_p38_p26, cospi_m26_p38, x7[22], x7[25], x8[22], x8[25]);
649   btf_16_sse2(cospi_p06_p58, cospi_m58_p06, x7[23], x7[24], x8[23], x8[24]);
650 
651   // stage 9
652   output[0] = x8[0];
653   output[1] = x8[16];
654   output[2] = x8[8];
655   output[3] = x8[24];
656   output[4] = x8[4];
657   output[5] = x8[20];
658   output[6] = x8[12];
659   output[7] = x8[28];
660   output[8] = x8[2];
661   output[9] = x8[18];
662   output[10] = x8[10];
663   output[11] = x8[26];
664   output[12] = x8[6];
665   output[13] = x8[22];
666   output[14] = x8[14];
667   output[15] = x8[30];
668   output[16] = x8[1];
669   output[17] = x8[17];
670   output[18] = x8[9];
671   output[19] = x8[25];
672   output[20] = x8[5];
673   output[21] = x8[21];
674   output[22] = x8[13];
675   output[23] = x8[29];
676   output[24] = x8[3];
677   output[25] = x8[19];
678   output[26] = x8[11];
679   output[27] = x8[27];
680   output[28] = x8[7];
681   output[29] = x8[23];
682   output[30] = x8[15];
683   output[31] = x8[31];
684 }
685 
av1_fdct8x64_new_sse2(const __m128i * input,__m128i * output,int8_t cos_bit)686 void av1_fdct8x64_new_sse2(const __m128i *input, __m128i *output,
687                            int8_t cos_bit) {
688   const int32_t *cospi = cospi_arr(cos_bit);
689   const __m128i __rounding = _mm_set1_epi32(1 << (cos_bit - 1));
690 
691   __m128i cospi_m32_p32 = pair_set_epi16(-cospi[32], cospi[32]);
692   __m128i cospi_p32_p32 = pair_set_epi16(cospi[32], cospi[32]);
693   __m128i cospi_m16_p48 = pair_set_epi16(-cospi[16], cospi[48]);
694   __m128i cospi_p48_p16 = pair_set_epi16(cospi[48], cospi[16]);
695   __m128i cospi_m48_m16 = pair_set_epi16(-cospi[48], -cospi[16]);
696   __m128i cospi_p32_m32 = pair_set_epi16(cospi[32], -cospi[32]);
697   __m128i cospi_m08_p56 = pair_set_epi16(-cospi[8], cospi[56]);
698   __m128i cospi_p56_p08 = pair_set_epi16(cospi[56], cospi[8]);
699   __m128i cospi_m56_m08 = pair_set_epi16(-cospi[56], -cospi[8]);
700   __m128i cospi_m40_p24 = pair_set_epi16(-cospi[40], cospi[24]);
701   __m128i cospi_p24_p40 = pair_set_epi16(cospi[24], cospi[40]);
702   __m128i cospi_m24_m40 = pair_set_epi16(-cospi[24], -cospi[40]);
703   __m128i cospi_p60_p04 = pair_set_epi16(cospi[60], cospi[4]);
704   __m128i cospi_m04_p60 = pair_set_epi16(-cospi[4], cospi[60]);
705   __m128i cospi_p28_p36 = pair_set_epi16(cospi[28], cospi[36]);
706   __m128i cospi_m36_p28 = pair_set_epi16(-cospi[36], cospi[28]);
707   __m128i cospi_p44_p20 = pair_set_epi16(cospi[44], cospi[20]);
708   __m128i cospi_m20_p44 = pair_set_epi16(-cospi[20], cospi[44]);
709   __m128i cospi_p12_p52 = pair_set_epi16(cospi[12], cospi[52]);
710   __m128i cospi_m52_p12 = pair_set_epi16(-cospi[52], cospi[12]);
711   __m128i cospi_m60_m04 = pair_set_epi16(-cospi[60], -cospi[4]);
712   __m128i cospi_m28_m36 = pair_set_epi16(-cospi[28], -cospi[36]);
713   __m128i cospi_m44_m20 = pair_set_epi16(-cospi[44], -cospi[20]);
714   __m128i cospi_m12_m52 = pair_set_epi16(-cospi[12], -cospi[52]);
715   __m128i cospi_p62_p02 = pair_set_epi16(cospi[62], cospi[2]);
716   __m128i cospi_m02_p62 = pair_set_epi16(-cospi[2], cospi[62]);
717   __m128i cospi_p30_p34 = pair_set_epi16(cospi[30], cospi[34]);
718   __m128i cospi_m34_p30 = pair_set_epi16(-cospi[34], cospi[30]);
719   __m128i cospi_p46_p18 = pair_set_epi16(cospi[46], cospi[18]);
720   __m128i cospi_m18_p46 = pair_set_epi16(-cospi[18], cospi[46]);
721   __m128i cospi_p14_p50 = pair_set_epi16(cospi[14], cospi[50]);
722   __m128i cospi_m50_p14 = pair_set_epi16(-cospi[50], cospi[14]);
723   __m128i cospi_p54_p10 = pair_set_epi16(cospi[54], cospi[10]);
724   __m128i cospi_m10_p54 = pair_set_epi16(-cospi[10], cospi[54]);
725   __m128i cospi_p22_p42 = pair_set_epi16(cospi[22], cospi[42]);
726   __m128i cospi_m42_p22 = pair_set_epi16(-cospi[42], cospi[22]);
727   __m128i cospi_p38_p26 = pair_set_epi16(cospi[38], cospi[26]);
728   __m128i cospi_m26_p38 = pair_set_epi16(-cospi[26], cospi[38]);
729   __m128i cospi_p06_p58 = pair_set_epi16(cospi[6], cospi[58]);
730   __m128i cospi_m58_p06 = pair_set_epi16(-cospi[58], cospi[6]);
731   __m128i cospi_p63_p01 = pair_set_epi16(cospi[63], cospi[1]);
732   __m128i cospi_m01_p63 = pair_set_epi16(-cospi[1], cospi[63]);
733   __m128i cospi_p31_p33 = pair_set_epi16(cospi[31], cospi[33]);
734   __m128i cospi_m33_p31 = pair_set_epi16(-cospi[33], cospi[31]);
735   __m128i cospi_p47_p17 = pair_set_epi16(cospi[47], cospi[17]);
736   __m128i cospi_m17_p47 = pair_set_epi16(-cospi[17], cospi[47]);
737   __m128i cospi_p15_p49 = pair_set_epi16(cospi[15], cospi[49]);
738   __m128i cospi_m49_p15 = pair_set_epi16(-cospi[49], cospi[15]);
739   __m128i cospi_p55_p09 = pair_set_epi16(cospi[55], cospi[9]);
740   __m128i cospi_m09_p55 = pair_set_epi16(-cospi[9], cospi[55]);
741   __m128i cospi_p23_p41 = pair_set_epi16(cospi[23], cospi[41]);
742   __m128i cospi_m41_p23 = pair_set_epi16(-cospi[41], cospi[23]);
743   __m128i cospi_p39_p25 = pair_set_epi16(cospi[39], cospi[25]);
744   __m128i cospi_m25_p39 = pair_set_epi16(-cospi[25], cospi[39]);
745   __m128i cospi_p07_p57 = pair_set_epi16(cospi[7], cospi[57]);
746   __m128i cospi_m57_p07 = pair_set_epi16(-cospi[57], cospi[7]);
747   __m128i cospi_p59_p05 = pair_set_epi16(cospi[59], cospi[5]);
748   __m128i cospi_m05_p59 = pair_set_epi16(-cospi[5], cospi[59]);
749   __m128i cospi_p27_p37 = pair_set_epi16(cospi[27], cospi[37]);
750   __m128i cospi_m37_p27 = pair_set_epi16(-cospi[37], cospi[27]);
751   __m128i cospi_p43_p21 = pair_set_epi16(cospi[43], cospi[21]);
752   __m128i cospi_m21_p43 = pair_set_epi16(-cospi[21], cospi[43]);
753   __m128i cospi_p11_p53 = pair_set_epi16(cospi[11], cospi[53]);
754   __m128i cospi_m53_p11 = pair_set_epi16(-cospi[53], cospi[11]);
755   __m128i cospi_p51_p13 = pair_set_epi16(cospi[51], cospi[13]);
756   __m128i cospi_m13_p51 = pair_set_epi16(-cospi[13], cospi[51]);
757   __m128i cospi_p19_p45 = pair_set_epi16(cospi[19], cospi[45]);
758   __m128i cospi_m45_p19 = pair_set_epi16(-cospi[45], cospi[19]);
759   __m128i cospi_p35_p29 = pair_set_epi16(cospi[35], cospi[29]);
760   __m128i cospi_m29_p35 = pair_set_epi16(-cospi[29], cospi[35]);
761   __m128i cospi_p03_p61 = pair_set_epi16(cospi[3], cospi[61]);
762   __m128i cospi_m61_p03 = pair_set_epi16(-cospi[61], cospi[3]);
763 
764   // stage 1
765   __m128i x1[64];
766   x1[0] = _mm_adds_epi16(input[0], input[63]);
767   x1[63] = _mm_subs_epi16(input[0], input[63]);
768   x1[1] = _mm_adds_epi16(input[1], input[62]);
769   x1[62] = _mm_subs_epi16(input[1], input[62]);
770   x1[2] = _mm_adds_epi16(input[2], input[61]);
771   x1[61] = _mm_subs_epi16(input[2], input[61]);
772   x1[3] = _mm_adds_epi16(input[3], input[60]);
773   x1[60] = _mm_subs_epi16(input[3], input[60]);
774   x1[4] = _mm_adds_epi16(input[4], input[59]);
775   x1[59] = _mm_subs_epi16(input[4], input[59]);
776   x1[5] = _mm_adds_epi16(input[5], input[58]);
777   x1[58] = _mm_subs_epi16(input[5], input[58]);
778   x1[6] = _mm_adds_epi16(input[6], input[57]);
779   x1[57] = _mm_subs_epi16(input[6], input[57]);
780   x1[7] = _mm_adds_epi16(input[7], input[56]);
781   x1[56] = _mm_subs_epi16(input[7], input[56]);
782   x1[8] = _mm_adds_epi16(input[8], input[55]);
783   x1[55] = _mm_subs_epi16(input[8], input[55]);
784   x1[9] = _mm_adds_epi16(input[9], input[54]);
785   x1[54] = _mm_subs_epi16(input[9], input[54]);
786   x1[10] = _mm_adds_epi16(input[10], input[53]);
787   x1[53] = _mm_subs_epi16(input[10], input[53]);
788   x1[11] = _mm_adds_epi16(input[11], input[52]);
789   x1[52] = _mm_subs_epi16(input[11], input[52]);
790   x1[12] = _mm_adds_epi16(input[12], input[51]);
791   x1[51] = _mm_subs_epi16(input[12], input[51]);
792   x1[13] = _mm_adds_epi16(input[13], input[50]);
793   x1[50] = _mm_subs_epi16(input[13], input[50]);
794   x1[14] = _mm_adds_epi16(input[14], input[49]);
795   x1[49] = _mm_subs_epi16(input[14], input[49]);
796   x1[15] = _mm_adds_epi16(input[15], input[48]);
797   x1[48] = _mm_subs_epi16(input[15], input[48]);
798   x1[16] = _mm_adds_epi16(input[16], input[47]);
799   x1[47] = _mm_subs_epi16(input[16], input[47]);
800   x1[17] = _mm_adds_epi16(input[17], input[46]);
801   x1[46] = _mm_subs_epi16(input[17], input[46]);
802   x1[18] = _mm_adds_epi16(input[18], input[45]);
803   x1[45] = _mm_subs_epi16(input[18], input[45]);
804   x1[19] = _mm_adds_epi16(input[19], input[44]);
805   x1[44] = _mm_subs_epi16(input[19], input[44]);
806   x1[20] = _mm_adds_epi16(input[20], input[43]);
807   x1[43] = _mm_subs_epi16(input[20], input[43]);
808   x1[21] = _mm_adds_epi16(input[21], input[42]);
809   x1[42] = _mm_subs_epi16(input[21], input[42]);
810   x1[22] = _mm_adds_epi16(input[22], input[41]);
811   x1[41] = _mm_subs_epi16(input[22], input[41]);
812   x1[23] = _mm_adds_epi16(input[23], input[40]);
813   x1[40] = _mm_subs_epi16(input[23], input[40]);
814   x1[24] = _mm_adds_epi16(input[24], input[39]);
815   x1[39] = _mm_subs_epi16(input[24], input[39]);
816   x1[25] = _mm_adds_epi16(input[25], input[38]);
817   x1[38] = _mm_subs_epi16(input[25], input[38]);
818   x1[26] = _mm_adds_epi16(input[26], input[37]);
819   x1[37] = _mm_subs_epi16(input[26], input[37]);
820   x1[27] = _mm_adds_epi16(input[27], input[36]);
821   x1[36] = _mm_subs_epi16(input[27], input[36]);
822   x1[28] = _mm_adds_epi16(input[28], input[35]);
823   x1[35] = _mm_subs_epi16(input[28], input[35]);
824   x1[29] = _mm_adds_epi16(input[29], input[34]);
825   x1[34] = _mm_subs_epi16(input[29], input[34]);
826   x1[30] = _mm_adds_epi16(input[30], input[33]);
827   x1[33] = _mm_subs_epi16(input[30], input[33]);
828   x1[31] = _mm_adds_epi16(input[31], input[32]);
829   x1[32] = _mm_subs_epi16(input[31], input[32]);
830 
831   // stage 2
832   __m128i x2[64];
833   x2[0] = _mm_adds_epi16(x1[0], x1[31]);
834   x2[31] = _mm_subs_epi16(x1[0], x1[31]);
835   x2[1] = _mm_adds_epi16(x1[1], x1[30]);
836   x2[30] = _mm_subs_epi16(x1[1], x1[30]);
837   x2[2] = _mm_adds_epi16(x1[2], x1[29]);
838   x2[29] = _mm_subs_epi16(x1[2], x1[29]);
839   x2[3] = _mm_adds_epi16(x1[3], x1[28]);
840   x2[28] = _mm_subs_epi16(x1[3], x1[28]);
841   x2[4] = _mm_adds_epi16(x1[4], x1[27]);
842   x2[27] = _mm_subs_epi16(x1[4], x1[27]);
843   x2[5] = _mm_adds_epi16(x1[5], x1[26]);
844   x2[26] = _mm_subs_epi16(x1[5], x1[26]);
845   x2[6] = _mm_adds_epi16(x1[6], x1[25]);
846   x2[25] = _mm_subs_epi16(x1[6], x1[25]);
847   x2[7] = _mm_adds_epi16(x1[7], x1[24]);
848   x2[24] = _mm_subs_epi16(x1[7], x1[24]);
849   x2[8] = _mm_adds_epi16(x1[8], x1[23]);
850   x2[23] = _mm_subs_epi16(x1[8], x1[23]);
851   x2[9] = _mm_adds_epi16(x1[9], x1[22]);
852   x2[22] = _mm_subs_epi16(x1[9], x1[22]);
853   x2[10] = _mm_adds_epi16(x1[10], x1[21]);
854   x2[21] = _mm_subs_epi16(x1[10], x1[21]);
855   x2[11] = _mm_adds_epi16(x1[11], x1[20]);
856   x2[20] = _mm_subs_epi16(x1[11], x1[20]);
857   x2[12] = _mm_adds_epi16(x1[12], x1[19]);
858   x2[19] = _mm_subs_epi16(x1[12], x1[19]);
859   x2[13] = _mm_adds_epi16(x1[13], x1[18]);
860   x2[18] = _mm_subs_epi16(x1[13], x1[18]);
861   x2[14] = _mm_adds_epi16(x1[14], x1[17]);
862   x2[17] = _mm_subs_epi16(x1[14], x1[17]);
863   x2[15] = _mm_adds_epi16(x1[15], x1[16]);
864   x2[16] = _mm_subs_epi16(x1[15], x1[16]);
865   x2[32] = x1[32];
866   x2[33] = x1[33];
867   x2[34] = x1[34];
868   x2[35] = x1[35];
869   x2[36] = x1[36];
870   x2[37] = x1[37];
871   x2[38] = x1[38];
872   x2[39] = x1[39];
873   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[40], x1[55], x2[40], x2[55]);
874   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[41], x1[54], x2[41], x2[54]);
875   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[42], x1[53], x2[42], x2[53]);
876   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[43], x1[52], x2[43], x2[52]);
877   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[44], x1[51], x2[44], x2[51]);
878   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[45], x1[50], x2[45], x2[50]);
879   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[46], x1[49], x2[46], x2[49]);
880   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x1[47], x1[48], x2[47], x2[48]);
881   x2[56] = x1[56];
882   x2[57] = x1[57];
883   x2[58] = x1[58];
884   x2[59] = x1[59];
885   x2[60] = x1[60];
886   x2[61] = x1[61];
887   x2[62] = x1[62];
888   x2[63] = x1[63];
889 
890   // stage 3
891   __m128i x3[64];
892   x3[0] = _mm_adds_epi16(x2[0], x2[15]);
893   x3[15] = _mm_subs_epi16(x2[0], x2[15]);
894   x3[1] = _mm_adds_epi16(x2[1], x2[14]);
895   x3[14] = _mm_subs_epi16(x2[1], x2[14]);
896   x3[2] = _mm_adds_epi16(x2[2], x2[13]);
897   x3[13] = _mm_subs_epi16(x2[2], x2[13]);
898   x3[3] = _mm_adds_epi16(x2[3], x2[12]);
899   x3[12] = _mm_subs_epi16(x2[3], x2[12]);
900   x3[4] = _mm_adds_epi16(x2[4], x2[11]);
901   x3[11] = _mm_subs_epi16(x2[4], x2[11]);
902   x3[5] = _mm_adds_epi16(x2[5], x2[10]);
903   x3[10] = _mm_subs_epi16(x2[5], x2[10]);
904   x3[6] = _mm_adds_epi16(x2[6], x2[9]);
905   x3[9] = _mm_subs_epi16(x2[6], x2[9]);
906   x3[7] = _mm_adds_epi16(x2[7], x2[8]);
907   x3[8] = _mm_subs_epi16(x2[7], x2[8]);
908   x3[16] = x2[16];
909   x3[17] = x2[17];
910   x3[18] = x2[18];
911   x3[19] = x2[19];
912   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x2[20], x2[27], x3[20], x3[27]);
913   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x2[21], x2[26], x3[21], x3[26]);
914   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x2[22], x2[25], x3[22], x3[25]);
915   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x2[23], x2[24], x3[23], x3[24]);
916   x3[28] = x2[28];
917   x3[29] = x2[29];
918   x3[30] = x2[30];
919   x3[31] = x2[31];
920   x3[32] = _mm_adds_epi16(x2[32], x2[47]);
921   x3[47] = _mm_subs_epi16(x2[32], x2[47]);
922   x3[33] = _mm_adds_epi16(x2[33], x2[46]);
923   x3[46] = _mm_subs_epi16(x2[33], x2[46]);
924   x3[34] = _mm_adds_epi16(x2[34], x2[45]);
925   x3[45] = _mm_subs_epi16(x2[34], x2[45]);
926   x3[35] = _mm_adds_epi16(x2[35], x2[44]);
927   x3[44] = _mm_subs_epi16(x2[35], x2[44]);
928   x3[36] = _mm_adds_epi16(x2[36], x2[43]);
929   x3[43] = _mm_subs_epi16(x2[36], x2[43]);
930   x3[37] = _mm_adds_epi16(x2[37], x2[42]);
931   x3[42] = _mm_subs_epi16(x2[37], x2[42]);
932   x3[38] = _mm_adds_epi16(x2[38], x2[41]);
933   x3[41] = _mm_subs_epi16(x2[38], x2[41]);
934   x3[39] = _mm_adds_epi16(x2[39], x2[40]);
935   x3[40] = _mm_subs_epi16(x2[39], x2[40]);
936   x3[48] = _mm_subs_epi16(x2[63], x2[48]);
937   x3[63] = _mm_adds_epi16(x2[63], x2[48]);
938   x3[49] = _mm_subs_epi16(x2[62], x2[49]);
939   x3[62] = _mm_adds_epi16(x2[62], x2[49]);
940   x3[50] = _mm_subs_epi16(x2[61], x2[50]);
941   x3[61] = _mm_adds_epi16(x2[61], x2[50]);
942   x3[51] = _mm_subs_epi16(x2[60], x2[51]);
943   x3[60] = _mm_adds_epi16(x2[60], x2[51]);
944   x3[52] = _mm_subs_epi16(x2[59], x2[52]);
945   x3[59] = _mm_adds_epi16(x2[59], x2[52]);
946   x3[53] = _mm_subs_epi16(x2[58], x2[53]);
947   x3[58] = _mm_adds_epi16(x2[58], x2[53]);
948   x3[54] = _mm_subs_epi16(x2[57], x2[54]);
949   x3[57] = _mm_adds_epi16(x2[57], x2[54]);
950   x3[55] = _mm_subs_epi16(x2[56], x2[55]);
951   x3[56] = _mm_adds_epi16(x2[56], x2[55]);
952 
953   // stage 4
954   __m128i x4[64];
955   x4[0] = _mm_adds_epi16(x3[0], x3[7]);
956   x4[7] = _mm_subs_epi16(x3[0], x3[7]);
957   x4[1] = _mm_adds_epi16(x3[1], x3[6]);
958   x4[6] = _mm_subs_epi16(x3[1], x3[6]);
959   x4[2] = _mm_adds_epi16(x3[2], x3[5]);
960   x4[5] = _mm_subs_epi16(x3[2], x3[5]);
961   x4[3] = _mm_adds_epi16(x3[3], x3[4]);
962   x4[4] = _mm_subs_epi16(x3[3], x3[4]);
963   x4[8] = x3[8];
964   x4[9] = x3[9];
965   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x3[10], x3[13], x4[10], x4[13]);
966   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x3[11], x3[12], x4[11], x4[12]);
967   x4[14] = x3[14];
968   x4[15] = x3[15];
969   x4[16] = _mm_adds_epi16(x3[16], x3[23]);
970   x4[23] = _mm_subs_epi16(x3[16], x3[23]);
971   x4[17] = _mm_adds_epi16(x3[17], x3[22]);
972   x4[22] = _mm_subs_epi16(x3[17], x3[22]);
973   x4[18] = _mm_adds_epi16(x3[18], x3[21]);
974   x4[21] = _mm_subs_epi16(x3[18], x3[21]);
975   x4[19] = _mm_adds_epi16(x3[19], x3[20]);
976   x4[20] = _mm_subs_epi16(x3[19], x3[20]);
977   x4[24] = _mm_subs_epi16(x3[31], x3[24]);
978   x4[31] = _mm_adds_epi16(x3[31], x3[24]);
979   x4[25] = _mm_subs_epi16(x3[30], x3[25]);
980   x4[30] = _mm_adds_epi16(x3[30], x3[25]);
981   x4[26] = _mm_subs_epi16(x3[29], x3[26]);
982   x4[29] = _mm_adds_epi16(x3[29], x3[26]);
983   x4[27] = _mm_subs_epi16(x3[28], x3[27]);
984   x4[28] = _mm_adds_epi16(x3[28], x3[27]);
985   x4[32] = x3[32];
986   x4[33] = x3[33];
987   x4[34] = x3[34];
988   x4[35] = x3[35];
989   btf_16_sse2(cospi_m16_p48, cospi_p48_p16, x3[36], x3[59], x4[36], x4[59]);
990   btf_16_sse2(cospi_m16_p48, cospi_p48_p16, x3[37], x3[58], x4[37], x4[58]);
991   btf_16_sse2(cospi_m16_p48, cospi_p48_p16, x3[38], x3[57], x4[38], x4[57]);
992   btf_16_sse2(cospi_m16_p48, cospi_p48_p16, x3[39], x3[56], x4[39], x4[56]);
993   btf_16_sse2(cospi_m48_m16, cospi_m16_p48, x3[40], x3[55], x4[40], x4[55]);
994   btf_16_sse2(cospi_m48_m16, cospi_m16_p48, x3[41], x3[54], x4[41], x4[54]);
995   btf_16_sse2(cospi_m48_m16, cospi_m16_p48, x3[42], x3[53], x4[42], x4[53]);
996   btf_16_sse2(cospi_m48_m16, cospi_m16_p48, x3[43], x3[52], x4[43], x4[52]);
997   x4[44] = x3[44];
998   x4[45] = x3[45];
999   x4[46] = x3[46];
1000   x4[47] = x3[47];
1001   x4[48] = x3[48];
1002   x4[49] = x3[49];
1003   x4[50] = x3[50];
1004   x4[51] = x3[51];
1005   x4[60] = x3[60];
1006   x4[61] = x3[61];
1007   x4[62] = x3[62];
1008   x4[63] = x3[63];
1009 
1010   // stage 5
1011   __m128i x5[64];
1012   x5[0] = _mm_adds_epi16(x4[0], x4[3]);
1013   x5[3] = _mm_subs_epi16(x4[0], x4[3]);
1014   x5[1] = _mm_adds_epi16(x4[1], x4[2]);
1015   x5[2] = _mm_subs_epi16(x4[1], x4[2]);
1016   x5[4] = x4[4];
1017   btf_16_sse2(cospi_m32_p32, cospi_p32_p32, x4[5], x4[6], x5[5], x5[6]);
1018   x5[7] = x4[7];
1019   x5[8] = _mm_adds_epi16(x4[8], x4[11]);
1020   x5[11] = _mm_subs_epi16(x4[8], x4[11]);
1021   x5[9] = _mm_adds_epi16(x4[9], x4[10]);
1022   x5[10] = _mm_subs_epi16(x4[9], x4[10]);
1023   x5[12] = _mm_subs_epi16(x4[15], x4[12]);
1024   x5[15] = _mm_adds_epi16(x4[15], x4[12]);
1025   x5[13] = _mm_subs_epi16(x4[14], x4[13]);
1026   x5[14] = _mm_adds_epi16(x4[14], x4[13]);
1027   x5[16] = x4[16];
1028   x5[17] = x4[17];
1029   btf_16_sse2(cospi_m16_p48, cospi_p48_p16, x4[18], x4[29], x5[18], x5[29]);
1030   btf_16_sse2(cospi_m16_p48, cospi_p48_p16, x4[19], x4[28], x5[19], x5[28]);
1031   btf_16_sse2(cospi_m48_m16, cospi_m16_p48, x4[20], x4[27], x5[20], x5[27]);
1032   btf_16_sse2(cospi_m48_m16, cospi_m16_p48, x4[21], x4[26], x5[21], x5[26]);
1033   x5[22] = x4[22];
1034   x5[23] = x4[23];
1035   x5[24] = x4[24];
1036   x5[25] = x4[25];
1037   x5[30] = x4[30];
1038   x5[31] = x4[31];
1039   x5[32] = _mm_adds_epi16(x4[32], x4[39]);
1040   x5[39] = _mm_subs_epi16(x4[32], x4[39]);
1041   x5[33] = _mm_adds_epi16(x4[33], x4[38]);
1042   x5[38] = _mm_subs_epi16(x4[33], x4[38]);
1043   x5[34] = _mm_adds_epi16(x4[34], x4[37]);
1044   x5[37] = _mm_subs_epi16(x4[34], x4[37]);
1045   x5[35] = _mm_adds_epi16(x4[35], x4[36]);
1046   x5[36] = _mm_subs_epi16(x4[35], x4[36]);
1047   x5[40] = _mm_subs_epi16(x4[47], x4[40]);
1048   x5[47] = _mm_adds_epi16(x4[47], x4[40]);
1049   x5[41] = _mm_subs_epi16(x4[46], x4[41]);
1050   x5[46] = _mm_adds_epi16(x4[46], x4[41]);
1051   x5[42] = _mm_subs_epi16(x4[45], x4[42]);
1052   x5[45] = _mm_adds_epi16(x4[45], x4[42]);
1053   x5[43] = _mm_subs_epi16(x4[44], x4[43]);
1054   x5[44] = _mm_adds_epi16(x4[44], x4[43]);
1055   x5[48] = _mm_adds_epi16(x4[48], x4[55]);
1056   x5[55] = _mm_subs_epi16(x4[48], x4[55]);
1057   x5[49] = _mm_adds_epi16(x4[49], x4[54]);
1058   x5[54] = _mm_subs_epi16(x4[49], x4[54]);
1059   x5[50] = _mm_adds_epi16(x4[50], x4[53]);
1060   x5[53] = _mm_subs_epi16(x4[50], x4[53]);
1061   x5[51] = _mm_adds_epi16(x4[51], x4[52]);
1062   x5[52] = _mm_subs_epi16(x4[51], x4[52]);
1063   x5[56] = _mm_subs_epi16(x4[63], x4[56]);
1064   x5[63] = _mm_adds_epi16(x4[63], x4[56]);
1065   x5[57] = _mm_subs_epi16(x4[62], x4[57]);
1066   x5[62] = _mm_adds_epi16(x4[62], x4[57]);
1067   x5[58] = _mm_subs_epi16(x4[61], x4[58]);
1068   x5[61] = _mm_adds_epi16(x4[61], x4[58]);
1069   x5[59] = _mm_subs_epi16(x4[60], x4[59]);
1070   x5[60] = _mm_adds_epi16(x4[60], x4[59]);
1071 
1072   // stage 6
1073   __m128i x6[64];
1074   btf_16_sse2(cospi_p32_p32, cospi_p32_m32, x5[0], x5[1], x6[0], x6[1]);
1075   btf_16_sse2(cospi_p48_p16, cospi_m16_p48, x5[2], x5[3], x6[2], x6[3]);
1076   x6[4] = _mm_adds_epi16(x5[4], x5[5]);
1077   x6[5] = _mm_subs_epi16(x5[4], x5[5]);
1078   x6[6] = _mm_subs_epi16(x5[7], x5[6]);
1079   x6[7] = _mm_adds_epi16(x5[7], x5[6]);
1080   x6[8] = x5[8];
1081   btf_16_sse2(cospi_m16_p48, cospi_p48_p16, x5[9], x5[14], x6[9], x6[14]);
1082   btf_16_sse2(cospi_m48_m16, cospi_m16_p48, x5[10], x5[13], x6[10], x6[13]);
1083   x6[11] = x5[11];
1084   x6[12] = x5[12];
1085   x6[15] = x5[15];
1086   x6[16] = _mm_adds_epi16(x5[16], x5[19]);
1087   x6[19] = _mm_subs_epi16(x5[16], x5[19]);
1088   x6[17] = _mm_adds_epi16(x5[17], x5[18]);
1089   x6[18] = _mm_subs_epi16(x5[17], x5[18]);
1090   x6[20] = _mm_subs_epi16(x5[23], x5[20]);
1091   x6[23] = _mm_adds_epi16(x5[23], x5[20]);
1092   x6[21] = _mm_subs_epi16(x5[22], x5[21]);
1093   x6[22] = _mm_adds_epi16(x5[22], x5[21]);
1094   x6[24] = _mm_adds_epi16(x5[24], x5[27]);
1095   x6[27] = _mm_subs_epi16(x5[24], x5[27]);
1096   x6[25] = _mm_adds_epi16(x5[25], x5[26]);
1097   x6[26] = _mm_subs_epi16(x5[25], x5[26]);
1098   x6[28] = _mm_subs_epi16(x5[31], x5[28]);
1099   x6[31] = _mm_adds_epi16(x5[31], x5[28]);
1100   x6[29] = _mm_subs_epi16(x5[30], x5[29]);
1101   x6[30] = _mm_adds_epi16(x5[30], x5[29]);
1102   x6[32] = x5[32];
1103   x6[33] = x5[33];
1104   btf_16_sse2(cospi_m08_p56, cospi_p56_p08, x5[34], x5[61], x6[34], x6[61]);
1105   btf_16_sse2(cospi_m08_p56, cospi_p56_p08, x5[35], x5[60], x6[35], x6[60]);
1106   btf_16_sse2(cospi_m56_m08, cospi_m08_p56, x5[36], x5[59], x6[36], x6[59]);
1107   btf_16_sse2(cospi_m56_m08, cospi_m08_p56, x5[37], x5[58], x6[37], x6[58]);
1108   x6[38] = x5[38];
1109   x6[39] = x5[39];
1110   x6[40] = x5[40];
1111   x6[41] = x5[41];
1112   btf_16_sse2(cospi_m40_p24, cospi_p24_p40, x5[42], x5[53], x6[42], x6[53]);
1113   btf_16_sse2(cospi_m40_p24, cospi_p24_p40, x5[43], x5[52], x6[43], x6[52]);
1114   btf_16_sse2(cospi_m24_m40, cospi_m40_p24, x5[44], x5[51], x6[44], x6[51]);
1115   btf_16_sse2(cospi_m24_m40, cospi_m40_p24, x5[45], x5[50], x6[45], x6[50]);
1116   x6[46] = x5[46];
1117   x6[47] = x5[47];
1118   x6[48] = x5[48];
1119   x6[49] = x5[49];
1120   x6[54] = x5[54];
1121   x6[55] = x5[55];
1122   x6[56] = x5[56];
1123   x6[57] = x5[57];
1124   x6[62] = x5[62];
1125   x6[63] = x5[63];
1126 
1127   // stage 7
1128   __m128i x7[64];
1129   x7[0] = x6[0];
1130   x7[1] = x6[1];
1131   x7[2] = x6[2];
1132   x7[3] = x6[3];
1133   btf_16_sse2(cospi_p56_p08, cospi_m08_p56, x6[4], x6[7], x7[4], x7[7]);
1134   btf_16_sse2(cospi_p24_p40, cospi_m40_p24, x6[5], x6[6], x7[5], x7[6]);
1135   x7[8] = _mm_adds_epi16(x6[8], x6[9]);
1136   x7[9] = _mm_subs_epi16(x6[8], x6[9]);
1137   x7[10] = _mm_subs_epi16(x6[11], x6[10]);
1138   x7[11] = _mm_adds_epi16(x6[11], x6[10]);
1139   x7[12] = _mm_adds_epi16(x6[12], x6[13]);
1140   x7[13] = _mm_subs_epi16(x6[12], x6[13]);
1141   x7[14] = _mm_subs_epi16(x6[15], x6[14]);
1142   x7[15] = _mm_adds_epi16(x6[15], x6[14]);
1143   x7[16] = x6[16];
1144   btf_16_sse2(cospi_m08_p56, cospi_p56_p08, x6[17], x6[30], x7[17], x7[30]);
1145   btf_16_sse2(cospi_m56_m08, cospi_m08_p56, x6[18], x6[29], x7[18], x7[29]);
1146   x7[19] = x6[19];
1147   x7[20] = x6[20];
1148   btf_16_sse2(cospi_m40_p24, cospi_p24_p40, x6[21], x6[26], x7[21], x7[26]);
1149   btf_16_sse2(cospi_m24_m40, cospi_m40_p24, x6[22], x6[25], x7[22], x7[25]);
1150   x7[23] = x6[23];
1151   x7[24] = x6[24];
1152   x7[27] = x6[27];
1153   x7[28] = x6[28];
1154   x7[31] = x6[31];
1155   x7[32] = _mm_adds_epi16(x6[32], x6[35]);
1156   x7[35] = _mm_subs_epi16(x6[32], x6[35]);
1157   x7[33] = _mm_adds_epi16(x6[33], x6[34]);
1158   x7[34] = _mm_subs_epi16(x6[33], x6[34]);
1159   x7[36] = _mm_subs_epi16(x6[39], x6[36]);
1160   x7[39] = _mm_adds_epi16(x6[39], x6[36]);
1161   x7[37] = _mm_subs_epi16(x6[38], x6[37]);
1162   x7[38] = _mm_adds_epi16(x6[38], x6[37]);
1163   x7[40] = _mm_adds_epi16(x6[40], x6[43]);
1164   x7[43] = _mm_subs_epi16(x6[40], x6[43]);
1165   x7[41] = _mm_adds_epi16(x6[41], x6[42]);
1166   x7[42] = _mm_subs_epi16(x6[41], x6[42]);
1167   x7[44] = _mm_subs_epi16(x6[47], x6[44]);
1168   x7[47] = _mm_adds_epi16(x6[47], x6[44]);
1169   x7[45] = _mm_subs_epi16(x6[46], x6[45]);
1170   x7[46] = _mm_adds_epi16(x6[46], x6[45]);
1171   x7[48] = _mm_adds_epi16(x6[48], x6[51]);
1172   x7[51] = _mm_subs_epi16(x6[48], x6[51]);
1173   x7[49] = _mm_adds_epi16(x6[49], x6[50]);
1174   x7[50] = _mm_subs_epi16(x6[49], x6[50]);
1175   x7[52] = _mm_subs_epi16(x6[55], x6[52]);
1176   x7[55] = _mm_adds_epi16(x6[55], x6[52]);
1177   x7[53] = _mm_subs_epi16(x6[54], x6[53]);
1178   x7[54] = _mm_adds_epi16(x6[54], x6[53]);
1179   x7[56] = _mm_adds_epi16(x6[56], x6[59]);
1180   x7[59] = _mm_subs_epi16(x6[56], x6[59]);
1181   x7[57] = _mm_adds_epi16(x6[57], x6[58]);
1182   x7[58] = _mm_subs_epi16(x6[57], x6[58]);
1183   x7[60] = _mm_subs_epi16(x6[63], x6[60]);
1184   x7[63] = _mm_adds_epi16(x6[63], x6[60]);
1185   x7[61] = _mm_subs_epi16(x6[62], x6[61]);
1186   x7[62] = _mm_adds_epi16(x6[62], x6[61]);
1187 
1188   // stage 8
1189   __m128i x8[64];
1190   x8[0] = x7[0];
1191   x8[1] = x7[1];
1192   x8[2] = x7[2];
1193   x8[3] = x7[3];
1194   x8[4] = x7[4];
1195   x8[5] = x7[5];
1196   x8[6] = x7[6];
1197   x8[7] = x7[7];
1198   btf_16_sse2(cospi_p60_p04, cospi_m04_p60, x7[8], x7[15], x8[8], x8[15]);
1199   btf_16_sse2(cospi_p28_p36, cospi_m36_p28, x7[9], x7[14], x8[9], x8[14]);
1200   btf_16_sse2(cospi_p44_p20, cospi_m20_p44, x7[10], x7[13], x8[10], x8[13]);
1201   btf_16_sse2(cospi_p12_p52, cospi_m52_p12, x7[11], x7[12], x8[11], x8[12]);
1202   x8[16] = _mm_adds_epi16(x7[16], x7[17]);
1203   x8[17] = _mm_subs_epi16(x7[16], x7[17]);
1204   x8[18] = _mm_subs_epi16(x7[19], x7[18]);
1205   x8[19] = _mm_adds_epi16(x7[19], x7[18]);
1206   x8[20] = _mm_adds_epi16(x7[20], x7[21]);
1207   x8[21] = _mm_subs_epi16(x7[20], x7[21]);
1208   x8[22] = _mm_subs_epi16(x7[23], x7[22]);
1209   x8[23] = _mm_adds_epi16(x7[23], x7[22]);
1210   x8[24] = _mm_adds_epi16(x7[24], x7[25]);
1211   x8[25] = _mm_subs_epi16(x7[24], x7[25]);
1212   x8[26] = _mm_subs_epi16(x7[27], x7[26]);
1213   x8[27] = _mm_adds_epi16(x7[27], x7[26]);
1214   x8[28] = _mm_adds_epi16(x7[28], x7[29]);
1215   x8[29] = _mm_subs_epi16(x7[28], x7[29]);
1216   x8[30] = _mm_subs_epi16(x7[31], x7[30]);
1217   x8[31] = _mm_adds_epi16(x7[31], x7[30]);
1218   x8[32] = x7[32];
1219   btf_16_sse2(cospi_m04_p60, cospi_p60_p04, x7[33], x7[62], x8[33], x8[62]);
1220   btf_16_sse2(cospi_m60_m04, cospi_m04_p60, x7[34], x7[61], x8[34], x8[61]);
1221   x8[35] = x7[35];
1222   x8[36] = x7[36];
1223   btf_16_sse2(cospi_m36_p28, cospi_p28_p36, x7[37], x7[58], x8[37], x8[58]);
1224   btf_16_sse2(cospi_m28_m36, cospi_m36_p28, x7[38], x7[57], x8[38], x8[57]);
1225   x8[39] = x7[39];
1226   x8[40] = x7[40];
1227   btf_16_sse2(cospi_m20_p44, cospi_p44_p20, x7[41], x7[54], x8[41], x8[54]);
1228   btf_16_sse2(cospi_m44_m20, cospi_m20_p44, x7[42], x7[53], x8[42], x8[53]);
1229   x8[43] = x7[43];
1230   x8[44] = x7[44];
1231   btf_16_sse2(cospi_m52_p12, cospi_p12_p52, x7[45], x7[50], x8[45], x8[50]);
1232   btf_16_sse2(cospi_m12_m52, cospi_m52_p12, x7[46], x7[49], x8[46], x8[49]);
1233   x8[47] = x7[47];
1234   x8[48] = x7[48];
1235   x8[51] = x7[51];
1236   x8[52] = x7[52];
1237   x8[55] = x7[55];
1238   x8[56] = x7[56];
1239   x8[59] = x7[59];
1240   x8[60] = x7[60];
1241   x8[63] = x7[63];
1242 
1243   // stage 9
1244   __m128i x9[64];
1245   x9[0] = x8[0];
1246   x9[1] = x8[1];
1247   x9[2] = x8[2];
1248   x9[3] = x8[3];
1249   x9[4] = x8[4];
1250   x9[5] = x8[5];
1251   x9[6] = x8[6];
1252   x9[7] = x8[7];
1253   x9[8] = x8[8];
1254   x9[9] = x8[9];
1255   x9[10] = x8[10];
1256   x9[11] = x8[11];
1257   x9[12] = x8[12];
1258   x9[13] = x8[13];
1259   x9[14] = x8[14];
1260   x9[15] = x8[15];
1261   btf_16_sse2(cospi_p62_p02, cospi_m02_p62, x8[16], x8[31], x9[16], x9[31]);
1262   btf_16_sse2(cospi_p30_p34, cospi_m34_p30, x8[17], x8[30], x9[17], x9[30]);
1263   btf_16_sse2(cospi_p46_p18, cospi_m18_p46, x8[18], x8[29], x9[18], x9[29]);
1264   btf_16_sse2(cospi_p14_p50, cospi_m50_p14, x8[19], x8[28], x9[19], x9[28]);
1265   btf_16_sse2(cospi_p54_p10, cospi_m10_p54, x8[20], x8[27], x9[20], x9[27]);
1266   btf_16_sse2(cospi_p22_p42, cospi_m42_p22, x8[21], x8[26], x9[21], x9[26]);
1267   btf_16_sse2(cospi_p38_p26, cospi_m26_p38, x8[22], x8[25], x9[22], x9[25]);
1268   btf_16_sse2(cospi_p06_p58, cospi_m58_p06, x8[23], x8[24], x9[23], x9[24]);
1269   x9[32] = _mm_adds_epi16(x8[32], x8[33]);
1270   x9[33] = _mm_subs_epi16(x8[32], x8[33]);
1271   x9[34] = _mm_subs_epi16(x8[35], x8[34]);
1272   x9[35] = _mm_adds_epi16(x8[35], x8[34]);
1273   x9[36] = _mm_adds_epi16(x8[36], x8[37]);
1274   x9[37] = _mm_subs_epi16(x8[36], x8[37]);
1275   x9[38] = _mm_subs_epi16(x8[39], x8[38]);
1276   x9[39] = _mm_adds_epi16(x8[39], x8[38]);
1277   x9[40] = _mm_adds_epi16(x8[40], x8[41]);
1278   x9[41] = _mm_subs_epi16(x8[40], x8[41]);
1279   x9[42] = _mm_subs_epi16(x8[43], x8[42]);
1280   x9[43] = _mm_adds_epi16(x8[43], x8[42]);
1281   x9[44] = _mm_adds_epi16(x8[44], x8[45]);
1282   x9[45] = _mm_subs_epi16(x8[44], x8[45]);
1283   x9[46] = _mm_subs_epi16(x8[47], x8[46]);
1284   x9[47] = _mm_adds_epi16(x8[47], x8[46]);
1285   x9[48] = _mm_adds_epi16(x8[48], x8[49]);
1286   x9[49] = _mm_subs_epi16(x8[48], x8[49]);
1287   x9[50] = _mm_subs_epi16(x8[51], x8[50]);
1288   x9[51] = _mm_adds_epi16(x8[51], x8[50]);
1289   x9[52] = _mm_adds_epi16(x8[52], x8[53]);
1290   x9[53] = _mm_subs_epi16(x8[52], x8[53]);
1291   x9[54] = _mm_subs_epi16(x8[55], x8[54]);
1292   x9[55] = _mm_adds_epi16(x8[55], x8[54]);
1293   x9[56] = _mm_adds_epi16(x8[56], x8[57]);
1294   x9[57] = _mm_subs_epi16(x8[56], x8[57]);
1295   x9[58] = _mm_subs_epi16(x8[59], x8[58]);
1296   x9[59] = _mm_adds_epi16(x8[59], x8[58]);
1297   x9[60] = _mm_adds_epi16(x8[60], x8[61]);
1298   x9[61] = _mm_subs_epi16(x8[60], x8[61]);
1299   x9[62] = _mm_subs_epi16(x8[63], x8[62]);
1300   x9[63] = _mm_adds_epi16(x8[63], x8[62]);
1301 
1302   // stage 10
1303   __m128i x10[64];
1304   x10[0] = x9[0];
1305   x10[1] = x9[1];
1306   x10[2] = x9[2];
1307   x10[3] = x9[3];
1308   x10[4] = x9[4];
1309   x10[5] = x9[5];
1310   x10[6] = x9[6];
1311   x10[7] = x9[7];
1312   x10[8] = x9[8];
1313   x10[9] = x9[9];
1314   x10[10] = x9[10];
1315   x10[11] = x9[11];
1316   x10[12] = x9[12];
1317   x10[13] = x9[13];
1318   x10[14] = x9[14];
1319   x10[15] = x9[15];
1320   x10[16] = x9[16];
1321   x10[17] = x9[17];
1322   x10[18] = x9[18];
1323   x10[19] = x9[19];
1324   x10[20] = x9[20];
1325   x10[21] = x9[21];
1326   x10[22] = x9[22];
1327   x10[23] = x9[23];
1328   x10[24] = x9[24];
1329   x10[25] = x9[25];
1330   x10[26] = x9[26];
1331   x10[27] = x9[27];
1332   x10[28] = x9[28];
1333   x10[29] = x9[29];
1334   x10[30] = x9[30];
1335   x10[31] = x9[31];
1336   btf_16_sse2(cospi_p63_p01, cospi_m01_p63, x9[32], x9[63], x10[32], x10[63]);
1337   btf_16_sse2(cospi_p31_p33, cospi_m33_p31, x9[33], x9[62], x10[33], x10[62]);
1338   btf_16_sse2(cospi_p47_p17, cospi_m17_p47, x9[34], x9[61], x10[34], x10[61]);
1339   btf_16_sse2(cospi_p15_p49, cospi_m49_p15, x9[35], x9[60], x10[35], x10[60]);
1340   btf_16_sse2(cospi_p55_p09, cospi_m09_p55, x9[36], x9[59], x10[36], x10[59]);
1341   btf_16_sse2(cospi_p23_p41, cospi_m41_p23, x9[37], x9[58], x10[37], x10[58]);
1342   btf_16_sse2(cospi_p39_p25, cospi_m25_p39, x9[38], x9[57], x10[38], x10[57]);
1343   btf_16_sse2(cospi_p07_p57, cospi_m57_p07, x9[39], x9[56], x10[39], x10[56]);
1344   btf_16_sse2(cospi_p59_p05, cospi_m05_p59, x9[40], x9[55], x10[40], x10[55]);
1345   btf_16_sse2(cospi_p27_p37, cospi_m37_p27, x9[41], x9[54], x10[41], x10[54]);
1346   btf_16_sse2(cospi_p43_p21, cospi_m21_p43, x9[42], x9[53], x10[42], x10[53]);
1347   btf_16_sse2(cospi_p11_p53, cospi_m53_p11, x9[43], x9[52], x10[43], x10[52]);
1348   btf_16_sse2(cospi_p51_p13, cospi_m13_p51, x9[44], x9[51], x10[44], x10[51]);
1349   btf_16_sse2(cospi_p19_p45, cospi_m45_p19, x9[45], x9[50], x10[45], x10[50]);
1350   btf_16_sse2(cospi_p35_p29, cospi_m29_p35, x9[46], x9[49], x10[46], x10[49]);
1351   btf_16_sse2(cospi_p03_p61, cospi_m61_p03, x9[47], x9[48], x10[47], x10[48]);
1352 
1353   // stage 11
1354   output[0] = x10[0];
1355   output[1] = x10[32];
1356   output[2] = x10[16];
1357   output[3] = x10[48];
1358   output[4] = x10[8];
1359   output[5] = x10[40];
1360   output[6] = x10[24];
1361   output[7] = x10[56];
1362   output[8] = x10[4];
1363   output[9] = x10[36];
1364   output[10] = x10[20];
1365   output[11] = x10[52];
1366   output[12] = x10[12];
1367   output[13] = x10[44];
1368   output[14] = x10[28];
1369   output[15] = x10[60];
1370   output[16] = x10[2];
1371   output[17] = x10[34];
1372   output[18] = x10[18];
1373   output[19] = x10[50];
1374   output[20] = x10[10];
1375   output[21] = x10[42];
1376   output[22] = x10[26];
1377   output[23] = x10[58];
1378   output[24] = x10[6];
1379   output[25] = x10[38];
1380   output[26] = x10[22];
1381   output[27] = x10[54];
1382   output[28] = x10[14];
1383   output[29] = x10[46];
1384   output[30] = x10[30];
1385   output[31] = x10[62];
1386   output[32] = x10[1];
1387   output[33] = x10[33];
1388   output[34] = x10[17];
1389   output[35] = x10[49];
1390   output[36] = x10[9];
1391   output[37] = x10[41];
1392   output[38] = x10[25];
1393   output[39] = x10[57];
1394   output[40] = x10[5];
1395   output[41] = x10[37];
1396   output[42] = x10[21];
1397   output[43] = x10[53];
1398   output[44] = x10[13];
1399   output[45] = x10[45];
1400   output[46] = x10[29];
1401   output[47] = x10[61];
1402   output[48] = x10[3];
1403   output[49] = x10[35];
1404   output[50] = x10[19];
1405   output[51] = x10[51];
1406   output[52] = x10[11];
1407   output[53] = x10[43];
1408   output[54] = x10[27];
1409   output[55] = x10[59];
1410   output[56] = x10[7];
1411   output[57] = x10[39];
1412   output[58] = x10[23];
1413   output[59] = x10[55];
1414   output[60] = x10[15];
1415   output[61] = x10[47];
1416   output[62] = x10[31];
1417   output[63] = x10[63];
1418 }
1419 
fadst4x4_new_sse2(const __m128i * input,__m128i * output,int8_t cos_bit)1420 static void fadst4x4_new_sse2(const __m128i *input, __m128i *output,
1421                               int8_t cos_bit) {
1422   const int32_t *sinpi = sinpi_arr(cos_bit);
1423   const __m128i sinpi_p01_p02 = pair_set_epi16(sinpi[1], sinpi[2]);
1424   const __m128i sinpi_p04_m01 = pair_set_epi16(sinpi[4], -sinpi[1]);
1425   const __m128i sinpi_p03_p04 = pair_set_epi16(sinpi[3], sinpi[4]);
1426   const __m128i sinpi_m03_p02 = pair_set_epi16(-sinpi[3], sinpi[2]);
1427   const __m128i sinpi_p03_p03 = _mm_set1_epi16((int16_t)sinpi[3]);
1428   const __m128i __zero = _mm_set1_epi16(0);
1429   const __m128i __rounding = _mm_set1_epi32(1 << (cos_bit - 1));
1430   const __m128i in7 = _mm_add_epi16(input[0], input[1]);
1431   __m128i u[8], v[8];
1432 
1433   u[0] = _mm_unpacklo_epi16(input[0], input[1]);
1434   u[1] = _mm_unpacklo_epi16(input[2], input[3]);
1435   u[2] = _mm_unpacklo_epi16(in7, __zero);
1436   u[3] = _mm_unpacklo_epi16(input[2], __zero);
1437   u[4] = _mm_unpacklo_epi16(input[3], __zero);
1438 
1439   v[0] = _mm_madd_epi16(u[0], sinpi_p01_p02);  // s0 + s2
1440   v[1] = _mm_madd_epi16(u[1], sinpi_p03_p04);  // s4 + s5
1441   v[2] = _mm_madd_epi16(u[2], sinpi_p03_p03);  // x1
1442   v[3] = _mm_madd_epi16(u[0], sinpi_p04_m01);  // s1 - s3
1443   v[4] = _mm_madd_epi16(u[1], sinpi_m03_p02);  // -s4 + s6
1444   v[5] = _mm_madd_epi16(u[3], sinpi_p03_p03);  // s4
1445   v[6] = _mm_madd_epi16(u[4], sinpi_p03_p03);
1446 
1447   u[0] = _mm_add_epi32(v[0], v[1]);
1448   u[1] = _mm_sub_epi32(v[2], v[6]);
1449   u[2] = _mm_add_epi32(v[3], v[4]);
1450   u[3] = _mm_sub_epi32(u[2], u[0]);
1451   u[4] = _mm_slli_epi32(v[5], 2);
1452   u[5] = _mm_sub_epi32(u[4], v[5]);
1453   u[6] = _mm_add_epi32(u[3], u[5]);
1454 
1455   v[0] = _mm_add_epi32(u[0], __rounding);
1456   v[1] = _mm_add_epi32(u[1], __rounding);
1457   v[2] = _mm_add_epi32(u[2], __rounding);
1458   v[3] = _mm_add_epi32(u[6], __rounding);
1459 
1460   u[0] = _mm_srai_epi32(v[0], cos_bit);
1461   u[1] = _mm_srai_epi32(v[1], cos_bit);
1462   u[2] = _mm_srai_epi32(v[2], cos_bit);
1463   u[3] = _mm_srai_epi32(v[3], cos_bit);
1464 
1465   output[0] = _mm_packs_epi32(u[0], u[2]);
1466   output[1] = _mm_packs_epi32(u[1], u[3]);
1467   output[2] = _mm_srli_si128(output[0], 8);
1468   output[3] = _mm_srli_si128(output[1], 8);
1469 }
1470 
fadst4x8_new_sse2(const __m128i * input,__m128i * output,int8_t cos_bit)1471 static void fadst4x8_new_sse2(const __m128i *input, __m128i *output,
1472                               int8_t cos_bit) {
1473   const int32_t *cospi = cospi_arr(cos_bit);
1474   const __m128i __zero = _mm_setzero_si128();
1475   const __m128i __rounding = _mm_set1_epi32(1 << (cos_bit - 1));
1476 
1477   __m128i cospi_p32_p32 = pair_set_epi16(cospi[32], cospi[32]);
1478   __m128i cospi_p32_m32 = pair_set_epi16(cospi[32], -cospi[32]);
1479   __m128i cospi_p16_p48 = pair_set_epi16(cospi[16], cospi[48]);
1480   __m128i cospi_p48_m16 = pair_set_epi16(cospi[48], -cospi[16]);
1481   __m128i cospi_m48_p16 = pair_set_epi16(-cospi[48], cospi[16]);
1482   __m128i cospi_p04_p60 = pair_set_epi16(cospi[4], cospi[60]);
1483   __m128i cospi_p60_m04 = pair_set_epi16(cospi[60], -cospi[4]);
1484   __m128i cospi_p20_p44 = pair_set_epi16(cospi[20], cospi[44]);
1485   __m128i cospi_p44_m20 = pair_set_epi16(cospi[44], -cospi[20]);
1486   __m128i cospi_p36_p28 = pair_set_epi16(cospi[36], cospi[28]);
1487   __m128i cospi_p28_m36 = pair_set_epi16(cospi[28], -cospi[36]);
1488   __m128i cospi_p52_p12 = pair_set_epi16(cospi[52], cospi[12]);
1489   __m128i cospi_p12_m52 = pair_set_epi16(cospi[12], -cospi[52]);
1490 
1491   // stage 1
1492   __m128i x1[8];
1493   x1[0] = input[0];
1494   x1[1] = _mm_subs_epi16(__zero, input[7]);
1495   x1[2] = _mm_subs_epi16(__zero, input[3]);
1496   x1[3] = input[4];
1497   x1[4] = _mm_subs_epi16(__zero, input[1]);
1498   x1[5] = input[6];
1499   x1[6] = input[2];
1500   x1[7] = _mm_subs_epi16(__zero, input[5]);
1501 
1502   // stage 2
1503   __m128i x2[8];
1504   x2[0] = x1[0];
1505   x2[1] = x1[1];
1506   btf_16_w4_sse2(&cospi_p32_p32, &cospi_p32_m32, __rounding, cos_bit, &x1[2],
1507                  &x1[3], &x2[2], &x2[3]);
1508   x2[4] = x1[4];
1509   x2[5] = x1[5];
1510   btf_16_w4_sse2(&cospi_p32_p32, &cospi_p32_m32, __rounding, cos_bit, &x1[6],
1511                  &x1[7], &x2[6], &x2[7]);
1512 
1513   // stage 3
1514   __m128i x3[8];
1515   x3[0] = _mm_adds_epi16(x2[0], x2[2]);
1516   x3[2] = _mm_subs_epi16(x2[0], x2[2]);
1517   x3[1] = _mm_adds_epi16(x2[1], x2[3]);
1518   x3[3] = _mm_subs_epi16(x2[1], x2[3]);
1519   x3[4] = _mm_adds_epi16(x2[4], x2[6]);
1520   x3[6] = _mm_subs_epi16(x2[4], x2[6]);
1521   x3[5] = _mm_adds_epi16(x2[5], x2[7]);
1522   x3[7] = _mm_subs_epi16(x2[5], x2[7]);
1523 
1524   // stage 4
1525   __m128i x4[8];
1526   x4[0] = x3[0];
1527   x4[1] = x3[1];
1528   x4[2] = x3[2];
1529   x4[3] = x3[3];
1530   btf_16_w4_sse2(&cospi_p16_p48, &cospi_p48_m16, __rounding, cos_bit, &x3[4],
1531                  &x3[5], &x4[4], &x4[5]);
1532   btf_16_w4_sse2(&cospi_m48_p16, &cospi_p16_p48, __rounding, cos_bit, &x3[6],
1533                  &x3[7], &x4[6], &x4[7]);
1534 
1535   // stage 5
1536   __m128i x5[8];
1537   x5[0] = _mm_adds_epi16(x4[0], x4[4]);
1538   x5[4] = _mm_subs_epi16(x4[0], x4[4]);
1539   x5[1] = _mm_adds_epi16(x4[1], x4[5]);
1540   x5[5] = _mm_subs_epi16(x4[1], x4[5]);
1541   x5[2] = _mm_adds_epi16(x4[2], x4[6]);
1542   x5[6] = _mm_subs_epi16(x4[2], x4[6]);
1543   x5[3] = _mm_adds_epi16(x4[3], x4[7]);
1544   x5[7] = _mm_subs_epi16(x4[3], x4[7]);
1545 
1546   // stage 6
1547   __m128i x6[8];
1548   btf_16_w4_sse2(&cospi_p04_p60, &cospi_p60_m04, __rounding, cos_bit, &x5[0],
1549                  &x5[1], &x6[0], &x6[1]);
1550   btf_16_w4_sse2(&cospi_p20_p44, &cospi_p44_m20, __rounding, cos_bit, &x5[2],
1551                  &x5[3], &x6[2], &x6[3]);
1552   btf_16_w4_sse2(&cospi_p36_p28, &cospi_p28_m36, __rounding, cos_bit, &x5[4],
1553                  &x5[5], &x6[4], &x6[5]);
1554   btf_16_w4_sse2(&cospi_p52_p12, &cospi_p12_m52, __rounding, cos_bit, &x5[6],
1555                  &x5[7], &x6[6], &x6[7]);
1556 
1557   // stage 7
1558   output[0] = x6[1];
1559   output[1] = x6[6];
1560   output[2] = x6[3];
1561   output[3] = x6[4];
1562   output[4] = x6[5];
1563   output[5] = x6[2];
1564   output[6] = x6[7];
1565   output[7] = x6[0];
1566 }
1567 
fadst8x4_new_sse2(const __m128i * input,__m128i * output,int8_t cos_bit)1568 static void fadst8x4_new_sse2(const __m128i *input, __m128i *output,
1569                               int8_t cos_bit) {
1570   const int32_t *sinpi = sinpi_arr(cos_bit);
1571   const __m128i sinpi_p01_p02 = pair_set_epi16(sinpi[1], sinpi[2]);
1572   const __m128i sinpi_p04_m01 = pair_set_epi16(sinpi[4], -sinpi[1]);
1573   const __m128i sinpi_p03_p04 = pair_set_epi16(sinpi[3], sinpi[4]);
1574   const __m128i sinpi_m03_p02 = pair_set_epi16(-sinpi[3], sinpi[2]);
1575   const __m128i sinpi_p03_p03 = _mm_set1_epi16((int16_t)sinpi[3]);
1576   const __m128i __zero = _mm_set1_epi16(0);
1577   const __m128i __rounding = _mm_set1_epi32(1 << (cos_bit - 1));
1578   const __m128i in7 = _mm_add_epi16(input[0], input[1]);
1579   __m128i u_lo[8], u_hi[8], v_lo[8], v_hi[8];
1580 
1581   u_lo[0] = _mm_unpacklo_epi16(input[0], input[1]);
1582   u_hi[0] = _mm_unpackhi_epi16(input[0], input[1]);
1583   u_lo[1] = _mm_unpacklo_epi16(input[2], input[3]);
1584   u_hi[1] = _mm_unpackhi_epi16(input[2], input[3]);
1585   u_lo[2] = _mm_unpacklo_epi16(in7, __zero);
1586   u_hi[2] = _mm_unpackhi_epi16(in7, __zero);
1587   u_lo[3] = _mm_unpacklo_epi16(input[2], __zero);
1588   u_hi[3] = _mm_unpackhi_epi16(input[2], __zero);
1589   u_lo[4] = _mm_unpacklo_epi16(input[3], __zero);
1590   u_hi[4] = _mm_unpackhi_epi16(input[3], __zero);
1591 
1592   v_lo[0] = _mm_madd_epi16(u_lo[0], sinpi_p01_p02);  // s0 + s2
1593   v_hi[0] = _mm_madd_epi16(u_hi[0], sinpi_p01_p02);  // s0 + s2
1594   v_lo[1] = _mm_madd_epi16(u_lo[1], sinpi_p03_p04);  // s4 + s5
1595   v_hi[1] = _mm_madd_epi16(u_hi[1], sinpi_p03_p04);  // s4 + s5
1596   v_lo[2] = _mm_madd_epi16(u_lo[2], sinpi_p03_p03);  // x1
1597   v_hi[2] = _mm_madd_epi16(u_hi[2], sinpi_p03_p03);  // x1
1598   v_lo[3] = _mm_madd_epi16(u_lo[0], sinpi_p04_m01);  // s1 - s3
1599   v_hi[3] = _mm_madd_epi16(u_hi[0], sinpi_p04_m01);  // s1 - s3
1600   v_lo[4] = _mm_madd_epi16(u_lo[1], sinpi_m03_p02);  // -s4 + s6
1601   v_hi[4] = _mm_madd_epi16(u_hi[1], sinpi_m03_p02);  // -s4 + s6
1602   v_lo[5] = _mm_madd_epi16(u_lo[3], sinpi_p03_p03);  // s4
1603   v_hi[5] = _mm_madd_epi16(u_hi[3], sinpi_p03_p03);  // s4
1604   v_lo[6] = _mm_madd_epi16(u_lo[4], sinpi_p03_p03);
1605   v_hi[6] = _mm_madd_epi16(u_hi[4], sinpi_p03_p03);
1606 
1607   u_lo[0] = _mm_add_epi32(v_lo[0], v_lo[1]);
1608   u_hi[0] = _mm_add_epi32(v_hi[0], v_hi[1]);
1609   u_lo[1] = _mm_sub_epi32(v_lo[2], v_lo[6]);
1610   u_hi[1] = _mm_sub_epi32(v_hi[2], v_hi[6]);
1611   u_lo[2] = _mm_add_epi32(v_lo[3], v_lo[4]);
1612   u_hi[2] = _mm_add_epi32(v_hi[3], v_hi[4]);
1613   u_lo[3] = _mm_sub_epi32(u_lo[2], u_lo[0]);
1614   u_hi[3] = _mm_sub_epi32(u_hi[2], u_hi[0]);
1615   u_lo[4] = _mm_slli_epi32(v_lo[5], 2);
1616   u_hi[4] = _mm_slli_epi32(v_hi[5], 2);
1617   u_lo[5] = _mm_sub_epi32(u_lo[4], v_lo[5]);
1618   u_hi[5] = _mm_sub_epi32(u_hi[4], v_hi[5]);
1619   u_lo[6] = _mm_add_epi32(u_lo[3], u_lo[5]);
1620   u_hi[6] = _mm_add_epi32(u_hi[3], u_hi[5]);
1621 
1622   v_lo[0] = _mm_add_epi32(u_lo[0], __rounding);
1623   v_hi[0] = _mm_add_epi32(u_hi[0], __rounding);
1624   v_lo[1] = _mm_add_epi32(u_lo[1], __rounding);
1625   v_hi[1] = _mm_add_epi32(u_hi[1], __rounding);
1626   v_lo[2] = _mm_add_epi32(u_lo[2], __rounding);
1627   v_hi[2] = _mm_add_epi32(u_hi[2], __rounding);
1628   v_lo[3] = _mm_add_epi32(u_lo[6], __rounding);
1629   v_hi[3] = _mm_add_epi32(u_hi[6], __rounding);
1630 
1631   u_lo[0] = _mm_srai_epi32(v_lo[0], cos_bit);
1632   u_hi[0] = _mm_srai_epi32(v_hi[0], cos_bit);
1633   u_lo[1] = _mm_srai_epi32(v_lo[1], cos_bit);
1634   u_hi[1] = _mm_srai_epi32(v_hi[1], cos_bit);
1635   u_lo[2] = _mm_srai_epi32(v_lo[2], cos_bit);
1636   u_hi[2] = _mm_srai_epi32(v_hi[2], cos_bit);
1637   u_lo[3] = _mm_srai_epi32(v_lo[3], cos_bit);
1638   u_hi[3] = _mm_srai_epi32(v_hi[3], cos_bit);
1639 
1640   output[0] = _mm_packs_epi32(u_lo[0], u_hi[0]);
1641   output[1] = _mm_packs_epi32(u_lo[1], u_hi[1]);
1642   output[2] = _mm_packs_epi32(u_lo[2], u_hi[2]);
1643   output[3] = _mm_packs_epi32(u_lo[3], u_hi[3]);
1644 }
1645 
fadst8x8_new_sse2(const __m128i * input,__m128i * output,int8_t cos_bit)1646 static void fadst8x8_new_sse2(const __m128i *input, __m128i *output,
1647                               int8_t cos_bit) {
1648   const int32_t *cospi = cospi_arr(cos_bit);
1649   const __m128i __zero = _mm_setzero_si128();
1650   const __m128i __rounding = _mm_set1_epi32(1 << (cos_bit - 1));
1651 
1652   __m128i cospi_p32_p32 = pair_set_epi16(cospi[32], cospi[32]);
1653   __m128i cospi_p32_m32 = pair_set_epi16(cospi[32], -cospi[32]);
1654   __m128i cospi_p16_p48 = pair_set_epi16(cospi[16], cospi[48]);
1655   __m128i cospi_p48_m16 = pair_set_epi16(cospi[48], -cospi[16]);
1656   __m128i cospi_m48_p16 = pair_set_epi16(-cospi[48], cospi[16]);
1657   __m128i cospi_p04_p60 = pair_set_epi16(cospi[4], cospi[60]);
1658   __m128i cospi_p60_m04 = pair_set_epi16(cospi[60], -cospi[4]);
1659   __m128i cospi_p20_p44 = pair_set_epi16(cospi[20], cospi[44]);
1660   __m128i cospi_p44_m20 = pair_set_epi16(cospi[44], -cospi[20]);
1661   __m128i cospi_p36_p28 = pair_set_epi16(cospi[36], cospi[28]);
1662   __m128i cospi_p28_m36 = pair_set_epi16(cospi[28], -cospi[36]);
1663   __m128i cospi_p52_p12 = pair_set_epi16(cospi[52], cospi[12]);
1664   __m128i cospi_p12_m52 = pair_set_epi16(cospi[12], -cospi[52]);
1665 
1666   // stage 1
1667   __m128i x1[8];
1668   x1[0] = input[0];
1669   x1[1] = _mm_subs_epi16(__zero, input[7]);
1670   x1[2] = _mm_subs_epi16(__zero, input[3]);
1671   x1[3] = input[4];
1672   x1[4] = _mm_subs_epi16(__zero, input[1]);
1673   x1[5] = input[6];
1674   x1[6] = input[2];
1675   x1[7] = _mm_subs_epi16(__zero, input[5]);
1676 
1677   // stage 2
1678   __m128i x2[8];
1679   x2[0] = x1[0];
1680   x2[1] = x1[1];
1681   btf_16_sse2(cospi_p32_p32, cospi_p32_m32, x1[2], x1[3], x2[2], x2[3]);
1682   x2[4] = x1[4];
1683   x2[5] = x1[5];
1684   btf_16_sse2(cospi_p32_p32, cospi_p32_m32, x1[6], x1[7], x2[6], x2[7]);
1685 
1686   // stage 3
1687   __m128i x3[8];
1688   x3[0] = _mm_adds_epi16(x2[0], x2[2]);
1689   x3[2] = _mm_subs_epi16(x2[0], x2[2]);
1690   x3[1] = _mm_adds_epi16(x2[1], x2[3]);
1691   x3[3] = _mm_subs_epi16(x2[1], x2[3]);
1692   x3[4] = _mm_adds_epi16(x2[4], x2[6]);
1693   x3[6] = _mm_subs_epi16(x2[4], x2[6]);
1694   x3[5] = _mm_adds_epi16(x2[5], x2[7]);
1695   x3[7] = _mm_subs_epi16(x2[5], x2[7]);
1696 
1697   // stage 4
1698   __m128i x4[8];
1699   x4[0] = x3[0];
1700   x4[1] = x3[1];
1701   x4[2] = x3[2];
1702   x4[3] = x3[3];
1703   btf_16_sse2(cospi_p16_p48, cospi_p48_m16, x3[4], x3[5], x4[4], x4[5]);
1704   btf_16_sse2(cospi_m48_p16, cospi_p16_p48, x3[6], x3[7], x4[6], x4[7]);
1705 
1706   // stage 5
1707   __m128i x5[8];
1708   x5[0] = _mm_adds_epi16(x4[0], x4[4]);
1709   x5[4] = _mm_subs_epi16(x4[0], x4[4]);
1710   x5[1] = _mm_adds_epi16(x4[1], x4[5]);
1711   x5[5] = _mm_subs_epi16(x4[1], x4[5]);
1712   x5[2] = _mm_adds_epi16(x4[2], x4[6]);
1713   x5[6] = _mm_subs_epi16(x4[2], x4[6]);
1714   x5[3] = _mm_adds_epi16(x4[3], x4[7]);
1715   x5[7] = _mm_subs_epi16(x4[3], x4[7]);
1716 
1717   // stage 6
1718   __m128i x6[8];
1719   btf_16_sse2(cospi_p04_p60, cospi_p60_m04, x5[0], x5[1], x6[0], x6[1]);
1720   btf_16_sse2(cospi_p20_p44, cospi_p44_m20, x5[2], x5[3], x6[2], x6[3]);
1721   btf_16_sse2(cospi_p36_p28, cospi_p28_m36, x5[4], x5[5], x6[4], x6[5]);
1722   btf_16_sse2(cospi_p52_p12, cospi_p12_m52, x5[6], x5[7], x6[6], x6[7]);
1723 
1724   // stage 7
1725   output[0] = x6[1];
1726   output[1] = x6[6];
1727   output[2] = x6[3];
1728   output[3] = x6[4];
1729   output[4] = x6[5];
1730   output[5] = x6[2];
1731   output[6] = x6[7];
1732   output[7] = x6[0];
1733 }
1734 
fadst8x16_new_sse2(const __m128i * input,__m128i * output,int8_t cos_bit)1735 static void fadst8x16_new_sse2(const __m128i *input, __m128i *output,
1736                                int8_t cos_bit) {
1737   const int32_t *cospi = cospi_arr(cos_bit);
1738   const __m128i __zero = _mm_setzero_si128();
1739   const __m128i __rounding = _mm_set1_epi32(1 << (cos_bit - 1));
1740 
1741   __m128i cospi_p32_p32 = pair_set_epi16(cospi[32], cospi[32]);
1742   __m128i cospi_p32_m32 = pair_set_epi16(cospi[32], -cospi[32]);
1743   __m128i cospi_p16_p48 = pair_set_epi16(cospi[16], cospi[48]);
1744   __m128i cospi_p48_m16 = pair_set_epi16(cospi[48], -cospi[16]);
1745   __m128i cospi_m48_p16 = pair_set_epi16(-cospi[48], cospi[16]);
1746   __m128i cospi_p08_p56 = pair_set_epi16(cospi[8], cospi[56]);
1747   __m128i cospi_p56_m08 = pair_set_epi16(cospi[56], -cospi[8]);
1748   __m128i cospi_p40_p24 = pair_set_epi16(cospi[40], cospi[24]);
1749   __m128i cospi_p24_m40 = pair_set_epi16(cospi[24], -cospi[40]);
1750   __m128i cospi_m56_p08 = pair_set_epi16(-cospi[56], cospi[8]);
1751   __m128i cospi_m24_p40 = pair_set_epi16(-cospi[24], cospi[40]);
1752   __m128i cospi_p02_p62 = pair_set_epi16(cospi[2], cospi[62]);
1753   __m128i cospi_p62_m02 = pair_set_epi16(cospi[62], -cospi[2]);
1754   __m128i cospi_p10_p54 = pair_set_epi16(cospi[10], cospi[54]);
1755   __m128i cospi_p54_m10 = pair_set_epi16(cospi[54], -cospi[10]);
1756   __m128i cospi_p18_p46 = pair_set_epi16(cospi[18], cospi[46]);
1757   __m128i cospi_p46_m18 = pair_set_epi16(cospi[46], -cospi[18]);
1758   __m128i cospi_p26_p38 = pair_set_epi16(cospi[26], cospi[38]);
1759   __m128i cospi_p38_m26 = pair_set_epi16(cospi[38], -cospi[26]);
1760   __m128i cospi_p34_p30 = pair_set_epi16(cospi[34], cospi[30]);
1761   __m128i cospi_p30_m34 = pair_set_epi16(cospi[30], -cospi[34]);
1762   __m128i cospi_p42_p22 = pair_set_epi16(cospi[42], cospi[22]);
1763   __m128i cospi_p22_m42 = pair_set_epi16(cospi[22], -cospi[42]);
1764   __m128i cospi_p50_p14 = pair_set_epi16(cospi[50], cospi[14]);
1765   __m128i cospi_p14_m50 = pair_set_epi16(cospi[14], -cospi[50]);
1766   __m128i cospi_p58_p06 = pair_set_epi16(cospi[58], cospi[6]);
1767   __m128i cospi_p06_m58 = pair_set_epi16(cospi[6], -cospi[58]);
1768 
1769   // stage 1
1770   __m128i x1[16];
1771   x1[0] = input[0];
1772   x1[1] = _mm_subs_epi16(__zero, input[15]);
1773   x1[2] = _mm_subs_epi16(__zero, input[7]);
1774   x1[3] = input[8];
1775   x1[4] = _mm_subs_epi16(__zero, input[3]);
1776   x1[5] = input[12];
1777   x1[6] = input[4];
1778   x1[7] = _mm_subs_epi16(__zero, input[11]);
1779   x1[8] = _mm_subs_epi16(__zero, input[1]);
1780   x1[9] = input[14];
1781   x1[10] = input[6];
1782   x1[11] = _mm_subs_epi16(__zero, input[9]);
1783   x1[12] = input[2];
1784   x1[13] = _mm_subs_epi16(__zero, input[13]);
1785   x1[14] = _mm_subs_epi16(__zero, input[5]);
1786   x1[15] = input[10];
1787 
1788   // stage 2
1789   __m128i x2[16];
1790   x2[0] = x1[0];
1791   x2[1] = x1[1];
1792   btf_16_sse2(cospi_p32_p32, cospi_p32_m32, x1[2], x1[3], x2[2], x2[3]);
1793   x2[4] = x1[4];
1794   x2[5] = x1[5];
1795   btf_16_sse2(cospi_p32_p32, cospi_p32_m32, x1[6], x1[7], x2[6], x2[7]);
1796   x2[8] = x1[8];
1797   x2[9] = x1[9];
1798   btf_16_sse2(cospi_p32_p32, cospi_p32_m32, x1[10], x1[11], x2[10], x2[11]);
1799   x2[12] = x1[12];
1800   x2[13] = x1[13];
1801   btf_16_sse2(cospi_p32_p32, cospi_p32_m32, x1[14], x1[15], x2[14], x2[15]);
1802 
1803   // stage 3
1804   __m128i x3[16];
1805   x3[0] = _mm_adds_epi16(x2[0], x2[2]);
1806   x3[2] = _mm_subs_epi16(x2[0], x2[2]);
1807   x3[1] = _mm_adds_epi16(x2[1], x2[3]);
1808   x3[3] = _mm_subs_epi16(x2[1], x2[3]);
1809   x3[4] = _mm_adds_epi16(x2[4], x2[6]);
1810   x3[6] = _mm_subs_epi16(x2[4], x2[6]);
1811   x3[5] = _mm_adds_epi16(x2[5], x2[7]);
1812   x3[7] = _mm_subs_epi16(x2[5], x2[7]);
1813   x3[8] = _mm_adds_epi16(x2[8], x2[10]);
1814   x3[10] = _mm_subs_epi16(x2[8], x2[10]);
1815   x3[9] = _mm_adds_epi16(x2[9], x2[11]);
1816   x3[11] = _mm_subs_epi16(x2[9], x2[11]);
1817   x3[12] = _mm_adds_epi16(x2[12], x2[14]);
1818   x3[14] = _mm_subs_epi16(x2[12], x2[14]);
1819   x3[13] = _mm_adds_epi16(x2[13], x2[15]);
1820   x3[15] = _mm_subs_epi16(x2[13], x2[15]);
1821 
1822   // stage 4
1823   __m128i x4[16];
1824   x4[0] = x3[0];
1825   x4[1] = x3[1];
1826   x4[2] = x3[2];
1827   x4[3] = x3[3];
1828   btf_16_sse2(cospi_p16_p48, cospi_p48_m16, x3[4], x3[5], x4[4], x4[5]);
1829   btf_16_sse2(cospi_m48_p16, cospi_p16_p48, x3[6], x3[7], x4[6], x4[7]);
1830   x4[8] = x3[8];
1831   x4[9] = x3[9];
1832   x4[10] = x3[10];
1833   x4[11] = x3[11];
1834   btf_16_sse2(cospi_p16_p48, cospi_p48_m16, x3[12], x3[13], x4[12], x4[13]);
1835   btf_16_sse2(cospi_m48_p16, cospi_p16_p48, x3[14], x3[15], x4[14], x4[15]);
1836 
1837   // stage 5
1838   __m128i x5[16];
1839   x5[0] = _mm_adds_epi16(x4[0], x4[4]);
1840   x5[4] = _mm_subs_epi16(x4[0], x4[4]);
1841   x5[1] = _mm_adds_epi16(x4[1], x4[5]);
1842   x5[5] = _mm_subs_epi16(x4[1], x4[5]);
1843   x5[2] = _mm_adds_epi16(x4[2], x4[6]);
1844   x5[6] = _mm_subs_epi16(x4[2], x4[6]);
1845   x5[3] = _mm_adds_epi16(x4[3], x4[7]);
1846   x5[7] = _mm_subs_epi16(x4[3], x4[7]);
1847   x5[8] = _mm_adds_epi16(x4[8], x4[12]);
1848   x5[12] = _mm_subs_epi16(x4[8], x4[12]);
1849   x5[9] = _mm_adds_epi16(x4[9], x4[13]);
1850   x5[13] = _mm_subs_epi16(x4[9], x4[13]);
1851   x5[10] = _mm_adds_epi16(x4[10], x4[14]);
1852   x5[14] = _mm_subs_epi16(x4[10], x4[14]);
1853   x5[11] = _mm_adds_epi16(x4[11], x4[15]);
1854   x5[15] = _mm_subs_epi16(x4[11], x4[15]);
1855 
1856   // stage 6
1857   __m128i x6[16];
1858   x6[0] = x5[0];
1859   x6[1] = x5[1];
1860   x6[2] = x5[2];
1861   x6[3] = x5[3];
1862   x6[4] = x5[4];
1863   x6[5] = x5[5];
1864   x6[6] = x5[6];
1865   x6[7] = x5[7];
1866   btf_16_sse2(cospi_p08_p56, cospi_p56_m08, x5[8], x5[9], x6[8], x6[9]);
1867   btf_16_sse2(cospi_p40_p24, cospi_p24_m40, x5[10], x5[11], x6[10], x6[11]);
1868   btf_16_sse2(cospi_m56_p08, cospi_p08_p56, x5[12], x5[13], x6[12], x6[13]);
1869   btf_16_sse2(cospi_m24_p40, cospi_p40_p24, x5[14], x5[15], x6[14], x6[15]);
1870 
1871   // stage 7
1872   __m128i x7[16];
1873   x7[0] = _mm_adds_epi16(x6[0], x6[8]);
1874   x7[8] = _mm_subs_epi16(x6[0], x6[8]);
1875   x7[1] = _mm_adds_epi16(x6[1], x6[9]);
1876   x7[9] = _mm_subs_epi16(x6[1], x6[9]);
1877   x7[2] = _mm_adds_epi16(x6[2], x6[10]);
1878   x7[10] = _mm_subs_epi16(x6[2], x6[10]);
1879   x7[3] = _mm_adds_epi16(x6[3], x6[11]);
1880   x7[11] = _mm_subs_epi16(x6[3], x6[11]);
1881   x7[4] = _mm_adds_epi16(x6[4], x6[12]);
1882   x7[12] = _mm_subs_epi16(x6[4], x6[12]);
1883   x7[5] = _mm_adds_epi16(x6[5], x6[13]);
1884   x7[13] = _mm_subs_epi16(x6[5], x6[13]);
1885   x7[6] = _mm_adds_epi16(x6[6], x6[14]);
1886   x7[14] = _mm_subs_epi16(x6[6], x6[14]);
1887   x7[7] = _mm_adds_epi16(x6[7], x6[15]);
1888   x7[15] = _mm_subs_epi16(x6[7], x6[15]);
1889 
1890   // stage 8
1891   __m128i x8[16];
1892   btf_16_sse2(cospi_p02_p62, cospi_p62_m02, x7[0], x7[1], x8[0], x8[1]);
1893   btf_16_sse2(cospi_p10_p54, cospi_p54_m10, x7[2], x7[3], x8[2], x8[3]);
1894   btf_16_sse2(cospi_p18_p46, cospi_p46_m18, x7[4], x7[5], x8[4], x8[5]);
1895   btf_16_sse2(cospi_p26_p38, cospi_p38_m26, x7[6], x7[7], x8[6], x8[7]);
1896   btf_16_sse2(cospi_p34_p30, cospi_p30_m34, x7[8], x7[9], x8[8], x8[9]);
1897   btf_16_sse2(cospi_p42_p22, cospi_p22_m42, x7[10], x7[11], x8[10], x8[11]);
1898   btf_16_sse2(cospi_p50_p14, cospi_p14_m50, x7[12], x7[13], x8[12], x8[13]);
1899   btf_16_sse2(cospi_p58_p06, cospi_p06_m58, x7[14], x7[15], x8[14], x8[15]);
1900 
1901   // stage 9
1902   output[0] = x8[1];
1903   output[1] = x8[14];
1904   output[2] = x8[3];
1905   output[3] = x8[12];
1906   output[4] = x8[5];
1907   output[5] = x8[10];
1908   output[6] = x8[7];
1909   output[7] = x8[8];
1910   output[8] = x8[9];
1911   output[9] = x8[6];
1912   output[10] = x8[11];
1913   output[11] = x8[4];
1914   output[12] = x8[13];
1915   output[13] = x8[2];
1916   output[14] = x8[15];
1917   output[15] = x8[0];
1918 }
1919 
1920 static const transform_1d_sse2 col_txfm4x4_arr[TX_TYPES] = {
1921   fdct4x4_new_sse2,       // DCT_DCT
1922   fadst4x4_new_sse2,      // ADST_DCT
1923   fdct4x4_new_sse2,       // DCT_ADST
1924   fadst4x4_new_sse2,      // ADST_ADST
1925   fadst4x4_new_sse2,      // FLIPADST_DCT
1926   fdct4x4_new_sse2,       // DCT_FLIPADST
1927   fadst4x4_new_sse2,      // FLIPADST_FLIPADST
1928   fadst4x4_new_sse2,      // ADST_FLIPADST
1929   fadst4x4_new_sse2,      // FLIPADST_ADST
1930   fidentity4x4_new_sse2,  // IDTX
1931   fdct4x4_new_sse2,       // V_DCT
1932   fidentity4x4_new_sse2,  // H_DCT
1933   fadst4x4_new_sse2,      // V_ADST
1934   fidentity4x4_new_sse2,  // H_ADST
1935   fadst4x4_new_sse2,      // V_FLIPADST
1936   fidentity4x4_new_sse2   // H_FLIPADST
1937 };
1938 
1939 static const transform_1d_sse2 row_txfm4x4_arr[TX_TYPES] = {
1940   fdct4x4_new_sse2,       // DCT_DCT
1941   fdct4x4_new_sse2,       // ADST_DCT
1942   fadst4x4_new_sse2,      // DCT_ADST
1943   fadst4x4_new_sse2,      // ADST_ADST
1944   fdct4x4_new_sse2,       // FLIPADST_DCT
1945   fadst4x4_new_sse2,      // DCT_FLIPADST
1946   fadst4x4_new_sse2,      // FLIPADST_FLIPADST
1947   fadst4x4_new_sse2,      // ADST_FLIPADST
1948   fadst4x4_new_sse2,      // FLIPADST_ADST
1949   fidentity4x4_new_sse2,  // IDTX
1950   fidentity4x4_new_sse2,  // V_DCT
1951   fdct4x4_new_sse2,       // H_DCT
1952   fidentity4x4_new_sse2,  // V_ADST
1953   fadst4x4_new_sse2,      // H_ADST
1954   fidentity4x4_new_sse2,  // V_FLIPADST
1955   fadst4x4_new_sse2       // H_FLIPADST
1956 };
1957 
1958 static const transform_1d_sse2 col_txfm4x8_arr[TX_TYPES] = {
1959   fdct4x8_new_sse2,       // DCT_DCT
1960   fadst4x8_new_sse2,      // ADST_DCT
1961   fdct4x8_new_sse2,       // DCT_ADST
1962   fadst4x8_new_sse2,      // ADST_ADST
1963   fadst4x8_new_sse2,      // FLIPADST_DCT
1964   fdct4x8_new_sse2,       // DCT_FLIPADST
1965   fadst4x8_new_sse2,      // FLIPADST_FLIPADST
1966   fadst4x8_new_sse2,      // ADST_FLIPADST
1967   fadst4x8_new_sse2,      // FLIPADST_ADST
1968   fidentity8x8_new_sse2,  // IDTX
1969   fdct4x8_new_sse2,       // V_DCT
1970   fidentity8x8_new_sse2,  // H_DCT
1971   fadst4x8_new_sse2,      // V_ADST
1972   fidentity8x8_new_sse2,  // H_ADST
1973   fadst4x8_new_sse2,      // V_FLIPADST
1974   fidentity8x8_new_sse2   // H_FLIPADST
1975 };
1976 
1977 static const transform_1d_sse2 row_txfm8x4_arr[TX_TYPES] = {
1978   fdct8x4_new_sse2,       // DCT_DCT
1979   fdct8x4_new_sse2,       // ADST_DCT
1980   fadst8x4_new_sse2,      // DCT_ADST
1981   fadst8x4_new_sse2,      // ADST_ADST
1982   fdct8x4_new_sse2,       // FLIPADST_DCT
1983   fadst8x4_new_sse2,      // DCT_FLIPADST
1984   fadst8x4_new_sse2,      // FLIPADST_FLIPADST
1985   fadst8x4_new_sse2,      // ADST_FLIPADST
1986   fadst8x4_new_sse2,      // FLIPADST_ADST
1987   fidentity8x4_new_sse2,  // IDTX
1988   fidentity8x4_new_sse2,  // V_DCT
1989   fdct8x4_new_sse2,       // H_DCT
1990   fidentity8x4_new_sse2,  // V_ADST
1991   fadst8x4_new_sse2,      // H_ADST
1992   fidentity8x4_new_sse2,  // V_FLIPADST
1993   fadst8x4_new_sse2       // H_FLIPADST
1994 };
1995 
1996 static const transform_1d_sse2 col_txfm8x4_arr[TX_TYPES] = {
1997   fdct8x4_new_sse2,       // DCT_DCT
1998   fadst8x4_new_sse2,      // ADST_DCT
1999   fdct8x4_new_sse2,       // DCT_ADST
2000   fadst8x4_new_sse2,      // ADST_ADST
2001   fadst8x4_new_sse2,      // FLIPADST_DCT
2002   fdct8x4_new_sse2,       // DCT_FLIPADST
2003   fadst8x4_new_sse2,      // FLIPADST_FLIPADST
2004   fadst8x4_new_sse2,      // ADST_FLIPADST
2005   fadst8x4_new_sse2,      // FLIPADST_ADST
2006   fidentity8x4_new_sse2,  // IDTX
2007   fdct8x4_new_sse2,       // V_DCT
2008   fidentity8x4_new_sse2,  // H_DCT
2009   fadst8x4_new_sse2,      // V_ADST
2010   fidentity8x4_new_sse2,  // H_ADST
2011   fadst8x4_new_sse2,      // V_FLIPADST
2012   fidentity8x4_new_sse2   // H_FLIPADST
2013 };
2014 
2015 static const transform_1d_sse2 row_txfm4x8_arr[TX_TYPES] = {
2016   fdct4x8_new_sse2,       // DCT_DCT
2017   fdct4x8_new_sse2,       // ADST_DCT
2018   fadst4x8_new_sse2,      // DCT_ADST
2019   fadst4x8_new_sse2,      // ADST_ADST
2020   fdct4x8_new_sse2,       // FLIPADST_DCT
2021   fadst4x8_new_sse2,      // DCT_FLIPADST
2022   fadst4x8_new_sse2,      // FLIPADST_FLIPADST
2023   fadst4x8_new_sse2,      // ADST_FLIPADST
2024   fadst4x8_new_sse2,      // FLIPADST_ADST
2025   fidentity8x8_new_sse2,  // IDTX
2026   fidentity8x8_new_sse2,  // V_DCT
2027   fdct4x8_new_sse2,       // H_DCT
2028   fidentity8x8_new_sse2,  // V_ADST
2029   fadst4x8_new_sse2,      // H_ADST
2030   fidentity8x8_new_sse2,  // V_FLIPADST
2031   fadst4x8_new_sse2       // H_FLIPADST
2032 };
2033 
2034 static const transform_1d_sse2 col_txfm8x8_arr[TX_TYPES] = {
2035   fdct8x8_new_sse2,       // DCT_DCT
2036   fadst8x8_new_sse2,      // ADST_DCT
2037   fdct8x8_new_sse2,       // DCT_ADST
2038   fadst8x8_new_sse2,      // ADST_ADST
2039   fadst8x8_new_sse2,      // FLIPADST_DCT
2040   fdct8x8_new_sse2,       // DCT_FLIPADST
2041   fadst8x8_new_sse2,      // FLIPADST_FLIPADST
2042   fadst8x8_new_sse2,      // ADST_FLIPADST
2043   fadst8x8_new_sse2,      // FLIPADST_ADST
2044   fidentity8x8_new_sse2,  // IDTX
2045   fdct8x8_new_sse2,       // V_DCT
2046   fidentity8x8_new_sse2,  // H_DCT
2047   fadst8x8_new_sse2,      // V_ADST
2048   fidentity8x8_new_sse2,  // H_ADST
2049   fadst8x8_new_sse2,      // V_FLIPADST
2050   fidentity8x8_new_sse2,  // H_FLIPADST
2051 };
2052 
2053 static const transform_1d_sse2 row_txfm8x8_arr[TX_TYPES] = {
2054   fdct8x8_new_sse2,       // DCT_DCT
2055   fdct8x8_new_sse2,       // ADST_DCT
2056   fadst8x8_new_sse2,      // DCT_ADST
2057   fadst8x8_new_sse2,      // ADST_ADST
2058   fdct8x8_new_sse2,       // FLIPADST_DCT
2059   fadst8x8_new_sse2,      // DCT_FLIPADST
2060   fadst8x8_new_sse2,      // FLIPADST_FLIPADST
2061   fadst8x8_new_sse2,      // ADST_FLIPADST
2062   fadst8x8_new_sse2,      // FLIPADST_ADST
2063   fidentity8x8_new_sse2,  // IDTX
2064   fidentity8x8_new_sse2,  // V_DCT
2065   fdct8x8_new_sse2,       // H_DCT
2066   fidentity8x8_new_sse2,  // V_ADST
2067   fadst8x8_new_sse2,      // H_ADST
2068   fidentity8x8_new_sse2,  // V_FLIPADST
2069   fadst8x8_new_sse2       // H_FLIPADST
2070 };
2071 
2072 static const transform_1d_sse2 col_txfm8x16_arr[TX_TYPES] = {
2073   fdct8x16_new_sse2,       // DCT_DCT
2074   fadst8x16_new_sse2,      // ADST_DCT
2075   fdct8x16_new_sse2,       // DCT_ADST
2076   fadst8x16_new_sse2,      // ADST_ADST
2077   fadst8x16_new_sse2,      // FLIPADST_DCT
2078   fdct8x16_new_sse2,       // DCT_FLIPADST
2079   fadst8x16_new_sse2,      // FLIPADST_FLIPADST
2080   fadst8x16_new_sse2,      // ADST_FLIPADST
2081   fadst8x16_new_sse2,      // FLIPADST_ADST
2082   fidentity8x16_new_sse2,  // IDTX
2083   fdct8x16_new_sse2,       // V_DCT
2084   fidentity8x16_new_sse2,  // H_DCT
2085   fadst8x16_new_sse2,      // V_ADST
2086   fidentity8x16_new_sse2,  // H_ADST
2087   fadst8x16_new_sse2,      // V_FLIPADST
2088   fidentity8x16_new_sse2   // H_FLIPADST
2089 };
2090 
2091 static const transform_1d_sse2 row_txfm8x16_arr[TX_TYPES] = {
2092   fdct8x16_new_sse2,       // DCT_DCT
2093   fdct8x16_new_sse2,       // ADST_DCT
2094   fadst8x16_new_sse2,      // DCT_ADST
2095   fadst8x16_new_sse2,      // ADST_ADST
2096   fdct8x16_new_sse2,       // FLIPADST_DCT
2097   fadst8x16_new_sse2,      // DCT_FLIPADST
2098   fadst8x16_new_sse2,      // FLIPADST_FLIPADST
2099   fadst8x16_new_sse2,      // ADST_FLIPADST
2100   fadst8x16_new_sse2,      // FLIPADST_ADST
2101   fidentity8x16_new_sse2,  // IDTX
2102   fidentity8x16_new_sse2,  // V_DCT
2103   fdct8x16_new_sse2,       // H_DCT
2104   fidentity8x16_new_sse2,  // V_ADST
2105   fadst8x16_new_sse2,      // H_ADST
2106   fidentity8x16_new_sse2,  // V_FLIPADST
2107   fadst8x16_new_sse2       // H_FLIPADST
2108 };
2109 
2110 static const transform_1d_sse2 row_txfm8x32_arr[TX_TYPES] = {
2111   av1_fdct8x32_new_sse2,   // DCT_DCT
2112   NULL,                    // ADST_DCT
2113   NULL,                    // DCT_ADST
2114   NULL,                    // ADST_ADST
2115   NULL,                    // FLIPADST_DCT
2116   NULL,                    // DCT_FLIPADST
2117   NULL,                    // FLIPADST_FLIPADST
2118   NULL,                    // ADST_FLIPADST
2119   NULL,                    // FLIPADST_ADST
2120   fidentity8x32_new_sse2,  // IDTX
2121   fidentity8x32_new_sse2,  // V_DCT
2122   av1_fdct8x32_new_sse2,   // H_DCT
2123   NULL,                    // V_ADST
2124   NULL,                    // H_ADST
2125   NULL,                    // V_FLIPADST
2126   NULL                     // H_FLIPADST
2127 };
2128 
av1_lowbd_fwd_txfm2d_4x4_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2129 void av1_lowbd_fwd_txfm2d_4x4_sse2(const int16_t *input, int32_t *output,
2130                                    int stride, TX_TYPE tx_type, int bd) {
2131   (void)bd;
2132   __m128i buf0[4], buf1[4], *buf;
2133   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_4X4];
2134   const int txw_idx = get_txw_idx(TX_4X4);
2135   const int txh_idx = get_txh_idx(TX_4X4);
2136   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2137   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2138   const int width = 4;
2139   const int height = 4;
2140   const transform_1d_sse2 col_txfm = col_txfm4x4_arr[tx_type];
2141   const transform_1d_sse2 row_txfm = row_txfm4x4_arr[tx_type];
2142   int ud_flip, lr_flip;
2143 
2144   get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2145   if (ud_flip) {
2146     load_buffer_16bit_to_16bit_w4_flip(input, stride, buf0, height);
2147   } else {
2148     load_buffer_16bit_to_16bit_w4(input, stride, buf0, height);
2149   }
2150   round_shift_16bit(buf0, height, shift[0]);
2151   col_txfm(buf0, buf0, cos_bit_col);
2152   round_shift_16bit(buf0, height, shift[1]);
2153   transpose_16bit_4x4(buf0, buf1);
2154 
2155   if (lr_flip) {
2156     buf = buf0;
2157     flip_buf_sse2(buf1, buf, width);
2158   } else {
2159     buf = buf1;
2160   }
2161   row_txfm(buf, buf, cos_bit_row);
2162   round_shift_16bit(buf, width, shift[2]);
2163   transpose_16bit_4x4(buf, buf);
2164   store_buffer_16bit_to_32bit_w4(buf, output, width, height);
2165 }
2166 
av1_lowbd_fwd_txfm2d_4x8_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2167 void av1_lowbd_fwd_txfm2d_4x8_sse2(const int16_t *input, int32_t *output,
2168                                    int stride, TX_TYPE tx_type, int bd) {
2169   (void)stride;
2170   (void)bd;
2171   __m128i buf0[8], buf1[8], *buf;
2172   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_4X8];
2173   const int txw_idx = get_txw_idx(TX_4X8);
2174   const int txh_idx = get_txh_idx(TX_4X8);
2175   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2176   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2177   const int width = 4;
2178   const int height = 8;
2179   const transform_1d_sse2 col_txfm = col_txfm4x8_arr[tx_type];
2180   const transform_1d_sse2 row_txfm = row_txfm8x4_arr[tx_type];
2181   int ud_flip, lr_flip;
2182 
2183   get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2184   if (ud_flip) {
2185     load_buffer_16bit_to_16bit_w4_flip(input, stride, buf0, height);
2186   } else {
2187     load_buffer_16bit_to_16bit_w4(input, stride, buf0, height);
2188   }
2189   round_shift_16bit(buf0, height, shift[0]);
2190   col_txfm(buf0, buf0, cos_bit_col);
2191   round_shift_16bit(buf0, height, shift[1]);
2192   transpose_16bit_4x8(buf0, buf1);
2193 
2194   if (lr_flip) {
2195     buf = buf0;
2196     flip_buf_sse2(buf1, buf, width);
2197   } else {
2198     buf = buf1;
2199   }
2200   row_txfm(buf, buf, cos_bit_row);
2201   round_shift_16bit(buf, width, shift[2]);
2202   transpose_16bit_8x4(buf, buf);
2203   store_rect_buffer_16bit_to_32bit_w4(buf, output, width, height);
2204 }
2205 
av1_lowbd_fwd_txfm2d_4x16_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2206 void av1_lowbd_fwd_txfm2d_4x16_sse2(const int16_t *input, int32_t *output,
2207                                     int stride, TX_TYPE tx_type, int bd) {
2208   (void)bd;
2209   __m128i buf0[16], buf1[16];
2210   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_4X16];
2211   const int txw_idx = get_txw_idx(TX_4X16);
2212   const int txh_idx = get_txh_idx(TX_4X16);
2213   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2214   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2215   const int width = 4;
2216   const int height = 16;
2217   const transform_1d_sse2 col_txfm = col_txfm8x16_arr[tx_type];
2218   const transform_1d_sse2 row_txfm = row_txfm8x4_arr[tx_type];
2219   int ud_flip, lr_flip;
2220 
2221   get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2222   if (ud_flip) {
2223     load_buffer_16bit_to_16bit_w4_flip(input, stride, buf0, height);
2224   } else {
2225     load_buffer_16bit_to_16bit_w4(input, stride, buf0, height);
2226   }
2227   round_shift_16bit(buf0, height, shift[0]);
2228   col_txfm(buf0, buf0, cos_bit_col);
2229   round_shift_16bit(buf0, height, shift[1]);
2230   transpose_16bit_4x8(buf0, buf1);
2231   transpose_16bit_4x8(buf0 + 8, buf1 + 8);
2232 
2233   for (int i = 0; i < 2; i++) {
2234     __m128i *buf;
2235     if (lr_flip) {
2236       buf = buf0;
2237       flip_buf_sse2(buf1 + 8 * i, buf, width);
2238     } else {
2239       buf = buf1 + 8 * i;
2240     }
2241     row_txfm(buf, buf, cos_bit_row);
2242     round_shift_16bit(buf, width, shift[2]);
2243     transpose_16bit_8x4(buf, buf);
2244     store_buffer_16bit_to_32bit_w4(buf, output + 8 * width * i, width, 8);
2245   }
2246 }
2247 
av1_lowbd_fwd_txfm2d_8x4_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2248 void av1_lowbd_fwd_txfm2d_8x4_sse2(const int16_t *input, int32_t *output,
2249                                    int stride, TX_TYPE tx_type, int bd) {
2250   (void)bd;
2251   __m128i buf0[8], buf1[8], *buf;
2252   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_8X4];
2253   const int txw_idx = get_txw_idx(TX_8X4);
2254   const int txh_idx = get_txh_idx(TX_8X4);
2255   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2256   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2257   const int width = 8;
2258   const int height = 4;
2259   const transform_1d_sse2 col_txfm = col_txfm8x4_arr[tx_type];
2260   const transform_1d_sse2 row_txfm = row_txfm4x8_arr[tx_type];
2261   int ud_flip, lr_flip;
2262 
2263   get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2264   if (ud_flip)
2265     load_buffer_16bit_to_16bit_flip(input, stride, buf0, height);
2266   else
2267     load_buffer_16bit_to_16bit(input, stride, buf0, height);
2268   round_shift_16bit(buf0, height, shift[0]);
2269   col_txfm(buf0, buf0, cos_bit_col);
2270   round_shift_16bit(buf0, height, shift[1]);
2271   transpose_16bit_8x8(buf0, buf1);
2272 
2273   if (lr_flip) {
2274     buf = buf0;
2275     flip_buf_sse2(buf1, buf, width);
2276   } else {
2277     buf = buf1;
2278   }
2279   row_txfm(buf, buf, cos_bit_row);
2280   round_shift_16bit(buf, width, shift[2]);
2281   transpose_16bit_8x8(buf, buf);
2282   store_rect_buffer_16bit_to_32bit_w8(buf, output, width, height);
2283 }
2284 
av1_lowbd_fwd_txfm2d_8x8_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2285 void av1_lowbd_fwd_txfm2d_8x8_sse2(const int16_t *input, int32_t *output,
2286                                    int stride, TX_TYPE tx_type, int bd) {
2287   (void)bd;
2288   __m128i buf0[8], buf1[8], *buf;
2289   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_8X8];
2290   const int txw_idx = get_txw_idx(TX_8X8);
2291   const int txh_idx = get_txh_idx(TX_8X8);
2292   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2293   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2294   const int width = 8;
2295   const int height = 8;
2296   const transform_1d_sse2 col_txfm = col_txfm8x8_arr[tx_type];
2297   const transform_1d_sse2 row_txfm = row_txfm8x8_arr[tx_type];
2298   int ud_flip, lr_flip;
2299 
2300   get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2301   if (ud_flip)
2302     load_buffer_16bit_to_16bit_flip(input, stride, buf0, height);
2303   else
2304     load_buffer_16bit_to_16bit(input, stride, buf0, height);
2305   round_shift_16bit(buf0, height, shift[0]);
2306   col_txfm(buf0, buf0, cos_bit_col);
2307   round_shift_16bit(buf0, height, shift[1]);
2308   transpose_16bit_8x8(buf0, buf1);
2309 
2310   if (lr_flip) {
2311     buf = buf0;
2312     flip_buf_sse2(buf1, buf, width);
2313   } else {
2314     buf = buf1;
2315   }
2316   row_txfm(buf, buf, cos_bit_row);
2317   round_shift_16bit(buf, width, shift[2]);
2318   transpose_16bit_8x8(buf, buf);
2319   store_buffer_16bit_to_32bit_w8(buf, output, width, height);
2320 }
2321 
av1_lowbd_fwd_txfm2d_8x16_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2322 void av1_lowbd_fwd_txfm2d_8x16_sse2(const int16_t *input, int32_t *output,
2323                                     int stride, TX_TYPE tx_type, int bd) {
2324   (void)bd;
2325   __m128i buf0[16], buf1[16];
2326   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_8X16];
2327   const int txw_idx = get_txw_idx(TX_8X16);
2328   const int txh_idx = get_txh_idx(TX_8X16);
2329   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2330   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2331   const int width = 8;
2332   const int height = 16;
2333   const transform_1d_sse2 col_txfm = col_txfm8x16_arr[tx_type];
2334   const transform_1d_sse2 row_txfm = row_txfm8x8_arr[tx_type];
2335   int ud_flip, lr_flip;
2336 
2337   get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2338   if (ud_flip) {
2339     load_buffer_16bit_to_16bit_flip(input, stride, buf0, height);
2340   } else {
2341     load_buffer_16bit_to_16bit(input, stride, buf0, height);
2342   }
2343   round_shift_16bit(buf0, height, shift[0]);
2344   col_txfm(buf0, buf0, cos_bit_col);
2345   round_shift_16bit(buf0, height, shift[1]);
2346   transpose_16bit_8x8(buf0, buf1);
2347   transpose_16bit_8x8(buf0 + 8, buf1 + 8);
2348 
2349   for (int i = 0; i < 2; i++) {
2350     __m128i *buf;
2351     if (lr_flip) {
2352       buf = buf0;
2353       flip_buf_sse2(buf1 + width * i, buf, width);
2354     } else {
2355       buf = buf1 + width * i;
2356     }
2357     row_txfm(buf, buf, cos_bit_row);
2358     round_shift_16bit(buf, width, shift[2]);
2359     transpose_16bit_8x8(buf, buf);
2360     store_rect_buffer_16bit_to_32bit_w8(buf, output + 8 * width * i, width, 8);
2361   }
2362 }
2363 
av1_lowbd_fwd_txfm2d_8x32_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2364 void av1_lowbd_fwd_txfm2d_8x32_sse2(const int16_t *input, int32_t *output,
2365                                     int stride, TX_TYPE tx_type, int bd) {
2366   (void)bd;
2367   __m128i buf0[32], buf1[32];
2368   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_8X32];
2369   const int txw_idx = get_txw_idx(TX_8X32);
2370   const int txh_idx = get_txh_idx(TX_8X32);
2371   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2372   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2373   const int width = 8;
2374   const int height = 32;
2375   const transform_1d_sse2 col_txfm = col_txfm8x32_arr[tx_type];
2376   const transform_1d_sse2 row_txfm = row_txfm8x8_arr[tx_type];
2377   int ud_flip, lr_flip;
2378 
2379   get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2380   if (ud_flip) {
2381     load_buffer_16bit_to_16bit_flip(input, stride, buf0, height);
2382   } else {
2383     load_buffer_16bit_to_16bit(input, stride, buf0, height);
2384   }
2385   round_shift_16bit(buf0, height, shift[0]);
2386   col_txfm(buf0, buf0, cos_bit_col);
2387   round_shift_16bit(buf0, height, shift[1]);
2388   transpose_16bit_8x8(buf0, buf1);
2389   transpose_16bit_8x8(buf0 + 8, buf1 + 8);
2390   transpose_16bit_8x8(buf0 + 16, buf1 + 16);
2391   transpose_16bit_8x8(buf0 + 24, buf1 + 24);
2392 
2393   for (int i = 0; i < 4; i++) {
2394     __m128i *buf;
2395     if (lr_flip) {
2396       buf = buf0;
2397       flip_buf_sse2(buf1 + width * i, buf, width);
2398     } else {
2399       buf = buf1 + width * i;
2400     }
2401     row_txfm(buf, buf, cos_bit_row);
2402     round_shift_16bit(buf, width, shift[2]);
2403     transpose_16bit_8x8(buf, buf);
2404     store_buffer_16bit_to_32bit_w8(buf, output + 8 * width * i, width, 8);
2405   }
2406 }
2407 
av1_lowbd_fwd_txfm2d_16x4_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2408 void av1_lowbd_fwd_txfm2d_16x4_sse2(const int16_t *input, int32_t *output,
2409                                     int stride, TX_TYPE tx_type, int bd) {
2410   (void)bd;
2411   __m128i buf0[16], buf1[16];
2412   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_16X4];
2413   const int txw_idx = get_txw_idx(TX_16X4);
2414   const int txh_idx = get_txh_idx(TX_16X4);
2415   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2416   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2417   const int width = 16;
2418   const int height = 4;
2419   const transform_1d_sse2 col_txfm = col_txfm8x4_arr[tx_type];
2420   const transform_1d_sse2 row_txfm = row_txfm8x16_arr[tx_type];
2421   __m128i *buf;
2422   int ud_flip, lr_flip;
2423 
2424   get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2425   for (int i = 0; i < 2; i++) {
2426     if (ud_flip) {
2427       load_buffer_16bit_to_16bit_flip(input + 8 * i, stride, buf0, height);
2428     } else {
2429       load_buffer_16bit_to_16bit(input + 8 * i, stride, buf0, height);
2430     }
2431     round_shift_16bit(buf0, height, shift[0]);
2432     col_txfm(buf0, buf0, cos_bit_col);
2433     round_shift_16bit(buf0, height, shift[1]);
2434     transpose_16bit_8x4(buf0, buf1 + 8 * i);
2435   }
2436 
2437   if (lr_flip) {
2438     buf = buf0;
2439     flip_buf_sse2(buf1, buf, width);
2440   } else {
2441     buf = buf1;
2442   }
2443   row_txfm(buf, buf, cos_bit_row);
2444   round_shift_16bit(buf, width, shift[2]);
2445   transpose_16bit_4x8(buf, buf);
2446   store_buffer_16bit_to_32bit_w8(buf, output, width, height);
2447   transpose_16bit_4x8(buf + 8, buf + 8);
2448   store_buffer_16bit_to_32bit_w8(buf + 8, output + 8, width, height);
2449 }
2450 
av1_lowbd_fwd_txfm2d_16x8_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2451 void av1_lowbd_fwd_txfm2d_16x8_sse2(const int16_t *input, int32_t *output,
2452                                     int stride, TX_TYPE tx_type, int bd) {
2453   (void)bd;
2454   __m128i buf0[16], buf1[16];
2455   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_16X8];
2456   const int txw_idx = get_txw_idx(TX_16X8);
2457   const int txh_idx = get_txh_idx(TX_16X8);
2458   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2459   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2460   const int width = 16;
2461   const int height = 8;
2462   const transform_1d_sse2 col_txfm = col_txfm8x8_arr[tx_type];
2463   const transform_1d_sse2 row_txfm = row_txfm8x16_arr[tx_type];
2464   __m128i *buf;
2465   int ud_flip, lr_flip;
2466 
2467   get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2468   for (int i = 0; i < 2; i++) {
2469     if (ud_flip) {
2470       load_buffer_16bit_to_16bit_flip(input + 8 * i, stride, buf0, height);
2471     } else {
2472       load_buffer_16bit_to_16bit(input + 8 * i, stride, buf0, height);
2473     }
2474     round_shift_16bit(buf0, height, shift[0]);
2475     col_txfm(buf0, buf0, cos_bit_col);
2476     round_shift_16bit(buf0, height, shift[1]);
2477     transpose_16bit_8x8(buf0, buf1 + 8 * i);
2478   }
2479 
2480   if (lr_flip) {
2481     buf = buf0;
2482     flip_buf_sse2(buf1, buf, width);
2483   } else {
2484     buf = buf1;
2485   }
2486   row_txfm(buf, buf, cos_bit_row);
2487   round_shift_16bit(buf, width, shift[2]);
2488   transpose_16bit_8x8(buf, buf);
2489   store_rect_buffer_16bit_to_32bit_w8(buf, output, width, height);
2490   transpose_16bit_8x8(buf + 8, buf + 8);
2491   store_rect_buffer_16bit_to_32bit_w8(buf + 8, output + 8, width, height);
2492 }
2493 
av1_lowbd_fwd_txfm2d_16x16_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2494 void av1_lowbd_fwd_txfm2d_16x16_sse2(const int16_t *input, int32_t *output,
2495                                      int stride, TX_TYPE tx_type, int bd) {
2496   (void)bd;
2497   __m128i buf0[16], buf1[32];
2498   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_16X16];
2499   const int txw_idx = get_txw_idx(TX_16X16);
2500   const int txh_idx = get_txh_idx(TX_16X16);
2501   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2502   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2503   const int width = 16;
2504   const int height = 16;
2505   const transform_1d_sse2 col_txfm = col_txfm8x16_arr[tx_type];
2506   const transform_1d_sse2 row_txfm = row_txfm8x16_arr[tx_type];
2507   int ud_flip, lr_flip;
2508 
2509   get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2510   for (int i = 0; i < 2; i++) {
2511     if (ud_flip) {
2512       load_buffer_16bit_to_16bit_flip(input + 8 * i, stride, buf0, height);
2513     } else {
2514       load_buffer_16bit_to_16bit(input + 8 * i, stride, buf0, height);
2515     }
2516     round_shift_16bit(buf0, height, shift[0]);
2517     col_txfm(buf0, buf0, cos_bit_col);
2518     round_shift_16bit(buf0, height, shift[1]);
2519     transpose_16bit_8x8(buf0, buf1 + 0 * width + 8 * i);
2520     transpose_16bit_8x8(buf0 + 8, buf1 + 1 * width + 8 * i);
2521   }
2522 
2523   for (int i = 0; i < 2; i++) {
2524     __m128i *buf;
2525     if (lr_flip) {
2526       buf = buf0;
2527       flip_buf_sse2(buf1 + width * i, buf, width);
2528     } else {
2529       buf = buf1 + width * i;
2530     }
2531     row_txfm(buf, buf, cos_bit_row);
2532     round_shift_16bit(buf, width, shift[2]);
2533     transpose_16bit_8x8(buf, buf);
2534     store_buffer_16bit_to_32bit_w8(buf, output + 8 * width * i, width, 8);
2535     transpose_16bit_8x8(buf + 8, buf + 8);
2536     store_buffer_16bit_to_32bit_w8(buf + 8, output + 8 * width * i + 8, width,
2537                                    8);
2538   }
2539 }
2540 
av1_lowbd_fwd_txfm2d_16x32_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2541 void av1_lowbd_fwd_txfm2d_16x32_sse2(const int16_t *input, int32_t *output,
2542                                      int stride, TX_TYPE tx_type, int bd) {
2543   (void)bd;
2544   __m128i buf0[32], buf1[64];
2545   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_16X32];
2546   const int txw_idx = get_txw_idx(TX_16X32);
2547   const int txh_idx = get_txh_idx(TX_16X32);
2548   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2549   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2550   const int width = 16;
2551   const int height = 32;
2552   const transform_1d_sse2 col_txfm = col_txfm8x32_arr[tx_type];
2553   const transform_1d_sse2 row_txfm = row_txfm8x16_arr[tx_type];
2554 
2555   if (col_txfm != NULL && row_txfm != NULL) {
2556     int ud_flip, lr_flip;
2557     get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2558 
2559     for (int i = 0; i < 2; i++) {
2560       if (ud_flip) {
2561         load_buffer_16bit_to_16bit_flip(input + 8 * i, stride, buf0, height);
2562       } else {
2563         load_buffer_16bit_to_16bit(input + 8 * i, stride, buf0, height);
2564       }
2565       round_shift_16bit(buf0, height, shift[0]);
2566       col_txfm(buf0, buf0, cos_bit_col);
2567       round_shift_16bit(buf0, height, shift[1]);
2568       transpose_16bit_8x8(buf0 + 0 * 8, buf1 + 0 * width + 8 * i);
2569       transpose_16bit_8x8(buf0 + 1 * 8, buf1 + 1 * width + 8 * i);
2570       transpose_16bit_8x8(buf0 + 2 * 8, buf1 + 2 * width + 8 * i);
2571       transpose_16bit_8x8(buf0 + 3 * 8, buf1 + 3 * width + 8 * i);
2572     }
2573 
2574     for (int i = 0; i < 4; i++) {
2575       __m128i *buf;
2576       if (lr_flip) {
2577         buf = buf0;
2578         flip_buf_sse2(buf1 + width * i, buf, width);
2579       } else {
2580         buf = buf1 + width * i;
2581       }
2582       row_txfm(buf, buf, cos_bit_row);
2583       round_shift_16bit(buf, width, shift[2]);
2584       transpose_16bit_8x8(buf, buf);
2585       store_rect_buffer_16bit_to_32bit_w8(buf, output + 8 * width * i, width,
2586                                           8);
2587       transpose_16bit_8x8(buf + 8, buf + 8);
2588       store_rect_buffer_16bit_to_32bit_w8(buf + 8, output + 8 * width * i + 8,
2589                                           width, 8);
2590     }
2591   } else {
2592     av1_fwd_txfm2d_16x32_c(input, output, stride, tx_type, bd);
2593   }
2594 }
2595 
av1_lowbd_fwd_txfm2d_32x8_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2596 void av1_lowbd_fwd_txfm2d_32x8_sse2(const int16_t *input, int32_t *output,
2597                                     int stride, TX_TYPE tx_type, int bd) {
2598   (void)bd;
2599   __m128i buf0[32], buf1[32];
2600   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_32X8];
2601   const int txw_idx = get_txw_idx(TX_32X8);
2602   const int txh_idx = get_txh_idx(TX_32X8);
2603   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2604   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2605   const int width = 32;
2606   const int height = 8;
2607   const transform_1d_sse2 col_txfm = col_txfm8x8_arr[tx_type];
2608   const transform_1d_sse2 row_txfm = row_txfm8x32_arr[tx_type];
2609 
2610   if (col_txfm != NULL && row_txfm != NULL) {
2611     int ud_flip, lr_flip;
2612     get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2613 
2614     for (int i = 0; i < 4; i++) {
2615       if (ud_flip) {
2616         load_buffer_16bit_to_16bit_flip(input + 8 * i, stride, buf0, height);
2617       } else {
2618         load_buffer_16bit_to_16bit(input + 8 * i, stride, buf0, height);
2619       }
2620       round_shift_16bit(buf0, height, shift[0]);
2621       col_txfm(buf0, buf0, cos_bit_col);
2622       round_shift_16bit(buf0, height, shift[1]);
2623       transpose_16bit_8x8(buf0, buf1 + 0 * width + 8 * i);
2624     }
2625 
2626     for (int i = 0; i < 1; i++) {
2627       __m128i *buf;
2628       if (lr_flip) {
2629         buf = buf0;
2630         flip_buf_sse2(buf1 + width * i, buf, width);
2631       } else {
2632         buf = buf1 + width * i;
2633       }
2634       row_txfm(buf, buf, cos_bit_row);
2635       round_shift_16bit(buf, width, shift[2]);
2636       transpose_16bit_8x8(buf, buf);
2637       store_buffer_16bit_to_32bit_w8(buf, output + 8 * width * i, width,
2638                                      height);
2639       transpose_16bit_8x8(buf + 8, buf + 8);
2640       store_buffer_16bit_to_32bit_w8(buf + 8, output + 8 * width * i + 8, width,
2641                                      height);
2642       transpose_16bit_8x8(buf + 16, buf + 16);
2643       store_buffer_16bit_to_32bit_w8(buf + 16, output + 8 * width * i + 16,
2644                                      width, height);
2645       transpose_16bit_8x8(buf + 24, buf + 24);
2646       store_buffer_16bit_to_32bit_w8(buf + 24, output + 8 * width * i + 24,
2647                                      width, height);
2648     }
2649   } else {
2650     av1_fwd_txfm2d_32x16_c(input, output, stride, tx_type, bd);
2651   }
2652 }
2653 
av1_lowbd_fwd_txfm2d_32x16_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2654 void av1_lowbd_fwd_txfm2d_32x16_sse2(const int16_t *input, int32_t *output,
2655                                      int stride, TX_TYPE tx_type, int bd) {
2656   (void)bd;
2657   __m128i buf0[32], buf1[64];
2658   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_32X16];
2659   const int txw_idx = get_txw_idx(TX_32X16);
2660   const int txh_idx = get_txh_idx(TX_32X16);
2661   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2662   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2663   const int width = 32;
2664   const int height = 16;
2665   const transform_1d_sse2 col_txfm = col_txfm8x16_arr[tx_type];
2666   const transform_1d_sse2 row_txfm = row_txfm8x32_arr[tx_type];
2667 
2668   if (col_txfm != NULL && row_txfm != NULL) {
2669     int ud_flip, lr_flip;
2670     get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2671 
2672     for (int i = 0; i < 4; i++) {
2673       if (ud_flip) {
2674         load_buffer_16bit_to_16bit_flip(input + 8 * i, stride, buf0, height);
2675       } else {
2676         load_buffer_16bit_to_16bit(input + 8 * i, stride, buf0, height);
2677       }
2678       round_shift_16bit(buf0, height, shift[0]);
2679       col_txfm(buf0, buf0, cos_bit_col);
2680       round_shift_16bit(buf0, height, shift[1]);
2681       transpose_16bit_8x8(buf0, buf1 + 0 * width + 8 * i);
2682       transpose_16bit_8x8(buf0 + 8, buf1 + 1 * width + 8 * i);
2683     }
2684 
2685     for (int i = 0; i < 2; i++) {
2686       __m128i *buf;
2687       if (lr_flip) {
2688         buf = buf0;
2689         flip_buf_sse2(buf1 + width * i, buf, width);
2690       } else {
2691         buf = buf1 + width * i;
2692       }
2693       row_txfm(buf, buf, cos_bit_row);
2694       round_shift_16bit(buf, width, shift[2]);
2695       transpose_16bit_8x8(buf, buf);
2696       store_rect_buffer_16bit_to_32bit_w8(buf, output + 8 * width * i, width,
2697                                           8);
2698       transpose_16bit_8x8(buf + 8, buf + 8);
2699       store_rect_buffer_16bit_to_32bit_w8(buf + 8, output + 8 * width * i + 8,
2700                                           width, 8);
2701       transpose_16bit_8x8(buf + 16, buf + 16);
2702       store_rect_buffer_16bit_to_32bit_w8(buf + 16, output + 8 * width * i + 16,
2703                                           width, 8);
2704       transpose_16bit_8x8(buf + 24, buf + 24);
2705       store_rect_buffer_16bit_to_32bit_w8(buf + 24, output + 8 * width * i + 24,
2706                                           width, 8);
2707     }
2708   } else {
2709     av1_fwd_txfm2d_32x16_c(input, output, stride, tx_type, bd);
2710   }
2711 }
2712 
av1_lowbd_fwd_txfm2d_32x32_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2713 void av1_lowbd_fwd_txfm2d_32x32_sse2(const int16_t *input, int32_t *output,
2714                                      int stride, TX_TYPE tx_type, int bd) {
2715   (void)bd;
2716   __m128i buf0[32], buf1[128];
2717   const int8_t *shift = av1_fwd_txfm_shift_ls[TX_32X32];
2718   const int txw_idx = get_txw_idx(TX_32X32);
2719   const int txh_idx = get_txh_idx(TX_32X32);
2720   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2721   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2722   const int width = 32;
2723   const int height = 32;
2724   const transform_1d_sse2 col_txfm = col_txfm8x32_arr[tx_type];
2725   const transform_1d_sse2 row_txfm = row_txfm8x32_arr[tx_type];
2726 
2727   if (col_txfm != NULL && row_txfm != NULL) {
2728     int ud_flip, lr_flip;
2729     get_flip_cfg(tx_type, &ud_flip, &lr_flip);
2730 
2731     for (int i = 0; i < 4; i++) {
2732       if (ud_flip) {
2733         load_buffer_16bit_to_16bit_flip(input + 8 * i, stride, buf0, height);
2734       } else {
2735         load_buffer_16bit_to_16bit(input + 8 * i, stride, buf0, height);
2736       }
2737       round_shift_16bit(buf0, height, shift[0]);
2738       col_txfm(buf0, buf0, cos_bit_col);
2739       round_shift_16bit(buf0, height, shift[1]);
2740       transpose_16bit_8x8(buf0 + 0 * 8, buf1 + 0 * width + 8 * i);
2741       transpose_16bit_8x8(buf0 + 1 * 8, buf1 + 1 * width + 8 * i);
2742       transpose_16bit_8x8(buf0 + 2 * 8, buf1 + 2 * width + 8 * i);
2743       transpose_16bit_8x8(buf0 + 3 * 8, buf1 + 3 * width + 8 * i);
2744     }
2745 
2746     for (int i = 0; i < 4; i++) {
2747       __m128i *buf;
2748       if (lr_flip) {
2749         buf = buf0;
2750         flip_buf_sse2(buf1 + width * i, buf, width);
2751       } else {
2752         buf = buf1 + width * i;
2753       }
2754       row_txfm(buf, buf, cos_bit_row);
2755       round_shift_16bit(buf, width, shift[2]);
2756       transpose_16bit_8x8(buf, buf);
2757       store_buffer_16bit_to_32bit_w8(buf, output + 8 * width * i, width, 8);
2758       transpose_16bit_8x8(buf + 8, buf + 8);
2759       store_buffer_16bit_to_32bit_w8(buf + 8, output + 8 * width * i + 8, width,
2760                                      8);
2761       transpose_16bit_8x8(buf + 16, buf + 16);
2762       store_buffer_16bit_to_32bit_w8(buf + 16, output + 8 * width * i + 16,
2763                                      width, 8);
2764       transpose_16bit_8x8(buf + 24, buf + 24);
2765       store_buffer_16bit_to_32bit_w8(buf + 24, output + 8 * width * i + 24,
2766                                      width, 8);
2767     }
2768   } else {
2769     av1_fwd_txfm2d_32x32_c(input, output, stride, tx_type, bd);
2770   }
2771 }
2772 
av1_lowbd_fwd_txfm2d_64x16_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2773 void av1_lowbd_fwd_txfm2d_64x16_sse2(const int16_t *input, int32_t *output,
2774                                      int stride, TX_TYPE tx_type, int bd) {
2775   (void)bd;
2776   (void)tx_type;
2777   assert(tx_type == DCT_DCT);
2778   const TX_SIZE tx_size = TX_64X16;
2779   __m128i buf0[64], buf1[128];
2780   const int8_t *shift = av1_fwd_txfm_shift_ls[tx_size];
2781   const int txw_idx = get_txw_idx(tx_size);
2782   const int txh_idx = get_txh_idx(tx_size);
2783   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2784   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2785   const int width = tx_size_wide[tx_size];
2786   const int height = tx_size_high[tx_size];
2787   const transform_1d_sse2 col_txfm = fdct8x16_new_sse2;
2788   const transform_1d_sse2 row_txfm = av1_fdct8x64_new_sse2;
2789   const int width_div8 = (width >> 3);
2790   const int height_div8 = (height >> 3);
2791 
2792   for (int i = 0; i < width_div8; i++) {
2793     load_buffer_16bit_to_16bit(input + 8 * i, stride, buf0, height);
2794     round_shift_16bit(buf0, height, shift[0]);
2795     col_txfm(buf0, buf0, cos_bit_col);
2796     round_shift_16bit(buf0, height, shift[1]);
2797     for (int j = 0; j < height_div8; ++j) {
2798       transpose_16bit_8x8(buf0 + j * 8, buf1 + j * width + 8 * i);
2799     }
2800   }
2801 
2802   for (int i = 0; i < height_div8; i++) {
2803     __m128i *buf = buf1 + width * i;
2804     row_txfm(buf, buf, cos_bit_row);
2805     round_shift_16bit(buf, width, shift[2]);
2806     int32_t *output8 = output + 8 * 32 * i;
2807     for (int j = 0; j < 4; ++j) {
2808       __m128i *buf8 = buf + 8 * j;
2809       transpose_16bit_8x8(buf8, buf8);
2810       store_buffer_16bit_to_32bit_w8(buf8, output8 + 8 * j, 32, 8);
2811     }
2812   }
2813 }
2814 
av1_lowbd_fwd_txfm2d_16x64_sse2(const int16_t * input,int32_t * output,int stride,TX_TYPE tx_type,int bd)2815 void av1_lowbd_fwd_txfm2d_16x64_sse2(const int16_t *input, int32_t *output,
2816                                      int stride, TX_TYPE tx_type, int bd) {
2817   (void)bd;
2818   (void)tx_type;
2819   assert(tx_type == DCT_DCT);
2820   const TX_SIZE tx_size = TX_16X64;
2821   __m128i buf0[64], buf1[128];
2822   const int8_t *shift = av1_fwd_txfm_shift_ls[tx_size];
2823   const int txw_idx = get_txw_idx(tx_size);
2824   const int txh_idx = get_txh_idx(tx_size);
2825   const int cos_bit_col = av1_fwd_cos_bit_col[txw_idx][txh_idx];
2826   const int cos_bit_row = av1_fwd_cos_bit_row[txw_idx][txh_idx];
2827   const int width = tx_size_wide[tx_size];
2828   const int height = tx_size_high[tx_size];
2829   const transform_1d_sse2 col_txfm = av1_fdct8x64_new_sse2;
2830   const transform_1d_sse2 row_txfm = fdct8x16_new_sse2;
2831   const int width_div8 = (width >> 3);
2832   const int height_div8 = (height >> 3);
2833 
2834   for (int i = 0; i < width_div8; i++) {
2835     load_buffer_16bit_to_16bit(input + 8 * i, stride, buf0, height);
2836     round_shift_16bit(buf0, height, shift[0]);
2837     col_txfm(buf0, buf0, cos_bit_col);
2838     round_shift_16bit(buf0, height, shift[1]);
2839     for (int j = 0; j < height_div8; ++j) {
2840       transpose_16bit_8x8(buf0 + j * 8, buf1 + j * width + 8 * i);
2841     }
2842   }
2843 
2844   for (int i = 0; i < AOMMIN(4, height_div8); i++) {
2845     __m128i *buf = buf1 + width * i;
2846     row_txfm(buf, buf, cos_bit_row);
2847     round_shift_16bit(buf, width, shift[2]);
2848     int32_t *output8 = output + 8 * width * i;
2849     for (int j = 0; j < width_div8; ++j) {
2850       __m128i *buf8 = buf + 8 * j;
2851       transpose_16bit_8x8(buf8, buf8);
2852       store_buffer_16bit_to_32bit_w8(buf8, output8 + 8 * j, width, 8);
2853     }
2854   }
2855   // Zero out the bottom 16x32 area.
2856   memset(output + 16 * 32, 0, 16 * 32 * sizeof(*output));
2857 }
2858 
2859 static FwdTxfm2dFunc fwd_txfm2d_func_ls[TX_SIZES_ALL] = {
2860   av1_lowbd_fwd_txfm2d_4x4_sse2,    // 4x4 transform
2861   av1_lowbd_fwd_txfm2d_8x8_sse2,    // 8x8 transform
2862   av1_lowbd_fwd_txfm2d_16x16_sse2,  // 16x16 transform
2863   av1_lowbd_fwd_txfm2d_32x32_sse2,  // 32x32 transform
2864   NULL,                             // 64x64 transform
2865   av1_lowbd_fwd_txfm2d_4x8_sse2,    // 4x8 transform
2866   av1_lowbd_fwd_txfm2d_8x4_sse2,    // 8x4 transform
2867   av1_lowbd_fwd_txfm2d_8x16_sse2,   // 8x16 transform
2868   av1_lowbd_fwd_txfm2d_16x8_sse2,   // 16x8 transform
2869   av1_lowbd_fwd_txfm2d_16x32_sse2,  // 16x32 transform
2870   av1_lowbd_fwd_txfm2d_32x16_sse2,  // 32x16 transform
2871   NULL,                             // 32x64 transform
2872   NULL,                             // 64x32 transform
2873   av1_lowbd_fwd_txfm2d_4x16_sse2,   // 4x16 transform
2874   av1_lowbd_fwd_txfm2d_16x4_sse2,   // 16x4 transform
2875   av1_lowbd_fwd_txfm2d_8x32_sse2,   // 8x32 transform
2876   av1_lowbd_fwd_txfm2d_32x8_sse2,   // 32x8 transform
2877   av1_lowbd_fwd_txfm2d_16x64_sse2,  // 16x64 transform
2878   av1_lowbd_fwd_txfm2d_64x16_sse2,  // 64x16 transform
2879 };
2880 
av1_lowbd_fwd_txfm_sse2(const int16_t * src_diff,tran_low_t * coeff,int diff_stride,TxfmParam * txfm_param)2881 void av1_lowbd_fwd_txfm_sse2(const int16_t *src_diff, tran_low_t *coeff,
2882                              int diff_stride, TxfmParam *txfm_param) {
2883   FwdTxfm2dFunc fwd_txfm2d_func = fwd_txfm2d_func_ls[txfm_param->tx_size];
2884 
2885   if ((fwd_txfm2d_func == NULL) ||
2886       (txfm_param->lossless && txfm_param->tx_size == TX_4X4))
2887     av1_lowbd_fwd_txfm_c(src_diff, coeff, diff_stride, txfm_param);
2888   else
2889     fwd_txfm2d_func(src_diff, coeff, diff_stride, txfm_param->tx_type,
2890                     txfm_param->bd);
2891 }
2892