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