1 /*
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <emmintrin.h> // SSE2
12 #include "vp9/common/vp9_idct.h" // for cospi constants
13 #include "vpx_ports/mem.h"
14
15 #define pair_set_epi32(a, b) \
16 _mm_set_epi32(b, a, b, a)
17
18 #if FDCT32x32_HIGH_PRECISION
k_madd_epi32(__m128i a,__m128i b)19 static INLINE __m128i k_madd_epi32(__m128i a, __m128i b) {
20 __m128i buf0, buf1;
21 buf0 = _mm_mul_epu32(a, b);
22 a = _mm_srli_epi64(a, 32);
23 b = _mm_srli_epi64(b, 32);
24 buf1 = _mm_mul_epu32(a, b);
25 return _mm_add_epi64(buf0, buf1);
26 }
27
k_packs_epi64(__m128i a,__m128i b)28 static INLINE __m128i k_packs_epi64(__m128i a, __m128i b) {
29 __m128i buf0 = _mm_shuffle_epi32(a, _MM_SHUFFLE(0, 0, 2, 0));
30 __m128i buf1 = _mm_shuffle_epi32(b, _MM_SHUFFLE(0, 0, 2, 0));
31 return _mm_unpacklo_epi64(buf0, buf1);
32 }
33 #endif
34
FDCT32x32_2D(const int16_t * input,int16_t * output_org,int stride)35 void FDCT32x32_2D(const int16_t *input,
36 int16_t *output_org, int stride) {
37 // Calculate pre-multiplied strides
38 const int str1 = stride;
39 const int str2 = 2 * stride;
40 const int str3 = 2 * stride + str1;
41 // We need an intermediate buffer between passes.
42 DECLARE_ALIGNED(16, int16_t, intermediate[32 * 32]);
43 // Constants
44 // When we use them, in one case, they are all the same. In all others
45 // it's a pair of them that we need to repeat four times. This is done
46 // by constructing the 32 bit constant corresponding to that pair.
47 const __m128i k__cospi_p16_p16 = _mm_set1_epi16(+cospi_16_64);
48 const __m128i k__cospi_p16_m16 = pair_set_epi16(+cospi_16_64, -cospi_16_64);
49 const __m128i k__cospi_m08_p24 = pair_set_epi16(-cospi_8_64, cospi_24_64);
50 const __m128i k__cospi_m24_m08 = pair_set_epi16(-cospi_24_64, -cospi_8_64);
51 const __m128i k__cospi_p24_p08 = pair_set_epi16(+cospi_24_64, cospi_8_64);
52 const __m128i k__cospi_p12_p20 = pair_set_epi16(+cospi_12_64, cospi_20_64);
53 const __m128i k__cospi_m20_p12 = pair_set_epi16(-cospi_20_64, cospi_12_64);
54 const __m128i k__cospi_m04_p28 = pair_set_epi16(-cospi_4_64, cospi_28_64);
55 const __m128i k__cospi_p28_p04 = pair_set_epi16(+cospi_28_64, cospi_4_64);
56 const __m128i k__cospi_m28_m04 = pair_set_epi16(-cospi_28_64, -cospi_4_64);
57 const __m128i k__cospi_m12_m20 = pair_set_epi16(-cospi_12_64, -cospi_20_64);
58 const __m128i k__cospi_p30_p02 = pair_set_epi16(+cospi_30_64, cospi_2_64);
59 const __m128i k__cospi_p14_p18 = pair_set_epi16(+cospi_14_64, cospi_18_64);
60 const __m128i k__cospi_p22_p10 = pair_set_epi16(+cospi_22_64, cospi_10_64);
61 const __m128i k__cospi_p06_p26 = pair_set_epi16(+cospi_6_64, cospi_26_64);
62 const __m128i k__cospi_m26_p06 = pair_set_epi16(-cospi_26_64, cospi_6_64);
63 const __m128i k__cospi_m10_p22 = pair_set_epi16(-cospi_10_64, cospi_22_64);
64 const __m128i k__cospi_m18_p14 = pair_set_epi16(-cospi_18_64, cospi_14_64);
65 const __m128i k__cospi_m02_p30 = pair_set_epi16(-cospi_2_64, cospi_30_64);
66 const __m128i k__cospi_p31_p01 = pair_set_epi16(+cospi_31_64, cospi_1_64);
67 const __m128i k__cospi_p15_p17 = pair_set_epi16(+cospi_15_64, cospi_17_64);
68 const __m128i k__cospi_p23_p09 = pair_set_epi16(+cospi_23_64, cospi_9_64);
69 const __m128i k__cospi_p07_p25 = pair_set_epi16(+cospi_7_64, cospi_25_64);
70 const __m128i k__cospi_m25_p07 = pair_set_epi16(-cospi_25_64, cospi_7_64);
71 const __m128i k__cospi_m09_p23 = pair_set_epi16(-cospi_9_64, cospi_23_64);
72 const __m128i k__cospi_m17_p15 = pair_set_epi16(-cospi_17_64, cospi_15_64);
73 const __m128i k__cospi_m01_p31 = pair_set_epi16(-cospi_1_64, cospi_31_64);
74 const __m128i k__cospi_p27_p05 = pair_set_epi16(+cospi_27_64, cospi_5_64);
75 const __m128i k__cospi_p11_p21 = pair_set_epi16(+cospi_11_64, cospi_21_64);
76 const __m128i k__cospi_p19_p13 = pair_set_epi16(+cospi_19_64, cospi_13_64);
77 const __m128i k__cospi_p03_p29 = pair_set_epi16(+cospi_3_64, cospi_29_64);
78 const __m128i k__cospi_m29_p03 = pair_set_epi16(-cospi_29_64, cospi_3_64);
79 const __m128i k__cospi_m13_p19 = pair_set_epi16(-cospi_13_64, cospi_19_64);
80 const __m128i k__cospi_m21_p11 = pair_set_epi16(-cospi_21_64, cospi_11_64);
81 const __m128i k__cospi_m05_p27 = pair_set_epi16(-cospi_5_64, cospi_27_64);
82 const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
83 const __m128i kZero = _mm_set1_epi16(0);
84 const __m128i kOne = _mm_set1_epi16(1);
85 // Do the two transform/transpose passes
86 int pass;
87 for (pass = 0; pass < 2; ++pass) {
88 // We process eight columns (transposed rows in second pass) at a time.
89 int column_start;
90 for (column_start = 0; column_start < 32; column_start += 8) {
91 __m128i step1[32];
92 __m128i step2[32];
93 __m128i step3[32];
94 __m128i out[32];
95 // Stage 1
96 // Note: even though all the loads below are aligned, using the aligned
97 // intrinsic make the code slightly slower.
98 if (0 == pass) {
99 const int16_t *in = &input[column_start];
100 // step1[i] = (in[ 0 * stride] + in[(32 - 1) * stride]) << 2;
101 // Note: the next four blocks could be in a loop. That would help the
102 // instruction cache but is actually slower.
103 {
104 const int16_t *ina = in + 0 * str1;
105 const int16_t *inb = in + 31 * str1;
106 __m128i *step1a = &step1[ 0];
107 __m128i *step1b = &step1[31];
108 const __m128i ina0 = _mm_loadu_si128((const __m128i *)(ina));
109 const __m128i ina1 = _mm_loadu_si128((const __m128i *)(ina + str1));
110 const __m128i ina2 = _mm_loadu_si128((const __m128i *)(ina + str2));
111 const __m128i ina3 = _mm_loadu_si128((const __m128i *)(ina + str3));
112 const __m128i inb3 = _mm_loadu_si128((const __m128i *)(inb - str3));
113 const __m128i inb2 = _mm_loadu_si128((const __m128i *)(inb - str2));
114 const __m128i inb1 = _mm_loadu_si128((const __m128i *)(inb - str1));
115 const __m128i inb0 = _mm_loadu_si128((const __m128i *)(inb));
116 step1a[ 0] = _mm_add_epi16(ina0, inb0);
117 step1a[ 1] = _mm_add_epi16(ina1, inb1);
118 step1a[ 2] = _mm_add_epi16(ina2, inb2);
119 step1a[ 3] = _mm_add_epi16(ina3, inb3);
120 step1b[-3] = _mm_sub_epi16(ina3, inb3);
121 step1b[-2] = _mm_sub_epi16(ina2, inb2);
122 step1b[-1] = _mm_sub_epi16(ina1, inb1);
123 step1b[-0] = _mm_sub_epi16(ina0, inb0);
124 step1a[ 0] = _mm_slli_epi16(step1a[ 0], 2);
125 step1a[ 1] = _mm_slli_epi16(step1a[ 1], 2);
126 step1a[ 2] = _mm_slli_epi16(step1a[ 2], 2);
127 step1a[ 3] = _mm_slli_epi16(step1a[ 3], 2);
128 step1b[-3] = _mm_slli_epi16(step1b[-3], 2);
129 step1b[-2] = _mm_slli_epi16(step1b[-2], 2);
130 step1b[-1] = _mm_slli_epi16(step1b[-1], 2);
131 step1b[-0] = _mm_slli_epi16(step1b[-0], 2);
132 }
133 {
134 const int16_t *ina = in + 4 * str1;
135 const int16_t *inb = in + 27 * str1;
136 __m128i *step1a = &step1[ 4];
137 __m128i *step1b = &step1[27];
138 const __m128i ina0 = _mm_loadu_si128((const __m128i *)(ina));
139 const __m128i ina1 = _mm_loadu_si128((const __m128i *)(ina + str1));
140 const __m128i ina2 = _mm_loadu_si128((const __m128i *)(ina + str2));
141 const __m128i ina3 = _mm_loadu_si128((const __m128i *)(ina + str3));
142 const __m128i inb3 = _mm_loadu_si128((const __m128i *)(inb - str3));
143 const __m128i inb2 = _mm_loadu_si128((const __m128i *)(inb - str2));
144 const __m128i inb1 = _mm_loadu_si128((const __m128i *)(inb - str1));
145 const __m128i inb0 = _mm_loadu_si128((const __m128i *)(inb));
146 step1a[ 0] = _mm_add_epi16(ina0, inb0);
147 step1a[ 1] = _mm_add_epi16(ina1, inb1);
148 step1a[ 2] = _mm_add_epi16(ina2, inb2);
149 step1a[ 3] = _mm_add_epi16(ina3, inb3);
150 step1b[-3] = _mm_sub_epi16(ina3, inb3);
151 step1b[-2] = _mm_sub_epi16(ina2, inb2);
152 step1b[-1] = _mm_sub_epi16(ina1, inb1);
153 step1b[-0] = _mm_sub_epi16(ina0, inb0);
154 step1a[ 0] = _mm_slli_epi16(step1a[ 0], 2);
155 step1a[ 1] = _mm_slli_epi16(step1a[ 1], 2);
156 step1a[ 2] = _mm_slli_epi16(step1a[ 2], 2);
157 step1a[ 3] = _mm_slli_epi16(step1a[ 3], 2);
158 step1b[-3] = _mm_slli_epi16(step1b[-3], 2);
159 step1b[-2] = _mm_slli_epi16(step1b[-2], 2);
160 step1b[-1] = _mm_slli_epi16(step1b[-1], 2);
161 step1b[-0] = _mm_slli_epi16(step1b[-0], 2);
162 }
163 {
164 const int16_t *ina = in + 8 * str1;
165 const int16_t *inb = in + 23 * str1;
166 __m128i *step1a = &step1[ 8];
167 __m128i *step1b = &step1[23];
168 const __m128i ina0 = _mm_loadu_si128((const __m128i *)(ina));
169 const __m128i ina1 = _mm_loadu_si128((const __m128i *)(ina + str1));
170 const __m128i ina2 = _mm_loadu_si128((const __m128i *)(ina + str2));
171 const __m128i ina3 = _mm_loadu_si128((const __m128i *)(ina + str3));
172 const __m128i inb3 = _mm_loadu_si128((const __m128i *)(inb - str3));
173 const __m128i inb2 = _mm_loadu_si128((const __m128i *)(inb - str2));
174 const __m128i inb1 = _mm_loadu_si128((const __m128i *)(inb - str1));
175 const __m128i inb0 = _mm_loadu_si128((const __m128i *)(inb));
176 step1a[ 0] = _mm_add_epi16(ina0, inb0);
177 step1a[ 1] = _mm_add_epi16(ina1, inb1);
178 step1a[ 2] = _mm_add_epi16(ina2, inb2);
179 step1a[ 3] = _mm_add_epi16(ina3, inb3);
180 step1b[-3] = _mm_sub_epi16(ina3, inb3);
181 step1b[-2] = _mm_sub_epi16(ina2, inb2);
182 step1b[-1] = _mm_sub_epi16(ina1, inb1);
183 step1b[-0] = _mm_sub_epi16(ina0, inb0);
184 step1a[ 0] = _mm_slli_epi16(step1a[ 0], 2);
185 step1a[ 1] = _mm_slli_epi16(step1a[ 1], 2);
186 step1a[ 2] = _mm_slli_epi16(step1a[ 2], 2);
187 step1a[ 3] = _mm_slli_epi16(step1a[ 3], 2);
188 step1b[-3] = _mm_slli_epi16(step1b[-3], 2);
189 step1b[-2] = _mm_slli_epi16(step1b[-2], 2);
190 step1b[-1] = _mm_slli_epi16(step1b[-1], 2);
191 step1b[-0] = _mm_slli_epi16(step1b[-0], 2);
192 }
193 {
194 const int16_t *ina = in + 12 * str1;
195 const int16_t *inb = in + 19 * str1;
196 __m128i *step1a = &step1[12];
197 __m128i *step1b = &step1[19];
198 const __m128i ina0 = _mm_loadu_si128((const __m128i *)(ina));
199 const __m128i ina1 = _mm_loadu_si128((const __m128i *)(ina + str1));
200 const __m128i ina2 = _mm_loadu_si128((const __m128i *)(ina + str2));
201 const __m128i ina3 = _mm_loadu_si128((const __m128i *)(ina + str3));
202 const __m128i inb3 = _mm_loadu_si128((const __m128i *)(inb - str3));
203 const __m128i inb2 = _mm_loadu_si128((const __m128i *)(inb - str2));
204 const __m128i inb1 = _mm_loadu_si128((const __m128i *)(inb - str1));
205 const __m128i inb0 = _mm_loadu_si128((const __m128i *)(inb));
206 step1a[ 0] = _mm_add_epi16(ina0, inb0);
207 step1a[ 1] = _mm_add_epi16(ina1, inb1);
208 step1a[ 2] = _mm_add_epi16(ina2, inb2);
209 step1a[ 3] = _mm_add_epi16(ina3, inb3);
210 step1b[-3] = _mm_sub_epi16(ina3, inb3);
211 step1b[-2] = _mm_sub_epi16(ina2, inb2);
212 step1b[-1] = _mm_sub_epi16(ina1, inb1);
213 step1b[-0] = _mm_sub_epi16(ina0, inb0);
214 step1a[ 0] = _mm_slli_epi16(step1a[ 0], 2);
215 step1a[ 1] = _mm_slli_epi16(step1a[ 1], 2);
216 step1a[ 2] = _mm_slli_epi16(step1a[ 2], 2);
217 step1a[ 3] = _mm_slli_epi16(step1a[ 3], 2);
218 step1b[-3] = _mm_slli_epi16(step1b[-3], 2);
219 step1b[-2] = _mm_slli_epi16(step1b[-2], 2);
220 step1b[-1] = _mm_slli_epi16(step1b[-1], 2);
221 step1b[-0] = _mm_slli_epi16(step1b[-0], 2);
222 }
223 } else {
224 int16_t *in = &intermediate[column_start];
225 // step1[i] = in[ 0 * 32] + in[(32 - 1) * 32];
226 // Note: using the same approach as above to have common offset is
227 // counter-productive as all offsets can be calculated at compile
228 // time.
229 // Note: the next four blocks could be in a loop. That would help the
230 // instruction cache but is actually slower.
231 {
232 __m128i in00 = _mm_loadu_si128((const __m128i *)(in + 0 * 32));
233 __m128i in01 = _mm_loadu_si128((const __m128i *)(in + 1 * 32));
234 __m128i in02 = _mm_loadu_si128((const __m128i *)(in + 2 * 32));
235 __m128i in03 = _mm_loadu_si128((const __m128i *)(in + 3 * 32));
236 __m128i in28 = _mm_loadu_si128((const __m128i *)(in + 28 * 32));
237 __m128i in29 = _mm_loadu_si128((const __m128i *)(in + 29 * 32));
238 __m128i in30 = _mm_loadu_si128((const __m128i *)(in + 30 * 32));
239 __m128i in31 = _mm_loadu_si128((const __m128i *)(in + 31 * 32));
240 step1[ 0] = _mm_add_epi16(in00, in31);
241 step1[ 1] = _mm_add_epi16(in01, in30);
242 step1[ 2] = _mm_add_epi16(in02, in29);
243 step1[ 3] = _mm_add_epi16(in03, in28);
244 step1[28] = _mm_sub_epi16(in03, in28);
245 step1[29] = _mm_sub_epi16(in02, in29);
246 step1[30] = _mm_sub_epi16(in01, in30);
247 step1[31] = _mm_sub_epi16(in00, in31);
248 }
249 {
250 __m128i in04 = _mm_loadu_si128((const __m128i *)(in + 4 * 32));
251 __m128i in05 = _mm_loadu_si128((const __m128i *)(in + 5 * 32));
252 __m128i in06 = _mm_loadu_si128((const __m128i *)(in + 6 * 32));
253 __m128i in07 = _mm_loadu_si128((const __m128i *)(in + 7 * 32));
254 __m128i in24 = _mm_loadu_si128((const __m128i *)(in + 24 * 32));
255 __m128i in25 = _mm_loadu_si128((const __m128i *)(in + 25 * 32));
256 __m128i in26 = _mm_loadu_si128((const __m128i *)(in + 26 * 32));
257 __m128i in27 = _mm_loadu_si128((const __m128i *)(in + 27 * 32));
258 step1[ 4] = _mm_add_epi16(in04, in27);
259 step1[ 5] = _mm_add_epi16(in05, in26);
260 step1[ 6] = _mm_add_epi16(in06, in25);
261 step1[ 7] = _mm_add_epi16(in07, in24);
262 step1[24] = _mm_sub_epi16(in07, in24);
263 step1[25] = _mm_sub_epi16(in06, in25);
264 step1[26] = _mm_sub_epi16(in05, in26);
265 step1[27] = _mm_sub_epi16(in04, in27);
266 }
267 {
268 __m128i in08 = _mm_loadu_si128((const __m128i *)(in + 8 * 32));
269 __m128i in09 = _mm_loadu_si128((const __m128i *)(in + 9 * 32));
270 __m128i in10 = _mm_loadu_si128((const __m128i *)(in + 10 * 32));
271 __m128i in11 = _mm_loadu_si128((const __m128i *)(in + 11 * 32));
272 __m128i in20 = _mm_loadu_si128((const __m128i *)(in + 20 * 32));
273 __m128i in21 = _mm_loadu_si128((const __m128i *)(in + 21 * 32));
274 __m128i in22 = _mm_loadu_si128((const __m128i *)(in + 22 * 32));
275 __m128i in23 = _mm_loadu_si128((const __m128i *)(in + 23 * 32));
276 step1[ 8] = _mm_add_epi16(in08, in23);
277 step1[ 9] = _mm_add_epi16(in09, in22);
278 step1[10] = _mm_add_epi16(in10, in21);
279 step1[11] = _mm_add_epi16(in11, in20);
280 step1[20] = _mm_sub_epi16(in11, in20);
281 step1[21] = _mm_sub_epi16(in10, in21);
282 step1[22] = _mm_sub_epi16(in09, in22);
283 step1[23] = _mm_sub_epi16(in08, in23);
284 }
285 {
286 __m128i in12 = _mm_loadu_si128((const __m128i *)(in + 12 * 32));
287 __m128i in13 = _mm_loadu_si128((const __m128i *)(in + 13 * 32));
288 __m128i in14 = _mm_loadu_si128((const __m128i *)(in + 14 * 32));
289 __m128i in15 = _mm_loadu_si128((const __m128i *)(in + 15 * 32));
290 __m128i in16 = _mm_loadu_si128((const __m128i *)(in + 16 * 32));
291 __m128i in17 = _mm_loadu_si128((const __m128i *)(in + 17 * 32));
292 __m128i in18 = _mm_loadu_si128((const __m128i *)(in + 18 * 32));
293 __m128i in19 = _mm_loadu_si128((const __m128i *)(in + 19 * 32));
294 step1[12] = _mm_add_epi16(in12, in19);
295 step1[13] = _mm_add_epi16(in13, in18);
296 step1[14] = _mm_add_epi16(in14, in17);
297 step1[15] = _mm_add_epi16(in15, in16);
298 step1[16] = _mm_sub_epi16(in15, in16);
299 step1[17] = _mm_sub_epi16(in14, in17);
300 step1[18] = _mm_sub_epi16(in13, in18);
301 step1[19] = _mm_sub_epi16(in12, in19);
302 }
303 }
304 // Stage 2
305 {
306 step2[ 0] = _mm_add_epi16(step1[0], step1[15]);
307 step2[ 1] = _mm_add_epi16(step1[1], step1[14]);
308 step2[ 2] = _mm_add_epi16(step1[2], step1[13]);
309 step2[ 3] = _mm_add_epi16(step1[3], step1[12]);
310 step2[ 4] = _mm_add_epi16(step1[4], step1[11]);
311 step2[ 5] = _mm_add_epi16(step1[5], step1[10]);
312 step2[ 6] = _mm_add_epi16(step1[6], step1[ 9]);
313 step2[ 7] = _mm_add_epi16(step1[7], step1[ 8]);
314 step2[ 8] = _mm_sub_epi16(step1[7], step1[ 8]);
315 step2[ 9] = _mm_sub_epi16(step1[6], step1[ 9]);
316 step2[10] = _mm_sub_epi16(step1[5], step1[10]);
317 step2[11] = _mm_sub_epi16(step1[4], step1[11]);
318 step2[12] = _mm_sub_epi16(step1[3], step1[12]);
319 step2[13] = _mm_sub_epi16(step1[2], step1[13]);
320 step2[14] = _mm_sub_epi16(step1[1], step1[14]);
321 step2[15] = _mm_sub_epi16(step1[0], step1[15]);
322 }
323 {
324 const __m128i s2_20_0 = _mm_unpacklo_epi16(step1[27], step1[20]);
325 const __m128i s2_20_1 = _mm_unpackhi_epi16(step1[27], step1[20]);
326 const __m128i s2_21_0 = _mm_unpacklo_epi16(step1[26], step1[21]);
327 const __m128i s2_21_1 = _mm_unpackhi_epi16(step1[26], step1[21]);
328 const __m128i s2_22_0 = _mm_unpacklo_epi16(step1[25], step1[22]);
329 const __m128i s2_22_1 = _mm_unpackhi_epi16(step1[25], step1[22]);
330 const __m128i s2_23_0 = _mm_unpacklo_epi16(step1[24], step1[23]);
331 const __m128i s2_23_1 = _mm_unpackhi_epi16(step1[24], step1[23]);
332 const __m128i s2_20_2 = _mm_madd_epi16(s2_20_0, k__cospi_p16_m16);
333 const __m128i s2_20_3 = _mm_madd_epi16(s2_20_1, k__cospi_p16_m16);
334 const __m128i s2_21_2 = _mm_madd_epi16(s2_21_0, k__cospi_p16_m16);
335 const __m128i s2_21_3 = _mm_madd_epi16(s2_21_1, k__cospi_p16_m16);
336 const __m128i s2_22_2 = _mm_madd_epi16(s2_22_0, k__cospi_p16_m16);
337 const __m128i s2_22_3 = _mm_madd_epi16(s2_22_1, k__cospi_p16_m16);
338 const __m128i s2_23_2 = _mm_madd_epi16(s2_23_0, k__cospi_p16_m16);
339 const __m128i s2_23_3 = _mm_madd_epi16(s2_23_1, k__cospi_p16_m16);
340 const __m128i s2_24_2 = _mm_madd_epi16(s2_23_0, k__cospi_p16_p16);
341 const __m128i s2_24_3 = _mm_madd_epi16(s2_23_1, k__cospi_p16_p16);
342 const __m128i s2_25_2 = _mm_madd_epi16(s2_22_0, k__cospi_p16_p16);
343 const __m128i s2_25_3 = _mm_madd_epi16(s2_22_1, k__cospi_p16_p16);
344 const __m128i s2_26_2 = _mm_madd_epi16(s2_21_0, k__cospi_p16_p16);
345 const __m128i s2_26_3 = _mm_madd_epi16(s2_21_1, k__cospi_p16_p16);
346 const __m128i s2_27_2 = _mm_madd_epi16(s2_20_0, k__cospi_p16_p16);
347 const __m128i s2_27_3 = _mm_madd_epi16(s2_20_1, k__cospi_p16_p16);
348 // dct_const_round_shift
349 const __m128i s2_20_4 = _mm_add_epi32(s2_20_2, k__DCT_CONST_ROUNDING);
350 const __m128i s2_20_5 = _mm_add_epi32(s2_20_3, k__DCT_CONST_ROUNDING);
351 const __m128i s2_21_4 = _mm_add_epi32(s2_21_2, k__DCT_CONST_ROUNDING);
352 const __m128i s2_21_5 = _mm_add_epi32(s2_21_3, k__DCT_CONST_ROUNDING);
353 const __m128i s2_22_4 = _mm_add_epi32(s2_22_2, k__DCT_CONST_ROUNDING);
354 const __m128i s2_22_5 = _mm_add_epi32(s2_22_3, k__DCT_CONST_ROUNDING);
355 const __m128i s2_23_4 = _mm_add_epi32(s2_23_2, k__DCT_CONST_ROUNDING);
356 const __m128i s2_23_5 = _mm_add_epi32(s2_23_3, k__DCT_CONST_ROUNDING);
357 const __m128i s2_24_4 = _mm_add_epi32(s2_24_2, k__DCT_CONST_ROUNDING);
358 const __m128i s2_24_5 = _mm_add_epi32(s2_24_3, k__DCT_CONST_ROUNDING);
359 const __m128i s2_25_4 = _mm_add_epi32(s2_25_2, k__DCT_CONST_ROUNDING);
360 const __m128i s2_25_5 = _mm_add_epi32(s2_25_3, k__DCT_CONST_ROUNDING);
361 const __m128i s2_26_4 = _mm_add_epi32(s2_26_2, k__DCT_CONST_ROUNDING);
362 const __m128i s2_26_5 = _mm_add_epi32(s2_26_3, k__DCT_CONST_ROUNDING);
363 const __m128i s2_27_4 = _mm_add_epi32(s2_27_2, k__DCT_CONST_ROUNDING);
364 const __m128i s2_27_5 = _mm_add_epi32(s2_27_3, k__DCT_CONST_ROUNDING);
365 const __m128i s2_20_6 = _mm_srai_epi32(s2_20_4, DCT_CONST_BITS);
366 const __m128i s2_20_7 = _mm_srai_epi32(s2_20_5, DCT_CONST_BITS);
367 const __m128i s2_21_6 = _mm_srai_epi32(s2_21_4, DCT_CONST_BITS);
368 const __m128i s2_21_7 = _mm_srai_epi32(s2_21_5, DCT_CONST_BITS);
369 const __m128i s2_22_6 = _mm_srai_epi32(s2_22_4, DCT_CONST_BITS);
370 const __m128i s2_22_7 = _mm_srai_epi32(s2_22_5, DCT_CONST_BITS);
371 const __m128i s2_23_6 = _mm_srai_epi32(s2_23_4, DCT_CONST_BITS);
372 const __m128i s2_23_7 = _mm_srai_epi32(s2_23_5, DCT_CONST_BITS);
373 const __m128i s2_24_6 = _mm_srai_epi32(s2_24_4, DCT_CONST_BITS);
374 const __m128i s2_24_7 = _mm_srai_epi32(s2_24_5, DCT_CONST_BITS);
375 const __m128i s2_25_6 = _mm_srai_epi32(s2_25_4, DCT_CONST_BITS);
376 const __m128i s2_25_7 = _mm_srai_epi32(s2_25_5, DCT_CONST_BITS);
377 const __m128i s2_26_6 = _mm_srai_epi32(s2_26_4, DCT_CONST_BITS);
378 const __m128i s2_26_7 = _mm_srai_epi32(s2_26_5, DCT_CONST_BITS);
379 const __m128i s2_27_6 = _mm_srai_epi32(s2_27_4, DCT_CONST_BITS);
380 const __m128i s2_27_7 = _mm_srai_epi32(s2_27_5, DCT_CONST_BITS);
381 // Combine
382 step2[20] = _mm_packs_epi32(s2_20_6, s2_20_7);
383 step2[21] = _mm_packs_epi32(s2_21_6, s2_21_7);
384 step2[22] = _mm_packs_epi32(s2_22_6, s2_22_7);
385 step2[23] = _mm_packs_epi32(s2_23_6, s2_23_7);
386 step2[24] = _mm_packs_epi32(s2_24_6, s2_24_7);
387 step2[25] = _mm_packs_epi32(s2_25_6, s2_25_7);
388 step2[26] = _mm_packs_epi32(s2_26_6, s2_26_7);
389 step2[27] = _mm_packs_epi32(s2_27_6, s2_27_7);
390 }
391
392 #if !FDCT32x32_HIGH_PRECISION
393 // dump the magnitude by half, hence the intermediate values are within
394 // the range of 16 bits.
395 if (1 == pass) {
396 __m128i s3_00_0 = _mm_cmplt_epi16(step2[ 0], kZero);
397 __m128i s3_01_0 = _mm_cmplt_epi16(step2[ 1], kZero);
398 __m128i s3_02_0 = _mm_cmplt_epi16(step2[ 2], kZero);
399 __m128i s3_03_0 = _mm_cmplt_epi16(step2[ 3], kZero);
400 __m128i s3_04_0 = _mm_cmplt_epi16(step2[ 4], kZero);
401 __m128i s3_05_0 = _mm_cmplt_epi16(step2[ 5], kZero);
402 __m128i s3_06_0 = _mm_cmplt_epi16(step2[ 6], kZero);
403 __m128i s3_07_0 = _mm_cmplt_epi16(step2[ 7], kZero);
404 __m128i s2_08_0 = _mm_cmplt_epi16(step2[ 8], kZero);
405 __m128i s2_09_0 = _mm_cmplt_epi16(step2[ 9], kZero);
406 __m128i s3_10_0 = _mm_cmplt_epi16(step2[10], kZero);
407 __m128i s3_11_0 = _mm_cmplt_epi16(step2[11], kZero);
408 __m128i s3_12_0 = _mm_cmplt_epi16(step2[12], kZero);
409 __m128i s3_13_0 = _mm_cmplt_epi16(step2[13], kZero);
410 __m128i s2_14_0 = _mm_cmplt_epi16(step2[14], kZero);
411 __m128i s2_15_0 = _mm_cmplt_epi16(step2[15], kZero);
412 __m128i s3_16_0 = _mm_cmplt_epi16(step1[16], kZero);
413 __m128i s3_17_0 = _mm_cmplt_epi16(step1[17], kZero);
414 __m128i s3_18_0 = _mm_cmplt_epi16(step1[18], kZero);
415 __m128i s3_19_0 = _mm_cmplt_epi16(step1[19], kZero);
416 __m128i s3_20_0 = _mm_cmplt_epi16(step2[20], kZero);
417 __m128i s3_21_0 = _mm_cmplt_epi16(step2[21], kZero);
418 __m128i s3_22_0 = _mm_cmplt_epi16(step2[22], kZero);
419 __m128i s3_23_0 = _mm_cmplt_epi16(step2[23], kZero);
420 __m128i s3_24_0 = _mm_cmplt_epi16(step2[24], kZero);
421 __m128i s3_25_0 = _mm_cmplt_epi16(step2[25], kZero);
422 __m128i s3_26_0 = _mm_cmplt_epi16(step2[26], kZero);
423 __m128i s3_27_0 = _mm_cmplt_epi16(step2[27], kZero);
424 __m128i s3_28_0 = _mm_cmplt_epi16(step1[28], kZero);
425 __m128i s3_29_0 = _mm_cmplt_epi16(step1[29], kZero);
426 __m128i s3_30_0 = _mm_cmplt_epi16(step1[30], kZero);
427 __m128i s3_31_0 = _mm_cmplt_epi16(step1[31], kZero);
428
429 step2[ 0] = _mm_sub_epi16(step2[ 0], s3_00_0);
430 step2[ 1] = _mm_sub_epi16(step2[ 1], s3_01_0);
431 step2[ 2] = _mm_sub_epi16(step2[ 2], s3_02_0);
432 step2[ 3] = _mm_sub_epi16(step2[ 3], s3_03_0);
433 step2[ 4] = _mm_sub_epi16(step2[ 4], s3_04_0);
434 step2[ 5] = _mm_sub_epi16(step2[ 5], s3_05_0);
435 step2[ 6] = _mm_sub_epi16(step2[ 6], s3_06_0);
436 step2[ 7] = _mm_sub_epi16(step2[ 7], s3_07_0);
437 step2[ 8] = _mm_sub_epi16(step2[ 8], s2_08_0);
438 step2[ 9] = _mm_sub_epi16(step2[ 9], s2_09_0);
439 step2[10] = _mm_sub_epi16(step2[10], s3_10_0);
440 step2[11] = _mm_sub_epi16(step2[11], s3_11_0);
441 step2[12] = _mm_sub_epi16(step2[12], s3_12_0);
442 step2[13] = _mm_sub_epi16(step2[13], s3_13_0);
443 step2[14] = _mm_sub_epi16(step2[14], s2_14_0);
444 step2[15] = _mm_sub_epi16(step2[15], s2_15_0);
445 step1[16] = _mm_sub_epi16(step1[16], s3_16_0);
446 step1[17] = _mm_sub_epi16(step1[17], s3_17_0);
447 step1[18] = _mm_sub_epi16(step1[18], s3_18_0);
448 step1[19] = _mm_sub_epi16(step1[19], s3_19_0);
449 step2[20] = _mm_sub_epi16(step2[20], s3_20_0);
450 step2[21] = _mm_sub_epi16(step2[21], s3_21_0);
451 step2[22] = _mm_sub_epi16(step2[22], s3_22_0);
452 step2[23] = _mm_sub_epi16(step2[23], s3_23_0);
453 step2[24] = _mm_sub_epi16(step2[24], s3_24_0);
454 step2[25] = _mm_sub_epi16(step2[25], s3_25_0);
455 step2[26] = _mm_sub_epi16(step2[26], s3_26_0);
456 step2[27] = _mm_sub_epi16(step2[27], s3_27_0);
457 step1[28] = _mm_sub_epi16(step1[28], s3_28_0);
458 step1[29] = _mm_sub_epi16(step1[29], s3_29_0);
459 step1[30] = _mm_sub_epi16(step1[30], s3_30_0);
460 step1[31] = _mm_sub_epi16(step1[31], s3_31_0);
461
462 step2[ 0] = _mm_add_epi16(step2[ 0], kOne);
463 step2[ 1] = _mm_add_epi16(step2[ 1], kOne);
464 step2[ 2] = _mm_add_epi16(step2[ 2], kOne);
465 step2[ 3] = _mm_add_epi16(step2[ 3], kOne);
466 step2[ 4] = _mm_add_epi16(step2[ 4], kOne);
467 step2[ 5] = _mm_add_epi16(step2[ 5], kOne);
468 step2[ 6] = _mm_add_epi16(step2[ 6], kOne);
469 step2[ 7] = _mm_add_epi16(step2[ 7], kOne);
470 step2[ 8] = _mm_add_epi16(step2[ 8], kOne);
471 step2[ 9] = _mm_add_epi16(step2[ 9], kOne);
472 step2[10] = _mm_add_epi16(step2[10], kOne);
473 step2[11] = _mm_add_epi16(step2[11], kOne);
474 step2[12] = _mm_add_epi16(step2[12], kOne);
475 step2[13] = _mm_add_epi16(step2[13], kOne);
476 step2[14] = _mm_add_epi16(step2[14], kOne);
477 step2[15] = _mm_add_epi16(step2[15], kOne);
478 step1[16] = _mm_add_epi16(step1[16], kOne);
479 step1[17] = _mm_add_epi16(step1[17], kOne);
480 step1[18] = _mm_add_epi16(step1[18], kOne);
481 step1[19] = _mm_add_epi16(step1[19], kOne);
482 step2[20] = _mm_add_epi16(step2[20], kOne);
483 step2[21] = _mm_add_epi16(step2[21], kOne);
484 step2[22] = _mm_add_epi16(step2[22], kOne);
485 step2[23] = _mm_add_epi16(step2[23], kOne);
486 step2[24] = _mm_add_epi16(step2[24], kOne);
487 step2[25] = _mm_add_epi16(step2[25], kOne);
488 step2[26] = _mm_add_epi16(step2[26], kOne);
489 step2[27] = _mm_add_epi16(step2[27], kOne);
490 step1[28] = _mm_add_epi16(step1[28], kOne);
491 step1[29] = _mm_add_epi16(step1[29], kOne);
492 step1[30] = _mm_add_epi16(step1[30], kOne);
493 step1[31] = _mm_add_epi16(step1[31], kOne);
494
495 step2[ 0] = _mm_srai_epi16(step2[ 0], 2);
496 step2[ 1] = _mm_srai_epi16(step2[ 1], 2);
497 step2[ 2] = _mm_srai_epi16(step2[ 2], 2);
498 step2[ 3] = _mm_srai_epi16(step2[ 3], 2);
499 step2[ 4] = _mm_srai_epi16(step2[ 4], 2);
500 step2[ 5] = _mm_srai_epi16(step2[ 5], 2);
501 step2[ 6] = _mm_srai_epi16(step2[ 6], 2);
502 step2[ 7] = _mm_srai_epi16(step2[ 7], 2);
503 step2[ 8] = _mm_srai_epi16(step2[ 8], 2);
504 step2[ 9] = _mm_srai_epi16(step2[ 9], 2);
505 step2[10] = _mm_srai_epi16(step2[10], 2);
506 step2[11] = _mm_srai_epi16(step2[11], 2);
507 step2[12] = _mm_srai_epi16(step2[12], 2);
508 step2[13] = _mm_srai_epi16(step2[13], 2);
509 step2[14] = _mm_srai_epi16(step2[14], 2);
510 step2[15] = _mm_srai_epi16(step2[15], 2);
511 step1[16] = _mm_srai_epi16(step1[16], 2);
512 step1[17] = _mm_srai_epi16(step1[17], 2);
513 step1[18] = _mm_srai_epi16(step1[18], 2);
514 step1[19] = _mm_srai_epi16(step1[19], 2);
515 step2[20] = _mm_srai_epi16(step2[20], 2);
516 step2[21] = _mm_srai_epi16(step2[21], 2);
517 step2[22] = _mm_srai_epi16(step2[22], 2);
518 step2[23] = _mm_srai_epi16(step2[23], 2);
519 step2[24] = _mm_srai_epi16(step2[24], 2);
520 step2[25] = _mm_srai_epi16(step2[25], 2);
521 step2[26] = _mm_srai_epi16(step2[26], 2);
522 step2[27] = _mm_srai_epi16(step2[27], 2);
523 step1[28] = _mm_srai_epi16(step1[28], 2);
524 step1[29] = _mm_srai_epi16(step1[29], 2);
525 step1[30] = _mm_srai_epi16(step1[30], 2);
526 step1[31] = _mm_srai_epi16(step1[31], 2);
527 }
528 #endif
529
530 #if FDCT32x32_HIGH_PRECISION
531 if (pass == 0) {
532 #endif
533 // Stage 3
534 {
535 step3[0] = _mm_add_epi16(step2[(8 - 1)], step2[0]);
536 step3[1] = _mm_add_epi16(step2[(8 - 2)], step2[1]);
537 step3[2] = _mm_add_epi16(step2[(8 - 3)], step2[2]);
538 step3[3] = _mm_add_epi16(step2[(8 - 4)], step2[3]);
539 step3[4] = _mm_sub_epi16(step2[(8 - 5)], step2[4]);
540 step3[5] = _mm_sub_epi16(step2[(8 - 6)], step2[5]);
541 step3[6] = _mm_sub_epi16(step2[(8 - 7)], step2[6]);
542 step3[7] = _mm_sub_epi16(step2[(8 - 8)], step2[7]);
543 }
544 {
545 const __m128i s3_10_0 = _mm_unpacklo_epi16(step2[13], step2[10]);
546 const __m128i s3_10_1 = _mm_unpackhi_epi16(step2[13], step2[10]);
547 const __m128i s3_11_0 = _mm_unpacklo_epi16(step2[12], step2[11]);
548 const __m128i s3_11_1 = _mm_unpackhi_epi16(step2[12], step2[11]);
549 const __m128i s3_10_2 = _mm_madd_epi16(s3_10_0, k__cospi_p16_m16);
550 const __m128i s3_10_3 = _mm_madd_epi16(s3_10_1, k__cospi_p16_m16);
551 const __m128i s3_11_2 = _mm_madd_epi16(s3_11_0, k__cospi_p16_m16);
552 const __m128i s3_11_3 = _mm_madd_epi16(s3_11_1, k__cospi_p16_m16);
553 const __m128i s3_12_2 = _mm_madd_epi16(s3_11_0, k__cospi_p16_p16);
554 const __m128i s3_12_3 = _mm_madd_epi16(s3_11_1, k__cospi_p16_p16);
555 const __m128i s3_13_2 = _mm_madd_epi16(s3_10_0, k__cospi_p16_p16);
556 const __m128i s3_13_3 = _mm_madd_epi16(s3_10_1, k__cospi_p16_p16);
557 // dct_const_round_shift
558 const __m128i s3_10_4 = _mm_add_epi32(s3_10_2, k__DCT_CONST_ROUNDING);
559 const __m128i s3_10_5 = _mm_add_epi32(s3_10_3, k__DCT_CONST_ROUNDING);
560 const __m128i s3_11_4 = _mm_add_epi32(s3_11_2, k__DCT_CONST_ROUNDING);
561 const __m128i s3_11_5 = _mm_add_epi32(s3_11_3, k__DCT_CONST_ROUNDING);
562 const __m128i s3_12_4 = _mm_add_epi32(s3_12_2, k__DCT_CONST_ROUNDING);
563 const __m128i s3_12_5 = _mm_add_epi32(s3_12_3, k__DCT_CONST_ROUNDING);
564 const __m128i s3_13_4 = _mm_add_epi32(s3_13_2, k__DCT_CONST_ROUNDING);
565 const __m128i s3_13_5 = _mm_add_epi32(s3_13_3, k__DCT_CONST_ROUNDING);
566 const __m128i s3_10_6 = _mm_srai_epi32(s3_10_4, DCT_CONST_BITS);
567 const __m128i s3_10_7 = _mm_srai_epi32(s3_10_5, DCT_CONST_BITS);
568 const __m128i s3_11_6 = _mm_srai_epi32(s3_11_4, DCT_CONST_BITS);
569 const __m128i s3_11_7 = _mm_srai_epi32(s3_11_5, DCT_CONST_BITS);
570 const __m128i s3_12_6 = _mm_srai_epi32(s3_12_4, DCT_CONST_BITS);
571 const __m128i s3_12_7 = _mm_srai_epi32(s3_12_5, DCT_CONST_BITS);
572 const __m128i s3_13_6 = _mm_srai_epi32(s3_13_4, DCT_CONST_BITS);
573 const __m128i s3_13_7 = _mm_srai_epi32(s3_13_5, DCT_CONST_BITS);
574 // Combine
575 step3[10] = _mm_packs_epi32(s3_10_6, s3_10_7);
576 step3[11] = _mm_packs_epi32(s3_11_6, s3_11_7);
577 step3[12] = _mm_packs_epi32(s3_12_6, s3_12_7);
578 step3[13] = _mm_packs_epi32(s3_13_6, s3_13_7);
579 }
580 {
581 step3[16] = _mm_add_epi16(step2[23], step1[16]);
582 step3[17] = _mm_add_epi16(step2[22], step1[17]);
583 step3[18] = _mm_add_epi16(step2[21], step1[18]);
584 step3[19] = _mm_add_epi16(step2[20], step1[19]);
585 step3[20] = _mm_sub_epi16(step1[19], step2[20]);
586 step3[21] = _mm_sub_epi16(step1[18], step2[21]);
587 step3[22] = _mm_sub_epi16(step1[17], step2[22]);
588 step3[23] = _mm_sub_epi16(step1[16], step2[23]);
589 step3[24] = _mm_sub_epi16(step1[31], step2[24]);
590 step3[25] = _mm_sub_epi16(step1[30], step2[25]);
591 step3[26] = _mm_sub_epi16(step1[29], step2[26]);
592 step3[27] = _mm_sub_epi16(step1[28], step2[27]);
593 step3[28] = _mm_add_epi16(step2[27], step1[28]);
594 step3[29] = _mm_add_epi16(step2[26], step1[29]);
595 step3[30] = _mm_add_epi16(step2[25], step1[30]);
596 step3[31] = _mm_add_epi16(step2[24], step1[31]);
597 }
598
599 // Stage 4
600 {
601 step1[ 0] = _mm_add_epi16(step3[ 3], step3[ 0]);
602 step1[ 1] = _mm_add_epi16(step3[ 2], step3[ 1]);
603 step1[ 2] = _mm_sub_epi16(step3[ 1], step3[ 2]);
604 step1[ 3] = _mm_sub_epi16(step3[ 0], step3[ 3]);
605 step1[ 8] = _mm_add_epi16(step3[11], step2[ 8]);
606 step1[ 9] = _mm_add_epi16(step3[10], step2[ 9]);
607 step1[10] = _mm_sub_epi16(step2[ 9], step3[10]);
608 step1[11] = _mm_sub_epi16(step2[ 8], step3[11]);
609 step1[12] = _mm_sub_epi16(step2[15], step3[12]);
610 step1[13] = _mm_sub_epi16(step2[14], step3[13]);
611 step1[14] = _mm_add_epi16(step3[13], step2[14]);
612 step1[15] = _mm_add_epi16(step3[12], step2[15]);
613 }
614 {
615 const __m128i s1_05_0 = _mm_unpacklo_epi16(step3[6], step3[5]);
616 const __m128i s1_05_1 = _mm_unpackhi_epi16(step3[6], step3[5]);
617 const __m128i s1_05_2 = _mm_madd_epi16(s1_05_0, k__cospi_p16_m16);
618 const __m128i s1_05_3 = _mm_madd_epi16(s1_05_1, k__cospi_p16_m16);
619 const __m128i s1_06_2 = _mm_madd_epi16(s1_05_0, k__cospi_p16_p16);
620 const __m128i s1_06_3 = _mm_madd_epi16(s1_05_1, k__cospi_p16_p16);
621 // dct_const_round_shift
622 const __m128i s1_05_4 = _mm_add_epi32(s1_05_2, k__DCT_CONST_ROUNDING);
623 const __m128i s1_05_5 = _mm_add_epi32(s1_05_3, k__DCT_CONST_ROUNDING);
624 const __m128i s1_06_4 = _mm_add_epi32(s1_06_2, k__DCT_CONST_ROUNDING);
625 const __m128i s1_06_5 = _mm_add_epi32(s1_06_3, k__DCT_CONST_ROUNDING);
626 const __m128i s1_05_6 = _mm_srai_epi32(s1_05_4, DCT_CONST_BITS);
627 const __m128i s1_05_7 = _mm_srai_epi32(s1_05_5, DCT_CONST_BITS);
628 const __m128i s1_06_6 = _mm_srai_epi32(s1_06_4, DCT_CONST_BITS);
629 const __m128i s1_06_7 = _mm_srai_epi32(s1_06_5, DCT_CONST_BITS);
630 // Combine
631 step1[5] = _mm_packs_epi32(s1_05_6, s1_05_7);
632 step1[6] = _mm_packs_epi32(s1_06_6, s1_06_7);
633 }
634 {
635 const __m128i s1_18_0 = _mm_unpacklo_epi16(step3[18], step3[29]);
636 const __m128i s1_18_1 = _mm_unpackhi_epi16(step3[18], step3[29]);
637 const __m128i s1_19_0 = _mm_unpacklo_epi16(step3[19], step3[28]);
638 const __m128i s1_19_1 = _mm_unpackhi_epi16(step3[19], step3[28]);
639 const __m128i s1_20_0 = _mm_unpacklo_epi16(step3[20], step3[27]);
640 const __m128i s1_20_1 = _mm_unpackhi_epi16(step3[20], step3[27]);
641 const __m128i s1_21_0 = _mm_unpacklo_epi16(step3[21], step3[26]);
642 const __m128i s1_21_1 = _mm_unpackhi_epi16(step3[21], step3[26]);
643 const __m128i s1_18_2 = _mm_madd_epi16(s1_18_0, k__cospi_m08_p24);
644 const __m128i s1_18_3 = _mm_madd_epi16(s1_18_1, k__cospi_m08_p24);
645 const __m128i s1_19_2 = _mm_madd_epi16(s1_19_0, k__cospi_m08_p24);
646 const __m128i s1_19_3 = _mm_madd_epi16(s1_19_1, k__cospi_m08_p24);
647 const __m128i s1_20_2 = _mm_madd_epi16(s1_20_0, k__cospi_m24_m08);
648 const __m128i s1_20_3 = _mm_madd_epi16(s1_20_1, k__cospi_m24_m08);
649 const __m128i s1_21_2 = _mm_madd_epi16(s1_21_0, k__cospi_m24_m08);
650 const __m128i s1_21_3 = _mm_madd_epi16(s1_21_1, k__cospi_m24_m08);
651 const __m128i s1_26_2 = _mm_madd_epi16(s1_21_0, k__cospi_m08_p24);
652 const __m128i s1_26_3 = _mm_madd_epi16(s1_21_1, k__cospi_m08_p24);
653 const __m128i s1_27_2 = _mm_madd_epi16(s1_20_0, k__cospi_m08_p24);
654 const __m128i s1_27_3 = _mm_madd_epi16(s1_20_1, k__cospi_m08_p24);
655 const __m128i s1_28_2 = _mm_madd_epi16(s1_19_0, k__cospi_p24_p08);
656 const __m128i s1_28_3 = _mm_madd_epi16(s1_19_1, k__cospi_p24_p08);
657 const __m128i s1_29_2 = _mm_madd_epi16(s1_18_0, k__cospi_p24_p08);
658 const __m128i s1_29_3 = _mm_madd_epi16(s1_18_1, k__cospi_p24_p08);
659 // dct_const_round_shift
660 const __m128i s1_18_4 = _mm_add_epi32(s1_18_2, k__DCT_CONST_ROUNDING);
661 const __m128i s1_18_5 = _mm_add_epi32(s1_18_3, k__DCT_CONST_ROUNDING);
662 const __m128i s1_19_4 = _mm_add_epi32(s1_19_2, k__DCT_CONST_ROUNDING);
663 const __m128i s1_19_5 = _mm_add_epi32(s1_19_3, k__DCT_CONST_ROUNDING);
664 const __m128i s1_20_4 = _mm_add_epi32(s1_20_2, k__DCT_CONST_ROUNDING);
665 const __m128i s1_20_5 = _mm_add_epi32(s1_20_3, k__DCT_CONST_ROUNDING);
666 const __m128i s1_21_4 = _mm_add_epi32(s1_21_2, k__DCT_CONST_ROUNDING);
667 const __m128i s1_21_5 = _mm_add_epi32(s1_21_3, k__DCT_CONST_ROUNDING);
668 const __m128i s1_26_4 = _mm_add_epi32(s1_26_2, k__DCT_CONST_ROUNDING);
669 const __m128i s1_26_5 = _mm_add_epi32(s1_26_3, k__DCT_CONST_ROUNDING);
670 const __m128i s1_27_4 = _mm_add_epi32(s1_27_2, k__DCT_CONST_ROUNDING);
671 const __m128i s1_27_5 = _mm_add_epi32(s1_27_3, k__DCT_CONST_ROUNDING);
672 const __m128i s1_28_4 = _mm_add_epi32(s1_28_2, k__DCT_CONST_ROUNDING);
673 const __m128i s1_28_5 = _mm_add_epi32(s1_28_3, k__DCT_CONST_ROUNDING);
674 const __m128i s1_29_4 = _mm_add_epi32(s1_29_2, k__DCT_CONST_ROUNDING);
675 const __m128i s1_29_5 = _mm_add_epi32(s1_29_3, k__DCT_CONST_ROUNDING);
676 const __m128i s1_18_6 = _mm_srai_epi32(s1_18_4, DCT_CONST_BITS);
677 const __m128i s1_18_7 = _mm_srai_epi32(s1_18_5, DCT_CONST_BITS);
678 const __m128i s1_19_6 = _mm_srai_epi32(s1_19_4, DCT_CONST_BITS);
679 const __m128i s1_19_7 = _mm_srai_epi32(s1_19_5, DCT_CONST_BITS);
680 const __m128i s1_20_6 = _mm_srai_epi32(s1_20_4, DCT_CONST_BITS);
681 const __m128i s1_20_7 = _mm_srai_epi32(s1_20_5, DCT_CONST_BITS);
682 const __m128i s1_21_6 = _mm_srai_epi32(s1_21_4, DCT_CONST_BITS);
683 const __m128i s1_21_7 = _mm_srai_epi32(s1_21_5, DCT_CONST_BITS);
684 const __m128i s1_26_6 = _mm_srai_epi32(s1_26_4, DCT_CONST_BITS);
685 const __m128i s1_26_7 = _mm_srai_epi32(s1_26_5, DCT_CONST_BITS);
686 const __m128i s1_27_6 = _mm_srai_epi32(s1_27_4, DCT_CONST_BITS);
687 const __m128i s1_27_7 = _mm_srai_epi32(s1_27_5, DCT_CONST_BITS);
688 const __m128i s1_28_6 = _mm_srai_epi32(s1_28_4, DCT_CONST_BITS);
689 const __m128i s1_28_7 = _mm_srai_epi32(s1_28_5, DCT_CONST_BITS);
690 const __m128i s1_29_6 = _mm_srai_epi32(s1_29_4, DCT_CONST_BITS);
691 const __m128i s1_29_7 = _mm_srai_epi32(s1_29_5, DCT_CONST_BITS);
692 // Combine
693 step1[18] = _mm_packs_epi32(s1_18_6, s1_18_7);
694 step1[19] = _mm_packs_epi32(s1_19_6, s1_19_7);
695 step1[20] = _mm_packs_epi32(s1_20_6, s1_20_7);
696 step1[21] = _mm_packs_epi32(s1_21_6, s1_21_7);
697 step1[26] = _mm_packs_epi32(s1_26_6, s1_26_7);
698 step1[27] = _mm_packs_epi32(s1_27_6, s1_27_7);
699 step1[28] = _mm_packs_epi32(s1_28_6, s1_28_7);
700 step1[29] = _mm_packs_epi32(s1_29_6, s1_29_7);
701 }
702 // Stage 5
703 {
704 step2[4] = _mm_add_epi16(step1[5], step3[4]);
705 step2[5] = _mm_sub_epi16(step3[4], step1[5]);
706 step2[6] = _mm_sub_epi16(step3[7], step1[6]);
707 step2[7] = _mm_add_epi16(step1[6], step3[7]);
708 }
709 {
710 const __m128i out_00_0 = _mm_unpacklo_epi16(step1[0], step1[1]);
711 const __m128i out_00_1 = _mm_unpackhi_epi16(step1[0], step1[1]);
712 const __m128i out_08_0 = _mm_unpacklo_epi16(step1[2], step1[3]);
713 const __m128i out_08_1 = _mm_unpackhi_epi16(step1[2], step1[3]);
714 const __m128i out_00_2 = _mm_madd_epi16(out_00_0, k__cospi_p16_p16);
715 const __m128i out_00_3 = _mm_madd_epi16(out_00_1, k__cospi_p16_p16);
716 const __m128i out_16_2 = _mm_madd_epi16(out_00_0, k__cospi_p16_m16);
717 const __m128i out_16_3 = _mm_madd_epi16(out_00_1, k__cospi_p16_m16);
718 const __m128i out_08_2 = _mm_madd_epi16(out_08_0, k__cospi_p24_p08);
719 const __m128i out_08_3 = _mm_madd_epi16(out_08_1, k__cospi_p24_p08);
720 const __m128i out_24_2 = _mm_madd_epi16(out_08_0, k__cospi_m08_p24);
721 const __m128i out_24_3 = _mm_madd_epi16(out_08_1, k__cospi_m08_p24);
722 // dct_const_round_shift
723 const __m128i out_00_4 = _mm_add_epi32(out_00_2, k__DCT_CONST_ROUNDING);
724 const __m128i out_00_5 = _mm_add_epi32(out_00_3, k__DCT_CONST_ROUNDING);
725 const __m128i out_16_4 = _mm_add_epi32(out_16_2, k__DCT_CONST_ROUNDING);
726 const __m128i out_16_5 = _mm_add_epi32(out_16_3, k__DCT_CONST_ROUNDING);
727 const __m128i out_08_4 = _mm_add_epi32(out_08_2, k__DCT_CONST_ROUNDING);
728 const __m128i out_08_5 = _mm_add_epi32(out_08_3, k__DCT_CONST_ROUNDING);
729 const __m128i out_24_4 = _mm_add_epi32(out_24_2, k__DCT_CONST_ROUNDING);
730 const __m128i out_24_5 = _mm_add_epi32(out_24_3, k__DCT_CONST_ROUNDING);
731 const __m128i out_00_6 = _mm_srai_epi32(out_00_4, DCT_CONST_BITS);
732 const __m128i out_00_7 = _mm_srai_epi32(out_00_5, DCT_CONST_BITS);
733 const __m128i out_16_6 = _mm_srai_epi32(out_16_4, DCT_CONST_BITS);
734 const __m128i out_16_7 = _mm_srai_epi32(out_16_5, DCT_CONST_BITS);
735 const __m128i out_08_6 = _mm_srai_epi32(out_08_4, DCT_CONST_BITS);
736 const __m128i out_08_7 = _mm_srai_epi32(out_08_5, DCT_CONST_BITS);
737 const __m128i out_24_6 = _mm_srai_epi32(out_24_4, DCT_CONST_BITS);
738 const __m128i out_24_7 = _mm_srai_epi32(out_24_5, DCT_CONST_BITS);
739 // Combine
740 out[ 0] = _mm_packs_epi32(out_00_6, out_00_7);
741 out[16] = _mm_packs_epi32(out_16_6, out_16_7);
742 out[ 8] = _mm_packs_epi32(out_08_6, out_08_7);
743 out[24] = _mm_packs_epi32(out_24_6, out_24_7);
744 }
745 {
746 const __m128i s2_09_0 = _mm_unpacklo_epi16(step1[ 9], step1[14]);
747 const __m128i s2_09_1 = _mm_unpackhi_epi16(step1[ 9], step1[14]);
748 const __m128i s2_10_0 = _mm_unpacklo_epi16(step1[10], step1[13]);
749 const __m128i s2_10_1 = _mm_unpackhi_epi16(step1[10], step1[13]);
750 const __m128i s2_09_2 = _mm_madd_epi16(s2_09_0, k__cospi_m08_p24);
751 const __m128i s2_09_3 = _mm_madd_epi16(s2_09_1, k__cospi_m08_p24);
752 const __m128i s2_10_2 = _mm_madd_epi16(s2_10_0, k__cospi_m24_m08);
753 const __m128i s2_10_3 = _mm_madd_epi16(s2_10_1, k__cospi_m24_m08);
754 const __m128i s2_13_2 = _mm_madd_epi16(s2_10_0, k__cospi_m08_p24);
755 const __m128i s2_13_3 = _mm_madd_epi16(s2_10_1, k__cospi_m08_p24);
756 const __m128i s2_14_2 = _mm_madd_epi16(s2_09_0, k__cospi_p24_p08);
757 const __m128i s2_14_3 = _mm_madd_epi16(s2_09_1, k__cospi_p24_p08);
758 // dct_const_round_shift
759 const __m128i s2_09_4 = _mm_add_epi32(s2_09_2, k__DCT_CONST_ROUNDING);
760 const __m128i s2_09_5 = _mm_add_epi32(s2_09_3, k__DCT_CONST_ROUNDING);
761 const __m128i s2_10_4 = _mm_add_epi32(s2_10_2, k__DCT_CONST_ROUNDING);
762 const __m128i s2_10_5 = _mm_add_epi32(s2_10_3, k__DCT_CONST_ROUNDING);
763 const __m128i s2_13_4 = _mm_add_epi32(s2_13_2, k__DCT_CONST_ROUNDING);
764 const __m128i s2_13_5 = _mm_add_epi32(s2_13_3, k__DCT_CONST_ROUNDING);
765 const __m128i s2_14_4 = _mm_add_epi32(s2_14_2, k__DCT_CONST_ROUNDING);
766 const __m128i s2_14_5 = _mm_add_epi32(s2_14_3, k__DCT_CONST_ROUNDING);
767 const __m128i s2_09_6 = _mm_srai_epi32(s2_09_4, DCT_CONST_BITS);
768 const __m128i s2_09_7 = _mm_srai_epi32(s2_09_5, DCT_CONST_BITS);
769 const __m128i s2_10_6 = _mm_srai_epi32(s2_10_4, DCT_CONST_BITS);
770 const __m128i s2_10_7 = _mm_srai_epi32(s2_10_5, DCT_CONST_BITS);
771 const __m128i s2_13_6 = _mm_srai_epi32(s2_13_4, DCT_CONST_BITS);
772 const __m128i s2_13_7 = _mm_srai_epi32(s2_13_5, DCT_CONST_BITS);
773 const __m128i s2_14_6 = _mm_srai_epi32(s2_14_4, DCT_CONST_BITS);
774 const __m128i s2_14_7 = _mm_srai_epi32(s2_14_5, DCT_CONST_BITS);
775 // Combine
776 step2[ 9] = _mm_packs_epi32(s2_09_6, s2_09_7);
777 step2[10] = _mm_packs_epi32(s2_10_6, s2_10_7);
778 step2[13] = _mm_packs_epi32(s2_13_6, s2_13_7);
779 step2[14] = _mm_packs_epi32(s2_14_6, s2_14_7);
780 }
781 {
782 step2[16] = _mm_add_epi16(step1[19], step3[16]);
783 step2[17] = _mm_add_epi16(step1[18], step3[17]);
784 step2[18] = _mm_sub_epi16(step3[17], step1[18]);
785 step2[19] = _mm_sub_epi16(step3[16], step1[19]);
786 step2[20] = _mm_sub_epi16(step3[23], step1[20]);
787 step2[21] = _mm_sub_epi16(step3[22], step1[21]);
788 step2[22] = _mm_add_epi16(step1[21], step3[22]);
789 step2[23] = _mm_add_epi16(step1[20], step3[23]);
790 step2[24] = _mm_add_epi16(step1[27], step3[24]);
791 step2[25] = _mm_add_epi16(step1[26], step3[25]);
792 step2[26] = _mm_sub_epi16(step3[25], step1[26]);
793 step2[27] = _mm_sub_epi16(step3[24], step1[27]);
794 step2[28] = _mm_sub_epi16(step3[31], step1[28]);
795 step2[29] = _mm_sub_epi16(step3[30], step1[29]);
796 step2[30] = _mm_add_epi16(step1[29], step3[30]);
797 step2[31] = _mm_add_epi16(step1[28], step3[31]);
798 }
799 // Stage 6
800 {
801 const __m128i out_04_0 = _mm_unpacklo_epi16(step2[4], step2[7]);
802 const __m128i out_04_1 = _mm_unpackhi_epi16(step2[4], step2[7]);
803 const __m128i out_20_0 = _mm_unpacklo_epi16(step2[5], step2[6]);
804 const __m128i out_20_1 = _mm_unpackhi_epi16(step2[5], step2[6]);
805 const __m128i out_12_0 = _mm_unpacklo_epi16(step2[5], step2[6]);
806 const __m128i out_12_1 = _mm_unpackhi_epi16(step2[5], step2[6]);
807 const __m128i out_28_0 = _mm_unpacklo_epi16(step2[4], step2[7]);
808 const __m128i out_28_1 = _mm_unpackhi_epi16(step2[4], step2[7]);
809 const __m128i out_04_2 = _mm_madd_epi16(out_04_0, k__cospi_p28_p04);
810 const __m128i out_04_3 = _mm_madd_epi16(out_04_1, k__cospi_p28_p04);
811 const __m128i out_20_2 = _mm_madd_epi16(out_20_0, k__cospi_p12_p20);
812 const __m128i out_20_3 = _mm_madd_epi16(out_20_1, k__cospi_p12_p20);
813 const __m128i out_12_2 = _mm_madd_epi16(out_12_0, k__cospi_m20_p12);
814 const __m128i out_12_3 = _mm_madd_epi16(out_12_1, k__cospi_m20_p12);
815 const __m128i out_28_2 = _mm_madd_epi16(out_28_0, k__cospi_m04_p28);
816 const __m128i out_28_3 = _mm_madd_epi16(out_28_1, k__cospi_m04_p28);
817 // dct_const_round_shift
818 const __m128i out_04_4 = _mm_add_epi32(out_04_2, k__DCT_CONST_ROUNDING);
819 const __m128i out_04_5 = _mm_add_epi32(out_04_3, k__DCT_CONST_ROUNDING);
820 const __m128i out_20_4 = _mm_add_epi32(out_20_2, k__DCT_CONST_ROUNDING);
821 const __m128i out_20_5 = _mm_add_epi32(out_20_3, k__DCT_CONST_ROUNDING);
822 const __m128i out_12_4 = _mm_add_epi32(out_12_2, k__DCT_CONST_ROUNDING);
823 const __m128i out_12_5 = _mm_add_epi32(out_12_3, k__DCT_CONST_ROUNDING);
824 const __m128i out_28_4 = _mm_add_epi32(out_28_2, k__DCT_CONST_ROUNDING);
825 const __m128i out_28_5 = _mm_add_epi32(out_28_3, k__DCT_CONST_ROUNDING);
826 const __m128i out_04_6 = _mm_srai_epi32(out_04_4, DCT_CONST_BITS);
827 const __m128i out_04_7 = _mm_srai_epi32(out_04_5, DCT_CONST_BITS);
828 const __m128i out_20_6 = _mm_srai_epi32(out_20_4, DCT_CONST_BITS);
829 const __m128i out_20_7 = _mm_srai_epi32(out_20_5, DCT_CONST_BITS);
830 const __m128i out_12_6 = _mm_srai_epi32(out_12_4, DCT_CONST_BITS);
831 const __m128i out_12_7 = _mm_srai_epi32(out_12_5, DCT_CONST_BITS);
832 const __m128i out_28_6 = _mm_srai_epi32(out_28_4, DCT_CONST_BITS);
833 const __m128i out_28_7 = _mm_srai_epi32(out_28_5, DCT_CONST_BITS);
834 // Combine
835 out[ 4] = _mm_packs_epi32(out_04_6, out_04_7);
836 out[20] = _mm_packs_epi32(out_20_6, out_20_7);
837 out[12] = _mm_packs_epi32(out_12_6, out_12_7);
838 out[28] = _mm_packs_epi32(out_28_6, out_28_7);
839 }
840 {
841 step3[ 8] = _mm_add_epi16(step2[ 9], step1[ 8]);
842 step3[ 9] = _mm_sub_epi16(step1[ 8], step2[ 9]);
843 step3[10] = _mm_sub_epi16(step1[11], step2[10]);
844 step3[11] = _mm_add_epi16(step2[10], step1[11]);
845 step3[12] = _mm_add_epi16(step2[13], step1[12]);
846 step3[13] = _mm_sub_epi16(step1[12], step2[13]);
847 step3[14] = _mm_sub_epi16(step1[15], step2[14]);
848 step3[15] = _mm_add_epi16(step2[14], step1[15]);
849 }
850 {
851 const __m128i s3_17_0 = _mm_unpacklo_epi16(step2[17], step2[30]);
852 const __m128i s3_17_1 = _mm_unpackhi_epi16(step2[17], step2[30]);
853 const __m128i s3_18_0 = _mm_unpacklo_epi16(step2[18], step2[29]);
854 const __m128i s3_18_1 = _mm_unpackhi_epi16(step2[18], step2[29]);
855 const __m128i s3_21_0 = _mm_unpacklo_epi16(step2[21], step2[26]);
856 const __m128i s3_21_1 = _mm_unpackhi_epi16(step2[21], step2[26]);
857 const __m128i s3_22_0 = _mm_unpacklo_epi16(step2[22], step2[25]);
858 const __m128i s3_22_1 = _mm_unpackhi_epi16(step2[22], step2[25]);
859 const __m128i s3_17_2 = _mm_madd_epi16(s3_17_0, k__cospi_m04_p28);
860 const __m128i s3_17_3 = _mm_madd_epi16(s3_17_1, k__cospi_m04_p28);
861 const __m128i s3_18_2 = _mm_madd_epi16(s3_18_0, k__cospi_m28_m04);
862 const __m128i s3_18_3 = _mm_madd_epi16(s3_18_1, k__cospi_m28_m04);
863 const __m128i s3_21_2 = _mm_madd_epi16(s3_21_0, k__cospi_m20_p12);
864 const __m128i s3_21_3 = _mm_madd_epi16(s3_21_1, k__cospi_m20_p12);
865 const __m128i s3_22_2 = _mm_madd_epi16(s3_22_0, k__cospi_m12_m20);
866 const __m128i s3_22_3 = _mm_madd_epi16(s3_22_1, k__cospi_m12_m20);
867 const __m128i s3_25_2 = _mm_madd_epi16(s3_22_0, k__cospi_m20_p12);
868 const __m128i s3_25_3 = _mm_madd_epi16(s3_22_1, k__cospi_m20_p12);
869 const __m128i s3_26_2 = _mm_madd_epi16(s3_21_0, k__cospi_p12_p20);
870 const __m128i s3_26_3 = _mm_madd_epi16(s3_21_1, k__cospi_p12_p20);
871 const __m128i s3_29_2 = _mm_madd_epi16(s3_18_0, k__cospi_m04_p28);
872 const __m128i s3_29_3 = _mm_madd_epi16(s3_18_1, k__cospi_m04_p28);
873 const __m128i s3_30_2 = _mm_madd_epi16(s3_17_0, k__cospi_p28_p04);
874 const __m128i s3_30_3 = _mm_madd_epi16(s3_17_1, k__cospi_p28_p04);
875 // dct_const_round_shift
876 const __m128i s3_17_4 = _mm_add_epi32(s3_17_2, k__DCT_CONST_ROUNDING);
877 const __m128i s3_17_5 = _mm_add_epi32(s3_17_3, k__DCT_CONST_ROUNDING);
878 const __m128i s3_18_4 = _mm_add_epi32(s3_18_2, k__DCT_CONST_ROUNDING);
879 const __m128i s3_18_5 = _mm_add_epi32(s3_18_3, k__DCT_CONST_ROUNDING);
880 const __m128i s3_21_4 = _mm_add_epi32(s3_21_2, k__DCT_CONST_ROUNDING);
881 const __m128i s3_21_5 = _mm_add_epi32(s3_21_3, k__DCT_CONST_ROUNDING);
882 const __m128i s3_22_4 = _mm_add_epi32(s3_22_2, k__DCT_CONST_ROUNDING);
883 const __m128i s3_22_5 = _mm_add_epi32(s3_22_3, k__DCT_CONST_ROUNDING);
884 const __m128i s3_17_6 = _mm_srai_epi32(s3_17_4, DCT_CONST_BITS);
885 const __m128i s3_17_7 = _mm_srai_epi32(s3_17_5, DCT_CONST_BITS);
886 const __m128i s3_18_6 = _mm_srai_epi32(s3_18_4, DCT_CONST_BITS);
887 const __m128i s3_18_7 = _mm_srai_epi32(s3_18_5, DCT_CONST_BITS);
888 const __m128i s3_21_6 = _mm_srai_epi32(s3_21_4, DCT_CONST_BITS);
889 const __m128i s3_21_7 = _mm_srai_epi32(s3_21_5, DCT_CONST_BITS);
890 const __m128i s3_22_6 = _mm_srai_epi32(s3_22_4, DCT_CONST_BITS);
891 const __m128i s3_22_7 = _mm_srai_epi32(s3_22_5, DCT_CONST_BITS);
892 const __m128i s3_25_4 = _mm_add_epi32(s3_25_2, k__DCT_CONST_ROUNDING);
893 const __m128i s3_25_5 = _mm_add_epi32(s3_25_3, k__DCT_CONST_ROUNDING);
894 const __m128i s3_26_4 = _mm_add_epi32(s3_26_2, k__DCT_CONST_ROUNDING);
895 const __m128i s3_26_5 = _mm_add_epi32(s3_26_3, k__DCT_CONST_ROUNDING);
896 const __m128i s3_29_4 = _mm_add_epi32(s3_29_2, k__DCT_CONST_ROUNDING);
897 const __m128i s3_29_5 = _mm_add_epi32(s3_29_3, k__DCT_CONST_ROUNDING);
898 const __m128i s3_30_4 = _mm_add_epi32(s3_30_2, k__DCT_CONST_ROUNDING);
899 const __m128i s3_30_5 = _mm_add_epi32(s3_30_3, k__DCT_CONST_ROUNDING);
900 const __m128i s3_25_6 = _mm_srai_epi32(s3_25_4, DCT_CONST_BITS);
901 const __m128i s3_25_7 = _mm_srai_epi32(s3_25_5, DCT_CONST_BITS);
902 const __m128i s3_26_6 = _mm_srai_epi32(s3_26_4, DCT_CONST_BITS);
903 const __m128i s3_26_7 = _mm_srai_epi32(s3_26_5, DCT_CONST_BITS);
904 const __m128i s3_29_6 = _mm_srai_epi32(s3_29_4, DCT_CONST_BITS);
905 const __m128i s3_29_7 = _mm_srai_epi32(s3_29_5, DCT_CONST_BITS);
906 const __m128i s3_30_6 = _mm_srai_epi32(s3_30_4, DCT_CONST_BITS);
907 const __m128i s3_30_7 = _mm_srai_epi32(s3_30_5, DCT_CONST_BITS);
908 // Combine
909 step3[17] = _mm_packs_epi32(s3_17_6, s3_17_7);
910 step3[18] = _mm_packs_epi32(s3_18_6, s3_18_7);
911 step3[21] = _mm_packs_epi32(s3_21_6, s3_21_7);
912 step3[22] = _mm_packs_epi32(s3_22_6, s3_22_7);
913 // Combine
914 step3[25] = _mm_packs_epi32(s3_25_6, s3_25_7);
915 step3[26] = _mm_packs_epi32(s3_26_6, s3_26_7);
916 step3[29] = _mm_packs_epi32(s3_29_6, s3_29_7);
917 step3[30] = _mm_packs_epi32(s3_30_6, s3_30_7);
918 }
919 // Stage 7
920 {
921 const __m128i out_02_0 = _mm_unpacklo_epi16(step3[ 8], step3[15]);
922 const __m128i out_02_1 = _mm_unpackhi_epi16(step3[ 8], step3[15]);
923 const __m128i out_18_0 = _mm_unpacklo_epi16(step3[ 9], step3[14]);
924 const __m128i out_18_1 = _mm_unpackhi_epi16(step3[ 9], step3[14]);
925 const __m128i out_10_0 = _mm_unpacklo_epi16(step3[10], step3[13]);
926 const __m128i out_10_1 = _mm_unpackhi_epi16(step3[10], step3[13]);
927 const __m128i out_26_0 = _mm_unpacklo_epi16(step3[11], step3[12]);
928 const __m128i out_26_1 = _mm_unpackhi_epi16(step3[11], step3[12]);
929 const __m128i out_02_2 = _mm_madd_epi16(out_02_0, k__cospi_p30_p02);
930 const __m128i out_02_3 = _mm_madd_epi16(out_02_1, k__cospi_p30_p02);
931 const __m128i out_18_2 = _mm_madd_epi16(out_18_0, k__cospi_p14_p18);
932 const __m128i out_18_3 = _mm_madd_epi16(out_18_1, k__cospi_p14_p18);
933 const __m128i out_10_2 = _mm_madd_epi16(out_10_0, k__cospi_p22_p10);
934 const __m128i out_10_3 = _mm_madd_epi16(out_10_1, k__cospi_p22_p10);
935 const __m128i out_26_2 = _mm_madd_epi16(out_26_0, k__cospi_p06_p26);
936 const __m128i out_26_3 = _mm_madd_epi16(out_26_1, k__cospi_p06_p26);
937 const __m128i out_06_2 = _mm_madd_epi16(out_26_0, k__cospi_m26_p06);
938 const __m128i out_06_3 = _mm_madd_epi16(out_26_1, k__cospi_m26_p06);
939 const __m128i out_22_2 = _mm_madd_epi16(out_10_0, k__cospi_m10_p22);
940 const __m128i out_22_3 = _mm_madd_epi16(out_10_1, k__cospi_m10_p22);
941 const __m128i out_14_2 = _mm_madd_epi16(out_18_0, k__cospi_m18_p14);
942 const __m128i out_14_3 = _mm_madd_epi16(out_18_1, k__cospi_m18_p14);
943 const __m128i out_30_2 = _mm_madd_epi16(out_02_0, k__cospi_m02_p30);
944 const __m128i out_30_3 = _mm_madd_epi16(out_02_1, k__cospi_m02_p30);
945 // dct_const_round_shift
946 const __m128i out_02_4 = _mm_add_epi32(out_02_2, k__DCT_CONST_ROUNDING);
947 const __m128i out_02_5 = _mm_add_epi32(out_02_3, k__DCT_CONST_ROUNDING);
948 const __m128i out_18_4 = _mm_add_epi32(out_18_2, k__DCT_CONST_ROUNDING);
949 const __m128i out_18_5 = _mm_add_epi32(out_18_3, k__DCT_CONST_ROUNDING);
950 const __m128i out_10_4 = _mm_add_epi32(out_10_2, k__DCT_CONST_ROUNDING);
951 const __m128i out_10_5 = _mm_add_epi32(out_10_3, k__DCT_CONST_ROUNDING);
952 const __m128i out_26_4 = _mm_add_epi32(out_26_2, k__DCT_CONST_ROUNDING);
953 const __m128i out_26_5 = _mm_add_epi32(out_26_3, k__DCT_CONST_ROUNDING);
954 const __m128i out_06_4 = _mm_add_epi32(out_06_2, k__DCT_CONST_ROUNDING);
955 const __m128i out_06_5 = _mm_add_epi32(out_06_3, k__DCT_CONST_ROUNDING);
956 const __m128i out_22_4 = _mm_add_epi32(out_22_2, k__DCT_CONST_ROUNDING);
957 const __m128i out_22_5 = _mm_add_epi32(out_22_3, k__DCT_CONST_ROUNDING);
958 const __m128i out_14_4 = _mm_add_epi32(out_14_2, k__DCT_CONST_ROUNDING);
959 const __m128i out_14_5 = _mm_add_epi32(out_14_3, k__DCT_CONST_ROUNDING);
960 const __m128i out_30_4 = _mm_add_epi32(out_30_2, k__DCT_CONST_ROUNDING);
961 const __m128i out_30_5 = _mm_add_epi32(out_30_3, k__DCT_CONST_ROUNDING);
962 const __m128i out_02_6 = _mm_srai_epi32(out_02_4, DCT_CONST_BITS);
963 const __m128i out_02_7 = _mm_srai_epi32(out_02_5, DCT_CONST_BITS);
964 const __m128i out_18_6 = _mm_srai_epi32(out_18_4, DCT_CONST_BITS);
965 const __m128i out_18_7 = _mm_srai_epi32(out_18_5, DCT_CONST_BITS);
966 const __m128i out_10_6 = _mm_srai_epi32(out_10_4, DCT_CONST_BITS);
967 const __m128i out_10_7 = _mm_srai_epi32(out_10_5, DCT_CONST_BITS);
968 const __m128i out_26_6 = _mm_srai_epi32(out_26_4, DCT_CONST_BITS);
969 const __m128i out_26_7 = _mm_srai_epi32(out_26_5, DCT_CONST_BITS);
970 const __m128i out_06_6 = _mm_srai_epi32(out_06_4, DCT_CONST_BITS);
971 const __m128i out_06_7 = _mm_srai_epi32(out_06_5, DCT_CONST_BITS);
972 const __m128i out_22_6 = _mm_srai_epi32(out_22_4, DCT_CONST_BITS);
973 const __m128i out_22_7 = _mm_srai_epi32(out_22_5, DCT_CONST_BITS);
974 const __m128i out_14_6 = _mm_srai_epi32(out_14_4, DCT_CONST_BITS);
975 const __m128i out_14_7 = _mm_srai_epi32(out_14_5, DCT_CONST_BITS);
976 const __m128i out_30_6 = _mm_srai_epi32(out_30_4, DCT_CONST_BITS);
977 const __m128i out_30_7 = _mm_srai_epi32(out_30_5, DCT_CONST_BITS);
978 // Combine
979 out[ 2] = _mm_packs_epi32(out_02_6, out_02_7);
980 out[18] = _mm_packs_epi32(out_18_6, out_18_7);
981 out[10] = _mm_packs_epi32(out_10_6, out_10_7);
982 out[26] = _mm_packs_epi32(out_26_6, out_26_7);
983 out[ 6] = _mm_packs_epi32(out_06_6, out_06_7);
984 out[22] = _mm_packs_epi32(out_22_6, out_22_7);
985 out[14] = _mm_packs_epi32(out_14_6, out_14_7);
986 out[30] = _mm_packs_epi32(out_30_6, out_30_7);
987 }
988 {
989 step1[16] = _mm_add_epi16(step3[17], step2[16]);
990 step1[17] = _mm_sub_epi16(step2[16], step3[17]);
991 step1[18] = _mm_sub_epi16(step2[19], step3[18]);
992 step1[19] = _mm_add_epi16(step3[18], step2[19]);
993 step1[20] = _mm_add_epi16(step3[21], step2[20]);
994 step1[21] = _mm_sub_epi16(step2[20], step3[21]);
995 step1[22] = _mm_sub_epi16(step2[23], step3[22]);
996 step1[23] = _mm_add_epi16(step3[22], step2[23]);
997 step1[24] = _mm_add_epi16(step3[25], step2[24]);
998 step1[25] = _mm_sub_epi16(step2[24], step3[25]);
999 step1[26] = _mm_sub_epi16(step2[27], step3[26]);
1000 step1[27] = _mm_add_epi16(step3[26], step2[27]);
1001 step1[28] = _mm_add_epi16(step3[29], step2[28]);
1002 step1[29] = _mm_sub_epi16(step2[28], step3[29]);
1003 step1[30] = _mm_sub_epi16(step2[31], step3[30]);
1004 step1[31] = _mm_add_epi16(step3[30], step2[31]);
1005 }
1006 // Final stage --- outputs indices are bit-reversed.
1007 {
1008 const __m128i out_01_0 = _mm_unpacklo_epi16(step1[16], step1[31]);
1009 const __m128i out_01_1 = _mm_unpackhi_epi16(step1[16], step1[31]);
1010 const __m128i out_17_0 = _mm_unpacklo_epi16(step1[17], step1[30]);
1011 const __m128i out_17_1 = _mm_unpackhi_epi16(step1[17], step1[30]);
1012 const __m128i out_09_0 = _mm_unpacklo_epi16(step1[18], step1[29]);
1013 const __m128i out_09_1 = _mm_unpackhi_epi16(step1[18], step1[29]);
1014 const __m128i out_25_0 = _mm_unpacklo_epi16(step1[19], step1[28]);
1015 const __m128i out_25_1 = _mm_unpackhi_epi16(step1[19], step1[28]);
1016 const __m128i out_01_2 = _mm_madd_epi16(out_01_0, k__cospi_p31_p01);
1017 const __m128i out_01_3 = _mm_madd_epi16(out_01_1, k__cospi_p31_p01);
1018 const __m128i out_17_2 = _mm_madd_epi16(out_17_0, k__cospi_p15_p17);
1019 const __m128i out_17_3 = _mm_madd_epi16(out_17_1, k__cospi_p15_p17);
1020 const __m128i out_09_2 = _mm_madd_epi16(out_09_0, k__cospi_p23_p09);
1021 const __m128i out_09_3 = _mm_madd_epi16(out_09_1, k__cospi_p23_p09);
1022 const __m128i out_25_2 = _mm_madd_epi16(out_25_0, k__cospi_p07_p25);
1023 const __m128i out_25_3 = _mm_madd_epi16(out_25_1, k__cospi_p07_p25);
1024 const __m128i out_07_2 = _mm_madd_epi16(out_25_0, k__cospi_m25_p07);
1025 const __m128i out_07_3 = _mm_madd_epi16(out_25_1, k__cospi_m25_p07);
1026 const __m128i out_23_2 = _mm_madd_epi16(out_09_0, k__cospi_m09_p23);
1027 const __m128i out_23_3 = _mm_madd_epi16(out_09_1, k__cospi_m09_p23);
1028 const __m128i out_15_2 = _mm_madd_epi16(out_17_0, k__cospi_m17_p15);
1029 const __m128i out_15_3 = _mm_madd_epi16(out_17_1, k__cospi_m17_p15);
1030 const __m128i out_31_2 = _mm_madd_epi16(out_01_0, k__cospi_m01_p31);
1031 const __m128i out_31_3 = _mm_madd_epi16(out_01_1, k__cospi_m01_p31);
1032 // dct_const_round_shift
1033 const __m128i out_01_4 = _mm_add_epi32(out_01_2, k__DCT_CONST_ROUNDING);
1034 const __m128i out_01_5 = _mm_add_epi32(out_01_3, k__DCT_CONST_ROUNDING);
1035 const __m128i out_17_4 = _mm_add_epi32(out_17_2, k__DCT_CONST_ROUNDING);
1036 const __m128i out_17_5 = _mm_add_epi32(out_17_3, k__DCT_CONST_ROUNDING);
1037 const __m128i out_09_4 = _mm_add_epi32(out_09_2, k__DCT_CONST_ROUNDING);
1038 const __m128i out_09_5 = _mm_add_epi32(out_09_3, k__DCT_CONST_ROUNDING);
1039 const __m128i out_25_4 = _mm_add_epi32(out_25_2, k__DCT_CONST_ROUNDING);
1040 const __m128i out_25_5 = _mm_add_epi32(out_25_3, k__DCT_CONST_ROUNDING);
1041 const __m128i out_07_4 = _mm_add_epi32(out_07_2, k__DCT_CONST_ROUNDING);
1042 const __m128i out_07_5 = _mm_add_epi32(out_07_3, k__DCT_CONST_ROUNDING);
1043 const __m128i out_23_4 = _mm_add_epi32(out_23_2, k__DCT_CONST_ROUNDING);
1044 const __m128i out_23_5 = _mm_add_epi32(out_23_3, k__DCT_CONST_ROUNDING);
1045 const __m128i out_15_4 = _mm_add_epi32(out_15_2, k__DCT_CONST_ROUNDING);
1046 const __m128i out_15_5 = _mm_add_epi32(out_15_3, k__DCT_CONST_ROUNDING);
1047 const __m128i out_31_4 = _mm_add_epi32(out_31_2, k__DCT_CONST_ROUNDING);
1048 const __m128i out_31_5 = _mm_add_epi32(out_31_3, k__DCT_CONST_ROUNDING);
1049 const __m128i out_01_6 = _mm_srai_epi32(out_01_4, DCT_CONST_BITS);
1050 const __m128i out_01_7 = _mm_srai_epi32(out_01_5, DCT_CONST_BITS);
1051 const __m128i out_17_6 = _mm_srai_epi32(out_17_4, DCT_CONST_BITS);
1052 const __m128i out_17_7 = _mm_srai_epi32(out_17_5, DCT_CONST_BITS);
1053 const __m128i out_09_6 = _mm_srai_epi32(out_09_4, DCT_CONST_BITS);
1054 const __m128i out_09_7 = _mm_srai_epi32(out_09_5, DCT_CONST_BITS);
1055 const __m128i out_25_6 = _mm_srai_epi32(out_25_4, DCT_CONST_BITS);
1056 const __m128i out_25_7 = _mm_srai_epi32(out_25_5, DCT_CONST_BITS);
1057 const __m128i out_07_6 = _mm_srai_epi32(out_07_4, DCT_CONST_BITS);
1058 const __m128i out_07_7 = _mm_srai_epi32(out_07_5, DCT_CONST_BITS);
1059 const __m128i out_23_6 = _mm_srai_epi32(out_23_4, DCT_CONST_BITS);
1060 const __m128i out_23_7 = _mm_srai_epi32(out_23_5, DCT_CONST_BITS);
1061 const __m128i out_15_6 = _mm_srai_epi32(out_15_4, DCT_CONST_BITS);
1062 const __m128i out_15_7 = _mm_srai_epi32(out_15_5, DCT_CONST_BITS);
1063 const __m128i out_31_6 = _mm_srai_epi32(out_31_4, DCT_CONST_BITS);
1064 const __m128i out_31_7 = _mm_srai_epi32(out_31_5, DCT_CONST_BITS);
1065 // Combine
1066 out[ 1] = _mm_packs_epi32(out_01_6, out_01_7);
1067 out[17] = _mm_packs_epi32(out_17_6, out_17_7);
1068 out[ 9] = _mm_packs_epi32(out_09_6, out_09_7);
1069 out[25] = _mm_packs_epi32(out_25_6, out_25_7);
1070 out[ 7] = _mm_packs_epi32(out_07_6, out_07_7);
1071 out[23] = _mm_packs_epi32(out_23_6, out_23_7);
1072 out[15] = _mm_packs_epi32(out_15_6, out_15_7);
1073 out[31] = _mm_packs_epi32(out_31_6, out_31_7);
1074 }
1075 {
1076 const __m128i out_05_0 = _mm_unpacklo_epi16(step1[20], step1[27]);
1077 const __m128i out_05_1 = _mm_unpackhi_epi16(step1[20], step1[27]);
1078 const __m128i out_21_0 = _mm_unpacklo_epi16(step1[21], step1[26]);
1079 const __m128i out_21_1 = _mm_unpackhi_epi16(step1[21], step1[26]);
1080 const __m128i out_13_0 = _mm_unpacklo_epi16(step1[22], step1[25]);
1081 const __m128i out_13_1 = _mm_unpackhi_epi16(step1[22], step1[25]);
1082 const __m128i out_29_0 = _mm_unpacklo_epi16(step1[23], step1[24]);
1083 const __m128i out_29_1 = _mm_unpackhi_epi16(step1[23], step1[24]);
1084 const __m128i out_05_2 = _mm_madd_epi16(out_05_0, k__cospi_p27_p05);
1085 const __m128i out_05_3 = _mm_madd_epi16(out_05_1, k__cospi_p27_p05);
1086 const __m128i out_21_2 = _mm_madd_epi16(out_21_0, k__cospi_p11_p21);
1087 const __m128i out_21_3 = _mm_madd_epi16(out_21_1, k__cospi_p11_p21);
1088 const __m128i out_13_2 = _mm_madd_epi16(out_13_0, k__cospi_p19_p13);
1089 const __m128i out_13_3 = _mm_madd_epi16(out_13_1, k__cospi_p19_p13);
1090 const __m128i out_29_2 = _mm_madd_epi16(out_29_0, k__cospi_p03_p29);
1091 const __m128i out_29_3 = _mm_madd_epi16(out_29_1, k__cospi_p03_p29);
1092 const __m128i out_03_2 = _mm_madd_epi16(out_29_0, k__cospi_m29_p03);
1093 const __m128i out_03_3 = _mm_madd_epi16(out_29_1, k__cospi_m29_p03);
1094 const __m128i out_19_2 = _mm_madd_epi16(out_13_0, k__cospi_m13_p19);
1095 const __m128i out_19_3 = _mm_madd_epi16(out_13_1, k__cospi_m13_p19);
1096 const __m128i out_11_2 = _mm_madd_epi16(out_21_0, k__cospi_m21_p11);
1097 const __m128i out_11_3 = _mm_madd_epi16(out_21_1, k__cospi_m21_p11);
1098 const __m128i out_27_2 = _mm_madd_epi16(out_05_0, k__cospi_m05_p27);
1099 const __m128i out_27_3 = _mm_madd_epi16(out_05_1, k__cospi_m05_p27);
1100 // dct_const_round_shift
1101 const __m128i out_05_4 = _mm_add_epi32(out_05_2, k__DCT_CONST_ROUNDING);
1102 const __m128i out_05_5 = _mm_add_epi32(out_05_3, k__DCT_CONST_ROUNDING);
1103 const __m128i out_21_4 = _mm_add_epi32(out_21_2, k__DCT_CONST_ROUNDING);
1104 const __m128i out_21_5 = _mm_add_epi32(out_21_3, k__DCT_CONST_ROUNDING);
1105 const __m128i out_13_4 = _mm_add_epi32(out_13_2, k__DCT_CONST_ROUNDING);
1106 const __m128i out_13_5 = _mm_add_epi32(out_13_3, k__DCT_CONST_ROUNDING);
1107 const __m128i out_29_4 = _mm_add_epi32(out_29_2, k__DCT_CONST_ROUNDING);
1108 const __m128i out_29_5 = _mm_add_epi32(out_29_3, k__DCT_CONST_ROUNDING);
1109 const __m128i out_03_4 = _mm_add_epi32(out_03_2, k__DCT_CONST_ROUNDING);
1110 const __m128i out_03_5 = _mm_add_epi32(out_03_3, k__DCT_CONST_ROUNDING);
1111 const __m128i out_19_4 = _mm_add_epi32(out_19_2, k__DCT_CONST_ROUNDING);
1112 const __m128i out_19_5 = _mm_add_epi32(out_19_3, k__DCT_CONST_ROUNDING);
1113 const __m128i out_11_4 = _mm_add_epi32(out_11_2, k__DCT_CONST_ROUNDING);
1114 const __m128i out_11_5 = _mm_add_epi32(out_11_3, k__DCT_CONST_ROUNDING);
1115 const __m128i out_27_4 = _mm_add_epi32(out_27_2, k__DCT_CONST_ROUNDING);
1116 const __m128i out_27_5 = _mm_add_epi32(out_27_3, k__DCT_CONST_ROUNDING);
1117 const __m128i out_05_6 = _mm_srai_epi32(out_05_4, DCT_CONST_BITS);
1118 const __m128i out_05_7 = _mm_srai_epi32(out_05_5, DCT_CONST_BITS);
1119 const __m128i out_21_6 = _mm_srai_epi32(out_21_4, DCT_CONST_BITS);
1120 const __m128i out_21_7 = _mm_srai_epi32(out_21_5, DCT_CONST_BITS);
1121 const __m128i out_13_6 = _mm_srai_epi32(out_13_4, DCT_CONST_BITS);
1122 const __m128i out_13_7 = _mm_srai_epi32(out_13_5, DCT_CONST_BITS);
1123 const __m128i out_29_6 = _mm_srai_epi32(out_29_4, DCT_CONST_BITS);
1124 const __m128i out_29_7 = _mm_srai_epi32(out_29_5, DCT_CONST_BITS);
1125 const __m128i out_03_6 = _mm_srai_epi32(out_03_4, DCT_CONST_BITS);
1126 const __m128i out_03_7 = _mm_srai_epi32(out_03_5, DCT_CONST_BITS);
1127 const __m128i out_19_6 = _mm_srai_epi32(out_19_4, DCT_CONST_BITS);
1128 const __m128i out_19_7 = _mm_srai_epi32(out_19_5, DCT_CONST_BITS);
1129 const __m128i out_11_6 = _mm_srai_epi32(out_11_4, DCT_CONST_BITS);
1130 const __m128i out_11_7 = _mm_srai_epi32(out_11_5, DCT_CONST_BITS);
1131 const __m128i out_27_6 = _mm_srai_epi32(out_27_4, DCT_CONST_BITS);
1132 const __m128i out_27_7 = _mm_srai_epi32(out_27_5, DCT_CONST_BITS);
1133 // Combine
1134 out[ 5] = _mm_packs_epi32(out_05_6, out_05_7);
1135 out[21] = _mm_packs_epi32(out_21_6, out_21_7);
1136 out[13] = _mm_packs_epi32(out_13_6, out_13_7);
1137 out[29] = _mm_packs_epi32(out_29_6, out_29_7);
1138 out[ 3] = _mm_packs_epi32(out_03_6, out_03_7);
1139 out[19] = _mm_packs_epi32(out_19_6, out_19_7);
1140 out[11] = _mm_packs_epi32(out_11_6, out_11_7);
1141 out[27] = _mm_packs_epi32(out_27_6, out_27_7);
1142 }
1143 #if FDCT32x32_HIGH_PRECISION
1144 } else {
1145 __m128i lstep1[64], lstep2[64], lstep3[64];
1146 __m128i u[32], v[32], sign[16];
1147 const __m128i K32One = _mm_set_epi32(1, 1, 1, 1);
1148 // start using 32-bit operations
1149 // stage 3
1150 {
1151 // expanding to 32-bit length priori to addition operations
1152 lstep2[ 0] = _mm_unpacklo_epi16(step2[ 0], kZero);
1153 lstep2[ 1] = _mm_unpackhi_epi16(step2[ 0], kZero);
1154 lstep2[ 2] = _mm_unpacklo_epi16(step2[ 1], kZero);
1155 lstep2[ 3] = _mm_unpackhi_epi16(step2[ 1], kZero);
1156 lstep2[ 4] = _mm_unpacklo_epi16(step2[ 2], kZero);
1157 lstep2[ 5] = _mm_unpackhi_epi16(step2[ 2], kZero);
1158 lstep2[ 6] = _mm_unpacklo_epi16(step2[ 3], kZero);
1159 lstep2[ 7] = _mm_unpackhi_epi16(step2[ 3], kZero);
1160 lstep2[ 8] = _mm_unpacklo_epi16(step2[ 4], kZero);
1161 lstep2[ 9] = _mm_unpackhi_epi16(step2[ 4], kZero);
1162 lstep2[10] = _mm_unpacklo_epi16(step2[ 5], kZero);
1163 lstep2[11] = _mm_unpackhi_epi16(step2[ 5], kZero);
1164 lstep2[12] = _mm_unpacklo_epi16(step2[ 6], kZero);
1165 lstep2[13] = _mm_unpackhi_epi16(step2[ 6], kZero);
1166 lstep2[14] = _mm_unpacklo_epi16(step2[ 7], kZero);
1167 lstep2[15] = _mm_unpackhi_epi16(step2[ 7], kZero);
1168 lstep2[ 0] = _mm_madd_epi16(lstep2[ 0], kOne);
1169 lstep2[ 1] = _mm_madd_epi16(lstep2[ 1], kOne);
1170 lstep2[ 2] = _mm_madd_epi16(lstep2[ 2], kOne);
1171 lstep2[ 3] = _mm_madd_epi16(lstep2[ 3], kOne);
1172 lstep2[ 4] = _mm_madd_epi16(lstep2[ 4], kOne);
1173 lstep2[ 5] = _mm_madd_epi16(lstep2[ 5], kOne);
1174 lstep2[ 6] = _mm_madd_epi16(lstep2[ 6], kOne);
1175 lstep2[ 7] = _mm_madd_epi16(lstep2[ 7], kOne);
1176 lstep2[ 8] = _mm_madd_epi16(lstep2[ 8], kOne);
1177 lstep2[ 9] = _mm_madd_epi16(lstep2[ 9], kOne);
1178 lstep2[10] = _mm_madd_epi16(lstep2[10], kOne);
1179 lstep2[11] = _mm_madd_epi16(lstep2[11], kOne);
1180 lstep2[12] = _mm_madd_epi16(lstep2[12], kOne);
1181 lstep2[13] = _mm_madd_epi16(lstep2[13], kOne);
1182 lstep2[14] = _mm_madd_epi16(lstep2[14], kOne);
1183 lstep2[15] = _mm_madd_epi16(lstep2[15], kOne);
1184
1185 lstep3[ 0] = _mm_add_epi32(lstep2[14], lstep2[ 0]);
1186 lstep3[ 1] = _mm_add_epi32(lstep2[15], lstep2[ 1]);
1187 lstep3[ 2] = _mm_add_epi32(lstep2[12], lstep2[ 2]);
1188 lstep3[ 3] = _mm_add_epi32(lstep2[13], lstep2[ 3]);
1189 lstep3[ 4] = _mm_add_epi32(lstep2[10], lstep2[ 4]);
1190 lstep3[ 5] = _mm_add_epi32(lstep2[11], lstep2[ 5]);
1191 lstep3[ 6] = _mm_add_epi32(lstep2[ 8], lstep2[ 6]);
1192 lstep3[ 7] = _mm_add_epi32(lstep2[ 9], lstep2[ 7]);
1193 lstep3[ 8] = _mm_sub_epi32(lstep2[ 6], lstep2[ 8]);
1194 lstep3[ 9] = _mm_sub_epi32(lstep2[ 7], lstep2[ 9]);
1195 lstep3[10] = _mm_sub_epi32(lstep2[ 4], lstep2[10]);
1196 lstep3[11] = _mm_sub_epi32(lstep2[ 5], lstep2[11]);
1197 lstep3[12] = _mm_sub_epi32(lstep2[ 2], lstep2[12]);
1198 lstep3[13] = _mm_sub_epi32(lstep2[ 3], lstep2[13]);
1199 lstep3[14] = _mm_sub_epi32(lstep2[ 0], lstep2[14]);
1200 lstep3[15] = _mm_sub_epi32(lstep2[ 1], lstep2[15]);
1201 }
1202 {
1203 const __m128i s3_10_0 = _mm_unpacklo_epi16(step2[13], step2[10]);
1204 const __m128i s3_10_1 = _mm_unpackhi_epi16(step2[13], step2[10]);
1205 const __m128i s3_11_0 = _mm_unpacklo_epi16(step2[12], step2[11]);
1206 const __m128i s3_11_1 = _mm_unpackhi_epi16(step2[12], step2[11]);
1207 const __m128i s3_10_2 = _mm_madd_epi16(s3_10_0, k__cospi_p16_m16);
1208 const __m128i s3_10_3 = _mm_madd_epi16(s3_10_1, k__cospi_p16_m16);
1209 const __m128i s3_11_2 = _mm_madd_epi16(s3_11_0, k__cospi_p16_m16);
1210 const __m128i s3_11_3 = _mm_madd_epi16(s3_11_1, k__cospi_p16_m16);
1211 const __m128i s3_12_2 = _mm_madd_epi16(s3_11_0, k__cospi_p16_p16);
1212 const __m128i s3_12_3 = _mm_madd_epi16(s3_11_1, k__cospi_p16_p16);
1213 const __m128i s3_13_2 = _mm_madd_epi16(s3_10_0, k__cospi_p16_p16);
1214 const __m128i s3_13_3 = _mm_madd_epi16(s3_10_1, k__cospi_p16_p16);
1215 // dct_const_round_shift
1216 const __m128i s3_10_4 = _mm_add_epi32(s3_10_2, k__DCT_CONST_ROUNDING);
1217 const __m128i s3_10_5 = _mm_add_epi32(s3_10_3, k__DCT_CONST_ROUNDING);
1218 const __m128i s3_11_4 = _mm_add_epi32(s3_11_2, k__DCT_CONST_ROUNDING);
1219 const __m128i s3_11_5 = _mm_add_epi32(s3_11_3, k__DCT_CONST_ROUNDING);
1220 const __m128i s3_12_4 = _mm_add_epi32(s3_12_2, k__DCT_CONST_ROUNDING);
1221 const __m128i s3_12_5 = _mm_add_epi32(s3_12_3, k__DCT_CONST_ROUNDING);
1222 const __m128i s3_13_4 = _mm_add_epi32(s3_13_2, k__DCT_CONST_ROUNDING);
1223 const __m128i s3_13_5 = _mm_add_epi32(s3_13_3, k__DCT_CONST_ROUNDING);
1224 lstep3[20] = _mm_srai_epi32(s3_10_4, DCT_CONST_BITS);
1225 lstep3[21] = _mm_srai_epi32(s3_10_5, DCT_CONST_BITS);
1226 lstep3[22] = _mm_srai_epi32(s3_11_4, DCT_CONST_BITS);
1227 lstep3[23] = _mm_srai_epi32(s3_11_5, DCT_CONST_BITS);
1228 lstep3[24] = _mm_srai_epi32(s3_12_4, DCT_CONST_BITS);
1229 lstep3[25] = _mm_srai_epi32(s3_12_5, DCT_CONST_BITS);
1230 lstep3[26] = _mm_srai_epi32(s3_13_4, DCT_CONST_BITS);
1231 lstep3[27] = _mm_srai_epi32(s3_13_5, DCT_CONST_BITS);
1232 }
1233 {
1234 lstep2[40] = _mm_unpacklo_epi16(step2[20], kZero);
1235 lstep2[41] = _mm_unpackhi_epi16(step2[20], kZero);
1236 lstep2[42] = _mm_unpacklo_epi16(step2[21], kZero);
1237 lstep2[43] = _mm_unpackhi_epi16(step2[21], kZero);
1238 lstep2[44] = _mm_unpacklo_epi16(step2[22], kZero);
1239 lstep2[45] = _mm_unpackhi_epi16(step2[22], kZero);
1240 lstep2[46] = _mm_unpacklo_epi16(step2[23], kZero);
1241 lstep2[47] = _mm_unpackhi_epi16(step2[23], kZero);
1242 lstep2[48] = _mm_unpacklo_epi16(step2[24], kZero);
1243 lstep2[49] = _mm_unpackhi_epi16(step2[24], kZero);
1244 lstep2[50] = _mm_unpacklo_epi16(step2[25], kZero);
1245 lstep2[51] = _mm_unpackhi_epi16(step2[25], kZero);
1246 lstep2[52] = _mm_unpacklo_epi16(step2[26], kZero);
1247 lstep2[53] = _mm_unpackhi_epi16(step2[26], kZero);
1248 lstep2[54] = _mm_unpacklo_epi16(step2[27], kZero);
1249 lstep2[55] = _mm_unpackhi_epi16(step2[27], kZero);
1250 lstep2[40] = _mm_madd_epi16(lstep2[40], kOne);
1251 lstep2[41] = _mm_madd_epi16(lstep2[41], kOne);
1252 lstep2[42] = _mm_madd_epi16(lstep2[42], kOne);
1253 lstep2[43] = _mm_madd_epi16(lstep2[43], kOne);
1254 lstep2[44] = _mm_madd_epi16(lstep2[44], kOne);
1255 lstep2[45] = _mm_madd_epi16(lstep2[45], kOne);
1256 lstep2[46] = _mm_madd_epi16(lstep2[46], kOne);
1257 lstep2[47] = _mm_madd_epi16(lstep2[47], kOne);
1258 lstep2[48] = _mm_madd_epi16(lstep2[48], kOne);
1259 lstep2[49] = _mm_madd_epi16(lstep2[49], kOne);
1260 lstep2[50] = _mm_madd_epi16(lstep2[50], kOne);
1261 lstep2[51] = _mm_madd_epi16(lstep2[51], kOne);
1262 lstep2[52] = _mm_madd_epi16(lstep2[52], kOne);
1263 lstep2[53] = _mm_madd_epi16(lstep2[53], kOne);
1264 lstep2[54] = _mm_madd_epi16(lstep2[54], kOne);
1265 lstep2[55] = _mm_madd_epi16(lstep2[55], kOne);
1266
1267 lstep1[32] = _mm_unpacklo_epi16(step1[16], kZero);
1268 lstep1[33] = _mm_unpackhi_epi16(step1[16], kZero);
1269 lstep1[34] = _mm_unpacklo_epi16(step1[17], kZero);
1270 lstep1[35] = _mm_unpackhi_epi16(step1[17], kZero);
1271 lstep1[36] = _mm_unpacklo_epi16(step1[18], kZero);
1272 lstep1[37] = _mm_unpackhi_epi16(step1[18], kZero);
1273 lstep1[38] = _mm_unpacklo_epi16(step1[19], kZero);
1274 lstep1[39] = _mm_unpackhi_epi16(step1[19], kZero);
1275 lstep1[56] = _mm_unpacklo_epi16(step1[28], kZero);
1276 lstep1[57] = _mm_unpackhi_epi16(step1[28], kZero);
1277 lstep1[58] = _mm_unpacklo_epi16(step1[29], kZero);
1278 lstep1[59] = _mm_unpackhi_epi16(step1[29], kZero);
1279 lstep1[60] = _mm_unpacklo_epi16(step1[30], kZero);
1280 lstep1[61] = _mm_unpackhi_epi16(step1[30], kZero);
1281 lstep1[62] = _mm_unpacklo_epi16(step1[31], kZero);
1282 lstep1[63] = _mm_unpackhi_epi16(step1[31], kZero);
1283 lstep1[32] = _mm_madd_epi16(lstep1[32], kOne);
1284 lstep1[33] = _mm_madd_epi16(lstep1[33], kOne);
1285 lstep1[34] = _mm_madd_epi16(lstep1[34], kOne);
1286 lstep1[35] = _mm_madd_epi16(lstep1[35], kOne);
1287 lstep1[36] = _mm_madd_epi16(lstep1[36], kOne);
1288 lstep1[37] = _mm_madd_epi16(lstep1[37], kOne);
1289 lstep1[38] = _mm_madd_epi16(lstep1[38], kOne);
1290 lstep1[39] = _mm_madd_epi16(lstep1[39], kOne);
1291 lstep1[56] = _mm_madd_epi16(lstep1[56], kOne);
1292 lstep1[57] = _mm_madd_epi16(lstep1[57], kOne);
1293 lstep1[58] = _mm_madd_epi16(lstep1[58], kOne);
1294 lstep1[59] = _mm_madd_epi16(lstep1[59], kOne);
1295 lstep1[60] = _mm_madd_epi16(lstep1[60], kOne);
1296 lstep1[61] = _mm_madd_epi16(lstep1[61], kOne);
1297 lstep1[62] = _mm_madd_epi16(lstep1[62], kOne);
1298 lstep1[63] = _mm_madd_epi16(lstep1[63], kOne);
1299
1300 lstep3[32] = _mm_add_epi32(lstep2[46], lstep1[32]);
1301 lstep3[33] = _mm_add_epi32(lstep2[47], lstep1[33]);
1302
1303 lstep3[34] = _mm_add_epi32(lstep2[44], lstep1[34]);
1304 lstep3[35] = _mm_add_epi32(lstep2[45], lstep1[35]);
1305 lstep3[36] = _mm_add_epi32(lstep2[42], lstep1[36]);
1306 lstep3[37] = _mm_add_epi32(lstep2[43], lstep1[37]);
1307 lstep3[38] = _mm_add_epi32(lstep2[40], lstep1[38]);
1308 lstep3[39] = _mm_add_epi32(lstep2[41], lstep1[39]);
1309 lstep3[40] = _mm_sub_epi32(lstep1[38], lstep2[40]);
1310 lstep3[41] = _mm_sub_epi32(lstep1[39], lstep2[41]);
1311 lstep3[42] = _mm_sub_epi32(lstep1[36], lstep2[42]);
1312 lstep3[43] = _mm_sub_epi32(lstep1[37], lstep2[43]);
1313 lstep3[44] = _mm_sub_epi32(lstep1[34], lstep2[44]);
1314 lstep3[45] = _mm_sub_epi32(lstep1[35], lstep2[45]);
1315 lstep3[46] = _mm_sub_epi32(lstep1[32], lstep2[46]);
1316 lstep3[47] = _mm_sub_epi32(lstep1[33], lstep2[47]);
1317 lstep3[48] = _mm_sub_epi32(lstep1[62], lstep2[48]);
1318 lstep3[49] = _mm_sub_epi32(lstep1[63], lstep2[49]);
1319 lstep3[50] = _mm_sub_epi32(lstep1[60], lstep2[50]);
1320 lstep3[51] = _mm_sub_epi32(lstep1[61], lstep2[51]);
1321 lstep3[52] = _mm_sub_epi32(lstep1[58], lstep2[52]);
1322 lstep3[53] = _mm_sub_epi32(lstep1[59], lstep2[53]);
1323 lstep3[54] = _mm_sub_epi32(lstep1[56], lstep2[54]);
1324 lstep3[55] = _mm_sub_epi32(lstep1[57], lstep2[55]);
1325 lstep3[56] = _mm_add_epi32(lstep2[54], lstep1[56]);
1326 lstep3[57] = _mm_add_epi32(lstep2[55], lstep1[57]);
1327 lstep3[58] = _mm_add_epi32(lstep2[52], lstep1[58]);
1328 lstep3[59] = _mm_add_epi32(lstep2[53], lstep1[59]);
1329 lstep3[60] = _mm_add_epi32(lstep2[50], lstep1[60]);
1330 lstep3[61] = _mm_add_epi32(lstep2[51], lstep1[61]);
1331 lstep3[62] = _mm_add_epi32(lstep2[48], lstep1[62]);
1332 lstep3[63] = _mm_add_epi32(lstep2[49], lstep1[63]);
1333 }
1334
1335 // stage 4
1336 {
1337 // expanding to 32-bit length priori to addition operations
1338 lstep2[16] = _mm_unpacklo_epi16(step2[ 8], kZero);
1339 lstep2[17] = _mm_unpackhi_epi16(step2[ 8], kZero);
1340 lstep2[18] = _mm_unpacklo_epi16(step2[ 9], kZero);
1341 lstep2[19] = _mm_unpackhi_epi16(step2[ 9], kZero);
1342 lstep2[28] = _mm_unpacklo_epi16(step2[14], kZero);
1343 lstep2[29] = _mm_unpackhi_epi16(step2[14], kZero);
1344 lstep2[30] = _mm_unpacklo_epi16(step2[15], kZero);
1345 lstep2[31] = _mm_unpackhi_epi16(step2[15], kZero);
1346 lstep2[16] = _mm_madd_epi16(lstep2[16], kOne);
1347 lstep2[17] = _mm_madd_epi16(lstep2[17], kOne);
1348 lstep2[18] = _mm_madd_epi16(lstep2[18], kOne);
1349 lstep2[19] = _mm_madd_epi16(lstep2[19], kOne);
1350 lstep2[28] = _mm_madd_epi16(lstep2[28], kOne);
1351 lstep2[29] = _mm_madd_epi16(lstep2[29], kOne);
1352 lstep2[30] = _mm_madd_epi16(lstep2[30], kOne);
1353 lstep2[31] = _mm_madd_epi16(lstep2[31], kOne);
1354
1355 lstep1[ 0] = _mm_add_epi32(lstep3[ 6], lstep3[ 0]);
1356 lstep1[ 1] = _mm_add_epi32(lstep3[ 7], lstep3[ 1]);
1357 lstep1[ 2] = _mm_add_epi32(lstep3[ 4], lstep3[ 2]);
1358 lstep1[ 3] = _mm_add_epi32(lstep3[ 5], lstep3[ 3]);
1359 lstep1[ 4] = _mm_sub_epi32(lstep3[ 2], lstep3[ 4]);
1360 lstep1[ 5] = _mm_sub_epi32(lstep3[ 3], lstep3[ 5]);
1361 lstep1[ 6] = _mm_sub_epi32(lstep3[ 0], lstep3[ 6]);
1362 lstep1[ 7] = _mm_sub_epi32(lstep3[ 1], lstep3[ 7]);
1363 lstep1[16] = _mm_add_epi32(lstep3[22], lstep2[16]);
1364 lstep1[17] = _mm_add_epi32(lstep3[23], lstep2[17]);
1365 lstep1[18] = _mm_add_epi32(lstep3[20], lstep2[18]);
1366 lstep1[19] = _mm_add_epi32(lstep3[21], lstep2[19]);
1367 lstep1[20] = _mm_sub_epi32(lstep2[18], lstep3[20]);
1368 lstep1[21] = _mm_sub_epi32(lstep2[19], lstep3[21]);
1369 lstep1[22] = _mm_sub_epi32(lstep2[16], lstep3[22]);
1370 lstep1[23] = _mm_sub_epi32(lstep2[17], lstep3[23]);
1371 lstep1[24] = _mm_sub_epi32(lstep2[30], lstep3[24]);
1372 lstep1[25] = _mm_sub_epi32(lstep2[31], lstep3[25]);
1373 lstep1[26] = _mm_sub_epi32(lstep2[28], lstep3[26]);
1374 lstep1[27] = _mm_sub_epi32(lstep2[29], lstep3[27]);
1375 lstep1[28] = _mm_add_epi32(lstep3[26], lstep2[28]);
1376 lstep1[29] = _mm_add_epi32(lstep3[27], lstep2[29]);
1377 lstep1[30] = _mm_add_epi32(lstep3[24], lstep2[30]);
1378 lstep1[31] = _mm_add_epi32(lstep3[25], lstep2[31]);
1379 }
1380 {
1381 // to be continued...
1382 //
1383 const __m128i k32_p16_p16 = pair_set_epi32(cospi_16_64, cospi_16_64);
1384 const __m128i k32_p16_m16 = pair_set_epi32(cospi_16_64, -cospi_16_64);
1385
1386 u[0] = _mm_unpacklo_epi32(lstep3[12], lstep3[10]);
1387 u[1] = _mm_unpackhi_epi32(lstep3[12], lstep3[10]);
1388 u[2] = _mm_unpacklo_epi32(lstep3[13], lstep3[11]);
1389 u[3] = _mm_unpackhi_epi32(lstep3[13], lstep3[11]);
1390
1391 // TODO(jingning): manually inline k_madd_epi32_ to further hide
1392 // instruction latency.
1393 v[ 0] = k_madd_epi32(u[0], k32_p16_m16);
1394 v[ 1] = k_madd_epi32(u[1], k32_p16_m16);
1395 v[ 2] = k_madd_epi32(u[2], k32_p16_m16);
1396 v[ 3] = k_madd_epi32(u[3], k32_p16_m16);
1397 v[ 4] = k_madd_epi32(u[0], k32_p16_p16);
1398 v[ 5] = k_madd_epi32(u[1], k32_p16_p16);
1399 v[ 6] = k_madd_epi32(u[2], k32_p16_p16);
1400 v[ 7] = k_madd_epi32(u[3], k32_p16_p16);
1401
1402 u[0] = k_packs_epi64(v[0], v[1]);
1403 u[1] = k_packs_epi64(v[2], v[3]);
1404 u[2] = k_packs_epi64(v[4], v[5]);
1405 u[3] = k_packs_epi64(v[6], v[7]);
1406
1407 v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
1408 v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
1409 v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
1410 v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
1411
1412 lstep1[10] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
1413 lstep1[11] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
1414 lstep1[12] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
1415 lstep1[13] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
1416 }
1417 {
1418 const __m128i k32_m08_p24 = pair_set_epi32(-cospi_8_64, cospi_24_64);
1419 const __m128i k32_m24_m08 = pair_set_epi32(-cospi_24_64, -cospi_8_64);
1420 const __m128i k32_p24_p08 = pair_set_epi32(cospi_24_64, cospi_8_64);
1421
1422 u[ 0] = _mm_unpacklo_epi32(lstep3[36], lstep3[58]);
1423 u[ 1] = _mm_unpackhi_epi32(lstep3[36], lstep3[58]);
1424 u[ 2] = _mm_unpacklo_epi32(lstep3[37], lstep3[59]);
1425 u[ 3] = _mm_unpackhi_epi32(lstep3[37], lstep3[59]);
1426 u[ 4] = _mm_unpacklo_epi32(lstep3[38], lstep3[56]);
1427 u[ 5] = _mm_unpackhi_epi32(lstep3[38], lstep3[56]);
1428 u[ 6] = _mm_unpacklo_epi32(lstep3[39], lstep3[57]);
1429 u[ 7] = _mm_unpackhi_epi32(lstep3[39], lstep3[57]);
1430 u[ 8] = _mm_unpacklo_epi32(lstep3[40], lstep3[54]);
1431 u[ 9] = _mm_unpackhi_epi32(lstep3[40], lstep3[54]);
1432 u[10] = _mm_unpacklo_epi32(lstep3[41], lstep3[55]);
1433 u[11] = _mm_unpackhi_epi32(lstep3[41], lstep3[55]);
1434 u[12] = _mm_unpacklo_epi32(lstep3[42], lstep3[52]);
1435 u[13] = _mm_unpackhi_epi32(lstep3[42], lstep3[52]);
1436 u[14] = _mm_unpacklo_epi32(lstep3[43], lstep3[53]);
1437 u[15] = _mm_unpackhi_epi32(lstep3[43], lstep3[53]);
1438
1439 v[ 0] = k_madd_epi32(u[ 0], k32_m08_p24);
1440 v[ 1] = k_madd_epi32(u[ 1], k32_m08_p24);
1441 v[ 2] = k_madd_epi32(u[ 2], k32_m08_p24);
1442 v[ 3] = k_madd_epi32(u[ 3], k32_m08_p24);
1443 v[ 4] = k_madd_epi32(u[ 4], k32_m08_p24);
1444 v[ 5] = k_madd_epi32(u[ 5], k32_m08_p24);
1445 v[ 6] = k_madd_epi32(u[ 6], k32_m08_p24);
1446 v[ 7] = k_madd_epi32(u[ 7], k32_m08_p24);
1447 v[ 8] = k_madd_epi32(u[ 8], k32_m24_m08);
1448 v[ 9] = k_madd_epi32(u[ 9], k32_m24_m08);
1449 v[10] = k_madd_epi32(u[10], k32_m24_m08);
1450 v[11] = k_madd_epi32(u[11], k32_m24_m08);
1451 v[12] = k_madd_epi32(u[12], k32_m24_m08);
1452 v[13] = k_madd_epi32(u[13], k32_m24_m08);
1453 v[14] = k_madd_epi32(u[14], k32_m24_m08);
1454 v[15] = k_madd_epi32(u[15], k32_m24_m08);
1455 v[16] = k_madd_epi32(u[12], k32_m08_p24);
1456 v[17] = k_madd_epi32(u[13], k32_m08_p24);
1457 v[18] = k_madd_epi32(u[14], k32_m08_p24);
1458 v[19] = k_madd_epi32(u[15], k32_m08_p24);
1459 v[20] = k_madd_epi32(u[ 8], k32_m08_p24);
1460 v[21] = k_madd_epi32(u[ 9], k32_m08_p24);
1461 v[22] = k_madd_epi32(u[10], k32_m08_p24);
1462 v[23] = k_madd_epi32(u[11], k32_m08_p24);
1463 v[24] = k_madd_epi32(u[ 4], k32_p24_p08);
1464 v[25] = k_madd_epi32(u[ 5], k32_p24_p08);
1465 v[26] = k_madd_epi32(u[ 6], k32_p24_p08);
1466 v[27] = k_madd_epi32(u[ 7], k32_p24_p08);
1467 v[28] = k_madd_epi32(u[ 0], k32_p24_p08);
1468 v[29] = k_madd_epi32(u[ 1], k32_p24_p08);
1469 v[30] = k_madd_epi32(u[ 2], k32_p24_p08);
1470 v[31] = k_madd_epi32(u[ 3], k32_p24_p08);
1471
1472 u[ 0] = k_packs_epi64(v[ 0], v[ 1]);
1473 u[ 1] = k_packs_epi64(v[ 2], v[ 3]);
1474 u[ 2] = k_packs_epi64(v[ 4], v[ 5]);
1475 u[ 3] = k_packs_epi64(v[ 6], v[ 7]);
1476 u[ 4] = k_packs_epi64(v[ 8], v[ 9]);
1477 u[ 5] = k_packs_epi64(v[10], v[11]);
1478 u[ 6] = k_packs_epi64(v[12], v[13]);
1479 u[ 7] = k_packs_epi64(v[14], v[15]);
1480 u[ 8] = k_packs_epi64(v[16], v[17]);
1481 u[ 9] = k_packs_epi64(v[18], v[19]);
1482 u[10] = k_packs_epi64(v[20], v[21]);
1483 u[11] = k_packs_epi64(v[22], v[23]);
1484 u[12] = k_packs_epi64(v[24], v[25]);
1485 u[13] = k_packs_epi64(v[26], v[27]);
1486 u[14] = k_packs_epi64(v[28], v[29]);
1487 u[15] = k_packs_epi64(v[30], v[31]);
1488
1489 v[ 0] = _mm_add_epi32(u[ 0], k__DCT_CONST_ROUNDING);
1490 v[ 1] = _mm_add_epi32(u[ 1], k__DCT_CONST_ROUNDING);
1491 v[ 2] = _mm_add_epi32(u[ 2], k__DCT_CONST_ROUNDING);
1492 v[ 3] = _mm_add_epi32(u[ 3], k__DCT_CONST_ROUNDING);
1493 v[ 4] = _mm_add_epi32(u[ 4], k__DCT_CONST_ROUNDING);
1494 v[ 5] = _mm_add_epi32(u[ 5], k__DCT_CONST_ROUNDING);
1495 v[ 6] = _mm_add_epi32(u[ 6], k__DCT_CONST_ROUNDING);
1496 v[ 7] = _mm_add_epi32(u[ 7], k__DCT_CONST_ROUNDING);
1497 v[ 8] = _mm_add_epi32(u[ 8], k__DCT_CONST_ROUNDING);
1498 v[ 9] = _mm_add_epi32(u[ 9], k__DCT_CONST_ROUNDING);
1499 v[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
1500 v[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
1501 v[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
1502 v[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
1503 v[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
1504 v[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
1505
1506 lstep1[36] = _mm_srai_epi32(v[ 0], DCT_CONST_BITS);
1507 lstep1[37] = _mm_srai_epi32(v[ 1], DCT_CONST_BITS);
1508 lstep1[38] = _mm_srai_epi32(v[ 2], DCT_CONST_BITS);
1509 lstep1[39] = _mm_srai_epi32(v[ 3], DCT_CONST_BITS);
1510 lstep1[40] = _mm_srai_epi32(v[ 4], DCT_CONST_BITS);
1511 lstep1[41] = _mm_srai_epi32(v[ 5], DCT_CONST_BITS);
1512 lstep1[42] = _mm_srai_epi32(v[ 6], DCT_CONST_BITS);
1513 lstep1[43] = _mm_srai_epi32(v[ 7], DCT_CONST_BITS);
1514 lstep1[52] = _mm_srai_epi32(v[ 8], DCT_CONST_BITS);
1515 lstep1[53] = _mm_srai_epi32(v[ 9], DCT_CONST_BITS);
1516 lstep1[54] = _mm_srai_epi32(v[10], DCT_CONST_BITS);
1517 lstep1[55] = _mm_srai_epi32(v[11], DCT_CONST_BITS);
1518 lstep1[56] = _mm_srai_epi32(v[12], DCT_CONST_BITS);
1519 lstep1[57] = _mm_srai_epi32(v[13], DCT_CONST_BITS);
1520 lstep1[58] = _mm_srai_epi32(v[14], DCT_CONST_BITS);
1521 lstep1[59] = _mm_srai_epi32(v[15], DCT_CONST_BITS);
1522 }
1523 // stage 5
1524 {
1525 lstep2[ 8] = _mm_add_epi32(lstep1[10], lstep3[ 8]);
1526 lstep2[ 9] = _mm_add_epi32(lstep1[11], lstep3[ 9]);
1527 lstep2[10] = _mm_sub_epi32(lstep3[ 8], lstep1[10]);
1528 lstep2[11] = _mm_sub_epi32(lstep3[ 9], lstep1[11]);
1529 lstep2[12] = _mm_sub_epi32(lstep3[14], lstep1[12]);
1530 lstep2[13] = _mm_sub_epi32(lstep3[15], lstep1[13]);
1531 lstep2[14] = _mm_add_epi32(lstep1[12], lstep3[14]);
1532 lstep2[15] = _mm_add_epi32(lstep1[13], lstep3[15]);
1533 }
1534 {
1535 const __m128i k32_p16_p16 = pair_set_epi32(cospi_16_64, cospi_16_64);
1536 const __m128i k32_p16_m16 = pair_set_epi32(cospi_16_64, -cospi_16_64);
1537 const __m128i k32_p24_p08 = pair_set_epi32(cospi_24_64, cospi_8_64);
1538 const __m128i k32_m08_p24 = pair_set_epi32(-cospi_8_64, cospi_24_64);
1539
1540 u[0] = _mm_unpacklo_epi32(lstep1[0], lstep1[2]);
1541 u[1] = _mm_unpackhi_epi32(lstep1[0], lstep1[2]);
1542 u[2] = _mm_unpacklo_epi32(lstep1[1], lstep1[3]);
1543 u[3] = _mm_unpackhi_epi32(lstep1[1], lstep1[3]);
1544 u[4] = _mm_unpacklo_epi32(lstep1[4], lstep1[6]);
1545 u[5] = _mm_unpackhi_epi32(lstep1[4], lstep1[6]);
1546 u[6] = _mm_unpacklo_epi32(lstep1[5], lstep1[7]);
1547 u[7] = _mm_unpackhi_epi32(lstep1[5], lstep1[7]);
1548
1549 // TODO(jingning): manually inline k_madd_epi32_ to further hide
1550 // instruction latency.
1551 v[ 0] = k_madd_epi32(u[0], k32_p16_p16);
1552 v[ 1] = k_madd_epi32(u[1], k32_p16_p16);
1553 v[ 2] = k_madd_epi32(u[2], k32_p16_p16);
1554 v[ 3] = k_madd_epi32(u[3], k32_p16_p16);
1555 v[ 4] = k_madd_epi32(u[0], k32_p16_m16);
1556 v[ 5] = k_madd_epi32(u[1], k32_p16_m16);
1557 v[ 6] = k_madd_epi32(u[2], k32_p16_m16);
1558 v[ 7] = k_madd_epi32(u[3], k32_p16_m16);
1559 v[ 8] = k_madd_epi32(u[4], k32_p24_p08);
1560 v[ 9] = k_madd_epi32(u[5], k32_p24_p08);
1561 v[10] = k_madd_epi32(u[6], k32_p24_p08);
1562 v[11] = k_madd_epi32(u[7], k32_p24_p08);
1563 v[12] = k_madd_epi32(u[4], k32_m08_p24);
1564 v[13] = k_madd_epi32(u[5], k32_m08_p24);
1565 v[14] = k_madd_epi32(u[6], k32_m08_p24);
1566 v[15] = k_madd_epi32(u[7], k32_m08_p24);
1567
1568 u[0] = k_packs_epi64(v[0], v[1]);
1569 u[1] = k_packs_epi64(v[2], v[3]);
1570 u[2] = k_packs_epi64(v[4], v[5]);
1571 u[3] = k_packs_epi64(v[6], v[7]);
1572 u[4] = k_packs_epi64(v[8], v[9]);
1573 u[5] = k_packs_epi64(v[10], v[11]);
1574 u[6] = k_packs_epi64(v[12], v[13]);
1575 u[7] = k_packs_epi64(v[14], v[15]);
1576
1577 v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
1578 v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
1579 v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
1580 v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
1581 v[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
1582 v[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
1583 v[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
1584 v[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
1585
1586 u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
1587 u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
1588 u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
1589 u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
1590 u[4] = _mm_srai_epi32(v[4], DCT_CONST_BITS);
1591 u[5] = _mm_srai_epi32(v[5], DCT_CONST_BITS);
1592 u[6] = _mm_srai_epi32(v[6], DCT_CONST_BITS);
1593 u[7] = _mm_srai_epi32(v[7], DCT_CONST_BITS);
1594
1595 sign[0] = _mm_cmplt_epi32(u[0], kZero);
1596 sign[1] = _mm_cmplt_epi32(u[1], kZero);
1597 sign[2] = _mm_cmplt_epi32(u[2], kZero);
1598 sign[3] = _mm_cmplt_epi32(u[3], kZero);
1599 sign[4] = _mm_cmplt_epi32(u[4], kZero);
1600 sign[5] = _mm_cmplt_epi32(u[5], kZero);
1601 sign[6] = _mm_cmplt_epi32(u[6], kZero);
1602 sign[7] = _mm_cmplt_epi32(u[7], kZero);
1603
1604 u[0] = _mm_sub_epi32(u[0], sign[0]);
1605 u[1] = _mm_sub_epi32(u[1], sign[1]);
1606 u[2] = _mm_sub_epi32(u[2], sign[2]);
1607 u[3] = _mm_sub_epi32(u[3], sign[3]);
1608 u[4] = _mm_sub_epi32(u[4], sign[4]);
1609 u[5] = _mm_sub_epi32(u[5], sign[5]);
1610 u[6] = _mm_sub_epi32(u[6], sign[6]);
1611 u[7] = _mm_sub_epi32(u[7], sign[7]);
1612
1613 u[0] = _mm_add_epi32(u[0], K32One);
1614 u[1] = _mm_add_epi32(u[1], K32One);
1615 u[2] = _mm_add_epi32(u[2], K32One);
1616 u[3] = _mm_add_epi32(u[3], K32One);
1617 u[4] = _mm_add_epi32(u[4], K32One);
1618 u[5] = _mm_add_epi32(u[5], K32One);
1619 u[6] = _mm_add_epi32(u[6], K32One);
1620 u[7] = _mm_add_epi32(u[7], K32One);
1621
1622 u[0] = _mm_srai_epi32(u[0], 2);
1623 u[1] = _mm_srai_epi32(u[1], 2);
1624 u[2] = _mm_srai_epi32(u[2], 2);
1625 u[3] = _mm_srai_epi32(u[3], 2);
1626 u[4] = _mm_srai_epi32(u[4], 2);
1627 u[5] = _mm_srai_epi32(u[5], 2);
1628 u[6] = _mm_srai_epi32(u[6], 2);
1629 u[7] = _mm_srai_epi32(u[7], 2);
1630
1631 // Combine
1632 out[ 0] = _mm_packs_epi32(u[0], u[1]);
1633 out[16] = _mm_packs_epi32(u[2], u[3]);
1634 out[ 8] = _mm_packs_epi32(u[4], u[5]);
1635 out[24] = _mm_packs_epi32(u[6], u[7]);
1636 }
1637 {
1638 const __m128i k32_m08_p24 = pair_set_epi32(-cospi_8_64, cospi_24_64);
1639 const __m128i k32_m24_m08 = pair_set_epi32(-cospi_24_64, -cospi_8_64);
1640 const __m128i k32_p24_p08 = pair_set_epi32(cospi_24_64, cospi_8_64);
1641
1642 u[0] = _mm_unpacklo_epi32(lstep1[18], lstep1[28]);
1643 u[1] = _mm_unpackhi_epi32(lstep1[18], lstep1[28]);
1644 u[2] = _mm_unpacklo_epi32(lstep1[19], lstep1[29]);
1645 u[3] = _mm_unpackhi_epi32(lstep1[19], lstep1[29]);
1646 u[4] = _mm_unpacklo_epi32(lstep1[20], lstep1[26]);
1647 u[5] = _mm_unpackhi_epi32(lstep1[20], lstep1[26]);
1648 u[6] = _mm_unpacklo_epi32(lstep1[21], lstep1[27]);
1649 u[7] = _mm_unpackhi_epi32(lstep1[21], lstep1[27]);
1650
1651 v[0] = k_madd_epi32(u[0], k32_m08_p24);
1652 v[1] = k_madd_epi32(u[1], k32_m08_p24);
1653 v[2] = k_madd_epi32(u[2], k32_m08_p24);
1654 v[3] = k_madd_epi32(u[3], k32_m08_p24);
1655 v[4] = k_madd_epi32(u[4], k32_m24_m08);
1656 v[5] = k_madd_epi32(u[5], k32_m24_m08);
1657 v[6] = k_madd_epi32(u[6], k32_m24_m08);
1658 v[7] = k_madd_epi32(u[7], k32_m24_m08);
1659 v[ 8] = k_madd_epi32(u[4], k32_m08_p24);
1660 v[ 9] = k_madd_epi32(u[5], k32_m08_p24);
1661 v[10] = k_madd_epi32(u[6], k32_m08_p24);
1662 v[11] = k_madd_epi32(u[7], k32_m08_p24);
1663 v[12] = k_madd_epi32(u[0], k32_p24_p08);
1664 v[13] = k_madd_epi32(u[1], k32_p24_p08);
1665 v[14] = k_madd_epi32(u[2], k32_p24_p08);
1666 v[15] = k_madd_epi32(u[3], k32_p24_p08);
1667
1668 u[0] = k_packs_epi64(v[0], v[1]);
1669 u[1] = k_packs_epi64(v[2], v[3]);
1670 u[2] = k_packs_epi64(v[4], v[5]);
1671 u[3] = k_packs_epi64(v[6], v[7]);
1672 u[4] = k_packs_epi64(v[8], v[9]);
1673 u[5] = k_packs_epi64(v[10], v[11]);
1674 u[6] = k_packs_epi64(v[12], v[13]);
1675 u[7] = k_packs_epi64(v[14], v[15]);
1676
1677 u[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
1678 u[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
1679 u[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
1680 u[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
1681 u[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
1682 u[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
1683 u[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
1684 u[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
1685
1686 lstep2[18] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
1687 lstep2[19] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
1688 lstep2[20] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
1689 lstep2[21] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
1690 lstep2[26] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
1691 lstep2[27] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
1692 lstep2[28] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
1693 lstep2[29] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
1694 }
1695 {
1696 lstep2[32] = _mm_add_epi32(lstep1[38], lstep3[32]);
1697 lstep2[33] = _mm_add_epi32(lstep1[39], lstep3[33]);
1698 lstep2[34] = _mm_add_epi32(lstep1[36], lstep3[34]);
1699 lstep2[35] = _mm_add_epi32(lstep1[37], lstep3[35]);
1700 lstep2[36] = _mm_sub_epi32(lstep3[34], lstep1[36]);
1701 lstep2[37] = _mm_sub_epi32(lstep3[35], lstep1[37]);
1702 lstep2[38] = _mm_sub_epi32(lstep3[32], lstep1[38]);
1703 lstep2[39] = _mm_sub_epi32(lstep3[33], lstep1[39]);
1704 lstep2[40] = _mm_sub_epi32(lstep3[46], lstep1[40]);
1705 lstep2[41] = _mm_sub_epi32(lstep3[47], lstep1[41]);
1706 lstep2[42] = _mm_sub_epi32(lstep3[44], lstep1[42]);
1707 lstep2[43] = _mm_sub_epi32(lstep3[45], lstep1[43]);
1708 lstep2[44] = _mm_add_epi32(lstep1[42], lstep3[44]);
1709 lstep2[45] = _mm_add_epi32(lstep1[43], lstep3[45]);
1710 lstep2[46] = _mm_add_epi32(lstep1[40], lstep3[46]);
1711 lstep2[47] = _mm_add_epi32(lstep1[41], lstep3[47]);
1712 lstep2[48] = _mm_add_epi32(lstep1[54], lstep3[48]);
1713 lstep2[49] = _mm_add_epi32(lstep1[55], lstep3[49]);
1714 lstep2[50] = _mm_add_epi32(lstep1[52], lstep3[50]);
1715 lstep2[51] = _mm_add_epi32(lstep1[53], lstep3[51]);
1716 lstep2[52] = _mm_sub_epi32(lstep3[50], lstep1[52]);
1717 lstep2[53] = _mm_sub_epi32(lstep3[51], lstep1[53]);
1718 lstep2[54] = _mm_sub_epi32(lstep3[48], lstep1[54]);
1719 lstep2[55] = _mm_sub_epi32(lstep3[49], lstep1[55]);
1720 lstep2[56] = _mm_sub_epi32(lstep3[62], lstep1[56]);
1721 lstep2[57] = _mm_sub_epi32(lstep3[63], lstep1[57]);
1722 lstep2[58] = _mm_sub_epi32(lstep3[60], lstep1[58]);
1723 lstep2[59] = _mm_sub_epi32(lstep3[61], lstep1[59]);
1724 lstep2[60] = _mm_add_epi32(lstep1[58], lstep3[60]);
1725 lstep2[61] = _mm_add_epi32(lstep1[59], lstep3[61]);
1726 lstep2[62] = _mm_add_epi32(lstep1[56], lstep3[62]);
1727 lstep2[63] = _mm_add_epi32(lstep1[57], lstep3[63]);
1728 }
1729 // stage 6
1730 {
1731 const __m128i k32_p28_p04 = pair_set_epi32(cospi_28_64, cospi_4_64);
1732 const __m128i k32_p12_p20 = pair_set_epi32(cospi_12_64, cospi_20_64);
1733 const __m128i k32_m20_p12 = pair_set_epi32(-cospi_20_64, cospi_12_64);
1734 const __m128i k32_m04_p28 = pair_set_epi32(-cospi_4_64, cospi_28_64);
1735
1736 u[0] = _mm_unpacklo_epi32(lstep2[ 8], lstep2[14]);
1737 u[1] = _mm_unpackhi_epi32(lstep2[ 8], lstep2[14]);
1738 u[2] = _mm_unpacklo_epi32(lstep2[ 9], lstep2[15]);
1739 u[3] = _mm_unpackhi_epi32(lstep2[ 9], lstep2[15]);
1740 u[4] = _mm_unpacklo_epi32(lstep2[10], lstep2[12]);
1741 u[5] = _mm_unpackhi_epi32(lstep2[10], lstep2[12]);
1742 u[6] = _mm_unpacklo_epi32(lstep2[11], lstep2[13]);
1743 u[7] = _mm_unpackhi_epi32(lstep2[11], lstep2[13]);
1744 u[8] = _mm_unpacklo_epi32(lstep2[10], lstep2[12]);
1745 u[9] = _mm_unpackhi_epi32(lstep2[10], lstep2[12]);
1746 u[10] = _mm_unpacklo_epi32(lstep2[11], lstep2[13]);
1747 u[11] = _mm_unpackhi_epi32(lstep2[11], lstep2[13]);
1748 u[12] = _mm_unpacklo_epi32(lstep2[ 8], lstep2[14]);
1749 u[13] = _mm_unpackhi_epi32(lstep2[ 8], lstep2[14]);
1750 u[14] = _mm_unpacklo_epi32(lstep2[ 9], lstep2[15]);
1751 u[15] = _mm_unpackhi_epi32(lstep2[ 9], lstep2[15]);
1752
1753 v[0] = k_madd_epi32(u[0], k32_p28_p04);
1754 v[1] = k_madd_epi32(u[1], k32_p28_p04);
1755 v[2] = k_madd_epi32(u[2], k32_p28_p04);
1756 v[3] = k_madd_epi32(u[3], k32_p28_p04);
1757 v[4] = k_madd_epi32(u[4], k32_p12_p20);
1758 v[5] = k_madd_epi32(u[5], k32_p12_p20);
1759 v[6] = k_madd_epi32(u[6], k32_p12_p20);
1760 v[7] = k_madd_epi32(u[7], k32_p12_p20);
1761 v[ 8] = k_madd_epi32(u[ 8], k32_m20_p12);
1762 v[ 9] = k_madd_epi32(u[ 9], k32_m20_p12);
1763 v[10] = k_madd_epi32(u[10], k32_m20_p12);
1764 v[11] = k_madd_epi32(u[11], k32_m20_p12);
1765 v[12] = k_madd_epi32(u[12], k32_m04_p28);
1766 v[13] = k_madd_epi32(u[13], k32_m04_p28);
1767 v[14] = k_madd_epi32(u[14], k32_m04_p28);
1768 v[15] = k_madd_epi32(u[15], k32_m04_p28);
1769
1770 u[0] = k_packs_epi64(v[0], v[1]);
1771 u[1] = k_packs_epi64(v[2], v[3]);
1772 u[2] = k_packs_epi64(v[4], v[5]);
1773 u[3] = k_packs_epi64(v[6], v[7]);
1774 u[4] = k_packs_epi64(v[8], v[9]);
1775 u[5] = k_packs_epi64(v[10], v[11]);
1776 u[6] = k_packs_epi64(v[12], v[13]);
1777 u[7] = k_packs_epi64(v[14], v[15]);
1778
1779 v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
1780 v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
1781 v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
1782 v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
1783 v[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
1784 v[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
1785 v[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
1786 v[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
1787
1788 u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
1789 u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
1790 u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
1791 u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
1792 u[4] = _mm_srai_epi32(v[4], DCT_CONST_BITS);
1793 u[5] = _mm_srai_epi32(v[5], DCT_CONST_BITS);
1794 u[6] = _mm_srai_epi32(v[6], DCT_CONST_BITS);
1795 u[7] = _mm_srai_epi32(v[7], DCT_CONST_BITS);
1796
1797 sign[0] = _mm_cmplt_epi32(u[0], kZero);
1798 sign[1] = _mm_cmplt_epi32(u[1], kZero);
1799 sign[2] = _mm_cmplt_epi32(u[2], kZero);
1800 sign[3] = _mm_cmplt_epi32(u[3], kZero);
1801 sign[4] = _mm_cmplt_epi32(u[4], kZero);
1802 sign[5] = _mm_cmplt_epi32(u[5], kZero);
1803 sign[6] = _mm_cmplt_epi32(u[6], kZero);
1804 sign[7] = _mm_cmplt_epi32(u[7], kZero);
1805
1806 u[0] = _mm_sub_epi32(u[0], sign[0]);
1807 u[1] = _mm_sub_epi32(u[1], sign[1]);
1808 u[2] = _mm_sub_epi32(u[2], sign[2]);
1809 u[3] = _mm_sub_epi32(u[3], sign[3]);
1810 u[4] = _mm_sub_epi32(u[4], sign[4]);
1811 u[5] = _mm_sub_epi32(u[5], sign[5]);
1812 u[6] = _mm_sub_epi32(u[6], sign[6]);
1813 u[7] = _mm_sub_epi32(u[7], sign[7]);
1814
1815 u[0] = _mm_add_epi32(u[0], K32One);
1816 u[1] = _mm_add_epi32(u[1], K32One);
1817 u[2] = _mm_add_epi32(u[2], K32One);
1818 u[3] = _mm_add_epi32(u[3], K32One);
1819 u[4] = _mm_add_epi32(u[4], K32One);
1820 u[5] = _mm_add_epi32(u[5], K32One);
1821 u[6] = _mm_add_epi32(u[6], K32One);
1822 u[7] = _mm_add_epi32(u[7], K32One);
1823
1824 u[0] = _mm_srai_epi32(u[0], 2);
1825 u[1] = _mm_srai_epi32(u[1], 2);
1826 u[2] = _mm_srai_epi32(u[2], 2);
1827 u[3] = _mm_srai_epi32(u[3], 2);
1828 u[4] = _mm_srai_epi32(u[4], 2);
1829 u[5] = _mm_srai_epi32(u[5], 2);
1830 u[6] = _mm_srai_epi32(u[6], 2);
1831 u[7] = _mm_srai_epi32(u[7], 2);
1832
1833 out[ 4] = _mm_packs_epi32(u[0], u[1]);
1834 out[20] = _mm_packs_epi32(u[2], u[3]);
1835 out[12] = _mm_packs_epi32(u[4], u[5]);
1836 out[28] = _mm_packs_epi32(u[6], u[7]);
1837 }
1838 {
1839 lstep3[16] = _mm_add_epi32(lstep2[18], lstep1[16]);
1840 lstep3[17] = _mm_add_epi32(lstep2[19], lstep1[17]);
1841 lstep3[18] = _mm_sub_epi32(lstep1[16], lstep2[18]);
1842 lstep3[19] = _mm_sub_epi32(lstep1[17], lstep2[19]);
1843 lstep3[20] = _mm_sub_epi32(lstep1[22], lstep2[20]);
1844 lstep3[21] = _mm_sub_epi32(lstep1[23], lstep2[21]);
1845 lstep3[22] = _mm_add_epi32(lstep2[20], lstep1[22]);
1846 lstep3[23] = _mm_add_epi32(lstep2[21], lstep1[23]);
1847 lstep3[24] = _mm_add_epi32(lstep2[26], lstep1[24]);
1848 lstep3[25] = _mm_add_epi32(lstep2[27], lstep1[25]);
1849 lstep3[26] = _mm_sub_epi32(lstep1[24], lstep2[26]);
1850 lstep3[27] = _mm_sub_epi32(lstep1[25], lstep2[27]);
1851 lstep3[28] = _mm_sub_epi32(lstep1[30], lstep2[28]);
1852 lstep3[29] = _mm_sub_epi32(lstep1[31], lstep2[29]);
1853 lstep3[30] = _mm_add_epi32(lstep2[28], lstep1[30]);
1854 lstep3[31] = _mm_add_epi32(lstep2[29], lstep1[31]);
1855 }
1856 {
1857 const __m128i k32_m04_p28 = pair_set_epi32(-cospi_4_64, cospi_28_64);
1858 const __m128i k32_m28_m04 = pair_set_epi32(-cospi_28_64, -cospi_4_64);
1859 const __m128i k32_m20_p12 = pair_set_epi32(-cospi_20_64, cospi_12_64);
1860 const __m128i k32_m12_m20 = pair_set_epi32(-cospi_12_64,
1861 -cospi_20_64);
1862 const __m128i k32_p12_p20 = pair_set_epi32(cospi_12_64, cospi_20_64);
1863 const __m128i k32_p28_p04 = pair_set_epi32(cospi_28_64, cospi_4_64);
1864
1865 u[ 0] = _mm_unpacklo_epi32(lstep2[34], lstep2[60]);
1866 u[ 1] = _mm_unpackhi_epi32(lstep2[34], lstep2[60]);
1867 u[ 2] = _mm_unpacklo_epi32(lstep2[35], lstep2[61]);
1868 u[ 3] = _mm_unpackhi_epi32(lstep2[35], lstep2[61]);
1869 u[ 4] = _mm_unpacklo_epi32(lstep2[36], lstep2[58]);
1870 u[ 5] = _mm_unpackhi_epi32(lstep2[36], lstep2[58]);
1871 u[ 6] = _mm_unpacklo_epi32(lstep2[37], lstep2[59]);
1872 u[ 7] = _mm_unpackhi_epi32(lstep2[37], lstep2[59]);
1873 u[ 8] = _mm_unpacklo_epi32(lstep2[42], lstep2[52]);
1874 u[ 9] = _mm_unpackhi_epi32(lstep2[42], lstep2[52]);
1875 u[10] = _mm_unpacklo_epi32(lstep2[43], lstep2[53]);
1876 u[11] = _mm_unpackhi_epi32(lstep2[43], lstep2[53]);
1877 u[12] = _mm_unpacklo_epi32(lstep2[44], lstep2[50]);
1878 u[13] = _mm_unpackhi_epi32(lstep2[44], lstep2[50]);
1879 u[14] = _mm_unpacklo_epi32(lstep2[45], lstep2[51]);
1880 u[15] = _mm_unpackhi_epi32(lstep2[45], lstep2[51]);
1881
1882 v[ 0] = k_madd_epi32(u[ 0], k32_m04_p28);
1883 v[ 1] = k_madd_epi32(u[ 1], k32_m04_p28);
1884 v[ 2] = k_madd_epi32(u[ 2], k32_m04_p28);
1885 v[ 3] = k_madd_epi32(u[ 3], k32_m04_p28);
1886 v[ 4] = k_madd_epi32(u[ 4], k32_m28_m04);
1887 v[ 5] = k_madd_epi32(u[ 5], k32_m28_m04);
1888 v[ 6] = k_madd_epi32(u[ 6], k32_m28_m04);
1889 v[ 7] = k_madd_epi32(u[ 7], k32_m28_m04);
1890 v[ 8] = k_madd_epi32(u[ 8], k32_m20_p12);
1891 v[ 9] = k_madd_epi32(u[ 9], k32_m20_p12);
1892 v[10] = k_madd_epi32(u[10], k32_m20_p12);
1893 v[11] = k_madd_epi32(u[11], k32_m20_p12);
1894 v[12] = k_madd_epi32(u[12], k32_m12_m20);
1895 v[13] = k_madd_epi32(u[13], k32_m12_m20);
1896 v[14] = k_madd_epi32(u[14], k32_m12_m20);
1897 v[15] = k_madd_epi32(u[15], k32_m12_m20);
1898 v[16] = k_madd_epi32(u[12], k32_m20_p12);
1899 v[17] = k_madd_epi32(u[13], k32_m20_p12);
1900 v[18] = k_madd_epi32(u[14], k32_m20_p12);
1901 v[19] = k_madd_epi32(u[15], k32_m20_p12);
1902 v[20] = k_madd_epi32(u[ 8], k32_p12_p20);
1903 v[21] = k_madd_epi32(u[ 9], k32_p12_p20);
1904 v[22] = k_madd_epi32(u[10], k32_p12_p20);
1905 v[23] = k_madd_epi32(u[11], k32_p12_p20);
1906 v[24] = k_madd_epi32(u[ 4], k32_m04_p28);
1907 v[25] = k_madd_epi32(u[ 5], k32_m04_p28);
1908 v[26] = k_madd_epi32(u[ 6], k32_m04_p28);
1909 v[27] = k_madd_epi32(u[ 7], k32_m04_p28);
1910 v[28] = k_madd_epi32(u[ 0], k32_p28_p04);
1911 v[29] = k_madd_epi32(u[ 1], k32_p28_p04);
1912 v[30] = k_madd_epi32(u[ 2], k32_p28_p04);
1913 v[31] = k_madd_epi32(u[ 3], k32_p28_p04);
1914
1915 u[ 0] = k_packs_epi64(v[ 0], v[ 1]);
1916 u[ 1] = k_packs_epi64(v[ 2], v[ 3]);
1917 u[ 2] = k_packs_epi64(v[ 4], v[ 5]);
1918 u[ 3] = k_packs_epi64(v[ 6], v[ 7]);
1919 u[ 4] = k_packs_epi64(v[ 8], v[ 9]);
1920 u[ 5] = k_packs_epi64(v[10], v[11]);
1921 u[ 6] = k_packs_epi64(v[12], v[13]);
1922 u[ 7] = k_packs_epi64(v[14], v[15]);
1923 u[ 8] = k_packs_epi64(v[16], v[17]);
1924 u[ 9] = k_packs_epi64(v[18], v[19]);
1925 u[10] = k_packs_epi64(v[20], v[21]);
1926 u[11] = k_packs_epi64(v[22], v[23]);
1927 u[12] = k_packs_epi64(v[24], v[25]);
1928 u[13] = k_packs_epi64(v[26], v[27]);
1929 u[14] = k_packs_epi64(v[28], v[29]);
1930 u[15] = k_packs_epi64(v[30], v[31]);
1931
1932 v[ 0] = _mm_add_epi32(u[ 0], k__DCT_CONST_ROUNDING);
1933 v[ 1] = _mm_add_epi32(u[ 1], k__DCT_CONST_ROUNDING);
1934 v[ 2] = _mm_add_epi32(u[ 2], k__DCT_CONST_ROUNDING);
1935 v[ 3] = _mm_add_epi32(u[ 3], k__DCT_CONST_ROUNDING);
1936 v[ 4] = _mm_add_epi32(u[ 4], k__DCT_CONST_ROUNDING);
1937 v[ 5] = _mm_add_epi32(u[ 5], k__DCT_CONST_ROUNDING);
1938 v[ 6] = _mm_add_epi32(u[ 6], k__DCT_CONST_ROUNDING);
1939 v[ 7] = _mm_add_epi32(u[ 7], k__DCT_CONST_ROUNDING);
1940 v[ 8] = _mm_add_epi32(u[ 8], k__DCT_CONST_ROUNDING);
1941 v[ 9] = _mm_add_epi32(u[ 9], k__DCT_CONST_ROUNDING);
1942 v[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
1943 v[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
1944 v[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
1945 v[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
1946 v[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
1947 v[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
1948
1949 lstep3[34] = _mm_srai_epi32(v[ 0], DCT_CONST_BITS);
1950 lstep3[35] = _mm_srai_epi32(v[ 1], DCT_CONST_BITS);
1951 lstep3[36] = _mm_srai_epi32(v[ 2], DCT_CONST_BITS);
1952 lstep3[37] = _mm_srai_epi32(v[ 3], DCT_CONST_BITS);
1953 lstep3[42] = _mm_srai_epi32(v[ 4], DCT_CONST_BITS);
1954 lstep3[43] = _mm_srai_epi32(v[ 5], DCT_CONST_BITS);
1955 lstep3[44] = _mm_srai_epi32(v[ 6], DCT_CONST_BITS);
1956 lstep3[45] = _mm_srai_epi32(v[ 7], DCT_CONST_BITS);
1957 lstep3[50] = _mm_srai_epi32(v[ 8], DCT_CONST_BITS);
1958 lstep3[51] = _mm_srai_epi32(v[ 9], DCT_CONST_BITS);
1959 lstep3[52] = _mm_srai_epi32(v[10], DCT_CONST_BITS);
1960 lstep3[53] = _mm_srai_epi32(v[11], DCT_CONST_BITS);
1961 lstep3[58] = _mm_srai_epi32(v[12], DCT_CONST_BITS);
1962 lstep3[59] = _mm_srai_epi32(v[13], DCT_CONST_BITS);
1963 lstep3[60] = _mm_srai_epi32(v[14], DCT_CONST_BITS);
1964 lstep3[61] = _mm_srai_epi32(v[15], DCT_CONST_BITS);
1965 }
1966 // stage 7
1967 {
1968 const __m128i k32_p30_p02 = pair_set_epi32(cospi_30_64, cospi_2_64);
1969 const __m128i k32_p14_p18 = pair_set_epi32(cospi_14_64, cospi_18_64);
1970 const __m128i k32_p22_p10 = pair_set_epi32(cospi_22_64, cospi_10_64);
1971 const __m128i k32_p06_p26 = pair_set_epi32(cospi_6_64, cospi_26_64);
1972 const __m128i k32_m26_p06 = pair_set_epi32(-cospi_26_64, cospi_6_64);
1973 const __m128i k32_m10_p22 = pair_set_epi32(-cospi_10_64, cospi_22_64);
1974 const __m128i k32_m18_p14 = pair_set_epi32(-cospi_18_64, cospi_14_64);
1975 const __m128i k32_m02_p30 = pair_set_epi32(-cospi_2_64, cospi_30_64);
1976
1977 u[ 0] = _mm_unpacklo_epi32(lstep3[16], lstep3[30]);
1978 u[ 1] = _mm_unpackhi_epi32(lstep3[16], lstep3[30]);
1979 u[ 2] = _mm_unpacklo_epi32(lstep3[17], lstep3[31]);
1980 u[ 3] = _mm_unpackhi_epi32(lstep3[17], lstep3[31]);
1981 u[ 4] = _mm_unpacklo_epi32(lstep3[18], lstep3[28]);
1982 u[ 5] = _mm_unpackhi_epi32(lstep3[18], lstep3[28]);
1983 u[ 6] = _mm_unpacklo_epi32(lstep3[19], lstep3[29]);
1984 u[ 7] = _mm_unpackhi_epi32(lstep3[19], lstep3[29]);
1985 u[ 8] = _mm_unpacklo_epi32(lstep3[20], lstep3[26]);
1986 u[ 9] = _mm_unpackhi_epi32(lstep3[20], lstep3[26]);
1987 u[10] = _mm_unpacklo_epi32(lstep3[21], lstep3[27]);
1988 u[11] = _mm_unpackhi_epi32(lstep3[21], lstep3[27]);
1989 u[12] = _mm_unpacklo_epi32(lstep3[22], lstep3[24]);
1990 u[13] = _mm_unpackhi_epi32(lstep3[22], lstep3[24]);
1991 u[14] = _mm_unpacklo_epi32(lstep3[23], lstep3[25]);
1992 u[15] = _mm_unpackhi_epi32(lstep3[23], lstep3[25]);
1993
1994 v[ 0] = k_madd_epi32(u[ 0], k32_p30_p02);
1995 v[ 1] = k_madd_epi32(u[ 1], k32_p30_p02);
1996 v[ 2] = k_madd_epi32(u[ 2], k32_p30_p02);
1997 v[ 3] = k_madd_epi32(u[ 3], k32_p30_p02);
1998 v[ 4] = k_madd_epi32(u[ 4], k32_p14_p18);
1999 v[ 5] = k_madd_epi32(u[ 5], k32_p14_p18);
2000 v[ 6] = k_madd_epi32(u[ 6], k32_p14_p18);
2001 v[ 7] = k_madd_epi32(u[ 7], k32_p14_p18);
2002 v[ 8] = k_madd_epi32(u[ 8], k32_p22_p10);
2003 v[ 9] = k_madd_epi32(u[ 9], k32_p22_p10);
2004 v[10] = k_madd_epi32(u[10], k32_p22_p10);
2005 v[11] = k_madd_epi32(u[11], k32_p22_p10);
2006 v[12] = k_madd_epi32(u[12], k32_p06_p26);
2007 v[13] = k_madd_epi32(u[13], k32_p06_p26);
2008 v[14] = k_madd_epi32(u[14], k32_p06_p26);
2009 v[15] = k_madd_epi32(u[15], k32_p06_p26);
2010 v[16] = k_madd_epi32(u[12], k32_m26_p06);
2011 v[17] = k_madd_epi32(u[13], k32_m26_p06);
2012 v[18] = k_madd_epi32(u[14], k32_m26_p06);
2013 v[19] = k_madd_epi32(u[15], k32_m26_p06);
2014 v[20] = k_madd_epi32(u[ 8], k32_m10_p22);
2015 v[21] = k_madd_epi32(u[ 9], k32_m10_p22);
2016 v[22] = k_madd_epi32(u[10], k32_m10_p22);
2017 v[23] = k_madd_epi32(u[11], k32_m10_p22);
2018 v[24] = k_madd_epi32(u[ 4], k32_m18_p14);
2019 v[25] = k_madd_epi32(u[ 5], k32_m18_p14);
2020 v[26] = k_madd_epi32(u[ 6], k32_m18_p14);
2021 v[27] = k_madd_epi32(u[ 7], k32_m18_p14);
2022 v[28] = k_madd_epi32(u[ 0], k32_m02_p30);
2023 v[29] = k_madd_epi32(u[ 1], k32_m02_p30);
2024 v[30] = k_madd_epi32(u[ 2], k32_m02_p30);
2025 v[31] = k_madd_epi32(u[ 3], k32_m02_p30);
2026
2027 u[ 0] = k_packs_epi64(v[ 0], v[ 1]);
2028 u[ 1] = k_packs_epi64(v[ 2], v[ 3]);
2029 u[ 2] = k_packs_epi64(v[ 4], v[ 5]);
2030 u[ 3] = k_packs_epi64(v[ 6], v[ 7]);
2031 u[ 4] = k_packs_epi64(v[ 8], v[ 9]);
2032 u[ 5] = k_packs_epi64(v[10], v[11]);
2033 u[ 6] = k_packs_epi64(v[12], v[13]);
2034 u[ 7] = k_packs_epi64(v[14], v[15]);
2035 u[ 8] = k_packs_epi64(v[16], v[17]);
2036 u[ 9] = k_packs_epi64(v[18], v[19]);
2037 u[10] = k_packs_epi64(v[20], v[21]);
2038 u[11] = k_packs_epi64(v[22], v[23]);
2039 u[12] = k_packs_epi64(v[24], v[25]);
2040 u[13] = k_packs_epi64(v[26], v[27]);
2041 u[14] = k_packs_epi64(v[28], v[29]);
2042 u[15] = k_packs_epi64(v[30], v[31]);
2043
2044 v[ 0] = _mm_add_epi32(u[ 0], k__DCT_CONST_ROUNDING);
2045 v[ 1] = _mm_add_epi32(u[ 1], k__DCT_CONST_ROUNDING);
2046 v[ 2] = _mm_add_epi32(u[ 2], k__DCT_CONST_ROUNDING);
2047 v[ 3] = _mm_add_epi32(u[ 3], k__DCT_CONST_ROUNDING);
2048 v[ 4] = _mm_add_epi32(u[ 4], k__DCT_CONST_ROUNDING);
2049 v[ 5] = _mm_add_epi32(u[ 5], k__DCT_CONST_ROUNDING);
2050 v[ 6] = _mm_add_epi32(u[ 6], k__DCT_CONST_ROUNDING);
2051 v[ 7] = _mm_add_epi32(u[ 7], k__DCT_CONST_ROUNDING);
2052 v[ 8] = _mm_add_epi32(u[ 8], k__DCT_CONST_ROUNDING);
2053 v[ 9] = _mm_add_epi32(u[ 9], k__DCT_CONST_ROUNDING);
2054 v[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
2055 v[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
2056 v[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
2057 v[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
2058 v[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
2059 v[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
2060
2061 u[ 0] = _mm_srai_epi32(v[ 0], DCT_CONST_BITS);
2062 u[ 1] = _mm_srai_epi32(v[ 1], DCT_CONST_BITS);
2063 u[ 2] = _mm_srai_epi32(v[ 2], DCT_CONST_BITS);
2064 u[ 3] = _mm_srai_epi32(v[ 3], DCT_CONST_BITS);
2065 u[ 4] = _mm_srai_epi32(v[ 4], DCT_CONST_BITS);
2066 u[ 5] = _mm_srai_epi32(v[ 5], DCT_CONST_BITS);
2067 u[ 6] = _mm_srai_epi32(v[ 6], DCT_CONST_BITS);
2068 u[ 7] = _mm_srai_epi32(v[ 7], DCT_CONST_BITS);
2069 u[ 8] = _mm_srai_epi32(v[ 8], DCT_CONST_BITS);
2070 u[ 9] = _mm_srai_epi32(v[ 9], DCT_CONST_BITS);
2071 u[10] = _mm_srai_epi32(v[10], DCT_CONST_BITS);
2072 u[11] = _mm_srai_epi32(v[11], DCT_CONST_BITS);
2073 u[12] = _mm_srai_epi32(v[12], DCT_CONST_BITS);
2074 u[13] = _mm_srai_epi32(v[13], DCT_CONST_BITS);
2075 u[14] = _mm_srai_epi32(v[14], DCT_CONST_BITS);
2076 u[15] = _mm_srai_epi32(v[15], DCT_CONST_BITS);
2077
2078 v[ 0] = _mm_cmplt_epi32(u[ 0], kZero);
2079 v[ 1] = _mm_cmplt_epi32(u[ 1], kZero);
2080 v[ 2] = _mm_cmplt_epi32(u[ 2], kZero);
2081 v[ 3] = _mm_cmplt_epi32(u[ 3], kZero);
2082 v[ 4] = _mm_cmplt_epi32(u[ 4], kZero);
2083 v[ 5] = _mm_cmplt_epi32(u[ 5], kZero);
2084 v[ 6] = _mm_cmplt_epi32(u[ 6], kZero);
2085 v[ 7] = _mm_cmplt_epi32(u[ 7], kZero);
2086 v[ 8] = _mm_cmplt_epi32(u[ 8], kZero);
2087 v[ 9] = _mm_cmplt_epi32(u[ 9], kZero);
2088 v[10] = _mm_cmplt_epi32(u[10], kZero);
2089 v[11] = _mm_cmplt_epi32(u[11], kZero);
2090 v[12] = _mm_cmplt_epi32(u[12], kZero);
2091 v[13] = _mm_cmplt_epi32(u[13], kZero);
2092 v[14] = _mm_cmplt_epi32(u[14], kZero);
2093 v[15] = _mm_cmplt_epi32(u[15], kZero);
2094
2095 u[ 0] = _mm_sub_epi32(u[ 0], v[ 0]);
2096 u[ 1] = _mm_sub_epi32(u[ 1], v[ 1]);
2097 u[ 2] = _mm_sub_epi32(u[ 2], v[ 2]);
2098 u[ 3] = _mm_sub_epi32(u[ 3], v[ 3]);
2099 u[ 4] = _mm_sub_epi32(u[ 4], v[ 4]);
2100 u[ 5] = _mm_sub_epi32(u[ 5], v[ 5]);
2101 u[ 6] = _mm_sub_epi32(u[ 6], v[ 6]);
2102 u[ 7] = _mm_sub_epi32(u[ 7], v[ 7]);
2103 u[ 8] = _mm_sub_epi32(u[ 8], v[ 8]);
2104 u[ 9] = _mm_sub_epi32(u[ 9], v[ 9]);
2105 u[10] = _mm_sub_epi32(u[10], v[10]);
2106 u[11] = _mm_sub_epi32(u[11], v[11]);
2107 u[12] = _mm_sub_epi32(u[12], v[12]);
2108 u[13] = _mm_sub_epi32(u[13], v[13]);
2109 u[14] = _mm_sub_epi32(u[14], v[14]);
2110 u[15] = _mm_sub_epi32(u[15], v[15]);
2111
2112 v[ 0] = _mm_add_epi32(u[ 0], K32One);
2113 v[ 1] = _mm_add_epi32(u[ 1], K32One);
2114 v[ 2] = _mm_add_epi32(u[ 2], K32One);
2115 v[ 3] = _mm_add_epi32(u[ 3], K32One);
2116 v[ 4] = _mm_add_epi32(u[ 4], K32One);
2117 v[ 5] = _mm_add_epi32(u[ 5], K32One);
2118 v[ 6] = _mm_add_epi32(u[ 6], K32One);
2119 v[ 7] = _mm_add_epi32(u[ 7], K32One);
2120 v[ 8] = _mm_add_epi32(u[ 8], K32One);
2121 v[ 9] = _mm_add_epi32(u[ 9], K32One);
2122 v[10] = _mm_add_epi32(u[10], K32One);
2123 v[11] = _mm_add_epi32(u[11], K32One);
2124 v[12] = _mm_add_epi32(u[12], K32One);
2125 v[13] = _mm_add_epi32(u[13], K32One);
2126 v[14] = _mm_add_epi32(u[14], K32One);
2127 v[15] = _mm_add_epi32(u[15], K32One);
2128
2129 u[ 0] = _mm_srai_epi32(v[ 0], 2);
2130 u[ 1] = _mm_srai_epi32(v[ 1], 2);
2131 u[ 2] = _mm_srai_epi32(v[ 2], 2);
2132 u[ 3] = _mm_srai_epi32(v[ 3], 2);
2133 u[ 4] = _mm_srai_epi32(v[ 4], 2);
2134 u[ 5] = _mm_srai_epi32(v[ 5], 2);
2135 u[ 6] = _mm_srai_epi32(v[ 6], 2);
2136 u[ 7] = _mm_srai_epi32(v[ 7], 2);
2137 u[ 8] = _mm_srai_epi32(v[ 8], 2);
2138 u[ 9] = _mm_srai_epi32(v[ 9], 2);
2139 u[10] = _mm_srai_epi32(v[10], 2);
2140 u[11] = _mm_srai_epi32(v[11], 2);
2141 u[12] = _mm_srai_epi32(v[12], 2);
2142 u[13] = _mm_srai_epi32(v[13], 2);
2143 u[14] = _mm_srai_epi32(v[14], 2);
2144 u[15] = _mm_srai_epi32(v[15], 2);
2145
2146 out[ 2] = _mm_packs_epi32(u[0], u[1]);
2147 out[18] = _mm_packs_epi32(u[2], u[3]);
2148 out[10] = _mm_packs_epi32(u[4], u[5]);
2149 out[26] = _mm_packs_epi32(u[6], u[7]);
2150 out[ 6] = _mm_packs_epi32(u[8], u[9]);
2151 out[22] = _mm_packs_epi32(u[10], u[11]);
2152 out[14] = _mm_packs_epi32(u[12], u[13]);
2153 out[30] = _mm_packs_epi32(u[14], u[15]);
2154 }
2155 {
2156 lstep1[32] = _mm_add_epi32(lstep3[34], lstep2[32]);
2157 lstep1[33] = _mm_add_epi32(lstep3[35], lstep2[33]);
2158 lstep1[34] = _mm_sub_epi32(lstep2[32], lstep3[34]);
2159 lstep1[35] = _mm_sub_epi32(lstep2[33], lstep3[35]);
2160 lstep1[36] = _mm_sub_epi32(lstep2[38], lstep3[36]);
2161 lstep1[37] = _mm_sub_epi32(lstep2[39], lstep3[37]);
2162 lstep1[38] = _mm_add_epi32(lstep3[36], lstep2[38]);
2163 lstep1[39] = _mm_add_epi32(lstep3[37], lstep2[39]);
2164 lstep1[40] = _mm_add_epi32(lstep3[42], lstep2[40]);
2165 lstep1[41] = _mm_add_epi32(lstep3[43], lstep2[41]);
2166 lstep1[42] = _mm_sub_epi32(lstep2[40], lstep3[42]);
2167 lstep1[43] = _mm_sub_epi32(lstep2[41], lstep3[43]);
2168 lstep1[44] = _mm_sub_epi32(lstep2[46], lstep3[44]);
2169 lstep1[45] = _mm_sub_epi32(lstep2[47], lstep3[45]);
2170 lstep1[46] = _mm_add_epi32(lstep3[44], lstep2[46]);
2171 lstep1[47] = _mm_add_epi32(lstep3[45], lstep2[47]);
2172 lstep1[48] = _mm_add_epi32(lstep3[50], lstep2[48]);
2173 lstep1[49] = _mm_add_epi32(lstep3[51], lstep2[49]);
2174 lstep1[50] = _mm_sub_epi32(lstep2[48], lstep3[50]);
2175 lstep1[51] = _mm_sub_epi32(lstep2[49], lstep3[51]);
2176 lstep1[52] = _mm_sub_epi32(lstep2[54], lstep3[52]);
2177 lstep1[53] = _mm_sub_epi32(lstep2[55], lstep3[53]);
2178 lstep1[54] = _mm_add_epi32(lstep3[52], lstep2[54]);
2179 lstep1[55] = _mm_add_epi32(lstep3[53], lstep2[55]);
2180 lstep1[56] = _mm_add_epi32(lstep3[58], lstep2[56]);
2181 lstep1[57] = _mm_add_epi32(lstep3[59], lstep2[57]);
2182 lstep1[58] = _mm_sub_epi32(lstep2[56], lstep3[58]);
2183 lstep1[59] = _mm_sub_epi32(lstep2[57], lstep3[59]);
2184 lstep1[60] = _mm_sub_epi32(lstep2[62], lstep3[60]);
2185 lstep1[61] = _mm_sub_epi32(lstep2[63], lstep3[61]);
2186 lstep1[62] = _mm_add_epi32(lstep3[60], lstep2[62]);
2187 lstep1[63] = _mm_add_epi32(lstep3[61], lstep2[63]);
2188 }
2189 // stage 8
2190 {
2191 const __m128i k32_p31_p01 = pair_set_epi32(cospi_31_64, cospi_1_64);
2192 const __m128i k32_p15_p17 = pair_set_epi32(cospi_15_64, cospi_17_64);
2193 const __m128i k32_p23_p09 = pair_set_epi32(cospi_23_64, cospi_9_64);
2194 const __m128i k32_p07_p25 = pair_set_epi32(cospi_7_64, cospi_25_64);
2195 const __m128i k32_m25_p07 = pair_set_epi32(-cospi_25_64, cospi_7_64);
2196 const __m128i k32_m09_p23 = pair_set_epi32(-cospi_9_64, cospi_23_64);
2197 const __m128i k32_m17_p15 = pair_set_epi32(-cospi_17_64, cospi_15_64);
2198 const __m128i k32_m01_p31 = pair_set_epi32(-cospi_1_64, cospi_31_64);
2199
2200 u[ 0] = _mm_unpacklo_epi32(lstep1[32], lstep1[62]);
2201 u[ 1] = _mm_unpackhi_epi32(lstep1[32], lstep1[62]);
2202 u[ 2] = _mm_unpacklo_epi32(lstep1[33], lstep1[63]);
2203 u[ 3] = _mm_unpackhi_epi32(lstep1[33], lstep1[63]);
2204 u[ 4] = _mm_unpacklo_epi32(lstep1[34], lstep1[60]);
2205 u[ 5] = _mm_unpackhi_epi32(lstep1[34], lstep1[60]);
2206 u[ 6] = _mm_unpacklo_epi32(lstep1[35], lstep1[61]);
2207 u[ 7] = _mm_unpackhi_epi32(lstep1[35], lstep1[61]);
2208 u[ 8] = _mm_unpacklo_epi32(lstep1[36], lstep1[58]);
2209 u[ 9] = _mm_unpackhi_epi32(lstep1[36], lstep1[58]);
2210 u[10] = _mm_unpacklo_epi32(lstep1[37], lstep1[59]);
2211 u[11] = _mm_unpackhi_epi32(lstep1[37], lstep1[59]);
2212 u[12] = _mm_unpacklo_epi32(lstep1[38], lstep1[56]);
2213 u[13] = _mm_unpackhi_epi32(lstep1[38], lstep1[56]);
2214 u[14] = _mm_unpacklo_epi32(lstep1[39], lstep1[57]);
2215 u[15] = _mm_unpackhi_epi32(lstep1[39], lstep1[57]);
2216
2217 v[ 0] = k_madd_epi32(u[ 0], k32_p31_p01);
2218 v[ 1] = k_madd_epi32(u[ 1], k32_p31_p01);
2219 v[ 2] = k_madd_epi32(u[ 2], k32_p31_p01);
2220 v[ 3] = k_madd_epi32(u[ 3], k32_p31_p01);
2221 v[ 4] = k_madd_epi32(u[ 4], k32_p15_p17);
2222 v[ 5] = k_madd_epi32(u[ 5], k32_p15_p17);
2223 v[ 6] = k_madd_epi32(u[ 6], k32_p15_p17);
2224 v[ 7] = k_madd_epi32(u[ 7], k32_p15_p17);
2225 v[ 8] = k_madd_epi32(u[ 8], k32_p23_p09);
2226 v[ 9] = k_madd_epi32(u[ 9], k32_p23_p09);
2227 v[10] = k_madd_epi32(u[10], k32_p23_p09);
2228 v[11] = k_madd_epi32(u[11], k32_p23_p09);
2229 v[12] = k_madd_epi32(u[12], k32_p07_p25);
2230 v[13] = k_madd_epi32(u[13], k32_p07_p25);
2231 v[14] = k_madd_epi32(u[14], k32_p07_p25);
2232 v[15] = k_madd_epi32(u[15], k32_p07_p25);
2233 v[16] = k_madd_epi32(u[12], k32_m25_p07);
2234 v[17] = k_madd_epi32(u[13], k32_m25_p07);
2235 v[18] = k_madd_epi32(u[14], k32_m25_p07);
2236 v[19] = k_madd_epi32(u[15], k32_m25_p07);
2237 v[20] = k_madd_epi32(u[ 8], k32_m09_p23);
2238 v[21] = k_madd_epi32(u[ 9], k32_m09_p23);
2239 v[22] = k_madd_epi32(u[10], k32_m09_p23);
2240 v[23] = k_madd_epi32(u[11], k32_m09_p23);
2241 v[24] = k_madd_epi32(u[ 4], k32_m17_p15);
2242 v[25] = k_madd_epi32(u[ 5], k32_m17_p15);
2243 v[26] = k_madd_epi32(u[ 6], k32_m17_p15);
2244 v[27] = k_madd_epi32(u[ 7], k32_m17_p15);
2245 v[28] = k_madd_epi32(u[ 0], k32_m01_p31);
2246 v[29] = k_madd_epi32(u[ 1], k32_m01_p31);
2247 v[30] = k_madd_epi32(u[ 2], k32_m01_p31);
2248 v[31] = k_madd_epi32(u[ 3], k32_m01_p31);
2249
2250 u[ 0] = k_packs_epi64(v[ 0], v[ 1]);
2251 u[ 1] = k_packs_epi64(v[ 2], v[ 3]);
2252 u[ 2] = k_packs_epi64(v[ 4], v[ 5]);
2253 u[ 3] = k_packs_epi64(v[ 6], v[ 7]);
2254 u[ 4] = k_packs_epi64(v[ 8], v[ 9]);
2255 u[ 5] = k_packs_epi64(v[10], v[11]);
2256 u[ 6] = k_packs_epi64(v[12], v[13]);
2257 u[ 7] = k_packs_epi64(v[14], v[15]);
2258 u[ 8] = k_packs_epi64(v[16], v[17]);
2259 u[ 9] = k_packs_epi64(v[18], v[19]);
2260 u[10] = k_packs_epi64(v[20], v[21]);
2261 u[11] = k_packs_epi64(v[22], v[23]);
2262 u[12] = k_packs_epi64(v[24], v[25]);
2263 u[13] = k_packs_epi64(v[26], v[27]);
2264 u[14] = k_packs_epi64(v[28], v[29]);
2265 u[15] = k_packs_epi64(v[30], v[31]);
2266
2267 v[ 0] = _mm_add_epi32(u[ 0], k__DCT_CONST_ROUNDING);
2268 v[ 1] = _mm_add_epi32(u[ 1], k__DCT_CONST_ROUNDING);
2269 v[ 2] = _mm_add_epi32(u[ 2], k__DCT_CONST_ROUNDING);
2270 v[ 3] = _mm_add_epi32(u[ 3], k__DCT_CONST_ROUNDING);
2271 v[ 4] = _mm_add_epi32(u[ 4], k__DCT_CONST_ROUNDING);
2272 v[ 5] = _mm_add_epi32(u[ 5], k__DCT_CONST_ROUNDING);
2273 v[ 6] = _mm_add_epi32(u[ 6], k__DCT_CONST_ROUNDING);
2274 v[ 7] = _mm_add_epi32(u[ 7], k__DCT_CONST_ROUNDING);
2275 v[ 8] = _mm_add_epi32(u[ 8], k__DCT_CONST_ROUNDING);
2276 v[ 9] = _mm_add_epi32(u[ 9], k__DCT_CONST_ROUNDING);
2277 v[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
2278 v[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
2279 v[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
2280 v[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
2281 v[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
2282 v[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
2283
2284 u[ 0] = _mm_srai_epi32(v[ 0], DCT_CONST_BITS);
2285 u[ 1] = _mm_srai_epi32(v[ 1], DCT_CONST_BITS);
2286 u[ 2] = _mm_srai_epi32(v[ 2], DCT_CONST_BITS);
2287 u[ 3] = _mm_srai_epi32(v[ 3], DCT_CONST_BITS);
2288 u[ 4] = _mm_srai_epi32(v[ 4], DCT_CONST_BITS);
2289 u[ 5] = _mm_srai_epi32(v[ 5], DCT_CONST_BITS);
2290 u[ 6] = _mm_srai_epi32(v[ 6], DCT_CONST_BITS);
2291 u[ 7] = _mm_srai_epi32(v[ 7], DCT_CONST_BITS);
2292 u[ 8] = _mm_srai_epi32(v[ 8], DCT_CONST_BITS);
2293 u[ 9] = _mm_srai_epi32(v[ 9], DCT_CONST_BITS);
2294 u[10] = _mm_srai_epi32(v[10], DCT_CONST_BITS);
2295 u[11] = _mm_srai_epi32(v[11], DCT_CONST_BITS);
2296 u[12] = _mm_srai_epi32(v[12], DCT_CONST_BITS);
2297 u[13] = _mm_srai_epi32(v[13], DCT_CONST_BITS);
2298 u[14] = _mm_srai_epi32(v[14], DCT_CONST_BITS);
2299 u[15] = _mm_srai_epi32(v[15], DCT_CONST_BITS);
2300
2301 v[ 0] = _mm_cmplt_epi32(u[ 0], kZero);
2302 v[ 1] = _mm_cmplt_epi32(u[ 1], kZero);
2303 v[ 2] = _mm_cmplt_epi32(u[ 2], kZero);
2304 v[ 3] = _mm_cmplt_epi32(u[ 3], kZero);
2305 v[ 4] = _mm_cmplt_epi32(u[ 4], kZero);
2306 v[ 5] = _mm_cmplt_epi32(u[ 5], kZero);
2307 v[ 6] = _mm_cmplt_epi32(u[ 6], kZero);
2308 v[ 7] = _mm_cmplt_epi32(u[ 7], kZero);
2309 v[ 8] = _mm_cmplt_epi32(u[ 8], kZero);
2310 v[ 9] = _mm_cmplt_epi32(u[ 9], kZero);
2311 v[10] = _mm_cmplt_epi32(u[10], kZero);
2312 v[11] = _mm_cmplt_epi32(u[11], kZero);
2313 v[12] = _mm_cmplt_epi32(u[12], kZero);
2314 v[13] = _mm_cmplt_epi32(u[13], kZero);
2315 v[14] = _mm_cmplt_epi32(u[14], kZero);
2316 v[15] = _mm_cmplt_epi32(u[15], kZero);
2317
2318 u[ 0] = _mm_sub_epi32(u[ 0], v[ 0]);
2319 u[ 1] = _mm_sub_epi32(u[ 1], v[ 1]);
2320 u[ 2] = _mm_sub_epi32(u[ 2], v[ 2]);
2321 u[ 3] = _mm_sub_epi32(u[ 3], v[ 3]);
2322 u[ 4] = _mm_sub_epi32(u[ 4], v[ 4]);
2323 u[ 5] = _mm_sub_epi32(u[ 5], v[ 5]);
2324 u[ 6] = _mm_sub_epi32(u[ 6], v[ 6]);
2325 u[ 7] = _mm_sub_epi32(u[ 7], v[ 7]);
2326 u[ 8] = _mm_sub_epi32(u[ 8], v[ 8]);
2327 u[ 9] = _mm_sub_epi32(u[ 9], v[ 9]);
2328 u[10] = _mm_sub_epi32(u[10], v[10]);
2329 u[11] = _mm_sub_epi32(u[11], v[11]);
2330 u[12] = _mm_sub_epi32(u[12], v[12]);
2331 u[13] = _mm_sub_epi32(u[13], v[13]);
2332 u[14] = _mm_sub_epi32(u[14], v[14]);
2333 u[15] = _mm_sub_epi32(u[15], v[15]);
2334
2335 v[0] = _mm_add_epi32(u[0], K32One);
2336 v[1] = _mm_add_epi32(u[1], K32One);
2337 v[2] = _mm_add_epi32(u[2], K32One);
2338 v[3] = _mm_add_epi32(u[3], K32One);
2339 v[4] = _mm_add_epi32(u[4], K32One);
2340 v[5] = _mm_add_epi32(u[5], K32One);
2341 v[6] = _mm_add_epi32(u[6], K32One);
2342 v[7] = _mm_add_epi32(u[7], K32One);
2343 v[8] = _mm_add_epi32(u[8], K32One);
2344 v[9] = _mm_add_epi32(u[9], K32One);
2345 v[10] = _mm_add_epi32(u[10], K32One);
2346 v[11] = _mm_add_epi32(u[11], K32One);
2347 v[12] = _mm_add_epi32(u[12], K32One);
2348 v[13] = _mm_add_epi32(u[13], K32One);
2349 v[14] = _mm_add_epi32(u[14], K32One);
2350 v[15] = _mm_add_epi32(u[15], K32One);
2351
2352 u[0] = _mm_srai_epi32(v[0], 2);
2353 u[1] = _mm_srai_epi32(v[1], 2);
2354 u[2] = _mm_srai_epi32(v[2], 2);
2355 u[3] = _mm_srai_epi32(v[3], 2);
2356 u[4] = _mm_srai_epi32(v[4], 2);
2357 u[5] = _mm_srai_epi32(v[5], 2);
2358 u[6] = _mm_srai_epi32(v[6], 2);
2359 u[7] = _mm_srai_epi32(v[7], 2);
2360 u[8] = _mm_srai_epi32(v[8], 2);
2361 u[9] = _mm_srai_epi32(v[9], 2);
2362 u[10] = _mm_srai_epi32(v[10], 2);
2363 u[11] = _mm_srai_epi32(v[11], 2);
2364 u[12] = _mm_srai_epi32(v[12], 2);
2365 u[13] = _mm_srai_epi32(v[13], 2);
2366 u[14] = _mm_srai_epi32(v[14], 2);
2367 u[15] = _mm_srai_epi32(v[15], 2);
2368
2369 out[ 1] = _mm_packs_epi32(u[0], u[1]);
2370 out[17] = _mm_packs_epi32(u[2], u[3]);
2371 out[ 9] = _mm_packs_epi32(u[4], u[5]);
2372 out[25] = _mm_packs_epi32(u[6], u[7]);
2373 out[ 7] = _mm_packs_epi32(u[8], u[9]);
2374 out[23] = _mm_packs_epi32(u[10], u[11]);
2375 out[15] = _mm_packs_epi32(u[12], u[13]);
2376 out[31] = _mm_packs_epi32(u[14], u[15]);
2377 }
2378 {
2379 const __m128i k32_p27_p05 = pair_set_epi32(cospi_27_64, cospi_5_64);
2380 const __m128i k32_p11_p21 = pair_set_epi32(cospi_11_64, cospi_21_64);
2381 const __m128i k32_p19_p13 = pair_set_epi32(cospi_19_64, cospi_13_64);
2382 const __m128i k32_p03_p29 = pair_set_epi32(cospi_3_64, cospi_29_64);
2383 const __m128i k32_m29_p03 = pair_set_epi32(-cospi_29_64, cospi_3_64);
2384 const __m128i k32_m13_p19 = pair_set_epi32(-cospi_13_64, cospi_19_64);
2385 const __m128i k32_m21_p11 = pair_set_epi32(-cospi_21_64, cospi_11_64);
2386 const __m128i k32_m05_p27 = pair_set_epi32(-cospi_5_64, cospi_27_64);
2387
2388 u[ 0] = _mm_unpacklo_epi32(lstep1[40], lstep1[54]);
2389 u[ 1] = _mm_unpackhi_epi32(lstep1[40], lstep1[54]);
2390 u[ 2] = _mm_unpacklo_epi32(lstep1[41], lstep1[55]);
2391 u[ 3] = _mm_unpackhi_epi32(lstep1[41], lstep1[55]);
2392 u[ 4] = _mm_unpacklo_epi32(lstep1[42], lstep1[52]);
2393 u[ 5] = _mm_unpackhi_epi32(lstep1[42], lstep1[52]);
2394 u[ 6] = _mm_unpacklo_epi32(lstep1[43], lstep1[53]);
2395 u[ 7] = _mm_unpackhi_epi32(lstep1[43], lstep1[53]);
2396 u[ 8] = _mm_unpacklo_epi32(lstep1[44], lstep1[50]);
2397 u[ 9] = _mm_unpackhi_epi32(lstep1[44], lstep1[50]);
2398 u[10] = _mm_unpacklo_epi32(lstep1[45], lstep1[51]);
2399 u[11] = _mm_unpackhi_epi32(lstep1[45], lstep1[51]);
2400 u[12] = _mm_unpacklo_epi32(lstep1[46], lstep1[48]);
2401 u[13] = _mm_unpackhi_epi32(lstep1[46], lstep1[48]);
2402 u[14] = _mm_unpacklo_epi32(lstep1[47], lstep1[49]);
2403 u[15] = _mm_unpackhi_epi32(lstep1[47], lstep1[49]);
2404
2405 v[ 0] = k_madd_epi32(u[ 0], k32_p27_p05);
2406 v[ 1] = k_madd_epi32(u[ 1], k32_p27_p05);
2407 v[ 2] = k_madd_epi32(u[ 2], k32_p27_p05);
2408 v[ 3] = k_madd_epi32(u[ 3], k32_p27_p05);
2409 v[ 4] = k_madd_epi32(u[ 4], k32_p11_p21);
2410 v[ 5] = k_madd_epi32(u[ 5], k32_p11_p21);
2411 v[ 6] = k_madd_epi32(u[ 6], k32_p11_p21);
2412 v[ 7] = k_madd_epi32(u[ 7], k32_p11_p21);
2413 v[ 8] = k_madd_epi32(u[ 8], k32_p19_p13);
2414 v[ 9] = k_madd_epi32(u[ 9], k32_p19_p13);
2415 v[10] = k_madd_epi32(u[10], k32_p19_p13);
2416 v[11] = k_madd_epi32(u[11], k32_p19_p13);
2417 v[12] = k_madd_epi32(u[12], k32_p03_p29);
2418 v[13] = k_madd_epi32(u[13], k32_p03_p29);
2419 v[14] = k_madd_epi32(u[14], k32_p03_p29);
2420 v[15] = k_madd_epi32(u[15], k32_p03_p29);
2421 v[16] = k_madd_epi32(u[12], k32_m29_p03);
2422 v[17] = k_madd_epi32(u[13], k32_m29_p03);
2423 v[18] = k_madd_epi32(u[14], k32_m29_p03);
2424 v[19] = k_madd_epi32(u[15], k32_m29_p03);
2425 v[20] = k_madd_epi32(u[ 8], k32_m13_p19);
2426 v[21] = k_madd_epi32(u[ 9], k32_m13_p19);
2427 v[22] = k_madd_epi32(u[10], k32_m13_p19);
2428 v[23] = k_madd_epi32(u[11], k32_m13_p19);
2429 v[24] = k_madd_epi32(u[ 4], k32_m21_p11);
2430 v[25] = k_madd_epi32(u[ 5], k32_m21_p11);
2431 v[26] = k_madd_epi32(u[ 6], k32_m21_p11);
2432 v[27] = k_madd_epi32(u[ 7], k32_m21_p11);
2433 v[28] = k_madd_epi32(u[ 0], k32_m05_p27);
2434 v[29] = k_madd_epi32(u[ 1], k32_m05_p27);
2435 v[30] = k_madd_epi32(u[ 2], k32_m05_p27);
2436 v[31] = k_madd_epi32(u[ 3], k32_m05_p27);
2437
2438 u[ 0] = k_packs_epi64(v[ 0], v[ 1]);
2439 u[ 1] = k_packs_epi64(v[ 2], v[ 3]);
2440 u[ 2] = k_packs_epi64(v[ 4], v[ 5]);
2441 u[ 3] = k_packs_epi64(v[ 6], v[ 7]);
2442 u[ 4] = k_packs_epi64(v[ 8], v[ 9]);
2443 u[ 5] = k_packs_epi64(v[10], v[11]);
2444 u[ 6] = k_packs_epi64(v[12], v[13]);
2445 u[ 7] = k_packs_epi64(v[14], v[15]);
2446 u[ 8] = k_packs_epi64(v[16], v[17]);
2447 u[ 9] = k_packs_epi64(v[18], v[19]);
2448 u[10] = k_packs_epi64(v[20], v[21]);
2449 u[11] = k_packs_epi64(v[22], v[23]);
2450 u[12] = k_packs_epi64(v[24], v[25]);
2451 u[13] = k_packs_epi64(v[26], v[27]);
2452 u[14] = k_packs_epi64(v[28], v[29]);
2453 u[15] = k_packs_epi64(v[30], v[31]);
2454
2455 v[ 0] = _mm_add_epi32(u[ 0], k__DCT_CONST_ROUNDING);
2456 v[ 1] = _mm_add_epi32(u[ 1], k__DCT_CONST_ROUNDING);
2457 v[ 2] = _mm_add_epi32(u[ 2], k__DCT_CONST_ROUNDING);
2458 v[ 3] = _mm_add_epi32(u[ 3], k__DCT_CONST_ROUNDING);
2459 v[ 4] = _mm_add_epi32(u[ 4], k__DCT_CONST_ROUNDING);
2460 v[ 5] = _mm_add_epi32(u[ 5], k__DCT_CONST_ROUNDING);
2461 v[ 6] = _mm_add_epi32(u[ 6], k__DCT_CONST_ROUNDING);
2462 v[ 7] = _mm_add_epi32(u[ 7], k__DCT_CONST_ROUNDING);
2463 v[ 8] = _mm_add_epi32(u[ 8], k__DCT_CONST_ROUNDING);
2464 v[ 9] = _mm_add_epi32(u[ 9], k__DCT_CONST_ROUNDING);
2465 v[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
2466 v[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
2467 v[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
2468 v[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
2469 v[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
2470 v[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
2471
2472 u[ 0] = _mm_srai_epi32(v[ 0], DCT_CONST_BITS);
2473 u[ 1] = _mm_srai_epi32(v[ 1], DCT_CONST_BITS);
2474 u[ 2] = _mm_srai_epi32(v[ 2], DCT_CONST_BITS);
2475 u[ 3] = _mm_srai_epi32(v[ 3], DCT_CONST_BITS);
2476 u[ 4] = _mm_srai_epi32(v[ 4], DCT_CONST_BITS);
2477 u[ 5] = _mm_srai_epi32(v[ 5], DCT_CONST_BITS);
2478 u[ 6] = _mm_srai_epi32(v[ 6], DCT_CONST_BITS);
2479 u[ 7] = _mm_srai_epi32(v[ 7], DCT_CONST_BITS);
2480 u[ 8] = _mm_srai_epi32(v[ 8], DCT_CONST_BITS);
2481 u[ 9] = _mm_srai_epi32(v[ 9], DCT_CONST_BITS);
2482 u[10] = _mm_srai_epi32(v[10], DCT_CONST_BITS);
2483 u[11] = _mm_srai_epi32(v[11], DCT_CONST_BITS);
2484 u[12] = _mm_srai_epi32(v[12], DCT_CONST_BITS);
2485 u[13] = _mm_srai_epi32(v[13], DCT_CONST_BITS);
2486 u[14] = _mm_srai_epi32(v[14], DCT_CONST_BITS);
2487 u[15] = _mm_srai_epi32(v[15], DCT_CONST_BITS);
2488
2489 v[ 0] = _mm_cmplt_epi32(u[ 0], kZero);
2490 v[ 1] = _mm_cmplt_epi32(u[ 1], kZero);
2491 v[ 2] = _mm_cmplt_epi32(u[ 2], kZero);
2492 v[ 3] = _mm_cmplt_epi32(u[ 3], kZero);
2493 v[ 4] = _mm_cmplt_epi32(u[ 4], kZero);
2494 v[ 5] = _mm_cmplt_epi32(u[ 5], kZero);
2495 v[ 6] = _mm_cmplt_epi32(u[ 6], kZero);
2496 v[ 7] = _mm_cmplt_epi32(u[ 7], kZero);
2497 v[ 8] = _mm_cmplt_epi32(u[ 8], kZero);
2498 v[ 9] = _mm_cmplt_epi32(u[ 9], kZero);
2499 v[10] = _mm_cmplt_epi32(u[10], kZero);
2500 v[11] = _mm_cmplt_epi32(u[11], kZero);
2501 v[12] = _mm_cmplt_epi32(u[12], kZero);
2502 v[13] = _mm_cmplt_epi32(u[13], kZero);
2503 v[14] = _mm_cmplt_epi32(u[14], kZero);
2504 v[15] = _mm_cmplt_epi32(u[15], kZero);
2505
2506 u[ 0] = _mm_sub_epi32(u[ 0], v[ 0]);
2507 u[ 1] = _mm_sub_epi32(u[ 1], v[ 1]);
2508 u[ 2] = _mm_sub_epi32(u[ 2], v[ 2]);
2509 u[ 3] = _mm_sub_epi32(u[ 3], v[ 3]);
2510 u[ 4] = _mm_sub_epi32(u[ 4], v[ 4]);
2511 u[ 5] = _mm_sub_epi32(u[ 5], v[ 5]);
2512 u[ 6] = _mm_sub_epi32(u[ 6], v[ 6]);
2513 u[ 7] = _mm_sub_epi32(u[ 7], v[ 7]);
2514 u[ 8] = _mm_sub_epi32(u[ 8], v[ 8]);
2515 u[ 9] = _mm_sub_epi32(u[ 9], v[ 9]);
2516 u[10] = _mm_sub_epi32(u[10], v[10]);
2517 u[11] = _mm_sub_epi32(u[11], v[11]);
2518 u[12] = _mm_sub_epi32(u[12], v[12]);
2519 u[13] = _mm_sub_epi32(u[13], v[13]);
2520 u[14] = _mm_sub_epi32(u[14], v[14]);
2521 u[15] = _mm_sub_epi32(u[15], v[15]);
2522
2523 v[0] = _mm_add_epi32(u[0], K32One);
2524 v[1] = _mm_add_epi32(u[1], K32One);
2525 v[2] = _mm_add_epi32(u[2], K32One);
2526 v[3] = _mm_add_epi32(u[3], K32One);
2527 v[4] = _mm_add_epi32(u[4], K32One);
2528 v[5] = _mm_add_epi32(u[5], K32One);
2529 v[6] = _mm_add_epi32(u[6], K32One);
2530 v[7] = _mm_add_epi32(u[7], K32One);
2531 v[8] = _mm_add_epi32(u[8], K32One);
2532 v[9] = _mm_add_epi32(u[9], K32One);
2533 v[10] = _mm_add_epi32(u[10], K32One);
2534 v[11] = _mm_add_epi32(u[11], K32One);
2535 v[12] = _mm_add_epi32(u[12], K32One);
2536 v[13] = _mm_add_epi32(u[13], K32One);
2537 v[14] = _mm_add_epi32(u[14], K32One);
2538 v[15] = _mm_add_epi32(u[15], K32One);
2539
2540 u[0] = _mm_srai_epi32(v[0], 2);
2541 u[1] = _mm_srai_epi32(v[1], 2);
2542 u[2] = _mm_srai_epi32(v[2], 2);
2543 u[3] = _mm_srai_epi32(v[3], 2);
2544 u[4] = _mm_srai_epi32(v[4], 2);
2545 u[5] = _mm_srai_epi32(v[5], 2);
2546 u[6] = _mm_srai_epi32(v[6], 2);
2547 u[7] = _mm_srai_epi32(v[7], 2);
2548 u[8] = _mm_srai_epi32(v[8], 2);
2549 u[9] = _mm_srai_epi32(v[9], 2);
2550 u[10] = _mm_srai_epi32(v[10], 2);
2551 u[11] = _mm_srai_epi32(v[11], 2);
2552 u[12] = _mm_srai_epi32(v[12], 2);
2553 u[13] = _mm_srai_epi32(v[13], 2);
2554 u[14] = _mm_srai_epi32(v[14], 2);
2555 u[15] = _mm_srai_epi32(v[15], 2);
2556
2557 out[ 5] = _mm_packs_epi32(u[0], u[1]);
2558 out[21] = _mm_packs_epi32(u[2], u[3]);
2559 out[13] = _mm_packs_epi32(u[4], u[5]);
2560 out[29] = _mm_packs_epi32(u[6], u[7]);
2561 out[ 3] = _mm_packs_epi32(u[8], u[9]);
2562 out[19] = _mm_packs_epi32(u[10], u[11]);
2563 out[11] = _mm_packs_epi32(u[12], u[13]);
2564 out[27] = _mm_packs_epi32(u[14], u[15]);
2565 }
2566 }
2567 #endif
2568 // Transpose the results, do it as four 8x8 transposes.
2569 {
2570 int transpose_block;
2571 int16_t *output;
2572 if (0 == pass) {
2573 output = &intermediate[column_start * 32];
2574 } else {
2575 output = &output_org[column_start * 32];
2576 }
2577 for (transpose_block = 0; transpose_block < 4; ++transpose_block) {
2578 __m128i *this_out = &out[8 * transpose_block];
2579 // 00 01 02 03 04 05 06 07
2580 // 10 11 12 13 14 15 16 17
2581 // 20 21 22 23 24 25 26 27
2582 // 30 31 32 33 34 35 36 37
2583 // 40 41 42 43 44 45 46 47
2584 // 50 51 52 53 54 55 56 57
2585 // 60 61 62 63 64 65 66 67
2586 // 70 71 72 73 74 75 76 77
2587 const __m128i tr0_0 = _mm_unpacklo_epi16(this_out[0], this_out[1]);
2588 const __m128i tr0_1 = _mm_unpacklo_epi16(this_out[2], this_out[3]);
2589 const __m128i tr0_2 = _mm_unpackhi_epi16(this_out[0], this_out[1]);
2590 const __m128i tr0_3 = _mm_unpackhi_epi16(this_out[2], this_out[3]);
2591 const __m128i tr0_4 = _mm_unpacklo_epi16(this_out[4], this_out[5]);
2592 const __m128i tr0_5 = _mm_unpacklo_epi16(this_out[6], this_out[7]);
2593 const __m128i tr0_6 = _mm_unpackhi_epi16(this_out[4], this_out[5]);
2594 const __m128i tr0_7 = _mm_unpackhi_epi16(this_out[6], this_out[7]);
2595 // 00 10 01 11 02 12 03 13
2596 // 20 30 21 31 22 32 23 33
2597 // 04 14 05 15 06 16 07 17
2598 // 24 34 25 35 26 36 27 37
2599 // 40 50 41 51 42 52 43 53
2600 // 60 70 61 71 62 72 63 73
2601 // 54 54 55 55 56 56 57 57
2602 // 64 74 65 75 66 76 67 77
2603 const __m128i tr1_0 = _mm_unpacklo_epi32(tr0_0, tr0_1);
2604 const __m128i tr1_1 = _mm_unpacklo_epi32(tr0_2, tr0_3);
2605 const __m128i tr1_2 = _mm_unpackhi_epi32(tr0_0, tr0_1);
2606 const __m128i tr1_3 = _mm_unpackhi_epi32(tr0_2, tr0_3);
2607 const __m128i tr1_4 = _mm_unpacklo_epi32(tr0_4, tr0_5);
2608 const __m128i tr1_5 = _mm_unpacklo_epi32(tr0_6, tr0_7);
2609 const __m128i tr1_6 = _mm_unpackhi_epi32(tr0_4, tr0_5);
2610 const __m128i tr1_7 = _mm_unpackhi_epi32(tr0_6, tr0_7);
2611 // 00 10 20 30 01 11 21 31
2612 // 40 50 60 70 41 51 61 71
2613 // 02 12 22 32 03 13 23 33
2614 // 42 52 62 72 43 53 63 73
2615 // 04 14 24 34 05 15 21 36
2616 // 44 54 64 74 45 55 61 76
2617 // 06 16 26 36 07 17 27 37
2618 // 46 56 66 76 47 57 67 77
2619 __m128i tr2_0 = _mm_unpacklo_epi64(tr1_0, tr1_4);
2620 __m128i tr2_1 = _mm_unpackhi_epi64(tr1_0, tr1_4);
2621 __m128i tr2_2 = _mm_unpacklo_epi64(tr1_2, tr1_6);
2622 __m128i tr2_3 = _mm_unpackhi_epi64(tr1_2, tr1_6);
2623 __m128i tr2_4 = _mm_unpacklo_epi64(tr1_1, tr1_5);
2624 __m128i tr2_5 = _mm_unpackhi_epi64(tr1_1, tr1_5);
2625 __m128i tr2_6 = _mm_unpacklo_epi64(tr1_3, tr1_7);
2626 __m128i tr2_7 = _mm_unpackhi_epi64(tr1_3, tr1_7);
2627 // 00 10 20 30 40 50 60 70
2628 // 01 11 21 31 41 51 61 71
2629 // 02 12 22 32 42 52 62 72
2630 // 03 13 23 33 43 53 63 73
2631 // 04 14 24 34 44 54 64 74
2632 // 05 15 25 35 45 55 65 75
2633 // 06 16 26 36 46 56 66 76
2634 // 07 17 27 37 47 57 67 77
2635 if (0 == pass) {
2636 // output[j] = (output[j] + 1 + (output[j] > 0)) >> 2;
2637 // TODO(cd): see quality impact of only doing
2638 // output[j] = (output[j] + 1) >> 2;
2639 // which would remove the code between here ...
2640 __m128i tr2_0_0 = _mm_cmpgt_epi16(tr2_0, kZero);
2641 __m128i tr2_1_0 = _mm_cmpgt_epi16(tr2_1, kZero);
2642 __m128i tr2_2_0 = _mm_cmpgt_epi16(tr2_2, kZero);
2643 __m128i tr2_3_0 = _mm_cmpgt_epi16(tr2_3, kZero);
2644 __m128i tr2_4_0 = _mm_cmpgt_epi16(tr2_4, kZero);
2645 __m128i tr2_5_0 = _mm_cmpgt_epi16(tr2_5, kZero);
2646 __m128i tr2_6_0 = _mm_cmpgt_epi16(tr2_6, kZero);
2647 __m128i tr2_7_0 = _mm_cmpgt_epi16(tr2_7, kZero);
2648 tr2_0 = _mm_sub_epi16(tr2_0, tr2_0_0);
2649 tr2_1 = _mm_sub_epi16(tr2_1, tr2_1_0);
2650 tr2_2 = _mm_sub_epi16(tr2_2, tr2_2_0);
2651 tr2_3 = _mm_sub_epi16(tr2_3, tr2_3_0);
2652 tr2_4 = _mm_sub_epi16(tr2_4, tr2_4_0);
2653 tr2_5 = _mm_sub_epi16(tr2_5, tr2_5_0);
2654 tr2_6 = _mm_sub_epi16(tr2_6, tr2_6_0);
2655 tr2_7 = _mm_sub_epi16(tr2_7, tr2_7_0);
2656 // ... and here.
2657 // PS: also change code in vp9/encoder/vp9_dct.c
2658 tr2_0 = _mm_add_epi16(tr2_0, kOne);
2659 tr2_1 = _mm_add_epi16(tr2_1, kOne);
2660 tr2_2 = _mm_add_epi16(tr2_2, kOne);
2661 tr2_3 = _mm_add_epi16(tr2_3, kOne);
2662 tr2_4 = _mm_add_epi16(tr2_4, kOne);
2663 tr2_5 = _mm_add_epi16(tr2_5, kOne);
2664 tr2_6 = _mm_add_epi16(tr2_6, kOne);
2665 tr2_7 = _mm_add_epi16(tr2_7, kOne);
2666 tr2_0 = _mm_srai_epi16(tr2_0, 2);
2667 tr2_1 = _mm_srai_epi16(tr2_1, 2);
2668 tr2_2 = _mm_srai_epi16(tr2_2, 2);
2669 tr2_3 = _mm_srai_epi16(tr2_3, 2);
2670 tr2_4 = _mm_srai_epi16(tr2_4, 2);
2671 tr2_5 = _mm_srai_epi16(tr2_5, 2);
2672 tr2_6 = _mm_srai_epi16(tr2_6, 2);
2673 tr2_7 = _mm_srai_epi16(tr2_7, 2);
2674 }
2675 // Note: even though all these stores are aligned, using the aligned
2676 // intrinsic make the code slightly slower.
2677 _mm_storeu_si128((__m128i *)(output + 0 * 32), tr2_0);
2678 _mm_storeu_si128((__m128i *)(output + 1 * 32), tr2_1);
2679 _mm_storeu_si128((__m128i *)(output + 2 * 32), tr2_2);
2680 _mm_storeu_si128((__m128i *)(output + 3 * 32), tr2_3);
2681 _mm_storeu_si128((__m128i *)(output + 4 * 32), tr2_4);
2682 _mm_storeu_si128((__m128i *)(output + 5 * 32), tr2_5);
2683 _mm_storeu_si128((__m128i *)(output + 6 * 32), tr2_6);
2684 _mm_storeu_si128((__m128i *)(output + 7 * 32), tr2_7);
2685 // Process next 8x8
2686 output += 8;
2687 }
2688 }
2689 }
2690 }
2691 } // NOLINT
2692