106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org/*
206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org *  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org *
406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org *  Use of this source code is governed by a BSD-style license
506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org *  that can be found in the LICENSE file in the root of the source
606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org *  tree. An additional intellectual property rights grant can be found
706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org *  in the file PATENTS.  All contributing project authors may
806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org *  be found in the AUTHORS file in the root of the source tree.
906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org */
1006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
1188b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org#include "vp9/common/x86/vp9_idct_intrin_sse2.h"
1206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
13d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org#define RECON_AND_STORE4X4(dest, in_x) \
14d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org{                                                     \
15d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  __m128i d0 = _mm_cvtsi32_si128(*(const int *)(dest)); \
16d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  d0 = _mm_unpacklo_epi8(d0, zero); \
17d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  d0 = _mm_add_epi16(in_x, d0); \
18d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  d0 = _mm_packus_epi16(d0, d0); \
19d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  *(int *)dest = _mm_cvtsi128_si32(d0); \
20d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  dest += stride; \
21d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org}
22d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org
23ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.orgvoid vp9_idct4x4_16_add_sse2(const int16_t *input, uint8_t *dest, int stride) {
2406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i zero = _mm_setzero_si128();
2506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i eight = _mm_set1_epi16(8);
2606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i cst = _mm_setr_epi16((int16_t)cospi_16_64, (int16_t)cospi_16_64,
2706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                                    (int16_t)cospi_16_64, (int16_t)-cospi_16_64,
2806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                                    (int16_t)cospi_24_64, (int16_t)-cospi_8_64,
2906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                                    (int16_t)cospi_8_64, (int16_t)cospi_24_64);
3006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i rounding = _mm_set1_epi32(DCT_CONST_ROUNDING);
3106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  __m128i input0, input1, input2, input3;
3206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
3306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Rows
34d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input0 = _mm_load_si128((const __m128i *)input);
35d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input2 = _mm_load_si128((const __m128i *)(input + 8));
3606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
3706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Construct i3, i1, i3, i1, i2, i0, i2, i0
3806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input0 = _mm_shufflelo_epi16(input0, 0xd8);
39d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input0 = _mm_shufflehi_epi16(input0, 0xd8);
4006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input2 = _mm_shufflelo_epi16(input2, 0xd8);
41d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input2 = _mm_shufflehi_epi16(input2, 0xd8);
4206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
43d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input1 = _mm_unpackhi_epi32(input0, input0);
4406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input0 = _mm_unpacklo_epi32(input0, input0);
45d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input3 = _mm_unpackhi_epi32(input2, input2);
4606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input2 = _mm_unpacklo_epi32(input2, input2);
4706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
4806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Stage 1
4906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input0 = _mm_madd_epi16(input0, cst);
5006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input1 = _mm_madd_epi16(input1, cst);
5106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input2 = _mm_madd_epi16(input2, cst);
5206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input3 = _mm_madd_epi16(input3, cst);
5306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
5406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input0 = _mm_add_epi32(input0, rounding);
5506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input1 = _mm_add_epi32(input1, rounding);
5606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input2 = _mm_add_epi32(input2, rounding);
5706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input3 = _mm_add_epi32(input3, rounding);
5806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
5906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input0 = _mm_srai_epi32(input0, DCT_CONST_BITS);
6006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input1 = _mm_srai_epi32(input1, DCT_CONST_BITS);
6106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input2 = _mm_srai_epi32(input2, DCT_CONST_BITS);
6206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input3 = _mm_srai_epi32(input3, DCT_CONST_BITS);
6306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
6406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Stage 2
65d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input0 = _mm_packs_epi32(input0, input1);
66d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input1 = _mm_packs_epi32(input2, input3);
6706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
6806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Transpose
69d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input2 = _mm_unpacklo_epi16(input0, input1);
70d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input3 = _mm_unpackhi_epi16(input0, input1);
71d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input0 = _mm_unpacklo_epi32(input2, input3);
72d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input1 = _mm_unpackhi_epi32(input2, input3);
7306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
7406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Switch column2, column 3, and then, we got:
7506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // input2: column1, column 0;  input3: column2, column 3.
7606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input1 = _mm_shuffle_epi32(input1, 0x4e);
7706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input2 = _mm_add_epi16(input0, input1);
7806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input3 = _mm_sub_epi16(input0, input1);
7906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
8006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Columns
8106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Construct i3, i1, i3, i1, i2, i0, i2, i0
82d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input0 = _mm_unpacklo_epi32(input2, input2);
83d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input1 = _mm_unpackhi_epi32(input2, input2);
84d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input2 = _mm_unpackhi_epi32(input3, input3);
8506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input3 = _mm_unpacklo_epi32(input3, input3);
8606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
8706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Stage 1
8806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input0 = _mm_madd_epi16(input0, cst);
8906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input1 = _mm_madd_epi16(input1, cst);
9006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input2 = _mm_madd_epi16(input2, cst);
9106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input3 = _mm_madd_epi16(input3, cst);
9206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
9306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input0 = _mm_add_epi32(input0, rounding);
9406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input1 = _mm_add_epi32(input1, rounding);
9506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input2 = _mm_add_epi32(input2, rounding);
9606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input3 = _mm_add_epi32(input3, rounding);
9706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
9806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input0 = _mm_srai_epi32(input0, DCT_CONST_BITS);
9906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input1 = _mm_srai_epi32(input1, DCT_CONST_BITS);
10006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input2 = _mm_srai_epi32(input2, DCT_CONST_BITS);
10106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input3 = _mm_srai_epi32(input3, DCT_CONST_BITS);
10206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
10306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Stage 2
104d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input0 = _mm_packs_epi32(input0, input2);
105d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input1 = _mm_packs_epi32(input1, input3);
10606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
10706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Transpose
108d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input2 = _mm_unpacklo_epi16(input0, input1);
109d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input3 = _mm_unpackhi_epi16(input0, input1);
110d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input0 = _mm_unpacklo_epi32(input2, input3);
111d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  input1 = _mm_unpackhi_epi32(input2, input3);
11206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
11306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Switch column2, column 3, and then, we got:
11406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // input2: column1, column 0;  input3: column2, column 3.
11506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input1 = _mm_shuffle_epi32(input1, 0x4e);
11606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input2 = _mm_add_epi16(input0, input1);
11706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input3 = _mm_sub_epi16(input0, input1);
11806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
11906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Final round and shift
12006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input2 = _mm_add_epi16(input2, eight);
12106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input3 = _mm_add_epi16(input3, eight);
12206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
12306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input2 = _mm_srai_epi16(input2, 4);
12406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  input3 = _mm_srai_epi16(input3, 4);
12506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
126d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  // Reconstruction and Store
127d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  {
128d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     __m128i d0 = _mm_cvtsi32_si128(*(const int *)(dest));
129d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     __m128i d2 = _mm_cvtsi32_si128(*(const int *)(dest + stride * 2));
130d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_unpacklo_epi32(d0,
131d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org          _mm_cvtsi32_si128(*(const int *) (dest + stride)));
132d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d2 = _mm_unpacklo_epi32(_mm_cvtsi32_si128(
133d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org                    *(const int *) (dest + stride * 3)), d2);
134d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_unpacklo_epi8(d0, zero);
135d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d2 = _mm_unpacklo_epi8(d2, zero);
136d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_add_epi16(d0, input2);
137d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d2 = _mm_add_epi16(d2, input3);
138d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_packus_epi16(d0, d2);
139d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     // store input0
140d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     *(int *)dest = _mm_cvtsi128_si32(d0);
141d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     // store input1
142d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_srli_si128(d0, 4);
143d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     *(int *)(dest + stride) = _mm_cvtsi128_si32(d0);
144d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     // store input2
145d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_srli_si128(d0, 4);
146d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     *(int *)(dest + stride * 3) = _mm_cvtsi128_si32(d0);
147d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     // store input3
148d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_srli_si128(d0, 4);
149d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     *(int *)(dest + stride * 2) = _mm_cvtsi128_si32(d0);
15010a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  }
15106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org}
15206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
153ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.orgvoid vp9_idct4x4_1_add_sse2(const int16_t *input, uint8_t *dest, int stride) {
15447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i dc_value;
15547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i zero = _mm_setzero_si128();
15647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  int a;
15747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
15847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  a = dct_const_round_shift(input[0] * cospi_16_64);
15947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  a = dct_const_round_shift(a * cospi_16_64);
16047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  a = ROUND_POWER_OF_TWO(a, 4);
16147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
16247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  dc_value = _mm_set1_epi16(a);
16347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
16447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  RECON_AND_STORE4X4(dest, dc_value);
16547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  RECON_AND_STORE4X4(dest, dc_value);
16647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  RECON_AND_STORE4X4(dest, dc_value);
16747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  RECON_AND_STORE4X4(dest, dc_value);
16847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org}
16947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
17047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.orgstatic INLINE void transpose_4x4(__m128i *res) {
17147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i tr0_0 = _mm_unpacklo_epi16(res[0], res[1]);
172d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  const __m128i tr0_1 = _mm_unpackhi_epi16(res[0], res[1]);
17347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
174d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  res[0] = _mm_unpacklo_epi16(tr0_0, tr0_1);
175d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  res[1] = _mm_unpackhi_epi16(tr0_0, tr0_1);
17647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org}
17747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
178dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.orgstatic void idct4_sse2(__m128i *in) {
17947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p16_p16 = pair_set_epi16(cospi_16_64, cospi_16_64);
18047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
18147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p24_m08 = pair_set_epi16(cospi_24_64, -cospi_8_64);
18247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p08_p24 = pair_set_epi16(cospi_8_64, cospi_24_64);
18347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
18447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i u[8], v[8];
18547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
18647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  transpose_4x4(in);
18747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // stage 1
188d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  u[0] = _mm_unpacklo_epi16(in[0], in[1]);
189d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  u[1] = _mm_unpackhi_epi16(in[0], in[1]);
19047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[0] = _mm_madd_epi16(u[0], k__cospi_p16_p16);
19147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[1] = _mm_madd_epi16(u[0], k__cospi_p16_m16);
19247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[2] = _mm_madd_epi16(u[1], k__cospi_p24_m08);
19347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[3] = _mm_madd_epi16(u[1], k__cospi_p08_p24);
19447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
19547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
19647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
19747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
19847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
19947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
20047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
20147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
20247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
20347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
20447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
205d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  u[0] = _mm_packs_epi32(v[0], v[1]);
206d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  u[1] = _mm_packs_epi32(v[3], v[2]);
20747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
20847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // stage 2
209d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  in[0] = _mm_add_epi16(u[0], u[1]);
210d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  in[1] = _mm_sub_epi16(u[0], u[1]);
211d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  in[1] = _mm_shuffle_epi32(in[1], 0x4E);
21247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org}
21347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
214dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.orgstatic void iadst4_sse2(__m128i *in) {
21547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__sinpi_p01_p04 = pair_set_epi16(sinpi_1_9, sinpi_4_9);
21647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__sinpi_p03_p02 = pair_set_epi16(sinpi_3_9, sinpi_2_9);
21747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__sinpi_p02_m01 = pair_set_epi16(sinpi_2_9, -sinpi_1_9);
21847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__sinpi_p03_m04 = pair_set_epi16(sinpi_3_9, -sinpi_4_9);
21947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__sinpi_p03_p03 = _mm_set1_epi16(sinpi_3_9);
22047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i kZero = _mm_set1_epi16(0);
22147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
22247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i u[8], v[8], in7;
22347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
22447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  transpose_4x4(in);
225d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  in7 = _mm_srli_si128(in[1], 8);
226d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  in7 = _mm_add_epi16(in7, in[0]);
227d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  in7 = _mm_sub_epi16(in7, in[1]);
22847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
229d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  u[0] = _mm_unpacklo_epi16(in[0], in[1]);
230d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  u[1] = _mm_unpackhi_epi16(in[0], in[1]);
23147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[2] = _mm_unpacklo_epi16(in7, kZero);
232d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  u[3] = _mm_unpackhi_epi16(in[0], kZero);
23347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
23447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[0] = _mm_madd_epi16(u[0], k__sinpi_p01_p04);  // s0 + s3
23547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[1] = _mm_madd_epi16(u[1], k__sinpi_p03_p02);  // s2 + s5
23647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[2] = _mm_madd_epi16(u[2], k__sinpi_p03_p03);  // x2
23747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[3] = _mm_madd_epi16(u[0], k__sinpi_p02_m01);  // s1 - s4
23847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[4] = _mm_madd_epi16(u[1], k__sinpi_p03_m04);  // s2 - s6
23947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[5] = _mm_madd_epi16(u[3], k__sinpi_p03_p03);  // s2
24047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
24147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[0] = _mm_add_epi32(v[0], v[1]);
24247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[1] = _mm_add_epi32(v[3], v[4]);
24347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[2] = v[2];
24447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[3] = _mm_add_epi32(u[0], u[1]);
24547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[4] = _mm_slli_epi32(v[5], 2);
24647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[5] = _mm_add_epi32(u[3], v[5]);
24747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[6] = _mm_sub_epi32(u[5], u[4]);
24847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
24947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
25047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
25147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
25247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[3] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
25347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
25447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
25547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
25647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
25747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
25847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
259d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  in[0] = _mm_packs_epi32(u[0], u[1]);
260d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  in[1] = _mm_packs_epi32(u[2], u[3]);
26147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org}
26247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
263ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.orgvoid vp9_iht4x4_16_add_sse2(const int16_t *input, uint8_t *dest, int stride,
264ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org                            int tx_type) {
265d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  __m128i in[2];
26647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i zero = _mm_setzero_si128();
26747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i eight = _mm_set1_epi16(8);
26847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
269d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  in[0]= _mm_loadu_si128((const __m128i *)(input));
270d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  in[1]= _mm_loadu_si128((const __m128i *)(input + 8));
27147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
27247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  switch (tx_type) {
27347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org    case 0:  // DCT_DCT
274dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      idct4_sse2(in);
275dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      idct4_sse2(in);
27647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org      break;
27747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org    case 1:  // ADST_DCT
278dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      idct4_sse2(in);
279dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      iadst4_sse2(in);
28047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org      break;
28147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org    case 2:  // DCT_ADST
282dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      iadst4_sse2(in);
283dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      idct4_sse2(in);
28447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org      break;
28547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org    case 3:  // ADST_ADST
286dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      iadst4_sse2(in);
287dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      iadst4_sse2(in);
28847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org      break;
28947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org    default:
29047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org      assert(0);
29147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org      break;
29247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  }
29347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
29447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // Final round and shift
29547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[0] = _mm_add_epi16(in[0], eight);
29647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[1] = _mm_add_epi16(in[1], eight);
29747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
29847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[0] = _mm_srai_epi16(in[0], 4);
29947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[1] = _mm_srai_epi16(in[1], 4);
30047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
301d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  // Reconstruction and Store
302d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  {
303d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     __m128i d0 = _mm_cvtsi32_si128(*(const int *)(dest));
304d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     __m128i d2 = _mm_cvtsi32_si128(*(const int *)(dest + stride * 2));
305d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_unpacklo_epi32(d0,
306d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org          _mm_cvtsi32_si128(*(const int *) (dest + stride)));
307d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d2 = _mm_unpacklo_epi32(d2, _mm_cvtsi32_si128(
308d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org                    *(const int *) (dest + stride * 3)));
309d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_unpacklo_epi8(d0, zero);
310d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d2 = _mm_unpacklo_epi8(d2, zero);
311d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_add_epi16(d0, in[0]);
312d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d2 = _mm_add_epi16(d2, in[1]);
313d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_packus_epi16(d0, d2);
314d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     // store result[0]
315d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     *(int *)dest = _mm_cvtsi128_si32(d0);
316d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     // store result[1]
317d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_srli_si128(d0, 4);
318d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     *(int *)(dest + stride) = _mm_cvtsi128_si32(d0);
319d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     // store result[2]
320d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_srli_si128(d0, 4);
321d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     *(int *)(dest + stride * 2) = _mm_cvtsi128_si32(d0);
322d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     // store result[3]
323d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     d0 = _mm_srli_si128(d0, 4);
324d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org     *(int *)(dest + stride * 3) = _mm_cvtsi128_si32(d0);
325d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  }
32647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org}
32747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
32806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org#define TRANSPOSE_8X8(in0, in1, in2, in3, in4, in5, in6, in7, \
32906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                      out0, out1, out2, out3, out4, out5, out6, out7) \
33006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  {                                                     \
33106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr0_0 = _mm_unpacklo_epi16(in0, in1); \
33206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr0_1 = _mm_unpacklo_epi16(in2, in3); \
33306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr0_2 = _mm_unpackhi_epi16(in0, in1); \
33406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr0_3 = _mm_unpackhi_epi16(in2, in3); \
33506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr0_4 = _mm_unpacklo_epi16(in4, in5); \
33606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr0_5 = _mm_unpacklo_epi16(in6, in7); \
33706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr0_6 = _mm_unpackhi_epi16(in4, in5); \
33806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr0_7 = _mm_unpackhi_epi16(in6, in7); \
33906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                                                        \
34006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr1_0 = _mm_unpacklo_epi32(tr0_0, tr0_1); \
34106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr1_1 = _mm_unpacklo_epi32(tr0_2, tr0_3); \
34206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr1_2 = _mm_unpackhi_epi32(tr0_0, tr0_1); \
34306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr1_3 = _mm_unpackhi_epi32(tr0_2, tr0_3); \
34406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr1_4 = _mm_unpacklo_epi32(tr0_4, tr0_5); \
34506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr1_5 = _mm_unpacklo_epi32(tr0_6, tr0_7); \
34606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr1_6 = _mm_unpackhi_epi32(tr0_4, tr0_5); \
34706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr1_7 = _mm_unpackhi_epi32(tr0_6, tr0_7); \
34806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                                                            \
34906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    out0 = _mm_unpacklo_epi64(tr1_0, tr1_4); \
35006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    out1 = _mm_unpackhi_epi64(tr1_0, tr1_4); \
35106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    out2 = _mm_unpacklo_epi64(tr1_2, tr1_6); \
35206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    out3 = _mm_unpackhi_epi64(tr1_2, tr1_6); \
35306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    out4 = _mm_unpacklo_epi64(tr1_1, tr1_5); \
35406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    out5 = _mm_unpackhi_epi64(tr1_1, tr1_5); \
35506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    out6 = _mm_unpacklo_epi64(tr1_3, tr1_7); \
35606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    out7 = _mm_unpackhi_epi64(tr1_3, tr1_7); \
35706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  }
35806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
359dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#define TRANSPOSE_4X8_10(tmp0, tmp1, tmp2, tmp3, \
360dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                         out0, out1, out2, out3) \
361dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  {                                              \
362dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    const __m128i tr0_0 = _mm_unpackhi_epi16(tmp0, tmp1); \
363dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    const __m128i tr0_1 = _mm_unpacklo_epi16(tmp1, tmp0); \
364dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    const __m128i tr0_4 = _mm_unpacklo_epi16(tmp2, tmp3); \
365dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    const __m128i tr0_5 = _mm_unpackhi_epi16(tmp3, tmp2); \
366dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    \
36706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr1_0 = _mm_unpacklo_epi32(tr0_0, tr0_1); \
36806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr1_2 = _mm_unpackhi_epi32(tr0_0, tr0_1); \
36906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr1_4 = _mm_unpacklo_epi32(tr0_4, tr0_5); \
37006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i tr1_6 = _mm_unpackhi_epi32(tr0_4, tr0_5); \
371dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    \
37206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    out0 = _mm_unpacklo_epi64(tr1_0, tr1_4); \
37306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    out1 = _mm_unpackhi_epi64(tr1_0, tr1_4); \
37406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    out2 = _mm_unpacklo_epi64(tr1_2, tr1_6); \
37506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    out3 = _mm_unpackhi_epi64(tr1_2, tr1_6); \
37606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  }
37706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
378dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#define TRANSPOSE_8X8_10(in0, in1, in2, in3, out0, out1) \
379dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  {                                            \
380dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    const __m128i tr0_0 = _mm_unpacklo_epi16(in0, in1); \
381dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    const __m128i tr0_1 = _mm_unpacklo_epi16(in2, in3); \
382dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    out0 = _mm_unpacklo_epi32(tr0_0, tr0_1); \
383dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    out1 = _mm_unpackhi_epi32(tr0_0, tr0_1); \
38406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  }
38506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
38606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org// Define Macro for multiplying elements by constants and adding them together.
38706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org#define MULTIPLICATION_AND_ADD(lo_0, hi_0, lo_1, hi_1, \
38806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                               cst0, cst1, cst2, cst3, res0, res1, res2, res3) \
38906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  {   \
39006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp0 = _mm_madd_epi16(lo_0, cst0); \
39106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp1 = _mm_madd_epi16(hi_0, cst0); \
39206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp2 = _mm_madd_epi16(lo_0, cst1); \
39306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp3 = _mm_madd_epi16(hi_0, cst1); \
39406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp4 = _mm_madd_epi16(lo_1, cst2); \
39506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp5 = _mm_madd_epi16(hi_1, cst2); \
39606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp6 = _mm_madd_epi16(lo_1, cst3); \
39706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp7 = _mm_madd_epi16(hi_1, cst3); \
39806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      \
39906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp0 = _mm_add_epi32(tmp0, rounding); \
40006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp1 = _mm_add_epi32(tmp1, rounding); \
40106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp2 = _mm_add_epi32(tmp2, rounding); \
40206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp3 = _mm_add_epi32(tmp3, rounding); \
40306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp4 = _mm_add_epi32(tmp4, rounding); \
40406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp5 = _mm_add_epi32(tmp5, rounding); \
40506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp6 = _mm_add_epi32(tmp6, rounding); \
40606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp7 = _mm_add_epi32(tmp7, rounding); \
40706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      \
40806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp0 = _mm_srai_epi32(tmp0, DCT_CONST_BITS); \
40906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp1 = _mm_srai_epi32(tmp1, DCT_CONST_BITS); \
41006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp2 = _mm_srai_epi32(tmp2, DCT_CONST_BITS); \
41106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp3 = _mm_srai_epi32(tmp3, DCT_CONST_BITS); \
41206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp4 = _mm_srai_epi32(tmp4, DCT_CONST_BITS); \
41306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp5 = _mm_srai_epi32(tmp5, DCT_CONST_BITS); \
41406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp6 = _mm_srai_epi32(tmp6, DCT_CONST_BITS); \
41506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      tmp7 = _mm_srai_epi32(tmp7, DCT_CONST_BITS); \
41606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      \
41706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      res0 = _mm_packs_epi32(tmp0, tmp1); \
41806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      res1 = _mm_packs_epi32(tmp2, tmp3); \
41906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      res2 = _mm_packs_epi32(tmp4, tmp5); \
42006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      res3 = _mm_packs_epi32(tmp6, tmp7); \
42106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  }
42206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
423d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org#define MULTIPLICATION_AND_ADD_2(lo_0, hi_0, cst0, cst1, res0, res1) \
424d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  {   \
425d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      tmp0 = _mm_madd_epi16(lo_0, cst0); \
426d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      tmp1 = _mm_madd_epi16(hi_0, cst0); \
427d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      tmp2 = _mm_madd_epi16(lo_0, cst1); \
428d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      tmp3 = _mm_madd_epi16(hi_0, cst1); \
429d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      \
430d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      tmp0 = _mm_add_epi32(tmp0, rounding); \
431d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      tmp1 = _mm_add_epi32(tmp1, rounding); \
432d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      tmp2 = _mm_add_epi32(tmp2, rounding); \
433d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      tmp3 = _mm_add_epi32(tmp3, rounding); \
434d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      \
435d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      tmp0 = _mm_srai_epi32(tmp0, DCT_CONST_BITS); \
436d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      tmp1 = _mm_srai_epi32(tmp1, DCT_CONST_BITS); \
437d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      tmp2 = _mm_srai_epi32(tmp2, DCT_CONST_BITS); \
438d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      tmp3 = _mm_srai_epi32(tmp3, DCT_CONST_BITS); \
439d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      \
440d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      res0 = _mm_packs_epi32(tmp0, tmp1); \
441d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      res1 = _mm_packs_epi32(tmp2, tmp3); \
442d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  }
443d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org
444dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#define IDCT8(in0, in1, in2, in3, in4, in5, in6, in7, \
445dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                 out0, out1, out2, out3, out4, out5, out6, out7)  \
446dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  { \
44706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  /* Stage1 */      \
44806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  { \
44906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i lo_17 = _mm_unpacklo_epi16(in1, in7); \
45006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i hi_17 = _mm_unpackhi_epi16(in1, in7); \
45106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i lo_35 = _mm_unpacklo_epi16(in3, in5); \
45206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i hi_35 = _mm_unpackhi_epi16(in3, in5); \
45306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
45406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    MULTIPLICATION_AND_ADD(lo_17, hi_17, lo_35, hi_35, stg1_0, \
45506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                          stg1_1, stg1_2, stg1_3, stp1_4,      \
45606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                          stp1_7, stp1_5, stp1_6)              \
45706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  } \
45806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
45906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  /* Stage2 */ \
46006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  { \
46106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i lo_04 = _mm_unpacklo_epi16(in0, in4); \
46206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i hi_04 = _mm_unpackhi_epi16(in0, in4); \
46306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i lo_26 = _mm_unpacklo_epi16(in2, in6); \
46406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i hi_26 = _mm_unpackhi_epi16(in2, in6); \
46506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
46606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    MULTIPLICATION_AND_ADD(lo_04, hi_04, lo_26, hi_26, stg2_0, \
46706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stg2_1, stg2_2, stg2_3, stp2_0,     \
46806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stp2_1, stp2_2, stp2_3)             \
46906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
47006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_4 = _mm_adds_epi16(stp1_4, stp1_5); \
47106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_5 = _mm_subs_epi16(stp1_4, stp1_5); \
47206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_6 = _mm_subs_epi16(stp1_7, stp1_6); \
47306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_7 = _mm_adds_epi16(stp1_7, stp1_6); \
47406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  } \
47506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
47606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  /* Stage3 */ \
47706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  { \
47806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i lo_56 = _mm_unpacklo_epi16(stp2_6, stp2_5); \
47906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i hi_56 = _mm_unpackhi_epi16(stp2_6, stp2_5); \
48006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
48106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_0 = _mm_adds_epi16(stp2_0, stp2_3); \
48206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_1 = _mm_adds_epi16(stp2_1, stp2_2); \
48306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_2 = _mm_subs_epi16(stp2_1, stp2_2); \
48406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_3 = _mm_subs_epi16(stp2_0, stp2_3); \
48506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
48606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_madd_epi16(lo_56, stg2_1); \
48706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp1 = _mm_madd_epi16(hi_56, stg2_1); \
48806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_madd_epi16(lo_56, stg2_0); \
48906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp3 = _mm_madd_epi16(hi_56, stg2_0); \
49006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
49106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_add_epi32(tmp0, rounding); \
49206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp1 = _mm_add_epi32(tmp1, rounding); \
49306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_add_epi32(tmp2, rounding); \
49406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp3 = _mm_add_epi32(tmp3, rounding); \
49506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
49606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_srai_epi32(tmp0, DCT_CONST_BITS); \
49706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp1 = _mm_srai_epi32(tmp1, DCT_CONST_BITS); \
49806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_srai_epi32(tmp2, DCT_CONST_BITS); \
49906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp3 = _mm_srai_epi32(tmp3, DCT_CONST_BITS); \
50006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
50106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_5 = _mm_packs_epi32(tmp0, tmp1); \
50206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_6 = _mm_packs_epi32(tmp2, tmp3); \
50306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  } \
50406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  \
50506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  /* Stage4  */ \
506dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  out0 = _mm_adds_epi16(stp1_0, stp2_7); \
507dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  out1 = _mm_adds_epi16(stp1_1, stp1_6); \
508dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  out2 = _mm_adds_epi16(stp1_2, stp1_5); \
509dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  out3 = _mm_adds_epi16(stp1_3, stp2_4); \
510dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  out4 = _mm_subs_epi16(stp1_3, stp2_4); \
511dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  out5 = _mm_subs_epi16(stp1_2, stp1_5); \
512dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  out6 = _mm_subs_epi16(stp1_1, stp1_6); \
513dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  out7 = _mm_subs_epi16(stp1_0, stp2_7); \
514dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  }
51506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
516ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.orgvoid vp9_idct8x8_64_add_sse2(const int16_t *input, uint8_t *dest, int stride) {
51710a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  const __m128i zero = _mm_setzero_si128();
51806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i rounding = _mm_set1_epi32(DCT_CONST_ROUNDING);
51906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i final_rounding = _mm_set1_epi16(1<<4);
52006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg1_0 = pair_set_epi16(cospi_28_64, -cospi_4_64);
52106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg1_1 = pair_set_epi16(cospi_4_64, cospi_28_64);
52206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg1_2 = pair_set_epi16(-cospi_20_64, cospi_12_64);
52306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg1_3 = pair_set_epi16(cospi_12_64, cospi_20_64);
52406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_0 = pair_set_epi16(cospi_16_64, cospi_16_64);
52506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_1 = pair_set_epi16(cospi_16_64, -cospi_16_64);
52606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_2 = pair_set_epi16(cospi_24_64, -cospi_8_64);
52706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_3 = pair_set_epi16(cospi_8_64, cospi_24_64);
52806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
52906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  __m128i in0, in1, in2, in3, in4, in5, in6, in7;
53006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  __m128i stp1_0, stp1_1, stp1_2, stp1_3, stp1_4, stp1_5, stp1_6, stp1_7;
53106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  __m128i stp2_0, stp2_1, stp2_2, stp2_3, stp2_4, stp2_5, stp2_6, stp2_7;
53206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  __m128i tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
53306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  int i;
53406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
53506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Load input data.
536ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in0 = _mm_load_si128((const __m128i *)input);
537ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in1 = _mm_load_si128((const __m128i *)(input + 8 * 1));
538ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in2 = _mm_load_si128((const __m128i *)(input + 8 * 2));
539ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in3 = _mm_load_si128((const __m128i *)(input + 8 * 3));
540ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in4 = _mm_load_si128((const __m128i *)(input + 8 * 4));
541ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in5 = _mm_load_si128((const __m128i *)(input + 8 * 5));
542ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in6 = _mm_load_si128((const __m128i *)(input + 8 * 6));
543ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in7 = _mm_load_si128((const __m128i *)(input + 8 * 7));
54406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
54506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // 2-D
54606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  for (i = 0; i < 2; i++) {
547ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org    // 8x8 Transpose is copied from vp9_fdct8x8_sse2()
548dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    TRANSPOSE_8X8(in0, in1, in2, in3, in4, in5, in6, in7,
549dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                  in0, in1, in2, in3, in4, in5, in6, in7);
55006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
55106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    // 4-stage 1D idct8x8
552dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    IDCT8(in0, in1, in2, in3, in4, in5, in6, in7,
553dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org             in0, in1, in2, in3, in4, in5, in6, in7);
55406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  }
55506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
55606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Final rounding and shift
55706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in0 = _mm_adds_epi16(in0, final_rounding);
55806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in1 = _mm_adds_epi16(in1, final_rounding);
55906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in2 = _mm_adds_epi16(in2, final_rounding);
56006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in3 = _mm_adds_epi16(in3, final_rounding);
56106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in4 = _mm_adds_epi16(in4, final_rounding);
56206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in5 = _mm_adds_epi16(in5, final_rounding);
56306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in6 = _mm_adds_epi16(in6, final_rounding);
56406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in7 = _mm_adds_epi16(in7, final_rounding);
56506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
56606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in0 = _mm_srai_epi16(in0, 5);
56706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in1 = _mm_srai_epi16(in1, 5);
56806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in2 = _mm_srai_epi16(in2, 5);
56906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in3 = _mm_srai_epi16(in3, 5);
57006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in4 = _mm_srai_epi16(in4, 5);
57106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in5 = _mm_srai_epi16(in5, 5);
57206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in6 = _mm_srai_epi16(in6, 5);
57306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in7 = _mm_srai_epi16(in7, 5);
57406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
57510a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in0);
57610a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in1);
57710a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in2);
57810a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in3);
57910a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in4);
58010a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in5);
58110a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in6);
58210a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in7);
58306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org}
58406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
585ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.orgvoid vp9_idct8x8_1_add_sse2(const int16_t *input, uint8_t *dest, int stride) {
58653a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  __m128i dc_value;
58753a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  const __m128i zero = _mm_setzero_si128();
58853a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  int a;
58953a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org
59053a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  a = dct_const_round_shift(input[0] * cospi_16_64);
59153a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  a = dct_const_round_shift(a * cospi_16_64);
59253a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  a = ROUND_POWER_OF_TWO(a, 5);
59353a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org
59453a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  dc_value = _mm_set1_epi16(a);
59553a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org
59653a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  RECON_AND_STORE(dest, dc_value);
59753a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  RECON_AND_STORE(dest, dc_value);
59853a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  RECON_AND_STORE(dest, dc_value);
59953a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  RECON_AND_STORE(dest, dc_value);
60053a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  RECON_AND_STORE(dest, dc_value);
60153a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  RECON_AND_STORE(dest, dc_value);
60253a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  RECON_AND_STORE(dest, dc_value);
60353a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  RECON_AND_STORE(dest, dc_value);
60453a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org}
60553a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org
606dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.orgstatic void idct8_sse2(__m128i *in) {
60747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i rounding = _mm_set1_epi32(DCT_CONST_ROUNDING);
60847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i stg1_0 = pair_set_epi16(cospi_28_64, -cospi_4_64);
60947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i stg1_1 = pair_set_epi16(cospi_4_64, cospi_28_64);
61047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i stg1_2 = pair_set_epi16(-cospi_20_64, cospi_12_64);
61147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i stg1_3 = pair_set_epi16(cospi_12_64, cospi_20_64);
61247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i stg2_0 = pair_set_epi16(cospi_16_64, cospi_16_64);
61347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i stg2_1 = pair_set_epi16(cospi_16_64, -cospi_16_64);
61447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i stg2_2 = pair_set_epi16(cospi_24_64, -cospi_8_64);
61547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i stg2_3 = pair_set_epi16(cospi_8_64, cospi_24_64);
61647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
61747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i in0, in1, in2, in3, in4, in5, in6, in7;
61847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i stp1_0, stp1_1, stp1_2, stp1_3, stp1_4, stp1_5, stp1_6, stp1_7;
61947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i stp2_0, stp2_1, stp2_2, stp2_3, stp2_4, stp2_5, stp2_6, stp2_7;
62047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
62147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
622ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  // 8x8 Transpose is copied from vp9_fdct8x8_sse2()
623dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  TRANSPOSE_8X8(in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7],
624dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                in0, in1, in2, in3, in4, in5, in6, in7);
62547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
62647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // 4-stage 1D idct8x8
627dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  IDCT8(in0, in1, in2, in3, in4, in5, in6, in7,
628dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org           in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]);
62947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org}
63047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
631dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.orgstatic void iadst8_sse2(__m128i *in) {
63247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p02_p30 = pair_set_epi16(cospi_2_64, cospi_30_64);
63347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p30_m02 = pair_set_epi16(cospi_30_64, -cospi_2_64);
63447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p10_p22 = pair_set_epi16(cospi_10_64, cospi_22_64);
63547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p22_m10 = pair_set_epi16(cospi_22_64, -cospi_10_64);
63647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p18_p14 = pair_set_epi16(cospi_18_64, cospi_14_64);
63747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p14_m18 = pair_set_epi16(cospi_14_64, -cospi_18_64);
63847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p26_p06 = pair_set_epi16(cospi_26_64, cospi_6_64);
63947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p06_m26 = pair_set_epi16(cospi_6_64, -cospi_26_64);
64047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p08_p24 = pair_set_epi16(cospi_8_64, cospi_24_64);
64147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p24_m08 = pair_set_epi16(cospi_24_64, -cospi_8_64);
64247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_m24_p08 = pair_set_epi16(-cospi_24_64, cospi_8_64);
64347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
64447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p16_p16 = _mm_set1_epi16(cospi_16_64);
64547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__const_0 = _mm_set1_epi16(0);
64647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
64747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
64847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i u0, u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, u11, u12, u13, u14, u15;
64947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15;
65047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15;
65147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i s0, s1, s2, s3, s4, s5, s6, s7;
65247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i in0, in1, in2, in3, in4, in5, in6, in7;
65347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
65447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // transpose
65547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  array_transpose_8x8(in, in);
65647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
65747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // properly aligned for butterfly input
65847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in0  = in[7];
65947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in1  = in[0];
66047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in2  = in[5];
66147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in3  = in[2];
66247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in4  = in[3];
66347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in5  = in[4];
66447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in6  = in[1];
66547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in7  = in[6];
66647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
66747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // column transformation
66847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // stage 1
66947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // interleave and multiply/add into 32-bit integer
67047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s0 = _mm_unpacklo_epi16(in0, in1);
67147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s1 = _mm_unpackhi_epi16(in0, in1);
67247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s2 = _mm_unpacklo_epi16(in2, in3);
67347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s3 = _mm_unpackhi_epi16(in2, in3);
67447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s4 = _mm_unpacklo_epi16(in4, in5);
67547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s5 = _mm_unpackhi_epi16(in4, in5);
67647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s6 = _mm_unpacklo_epi16(in6, in7);
67747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s7 = _mm_unpackhi_epi16(in6, in7);
67847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
67947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u0 = _mm_madd_epi16(s0, k__cospi_p02_p30);
68047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u1 = _mm_madd_epi16(s1, k__cospi_p02_p30);
68147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u2 = _mm_madd_epi16(s0, k__cospi_p30_m02);
68247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u3 = _mm_madd_epi16(s1, k__cospi_p30_m02);
68347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u4 = _mm_madd_epi16(s2, k__cospi_p10_p22);
68447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u5 = _mm_madd_epi16(s3, k__cospi_p10_p22);
68547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u6 = _mm_madd_epi16(s2, k__cospi_p22_m10);
68647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u7 = _mm_madd_epi16(s3, k__cospi_p22_m10);
68747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u8 = _mm_madd_epi16(s4, k__cospi_p18_p14);
68847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u9 = _mm_madd_epi16(s5, k__cospi_p18_p14);
68947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u10 = _mm_madd_epi16(s4, k__cospi_p14_m18);
69047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u11 = _mm_madd_epi16(s5, k__cospi_p14_m18);
69147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u12 = _mm_madd_epi16(s6, k__cospi_p26_p06);
69247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u13 = _mm_madd_epi16(s7, k__cospi_p26_p06);
69347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u14 = _mm_madd_epi16(s6, k__cospi_p06_m26);
69447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u15 = _mm_madd_epi16(s7, k__cospi_p06_m26);
69547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
69647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // addition
69747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w0 = _mm_add_epi32(u0, u8);
69847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w1 = _mm_add_epi32(u1, u9);
69947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w2 = _mm_add_epi32(u2, u10);
70047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w3 = _mm_add_epi32(u3, u11);
70147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w4 = _mm_add_epi32(u4, u12);
70247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w5 = _mm_add_epi32(u5, u13);
70347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w6 = _mm_add_epi32(u6, u14);
70447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w7 = _mm_add_epi32(u7, u15);
70547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w8 = _mm_sub_epi32(u0, u8);
70647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w9 = _mm_sub_epi32(u1, u9);
70747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w10 = _mm_sub_epi32(u2, u10);
70847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w11 = _mm_sub_epi32(u3, u11);
70947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w12 = _mm_sub_epi32(u4, u12);
71047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w13 = _mm_sub_epi32(u5, u13);
71147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w14 = _mm_sub_epi32(u6, u14);
71247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w15 = _mm_sub_epi32(u7, u15);
71347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
71447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // shift and rounding
71547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v0 = _mm_add_epi32(w0, k__DCT_CONST_ROUNDING);
71647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v1 = _mm_add_epi32(w1, k__DCT_CONST_ROUNDING);
71747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v2 = _mm_add_epi32(w2, k__DCT_CONST_ROUNDING);
71847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v3 = _mm_add_epi32(w3, k__DCT_CONST_ROUNDING);
71947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v4 = _mm_add_epi32(w4, k__DCT_CONST_ROUNDING);
72047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v5 = _mm_add_epi32(w5, k__DCT_CONST_ROUNDING);
72147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v6 = _mm_add_epi32(w6, k__DCT_CONST_ROUNDING);
72247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v7 = _mm_add_epi32(w7, k__DCT_CONST_ROUNDING);
72347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v8 = _mm_add_epi32(w8, k__DCT_CONST_ROUNDING);
72447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v9 = _mm_add_epi32(w9, k__DCT_CONST_ROUNDING);
72547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v10 = _mm_add_epi32(w10, k__DCT_CONST_ROUNDING);
72647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v11 = _mm_add_epi32(w11, k__DCT_CONST_ROUNDING);
72747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v12 = _mm_add_epi32(w12, k__DCT_CONST_ROUNDING);
72847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v13 = _mm_add_epi32(w13, k__DCT_CONST_ROUNDING);
72947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v14 = _mm_add_epi32(w14, k__DCT_CONST_ROUNDING);
73047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v15 = _mm_add_epi32(w15, k__DCT_CONST_ROUNDING);
73147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
73247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
73347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
73447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
73547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
73647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
73747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
73847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
73947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
74047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u8 = _mm_srai_epi32(v8, DCT_CONST_BITS);
74147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u9 = _mm_srai_epi32(v9, DCT_CONST_BITS);
74247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u10 = _mm_srai_epi32(v10, DCT_CONST_BITS);
74347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u11 = _mm_srai_epi32(v11, DCT_CONST_BITS);
74447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u12 = _mm_srai_epi32(v12, DCT_CONST_BITS);
74547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u13 = _mm_srai_epi32(v13, DCT_CONST_BITS);
74647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u14 = _mm_srai_epi32(v14, DCT_CONST_BITS);
74747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u15 = _mm_srai_epi32(v15, DCT_CONST_BITS);
74847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
74947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // back to 16-bit and pack 8 integers into __m128i
75047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[0] = _mm_packs_epi32(u0, u1);
75147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[1] = _mm_packs_epi32(u2, u3);
75247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[2] = _mm_packs_epi32(u4, u5);
75347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[3] = _mm_packs_epi32(u6, u7);
75447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[4] = _mm_packs_epi32(u8, u9);
75547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[5] = _mm_packs_epi32(u10, u11);
75647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[6] = _mm_packs_epi32(u12, u13);
75747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[7] = _mm_packs_epi32(u14, u15);
75847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
75947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // stage 2
76047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s0 = _mm_add_epi16(in[0], in[2]);
76147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s1 = _mm_add_epi16(in[1], in[3]);
76247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s2 = _mm_sub_epi16(in[0], in[2]);
76347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s3 = _mm_sub_epi16(in[1], in[3]);
76447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u0 = _mm_unpacklo_epi16(in[4], in[5]);
76547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u1 = _mm_unpackhi_epi16(in[4], in[5]);
76647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u2 = _mm_unpacklo_epi16(in[6], in[7]);
76747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u3 = _mm_unpackhi_epi16(in[6], in[7]);
76847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
76947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v0 = _mm_madd_epi16(u0, k__cospi_p08_p24);
77047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v1 = _mm_madd_epi16(u1, k__cospi_p08_p24);
77147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v2 = _mm_madd_epi16(u0, k__cospi_p24_m08);
77247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v3 = _mm_madd_epi16(u1, k__cospi_p24_m08);
77347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v4 = _mm_madd_epi16(u2, k__cospi_m24_p08);
77447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v5 = _mm_madd_epi16(u3, k__cospi_m24_p08);
77547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v6 = _mm_madd_epi16(u2, k__cospi_p08_p24);
77647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v7 = _mm_madd_epi16(u3, k__cospi_p08_p24);
77747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
77847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w0 = _mm_add_epi32(v0, v4);
77947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w1 = _mm_add_epi32(v1, v5);
78047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w2 = _mm_add_epi32(v2, v6);
78147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w3 = _mm_add_epi32(v3, v7);
78247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w4 = _mm_sub_epi32(v0, v4);
78347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w5 = _mm_sub_epi32(v1, v5);
78447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w6 = _mm_sub_epi32(v2, v6);
78547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  w7 = _mm_sub_epi32(v3, v7);
78647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
78747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v0 = _mm_add_epi32(w0, k__DCT_CONST_ROUNDING);
78847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v1 = _mm_add_epi32(w1, k__DCT_CONST_ROUNDING);
78947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v2 = _mm_add_epi32(w2, k__DCT_CONST_ROUNDING);
79047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v3 = _mm_add_epi32(w3, k__DCT_CONST_ROUNDING);
79147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v4 = _mm_add_epi32(w4, k__DCT_CONST_ROUNDING);
79247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v5 = _mm_add_epi32(w5, k__DCT_CONST_ROUNDING);
79347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v6 = _mm_add_epi32(w6, k__DCT_CONST_ROUNDING);
79447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v7 = _mm_add_epi32(w7, k__DCT_CONST_ROUNDING);
79547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
79647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
79747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
79847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
79947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
80047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
80147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
80247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
80347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
80447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
80547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // back to 16-bit intergers
80647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s4 = _mm_packs_epi32(u0, u1);
80747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s5 = _mm_packs_epi32(u2, u3);
80847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s6 = _mm_packs_epi32(u4, u5);
80947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s7 = _mm_packs_epi32(u6, u7);
81047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
81147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // stage 3
81247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u0 = _mm_unpacklo_epi16(s2, s3);
81347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u1 = _mm_unpackhi_epi16(s2, s3);
81447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u2 = _mm_unpacklo_epi16(s6, s7);
81547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u3 = _mm_unpackhi_epi16(s6, s7);
81647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
81747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v0 = _mm_madd_epi16(u0, k__cospi_p16_p16);
81847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v1 = _mm_madd_epi16(u1, k__cospi_p16_p16);
81947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v2 = _mm_madd_epi16(u0, k__cospi_p16_m16);
82047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v3 = _mm_madd_epi16(u1, k__cospi_p16_m16);
82147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v4 = _mm_madd_epi16(u2, k__cospi_p16_p16);
82247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v5 = _mm_madd_epi16(u3, k__cospi_p16_p16);
82347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v6 = _mm_madd_epi16(u2, k__cospi_p16_m16);
82447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v7 = _mm_madd_epi16(u3, k__cospi_p16_m16);
82547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
82647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u0 = _mm_add_epi32(v0, k__DCT_CONST_ROUNDING);
82747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u1 = _mm_add_epi32(v1, k__DCT_CONST_ROUNDING);
82847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u2 = _mm_add_epi32(v2, k__DCT_CONST_ROUNDING);
82947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u3 = _mm_add_epi32(v3, k__DCT_CONST_ROUNDING);
83047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u4 = _mm_add_epi32(v4, k__DCT_CONST_ROUNDING);
83147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u5 = _mm_add_epi32(v5, k__DCT_CONST_ROUNDING);
83247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u6 = _mm_add_epi32(v6, k__DCT_CONST_ROUNDING);
83347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u7 = _mm_add_epi32(v7, k__DCT_CONST_ROUNDING);
83447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
83547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v0 = _mm_srai_epi32(u0, DCT_CONST_BITS);
83647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v1 = _mm_srai_epi32(u1, DCT_CONST_BITS);
83747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v2 = _mm_srai_epi32(u2, DCT_CONST_BITS);
83847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v3 = _mm_srai_epi32(u3, DCT_CONST_BITS);
83947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v4 = _mm_srai_epi32(u4, DCT_CONST_BITS);
84047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v5 = _mm_srai_epi32(u5, DCT_CONST_BITS);
84147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v6 = _mm_srai_epi32(u6, DCT_CONST_BITS);
84247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v7 = _mm_srai_epi32(u7, DCT_CONST_BITS);
84347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
84447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s2 = _mm_packs_epi32(v0, v1);
84547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s3 = _mm_packs_epi32(v2, v3);
84647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s6 = _mm_packs_epi32(v4, v5);
84747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s7 = _mm_packs_epi32(v6, v7);
84847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
84947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[0] = s0;
85047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[1] = _mm_sub_epi16(k__const_0, s4);
85147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[2] = s6;
85247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[3] = _mm_sub_epi16(k__const_0, s2);
85347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[4] = s3;
85447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[5] = _mm_sub_epi16(k__const_0, s7);
85547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[6] = s5;
85647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[7] = _mm_sub_epi16(k__const_0, s1);
85747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org}
85847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
85947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
860ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.orgvoid vp9_iht8x8_64_add_sse2(const int16_t *input, uint8_t *dest, int stride,
861ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org                            int tx_type) {
86247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i in[8];
86347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i zero = _mm_setzero_si128();
86447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i final_rounding = _mm_set1_epi16(1<<4);
86547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
86647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // load input data
867ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in[0] = _mm_load_si128((const __m128i *)input);
868ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in[1] = _mm_load_si128((const __m128i *)(input + 8 * 1));
869ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in[2] = _mm_load_si128((const __m128i *)(input + 8 * 2));
870ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in[3] = _mm_load_si128((const __m128i *)(input + 8 * 3));
871ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in[4] = _mm_load_si128((const __m128i *)(input + 8 * 4));
872ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in[5] = _mm_load_si128((const __m128i *)(input + 8 * 5));
873ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in[6] = _mm_load_si128((const __m128i *)(input + 8 * 6));
874ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in[7] = _mm_load_si128((const __m128i *)(input + 8 * 7));
87547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
87647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  switch (tx_type) {
87747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org    case 0:  // DCT_DCT
878dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      idct8_sse2(in);
879dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      idct8_sse2(in);
88047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org      break;
88147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org    case 1:  // ADST_DCT
882dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      idct8_sse2(in);
883dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      iadst8_sse2(in);
88447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org      break;
88547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org    case 2:  // DCT_ADST
886dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      iadst8_sse2(in);
887dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      idct8_sse2(in);
88847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org      break;
88947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org    case 3:  // ADST_ADST
890dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      iadst8_sse2(in);
891dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      iadst8_sse2(in);
89247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org      break;
89347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org    default:
89447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org      assert(0);
89547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org      break;
89647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  }
89747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
89847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // Final rounding and shift
89947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[0] = _mm_adds_epi16(in[0], final_rounding);
90047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[1] = _mm_adds_epi16(in[1], final_rounding);
90147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[2] = _mm_adds_epi16(in[2], final_rounding);
90247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[3] = _mm_adds_epi16(in[3], final_rounding);
90347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[4] = _mm_adds_epi16(in[4], final_rounding);
90447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[5] = _mm_adds_epi16(in[5], final_rounding);
90547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[6] = _mm_adds_epi16(in[6], final_rounding);
90647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[7] = _mm_adds_epi16(in[7], final_rounding);
90747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
90847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[0] = _mm_srai_epi16(in[0], 5);
90947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[1] = _mm_srai_epi16(in[1], 5);
91047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[2] = _mm_srai_epi16(in[2], 5);
91147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[3] = _mm_srai_epi16(in[3], 5);
91247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[4] = _mm_srai_epi16(in[4], 5);
91347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[5] = _mm_srai_epi16(in[5], 5);
91447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[6] = _mm_srai_epi16(in[6], 5);
91547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  in[7] = _mm_srai_epi16(in[7], 5);
91647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
91747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  RECON_AND_STORE(dest, in[0]);
91847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  RECON_AND_STORE(dest, in[1]);
91947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  RECON_AND_STORE(dest, in[2]);
92047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  RECON_AND_STORE(dest, in[3]);
92147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  RECON_AND_STORE(dest, in[4]);
92247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  RECON_AND_STORE(dest, in[5]);
92347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  RECON_AND_STORE(dest, in[6]);
92447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  RECON_AND_STORE(dest, in[7]);
92547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org}
92647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
9277765c078fa920ba6c949c15f16b6cc979d8bb95bjohannkoenig@chromium.orgvoid vp9_idct8x8_12_add_sse2(const int16_t *input, uint8_t *dest, int stride) {
92806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i zero = _mm_setzero_si128();
92906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i rounding = _mm_set1_epi32(DCT_CONST_ROUNDING);
93006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i final_rounding = _mm_set1_epi16(1<<4);
93106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg1_0 = pair_set_epi16(cospi_28_64, -cospi_4_64);
93206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg1_1 = pair_set_epi16(cospi_4_64, cospi_28_64);
93306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg1_2 = pair_set_epi16(-cospi_20_64, cospi_12_64);
93406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg1_3 = pair_set_epi16(cospi_12_64, cospi_20_64);
93506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_0 = pair_set_epi16(cospi_16_64, cospi_16_64);
93606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_1 = pair_set_epi16(cospi_16_64, -cospi_16_64);
93706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_2 = pair_set_epi16(cospi_24_64, -cospi_8_64);
93806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_3 = pair_set_epi16(cospi_8_64, cospi_24_64);
93906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg3_0 = pair_set_epi16(-cospi_16_64, cospi_16_64);
94006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
94106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  __m128i in0, in1, in2, in3, in4, in5, in6, in7;
94206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  __m128i stp1_0, stp1_1, stp1_2, stp1_3, stp1_4, stp1_5, stp1_6, stp1_7;
94306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  __m128i stp2_0, stp2_1, stp2_2, stp2_3, stp2_4, stp2_5, stp2_6, stp2_7;
94406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  __m128i tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
94506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
94606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Rows. Load 4-row input data.
947ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in0 = _mm_load_si128((const __m128i *)input);
948ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in1 = _mm_load_si128((const __m128i *)(input + 8 * 1));
949ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in2 = _mm_load_si128((const __m128i *)(input + 8 * 2));
950ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  in3 = _mm_load_si128((const __m128i *)(input + 8 * 3));
95106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
95206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // 8x4 Transpose
953dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  TRANSPOSE_8X8_10(in0, in1, in2, in3, in0, in1);
95406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Stage1
955ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  { //NOLINT
956dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    const __m128i lo_17 = _mm_unpackhi_epi16(in0, zero);
957dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    const __m128i lo_35 = _mm_unpackhi_epi16(in1, zero);
95806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
95906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_madd_epi16(lo_17, stg1_0);
96006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_madd_epi16(lo_17, stg1_1);
96106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp4 = _mm_madd_epi16(lo_35, stg1_2);
96206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp6 = _mm_madd_epi16(lo_35, stg1_3);
96306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
96406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_add_epi32(tmp0, rounding);
96506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_add_epi32(tmp2, rounding);
96606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp4 = _mm_add_epi32(tmp4, rounding);
96706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp6 = _mm_add_epi32(tmp6, rounding);
96806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_srai_epi32(tmp0, DCT_CONST_BITS);
96906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_srai_epi32(tmp2, DCT_CONST_BITS);
97006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp4 = _mm_srai_epi32(tmp4, DCT_CONST_BITS);
97106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp6 = _mm_srai_epi32(tmp6, DCT_CONST_BITS);
97206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
973dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    stp1_4 = _mm_packs_epi32(tmp0, tmp2);
974dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    stp1_5 = _mm_packs_epi32(tmp4, tmp6);
97506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  }
97606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
97706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Stage2
978ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  { //NOLINT
979dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    const __m128i lo_04 = _mm_unpacklo_epi16(in0, zero);
980dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    const __m128i lo_26 = _mm_unpacklo_epi16(in1, zero);
98106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
98206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_madd_epi16(lo_04, stg2_0);
98306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_madd_epi16(lo_04, stg2_1);
98406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp4 = _mm_madd_epi16(lo_26, stg2_2);
98506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp6 = _mm_madd_epi16(lo_26, stg2_3);
98606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
98706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_add_epi32(tmp0, rounding);
98806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_add_epi32(tmp2, rounding);
98906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp4 = _mm_add_epi32(tmp4, rounding);
99006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp6 = _mm_add_epi32(tmp6, rounding);
99106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_srai_epi32(tmp0, DCT_CONST_BITS);
99206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_srai_epi32(tmp2, DCT_CONST_BITS);
99306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp4 = _mm_srai_epi32(tmp4, DCT_CONST_BITS);
99406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp6 = _mm_srai_epi32(tmp6, DCT_CONST_BITS);
99506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
996dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    stp2_0 = _mm_packs_epi32(tmp0, tmp2);
997dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    stp2_2 = _mm_packs_epi32(tmp6, tmp4);
998dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
999dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    tmp0 = _mm_adds_epi16(stp1_4, stp1_5);
1000dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    tmp1 = _mm_subs_epi16(stp1_4, stp1_5);
100106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
1002dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    stp2_4 = tmp0;
1003dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    stp2_5 = _mm_unpacklo_epi64(tmp1, zero);
1004dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    stp2_6 = _mm_unpackhi_epi64(tmp1, zero);
100506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  }
100606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
100706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Stage3
1008ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  { //NOLINT
100906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i lo_56 = _mm_unpacklo_epi16(stp2_5, stp2_6);
1010dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
1011dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    tmp4 = _mm_adds_epi16(stp2_0, stp2_2);
1012dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    tmp6 = _mm_subs_epi16(stp2_0, stp2_2);
1013dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
1014dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    stp1_2 = _mm_unpackhi_epi64(tmp6, tmp4);
1015dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    stp1_3 = _mm_unpacklo_epi64(tmp6, tmp4);
101606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
101706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_madd_epi16(lo_56, stg3_0);
101806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_madd_epi16(lo_56, stg2_0);  // stg3_1 = stg2_0
101906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
102006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_add_epi32(tmp0, rounding);
102106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_add_epi32(tmp2, rounding);
102206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_srai_epi32(tmp0, DCT_CONST_BITS);
102306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_srai_epi32(tmp2, DCT_CONST_BITS);
102406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
1025dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    stp1_5 = _mm_packs_epi32(tmp0, tmp2);
102606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  }
102706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
102806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Stage4
1029dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  tmp0 = _mm_adds_epi16(stp1_3, stp2_4);
1030dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  tmp1 = _mm_adds_epi16(stp1_2, stp1_5);
1031dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  tmp2 = _mm_subs_epi16(stp1_3, stp2_4);
1032dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  tmp3 = _mm_subs_epi16(stp1_2, stp1_5);
1033dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
1034dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  TRANSPOSE_4X8_10(tmp0, tmp1, tmp2, tmp3, in0, in1, in2, in3)
103506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
1036dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  IDCT8(in0, in1, in2, in3, zero, zero, zero, zero,
1037dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org           in0, in1, in2, in3, in4, in5, in6, in7);
103806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  // Final rounding and shift
103906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in0 = _mm_adds_epi16(in0, final_rounding);
104006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in1 = _mm_adds_epi16(in1, final_rounding);
104106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in2 = _mm_adds_epi16(in2, final_rounding);
104206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in3 = _mm_adds_epi16(in3, final_rounding);
104306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in4 = _mm_adds_epi16(in4, final_rounding);
104406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in5 = _mm_adds_epi16(in5, final_rounding);
104506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in6 = _mm_adds_epi16(in6, final_rounding);
104606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in7 = _mm_adds_epi16(in7, final_rounding);
104706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
104806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in0 = _mm_srai_epi16(in0, 5);
104906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in1 = _mm_srai_epi16(in1, 5);
105006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in2 = _mm_srai_epi16(in2, 5);
105106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in3 = _mm_srai_epi16(in3, 5);
105206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in4 = _mm_srai_epi16(in4, 5);
105306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in5 = _mm_srai_epi16(in5, 5);
105406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in6 = _mm_srai_epi16(in6, 5);
105506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  in7 = _mm_srai_epi16(in7, 5);
105606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
105710a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in0);
105810a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in1);
105910a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in2);
106010a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in3);
106110a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in4);
106210a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in5);
106310a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in6);
106410a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  RECON_AND_STORE(dest, in7);
106506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org}
106606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
1067dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#define IDCT16 \
106806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  /* Stage2 */ \
106906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  { \
1070d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i lo_1_15 = _mm_unpacklo_epi16(in[1], in[15]); \
1071d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i hi_1_15 = _mm_unpackhi_epi16(in[1], in[15]); \
1072d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i lo_9_7 = _mm_unpacklo_epi16(in[9], in[7]);   \
1073d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i hi_9_7 = _mm_unpackhi_epi16(in[9], in[7]);   \
1074d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i lo_5_11 = _mm_unpacklo_epi16(in[5], in[11]); \
1075d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i hi_5_11 = _mm_unpackhi_epi16(in[5], in[11]); \
1076d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i lo_13_3 = _mm_unpacklo_epi16(in[13], in[3]); \
1077d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i hi_13_3 = _mm_unpackhi_epi16(in[13], in[3]); \
107806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
107906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    MULTIPLICATION_AND_ADD(lo_1_15, hi_1_15, lo_9_7, hi_9_7, \
108006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stg2_0, stg2_1, stg2_2, stg2_3, \
108106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stp2_8, stp2_15, stp2_9, stp2_14) \
108206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
108306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    MULTIPLICATION_AND_ADD(lo_5_11, hi_5_11, lo_13_3, hi_13_3, \
108406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stg2_4, stg2_5, stg2_6, stg2_7, \
108506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stp2_10, stp2_13, stp2_11, stp2_12) \
108606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  } \
108706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
108806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  /* Stage3 */ \
108906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  { \
1090d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i lo_2_14 = _mm_unpacklo_epi16(in[2], in[14]); \
1091d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i hi_2_14 = _mm_unpackhi_epi16(in[2], in[14]); \
1092d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i lo_10_6 = _mm_unpacklo_epi16(in[10], in[6]); \
1093d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i hi_10_6 = _mm_unpackhi_epi16(in[10], in[6]); \
109406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
109506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    MULTIPLICATION_AND_ADD(lo_2_14, hi_2_14, lo_10_6, hi_10_6, \
109606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stg3_0, stg3_1, stg3_2, stg3_3, \
109706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stp1_4, stp1_7, stp1_5, stp1_6) \
109806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
109906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_8_0 = _mm_add_epi16(stp2_8, stp2_9);  \
110006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_9 = _mm_sub_epi16(stp2_8, stp2_9);    \
110106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_10 = _mm_sub_epi16(stp2_11, stp2_10); \
110206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_11 = _mm_add_epi16(stp2_11, stp2_10); \
110306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
110406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_12_0 = _mm_add_epi16(stp2_12, stp2_13); \
110506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_13 = _mm_sub_epi16(stp2_12, stp2_13); \
110606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_14 = _mm_sub_epi16(stp2_15, stp2_14); \
110706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_15 = _mm_add_epi16(stp2_15, stp2_14); \
110806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  } \
110906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  \
111006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  /* Stage4 */ \
111106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  { \
1112d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i lo_0_8 = _mm_unpacklo_epi16(in[0], in[8]); \
1113d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i hi_0_8 = _mm_unpackhi_epi16(in[0], in[8]); \
1114d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i lo_4_12 = _mm_unpacklo_epi16(in[4], in[12]); \
1115d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    const __m128i hi_4_12 = _mm_unpackhi_epi16(in[4], in[12]); \
111606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
111706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i lo_9_14 = _mm_unpacklo_epi16(stp1_9, stp1_14); \
111806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i hi_9_14 = _mm_unpackhi_epi16(stp1_9, stp1_14); \
111906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i lo_10_13 = _mm_unpacklo_epi16(stp1_10, stp1_13); \
112006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i hi_10_13 = _mm_unpackhi_epi16(stp1_10, stp1_13); \
112106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
112206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    MULTIPLICATION_AND_ADD(lo_0_8, hi_0_8, lo_4_12, hi_4_12, \
112306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stg4_0, stg4_1, stg4_2, stg4_3, \
112406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stp2_0, stp2_1, stp2_2, stp2_3) \
112506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
112606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_4 = _mm_add_epi16(stp1_4, stp1_5); \
112706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_5 = _mm_sub_epi16(stp1_4, stp1_5); \
112806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_6 = _mm_sub_epi16(stp1_7, stp1_6); \
112906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_7 = _mm_add_epi16(stp1_7, stp1_6); \
113006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
113106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    MULTIPLICATION_AND_ADD(lo_9_14, hi_9_14, lo_10_13, hi_10_13, \
113206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stg4_4, stg4_5, stg4_6, stg4_7, \
113306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stp2_9, stp2_14, stp2_10, stp2_13) \
113406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  } \
113506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
113606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  /* Stage5 */ \
113706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  { \
113806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i lo_6_5 = _mm_unpacklo_epi16(stp2_6, stp2_5); \
113906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i hi_6_5 = _mm_unpackhi_epi16(stp2_6, stp2_5); \
114006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
114106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_0 = _mm_add_epi16(stp2_0, stp2_3); \
114206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_1 = _mm_add_epi16(stp2_1, stp2_2); \
114306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_2 = _mm_sub_epi16(stp2_1, stp2_2); \
114406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_3 = _mm_sub_epi16(stp2_0, stp2_3); \
114506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
114606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_madd_epi16(lo_6_5, stg4_1); \
114706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp1 = _mm_madd_epi16(hi_6_5, stg4_1); \
114806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_madd_epi16(lo_6_5, stg4_0); \
114906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp3 = _mm_madd_epi16(hi_6_5, stg4_0); \
115006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
115106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_add_epi32(tmp0, rounding); \
115206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp1 = _mm_add_epi32(tmp1, rounding); \
115306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_add_epi32(tmp2, rounding); \
115406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp3 = _mm_add_epi32(tmp3, rounding); \
115506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
115606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp0 = _mm_srai_epi32(tmp0, DCT_CONST_BITS); \
115706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp1 = _mm_srai_epi32(tmp1, DCT_CONST_BITS); \
115806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp2 = _mm_srai_epi32(tmp2, DCT_CONST_BITS); \
115906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    tmp3 = _mm_srai_epi32(tmp3, DCT_CONST_BITS); \
116006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
116106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_5 = _mm_packs_epi32(tmp0, tmp1); \
116206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_6 = _mm_packs_epi32(tmp2, tmp3); \
116306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
116406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_8 = _mm_add_epi16(stp1_8_0, stp1_11);  \
116506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_9 = _mm_add_epi16(stp2_9, stp2_10);    \
116606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_10 = _mm_sub_epi16(stp2_9, stp2_10);   \
116706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_11 = _mm_sub_epi16(stp1_8_0, stp1_11); \
116806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
116906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_12 = _mm_sub_epi16(stp1_15, stp1_12_0); \
117006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_13 = _mm_sub_epi16(stp2_14, stp2_13);   \
117106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_14 = _mm_add_epi16(stp2_14, stp2_13);   \
117206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp1_15 = _mm_add_epi16(stp1_15, stp1_12_0); \
117306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  } \
117406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
117506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  /* Stage6 */ \
117606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  { \
117706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i lo_10_13 = _mm_unpacklo_epi16(stp1_10, stp1_13); \
117806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i hi_10_13 = _mm_unpackhi_epi16(stp1_10, stp1_13); \
117906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i lo_11_12 = _mm_unpacklo_epi16(stp1_11, stp1_12); \
118006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    const __m128i hi_11_12 = _mm_unpackhi_epi16(stp1_11, stp1_12); \
118106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
118206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_0 = _mm_add_epi16(stp1_0, stp2_7); \
118306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_1 = _mm_add_epi16(stp1_1, stp1_6); \
118406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_2 = _mm_add_epi16(stp1_2, stp1_5); \
118506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_3 = _mm_add_epi16(stp1_3, stp2_4); \
118606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_4 = _mm_sub_epi16(stp1_3, stp2_4); \
118706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_5 = _mm_sub_epi16(stp1_2, stp1_5); \
118806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_6 = _mm_sub_epi16(stp1_1, stp1_6); \
118906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    stp2_7 = _mm_sub_epi16(stp1_0, stp2_7); \
119006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    \
119106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org    MULTIPLICATION_AND_ADD(lo_10_13, hi_10_13, lo_11_12, hi_11_12, \
119206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stg6_0, stg4_0, stg6_0, stg4_0, \
119306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org                           stp2_10, stp2_13, stp2_11, stp2_12) \
119406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  }
119506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
1196dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#define IDCT16_10 \
1197dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    /* Stage2 */ \
1198dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    { \
1199dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i lo_1_15 = _mm_unpacklo_epi16(in[1], zero); \
1200dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i hi_1_15 = _mm_unpackhi_epi16(in[1], zero); \
1201dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i lo_13_3 = _mm_unpacklo_epi16(zero, in[3]); \
1202dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i hi_13_3 = _mm_unpackhi_epi16(zero, in[3]); \
1203dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1204dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      MULTIPLICATION_AND_ADD(lo_1_15, hi_1_15, lo_13_3, hi_13_3, \
1205dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                             stg2_0, stg2_1, stg2_6, stg2_7, \
1206dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                             stp1_8_0, stp1_15, stp1_11, stp1_12_0) \
1207dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    } \
1208dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1209dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    /* Stage3 */ \
1210dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    { \
1211dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i lo_2_14 = _mm_unpacklo_epi16(in[2], zero); \
1212dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i hi_2_14 = _mm_unpackhi_epi16(in[2], zero); \
1213dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1214dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      MULTIPLICATION_AND_ADD_2(lo_2_14, hi_2_14, \
1215dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                               stg3_0, stg3_1,  \
1216dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                               stp2_4, stp2_7) \
1217dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1218dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_9  =  stp1_8_0; \
1219dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_10 =  stp1_11;  \
1220dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1221dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_13 = stp1_12_0; \
1222dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_14 = stp1_15;   \
1223dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    } \
1224dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    \
1225dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    /* Stage4 */ \
1226dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    { \
1227dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i lo_0_8 = _mm_unpacklo_epi16(in[0], zero); \
1228dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i hi_0_8 = _mm_unpackhi_epi16(in[0], zero); \
1229dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1230dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i lo_9_14 = _mm_unpacklo_epi16(stp1_9, stp1_14); \
1231dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i hi_9_14 = _mm_unpackhi_epi16(stp1_9, stp1_14); \
1232dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i lo_10_13 = _mm_unpacklo_epi16(stp1_10, stp1_13); \
1233dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i hi_10_13 = _mm_unpackhi_epi16(stp1_10, stp1_13); \
1234dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1235dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      MULTIPLICATION_AND_ADD_2(lo_0_8, hi_0_8, \
1236dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                               stg4_0, stg4_1, \
1237dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                               stp1_0, stp1_1) \
1238dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp2_5 = stp2_4; \
1239dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp2_6 = stp2_7; \
1240dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1241dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      MULTIPLICATION_AND_ADD(lo_9_14, hi_9_14, lo_10_13, hi_10_13, \
1242dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                             stg4_4, stg4_5, stg4_6, stg4_7, \
1243dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                             stp2_9, stp2_14, stp2_10, stp2_13) \
1244dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    } \
1245dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1246dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    /* Stage5 */ \
1247dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    { \
1248dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i lo_6_5 = _mm_unpacklo_epi16(stp2_6, stp2_5); \
1249dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i hi_6_5 = _mm_unpackhi_epi16(stp2_6, stp2_5); \
1250dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1251dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_2 = stp1_1; \
1252dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_3 = stp1_0; \
1253dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1254dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      tmp0 = _mm_madd_epi16(lo_6_5, stg4_1); \
1255dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      tmp1 = _mm_madd_epi16(hi_6_5, stg4_1); \
1256dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      tmp2 = _mm_madd_epi16(lo_6_5, stg4_0); \
1257dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      tmp3 = _mm_madd_epi16(hi_6_5, stg4_0); \
1258dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1259dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      tmp0 = _mm_add_epi32(tmp0, rounding); \
1260dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      tmp1 = _mm_add_epi32(tmp1, rounding); \
1261dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      tmp2 = _mm_add_epi32(tmp2, rounding); \
1262dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      tmp3 = _mm_add_epi32(tmp3, rounding); \
1263dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1264dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      tmp0 = _mm_srai_epi32(tmp0, DCT_CONST_BITS); \
1265dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      tmp1 = _mm_srai_epi32(tmp1, DCT_CONST_BITS); \
1266dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      tmp2 = _mm_srai_epi32(tmp2, DCT_CONST_BITS); \
1267dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      tmp3 = _mm_srai_epi32(tmp3, DCT_CONST_BITS); \
1268dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1269dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_5 = _mm_packs_epi32(tmp0, tmp1); \
1270dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_6 = _mm_packs_epi32(tmp2, tmp3); \
1271dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1272dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_8 = _mm_add_epi16(stp1_8_0, stp1_11);  \
1273dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_9 = _mm_add_epi16(stp2_9, stp2_10);    \
1274dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_10 = _mm_sub_epi16(stp2_9, stp2_10);   \
1275dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_11 = _mm_sub_epi16(stp1_8_0, stp1_11); \
1276dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1277dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_12 = _mm_sub_epi16(stp1_15, stp1_12_0); \
1278dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_13 = _mm_sub_epi16(stp2_14, stp2_13);   \
1279dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_14 = _mm_add_epi16(stp2_14, stp2_13);   \
1280dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp1_15 = _mm_add_epi16(stp1_15, stp1_12_0); \
1281dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    } \
1282dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1283dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    /* Stage6 */ \
1284dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    { \
1285dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i lo_10_13 = _mm_unpacklo_epi16(stp1_10, stp1_13); \
1286dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i hi_10_13 = _mm_unpackhi_epi16(stp1_10, stp1_13); \
1287dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i lo_11_12 = _mm_unpacklo_epi16(stp1_11, stp1_12); \
1288dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      const __m128i hi_11_12 = _mm_unpackhi_epi16(stp1_11, stp1_12); \
1289dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1290dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp2_0 = _mm_add_epi16(stp1_0, stp2_7); \
1291dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp2_1 = _mm_add_epi16(stp1_1, stp1_6); \
1292dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp2_2 = _mm_add_epi16(stp1_2, stp1_5); \
1293dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp2_3 = _mm_add_epi16(stp1_3, stp2_4); \
1294dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp2_4 = _mm_sub_epi16(stp1_3, stp2_4); \
1295dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp2_5 = _mm_sub_epi16(stp1_2, stp1_5); \
1296dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp2_6 = _mm_sub_epi16(stp1_1, stp1_6); \
1297dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      stp2_7 = _mm_sub_epi16(stp1_0, stp2_7); \
1298dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      \
1299dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      MULTIPLICATION_AND_ADD(lo_10_13, hi_10_13, lo_11_12, hi_11_12, \
1300dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                             stg6_0, stg4_0, stg6_0, stg4_0, \
1301dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                             stp2_10, stp2_13, stp2_11, stp2_12) \
1302dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org    }
1303dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
1304ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.orgvoid vp9_idct16x16_256_add_sse2(const int16_t *input, uint8_t *dest,
1305ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org                                int stride) {
130606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i rounding = _mm_set1_epi32(DCT_CONST_ROUNDING);
130706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i final_rounding = _mm_set1_epi16(1<<5);
130806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i zero = _mm_setzero_si128();
130906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
131006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_0 = pair_set_epi16(cospi_30_64, -cospi_2_64);
131106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_1 = pair_set_epi16(cospi_2_64, cospi_30_64);
131206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_2 = pair_set_epi16(cospi_14_64, -cospi_18_64);
131306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_3 = pair_set_epi16(cospi_18_64, cospi_14_64);
131406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_4 = pair_set_epi16(cospi_22_64, -cospi_10_64);
131506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_5 = pair_set_epi16(cospi_10_64, cospi_22_64);
131606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_6 = pair_set_epi16(cospi_6_64, -cospi_26_64);
131706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg2_7 = pair_set_epi16(cospi_26_64, cospi_6_64);
131806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
131906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg3_0 = pair_set_epi16(cospi_28_64, -cospi_4_64);
132006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg3_1 = pair_set_epi16(cospi_4_64, cospi_28_64);
132106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg3_2 = pair_set_epi16(cospi_12_64, -cospi_20_64);
132206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg3_3 = pair_set_epi16(cospi_20_64, cospi_12_64);
132306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
132406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg4_0 = pair_set_epi16(cospi_16_64, cospi_16_64);
132506d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg4_1 = pair_set_epi16(cospi_16_64, -cospi_16_64);
132606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg4_2 = pair_set_epi16(cospi_24_64, -cospi_8_64);
132706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg4_3 = pair_set_epi16(cospi_8_64, cospi_24_64);
132806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg4_4 = pair_set_epi16(-cospi_8_64, cospi_24_64);
132906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg4_5 = pair_set_epi16(cospi_24_64, cospi_8_64);
133006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg4_6 = pair_set_epi16(-cospi_24_64, -cospi_8_64);
133106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg4_7 = pair_set_epi16(-cospi_8_64, cospi_24_64);
133206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
133306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  const __m128i stg6_0 = pair_set_epi16(-cospi_16_64, cospi_16_64);
133406d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
1335d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  __m128i in[16], l[16], r[16], *curr1;
133606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  __m128i stp1_0, stp1_1, stp1_2, stp1_3, stp1_4, stp1_5, stp1_6, stp1_7,
133706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org          stp1_8, stp1_9, stp1_10, stp1_11, stp1_12, stp1_13, stp1_14, stp1_15,
133806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org          stp1_8_0, stp1_12_0;
133906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  __m128i stp2_0, stp2_1, stp2_2, stp2_3, stp2_4, stp2_5, stp2_6, stp2_7,
134006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org          stp2_8, stp2_9, stp2_10, stp2_11, stp2_12, stp2_13, stp2_14, stp2_15;
134106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  __m128i tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
134206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  int i;
134306d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
1344d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  curr1 = l;
1345d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  for (i = 0; i < 2; i++) {
1346d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      // 1-D idct
134706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
134806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      // Load input data.
1349d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[0] = _mm_load_si128((const __m128i *)input);
1350d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[8] = _mm_load_si128((const __m128i *)(input + 8 * 1));
1351d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[1] = _mm_load_si128((const __m128i *)(input + 8 * 2));
1352d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[9] = _mm_load_si128((const __m128i *)(input + 8 * 3));
1353d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[2] = _mm_load_si128((const __m128i *)(input + 8 * 4));
1354d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[10] = _mm_load_si128((const __m128i *)(input + 8 * 5));
1355d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[3] = _mm_load_si128((const __m128i *)(input + 8 * 6));
1356d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[11] = _mm_load_si128((const __m128i *)(input + 8 * 7));
1357d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[4] = _mm_load_si128((const __m128i *)(input + 8 * 8));
1358d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[12] = _mm_load_si128((const __m128i *)(input + 8 * 9));
1359d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[5] = _mm_load_si128((const __m128i *)(input + 8 * 10));
1360d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[13] = _mm_load_si128((const __m128i *)(input + 8 * 11));
1361d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[6] = _mm_load_si128((const __m128i *)(input + 8 * 12));
1362d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[14] = _mm_load_si128((const __m128i *)(input + 8 * 13));
1363d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[7] = _mm_load_si128((const __m128i *)(input + 8 * 14));
1364d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[15] = _mm_load_si128((const __m128i *)(input + 8 * 15));
1365d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org
1366d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      array_transpose_8x8(in, in);
1367d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      array_transpose_8x8(in+8, in+8);
1368d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org
1369dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      IDCT16
1370d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org
1371d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      // Stage7
1372d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[0] = _mm_add_epi16(stp2_0, stp1_15);
1373d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[1] = _mm_add_epi16(stp2_1, stp1_14);
1374d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[2] = _mm_add_epi16(stp2_2, stp2_13);
1375d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[3] = _mm_add_epi16(stp2_3, stp2_12);
1376d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[4] = _mm_add_epi16(stp2_4, stp2_11);
1377d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[5] = _mm_add_epi16(stp2_5, stp2_10);
1378d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[6] = _mm_add_epi16(stp2_6, stp1_9);
1379d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[7] = _mm_add_epi16(stp2_7, stp1_8);
1380d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[8] = _mm_sub_epi16(stp2_7, stp1_8);
1381d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[9] = _mm_sub_epi16(stp2_6, stp1_9);
1382d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[10] = _mm_sub_epi16(stp2_5, stp2_10);
1383d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[11] = _mm_sub_epi16(stp2_4, stp2_11);
1384d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[12] = _mm_sub_epi16(stp2_3, stp2_12);
1385d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[13] = _mm_sub_epi16(stp2_2, stp2_13);
1386d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[14] = _mm_sub_epi16(stp2_1, stp1_14);
1387d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1[15] = _mm_sub_epi16(stp2_0, stp1_15);
1388d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org
1389d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      curr1 = r;
1390d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      input += 128;
1391d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  }
1392d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  for (i = 0; i < 2; i++) {
1393d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      // 1-D idct
1394d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      array_transpose_8x8(l+i*8, in);
1395d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      array_transpose_8x8(r+i*8, in+8);
139606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
1397dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org      IDCT16
139806d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
139906d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      // 2-D
1400d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[0] = _mm_add_epi16(stp2_0, stp1_15);
1401d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[1] = _mm_add_epi16(stp2_1, stp1_14);
1402d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[2] = _mm_add_epi16(stp2_2, stp2_13);
1403d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[3] = _mm_add_epi16(stp2_3, stp2_12);
1404d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[4] = _mm_add_epi16(stp2_4, stp2_11);
1405d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[5] = _mm_add_epi16(stp2_5, stp2_10);
1406d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[6] = _mm_add_epi16(stp2_6, stp1_9);
1407d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[7] = _mm_add_epi16(stp2_7, stp1_8);
1408d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[8] = _mm_sub_epi16(stp2_7, stp1_8);
1409d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[9] = _mm_sub_epi16(stp2_6, stp1_9);
1410d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[10] = _mm_sub_epi16(stp2_5, stp2_10);
1411d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[11] = _mm_sub_epi16(stp2_4, stp2_11);
1412d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[12] = _mm_sub_epi16(stp2_3, stp2_12);
1413d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[13] = _mm_sub_epi16(stp2_2, stp2_13);
1414d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[14] = _mm_sub_epi16(stp2_1, stp1_14);
1415d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[15] = _mm_sub_epi16(stp2_0, stp1_15);
141606d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
141706d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org      // Final rounding and shift
1418d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[0] = _mm_adds_epi16(in[0], final_rounding);
1419d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[1] = _mm_adds_epi16(in[1], final_rounding);
1420d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[2] = _mm_adds_epi16(in[2], final_rounding);
1421d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[3] = _mm_adds_epi16(in[3], final_rounding);
1422d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[4] = _mm_adds_epi16(in[4], final_rounding);
1423d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[5] = _mm_adds_epi16(in[5], final_rounding);
1424d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[6] = _mm_adds_epi16(in[6], final_rounding);
1425d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[7] = _mm_adds_epi16(in[7], final_rounding);
1426d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[8] = _mm_adds_epi16(in[8], final_rounding);
1427d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[9] = _mm_adds_epi16(in[9], final_rounding);
1428d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[10] = _mm_adds_epi16(in[10], final_rounding);
1429d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[11] = _mm_adds_epi16(in[11], final_rounding);
1430d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[12] = _mm_adds_epi16(in[12], final_rounding);
1431d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[13] = _mm_adds_epi16(in[13], final_rounding);
1432d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[14] = _mm_adds_epi16(in[14], final_rounding);
1433d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[15] = _mm_adds_epi16(in[15], final_rounding);
1434d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org
1435d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[0] = _mm_srai_epi16(in[0], 6);
1436d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[1] = _mm_srai_epi16(in[1], 6);
1437d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[2] = _mm_srai_epi16(in[2], 6);
1438d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[3] = _mm_srai_epi16(in[3], 6);
1439d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[4] = _mm_srai_epi16(in[4], 6);
1440d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[5] = _mm_srai_epi16(in[5], 6);
1441d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[6] = _mm_srai_epi16(in[6], 6);
1442d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[7] = _mm_srai_epi16(in[7], 6);
1443d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[8] = _mm_srai_epi16(in[8], 6);
1444d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[9] = _mm_srai_epi16(in[9], 6);
1445d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[10] = _mm_srai_epi16(in[10], 6);
1446d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[11] = _mm_srai_epi16(in[11], 6);
1447d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[12] = _mm_srai_epi16(in[12], 6);
1448d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[13] = _mm_srai_epi16(in[13], 6);
1449d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[14] = _mm_srai_epi16(in[14], 6);
1450d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      in[15] = _mm_srai_epi16(in[15], 6);
1451d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org
1452d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[0]);
1453d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[1]);
1454d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[2]);
1455d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[3]);
1456d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[4]);
1457d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[5]);
1458d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[6]);
1459d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[7]);
1460d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[8]);
1461d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[9]);
1462d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[10]);
1463d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[11]);
1464d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[12]);
1465d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[13]);
1466d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[14]);
1467d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org      RECON_AND_STORE(dest, in[15]);
146810a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org
146910a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org      dest += 8 - (stride * 16);
147006d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org  }
147106d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org}
147206d88a191f52640d533e6204ba067d1fd6fc0accjohannkoenig@chromium.org
1473ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.orgvoid vp9_idct16x16_1_add_sse2(const int16_t *input, uint8_t *dest, int stride) {
147453a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  __m128i dc_value;
147553a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  const __m128i zero = _mm_setzero_si128();
147653a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  int a, i;
147753a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org
147853a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  a = dct_const_round_shift(input[0] * cospi_16_64);
147953a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  a = dct_const_round_shift(a * cospi_16_64);
148053a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  a = ROUND_POWER_OF_TWO(a, 6);
148153a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org
148253a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  dc_value = _mm_set1_epi16(a);
148353a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org
148453a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  for (i = 0; i < 2; ++i) {
148553a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
148653a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
148753a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
148853a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
148953a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
149053a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
149153a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
149253a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
149353a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
149453a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
149553a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
149653a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
149753a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
149853a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
149953a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
150053a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    RECON_AND_STORE(dest, dc_value);
150153a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    dest += 8 - (stride * 16);
150253a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  }
150353a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org}
150453a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org
1505dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.orgstatic void iadst16_8col(__m128i *in) {
150647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // perform 16x16 1-D ADST for 8 columns
150747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  __m128i s[16], x[16], u[32], v[32];
150847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p01_p31 = pair_set_epi16(cospi_1_64, cospi_31_64);
150947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p31_m01 = pair_set_epi16(cospi_31_64, -cospi_1_64);
151047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p05_p27 = pair_set_epi16(cospi_5_64, cospi_27_64);
151147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p27_m05 = pair_set_epi16(cospi_27_64, -cospi_5_64);
151247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p09_p23 = pair_set_epi16(cospi_9_64, cospi_23_64);
151347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p23_m09 = pair_set_epi16(cospi_23_64, -cospi_9_64);
151447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p13_p19 = pair_set_epi16(cospi_13_64, cospi_19_64);
151547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p19_m13 = pair_set_epi16(cospi_19_64, -cospi_13_64);
151647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p17_p15 = pair_set_epi16(cospi_17_64, cospi_15_64);
151747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p15_m17 = pair_set_epi16(cospi_15_64, -cospi_17_64);
151847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p21_p11 = pair_set_epi16(cospi_21_64, cospi_11_64);
151947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p11_m21 = pair_set_epi16(cospi_11_64, -cospi_21_64);
152047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p25_p07 = pair_set_epi16(cospi_25_64, cospi_7_64);
152147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p07_m25 = pair_set_epi16(cospi_7_64, -cospi_25_64);
152247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p29_p03 = pair_set_epi16(cospi_29_64, cospi_3_64);
152347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p03_m29 = pair_set_epi16(cospi_3_64, -cospi_29_64);
152447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p04_p28 = pair_set_epi16(cospi_4_64, cospi_28_64);
152547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p28_m04 = pair_set_epi16(cospi_28_64, -cospi_4_64);
152647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p20_p12 = pair_set_epi16(cospi_20_64, cospi_12_64);
152747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p12_m20 = pair_set_epi16(cospi_12_64, -cospi_20_64);
152847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_m28_p04 = pair_set_epi16(-cospi_28_64, cospi_4_64);
152947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_m12_p20 = pair_set_epi16(-cospi_12_64, cospi_20_64);
153047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p08_p24 = pair_set_epi16(cospi_8_64, cospi_24_64);
153147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p24_m08 = pair_set_epi16(cospi_24_64, -cospi_8_64);
153247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_m24_p08 = pair_set_epi16(-cospi_24_64, cospi_8_64);
153347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_m16_m16 = _mm_set1_epi16(-cospi_16_64);
153447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p16_p16 = _mm_set1_epi16(cospi_16_64);
153547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
153647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__cospi_m16_p16 = pair_set_epi16(-cospi_16_64, cospi_16_64);
153747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
153847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  const __m128i kZero = _mm_set1_epi16(0);
153947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
154047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[0] = _mm_unpacklo_epi16(in[15], in[0]);
154147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[1] = _mm_unpackhi_epi16(in[15], in[0]);
154247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[2] = _mm_unpacklo_epi16(in[13], in[2]);
154347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[3] = _mm_unpackhi_epi16(in[13], in[2]);
154447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[4] = _mm_unpacklo_epi16(in[11], in[4]);
154547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[5] = _mm_unpackhi_epi16(in[11], in[4]);
154647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[6] = _mm_unpacklo_epi16(in[9], in[6]);
154747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[7] = _mm_unpackhi_epi16(in[9], in[6]);
154847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[8] = _mm_unpacklo_epi16(in[7], in[8]);
154947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[9] = _mm_unpackhi_epi16(in[7], in[8]);
155047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[10] = _mm_unpacklo_epi16(in[5], in[10]);
155147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[11] = _mm_unpackhi_epi16(in[5], in[10]);
155247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[12] = _mm_unpacklo_epi16(in[3], in[12]);
155347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[13] = _mm_unpackhi_epi16(in[3], in[12]);
155447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[14] = _mm_unpacklo_epi16(in[1], in[14]);
155547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[15] = _mm_unpackhi_epi16(in[1], in[14]);
155647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
155747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[0] = _mm_madd_epi16(u[0], k__cospi_p01_p31);
155847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[1] = _mm_madd_epi16(u[1], k__cospi_p01_p31);
155947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[2] = _mm_madd_epi16(u[0], k__cospi_p31_m01);
156047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[3] = _mm_madd_epi16(u[1], k__cospi_p31_m01);
156147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[4] = _mm_madd_epi16(u[2], k__cospi_p05_p27);
156247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[5] = _mm_madd_epi16(u[3], k__cospi_p05_p27);
156347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[6] = _mm_madd_epi16(u[2], k__cospi_p27_m05);
156447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[7] = _mm_madd_epi16(u[3], k__cospi_p27_m05);
156547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[8] = _mm_madd_epi16(u[4], k__cospi_p09_p23);
156647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[9] = _mm_madd_epi16(u[5], k__cospi_p09_p23);
156747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[10] = _mm_madd_epi16(u[4], k__cospi_p23_m09);
156847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[11] = _mm_madd_epi16(u[5], k__cospi_p23_m09);
156947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[12] = _mm_madd_epi16(u[6], k__cospi_p13_p19);
157047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[13] = _mm_madd_epi16(u[7], k__cospi_p13_p19);
157147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[14] = _mm_madd_epi16(u[6], k__cospi_p19_m13);
157247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[15] = _mm_madd_epi16(u[7], k__cospi_p19_m13);
157347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[16] = _mm_madd_epi16(u[8], k__cospi_p17_p15);
157447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[17] = _mm_madd_epi16(u[9], k__cospi_p17_p15);
157547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[18] = _mm_madd_epi16(u[8], k__cospi_p15_m17);
157647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[19] = _mm_madd_epi16(u[9], k__cospi_p15_m17);
157747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[20] = _mm_madd_epi16(u[10], k__cospi_p21_p11);
157847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[21] = _mm_madd_epi16(u[11], k__cospi_p21_p11);
157947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[22] = _mm_madd_epi16(u[10], k__cospi_p11_m21);
158047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[23] = _mm_madd_epi16(u[11], k__cospi_p11_m21);
158147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[24] = _mm_madd_epi16(u[12], k__cospi_p25_p07);
158247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[25] = _mm_madd_epi16(u[13], k__cospi_p25_p07);
158347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[26] = _mm_madd_epi16(u[12], k__cospi_p07_m25);
158447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[27] = _mm_madd_epi16(u[13], k__cospi_p07_m25);
158547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[28] = _mm_madd_epi16(u[14], k__cospi_p29_p03);
158647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[29] = _mm_madd_epi16(u[15], k__cospi_p29_p03);
158747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[30] = _mm_madd_epi16(u[14], k__cospi_p03_m29);
158847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[31] = _mm_madd_epi16(u[15], k__cospi_p03_m29);
158947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
159047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[0] = _mm_add_epi32(v[0], v[16]);
159147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[1] = _mm_add_epi32(v[1], v[17]);
159247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[2] = _mm_add_epi32(v[2], v[18]);
159347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[3] = _mm_add_epi32(v[3], v[19]);
159447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[4] = _mm_add_epi32(v[4], v[20]);
159547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[5] = _mm_add_epi32(v[5], v[21]);
159647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[6] = _mm_add_epi32(v[6], v[22]);
159747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[7] = _mm_add_epi32(v[7], v[23]);
159847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[8] = _mm_add_epi32(v[8], v[24]);
159947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[9] = _mm_add_epi32(v[9], v[25]);
160047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[10] = _mm_add_epi32(v[10], v[26]);
160147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[11] = _mm_add_epi32(v[11], v[27]);
160247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[12] = _mm_add_epi32(v[12], v[28]);
160347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[13] = _mm_add_epi32(v[13], v[29]);
160447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[14] = _mm_add_epi32(v[14], v[30]);
160547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[15] = _mm_add_epi32(v[15], v[31]);
160647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[16] = _mm_sub_epi32(v[0], v[16]);
160747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[17] = _mm_sub_epi32(v[1], v[17]);
160847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[18] = _mm_sub_epi32(v[2], v[18]);
160947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[19] = _mm_sub_epi32(v[3], v[19]);
161047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[20] = _mm_sub_epi32(v[4], v[20]);
161147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[21] = _mm_sub_epi32(v[5], v[21]);
161247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[22] = _mm_sub_epi32(v[6], v[22]);
161347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[23] = _mm_sub_epi32(v[7], v[23]);
161447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[24] = _mm_sub_epi32(v[8], v[24]);
161547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[25] = _mm_sub_epi32(v[9], v[25]);
161647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[26] = _mm_sub_epi32(v[10], v[26]);
161747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[27] = _mm_sub_epi32(v[11], v[27]);
161847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[28] = _mm_sub_epi32(v[12], v[28]);
161947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[29] = _mm_sub_epi32(v[13], v[29]);
162047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[30] = _mm_sub_epi32(v[14], v[30]);
162147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[31] = _mm_sub_epi32(v[15], v[31]);
162247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
162347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
162447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
162547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
162647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
162747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
162847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
162947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
163047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
163147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[8] = _mm_add_epi32(u[8], k__DCT_CONST_ROUNDING);
163247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[9] = _mm_add_epi32(u[9], k__DCT_CONST_ROUNDING);
163347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
163447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
163547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
163647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
163747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
163847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
163947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[16] = _mm_add_epi32(u[16], k__DCT_CONST_ROUNDING);
164047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[17] = _mm_add_epi32(u[17], k__DCT_CONST_ROUNDING);
164147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[18] = _mm_add_epi32(u[18], k__DCT_CONST_ROUNDING);
164247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[19] = _mm_add_epi32(u[19], k__DCT_CONST_ROUNDING);
164347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[20] = _mm_add_epi32(u[20], k__DCT_CONST_ROUNDING);
164447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[21] = _mm_add_epi32(u[21], k__DCT_CONST_ROUNDING);
164547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[22] = _mm_add_epi32(u[22], k__DCT_CONST_ROUNDING);
164647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[23] = _mm_add_epi32(u[23], k__DCT_CONST_ROUNDING);
164747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[24] = _mm_add_epi32(u[24], k__DCT_CONST_ROUNDING);
164847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[25] = _mm_add_epi32(u[25], k__DCT_CONST_ROUNDING);
164947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[26] = _mm_add_epi32(u[26], k__DCT_CONST_ROUNDING);
165047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[27] = _mm_add_epi32(u[27], k__DCT_CONST_ROUNDING);
165147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[28] = _mm_add_epi32(u[28], k__DCT_CONST_ROUNDING);
165247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[29] = _mm_add_epi32(u[29], k__DCT_CONST_ROUNDING);
165347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[30] = _mm_add_epi32(u[30], k__DCT_CONST_ROUNDING);
165447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[31] = _mm_add_epi32(u[31], k__DCT_CONST_ROUNDING);
165547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
165647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
165747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
165847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
165947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
166047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[4] = _mm_srai_epi32(v[4], DCT_CONST_BITS);
166147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[5] = _mm_srai_epi32(v[5], DCT_CONST_BITS);
166247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[6] = _mm_srai_epi32(v[6], DCT_CONST_BITS);
166347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[7] = _mm_srai_epi32(v[7], DCT_CONST_BITS);
166447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[8] = _mm_srai_epi32(v[8], DCT_CONST_BITS);
166547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[9] = _mm_srai_epi32(v[9], DCT_CONST_BITS);
166647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[10] = _mm_srai_epi32(v[10], DCT_CONST_BITS);
166747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[11] = _mm_srai_epi32(v[11], DCT_CONST_BITS);
166847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[12] = _mm_srai_epi32(v[12], DCT_CONST_BITS);
166947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[13] = _mm_srai_epi32(v[13], DCT_CONST_BITS);
167047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[14] = _mm_srai_epi32(v[14], DCT_CONST_BITS);
167147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[15] = _mm_srai_epi32(v[15], DCT_CONST_BITS);
167247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[16] = _mm_srai_epi32(v[16], DCT_CONST_BITS);
167347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[17] = _mm_srai_epi32(v[17], DCT_CONST_BITS);
167447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[18] = _mm_srai_epi32(v[18], DCT_CONST_BITS);
167547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[19] = _mm_srai_epi32(v[19], DCT_CONST_BITS);
167647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[20] = _mm_srai_epi32(v[20], DCT_CONST_BITS);
167747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[21] = _mm_srai_epi32(v[21], DCT_CONST_BITS);
167847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[22] = _mm_srai_epi32(v[22], DCT_CONST_BITS);
167947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[23] = _mm_srai_epi32(v[23], DCT_CONST_BITS);
168047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[24] = _mm_srai_epi32(v[24], DCT_CONST_BITS);
168147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[25] = _mm_srai_epi32(v[25], DCT_CONST_BITS);
168247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[26] = _mm_srai_epi32(v[26], DCT_CONST_BITS);
168347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[27] = _mm_srai_epi32(v[27], DCT_CONST_BITS);
168447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[28] = _mm_srai_epi32(v[28], DCT_CONST_BITS);
168547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[29] = _mm_srai_epi32(v[29], DCT_CONST_BITS);
168647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[30] = _mm_srai_epi32(v[30], DCT_CONST_BITS);
168747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[31] = _mm_srai_epi32(v[31], DCT_CONST_BITS);
168847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
168947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[0] = _mm_packs_epi32(u[0], u[1]);
169047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[1] = _mm_packs_epi32(u[2], u[3]);
169147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[2] = _mm_packs_epi32(u[4], u[5]);
169247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[3] = _mm_packs_epi32(u[6], u[7]);
169347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[4] = _mm_packs_epi32(u[8], u[9]);
169447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[5] = _mm_packs_epi32(u[10], u[11]);
169547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[6] = _mm_packs_epi32(u[12], u[13]);
169647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[7] = _mm_packs_epi32(u[14], u[15]);
169747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[8] = _mm_packs_epi32(u[16], u[17]);
169847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[9] = _mm_packs_epi32(u[18], u[19]);
169947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[10] = _mm_packs_epi32(u[20], u[21]);
170047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[11] = _mm_packs_epi32(u[22], u[23]);
170147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[12] = _mm_packs_epi32(u[24], u[25]);
170247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[13] = _mm_packs_epi32(u[26], u[27]);
170347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[14] = _mm_packs_epi32(u[28], u[29]);
170447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  s[15] = _mm_packs_epi32(u[30], u[31]);
170547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
170647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // stage 2
170747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[0] = _mm_unpacklo_epi16(s[8], s[9]);
170847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[1] = _mm_unpackhi_epi16(s[8], s[9]);
170947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[2] = _mm_unpacklo_epi16(s[10], s[11]);
171047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[3] = _mm_unpackhi_epi16(s[10], s[11]);
171147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[4] = _mm_unpacklo_epi16(s[12], s[13]);
171247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[5] = _mm_unpackhi_epi16(s[12], s[13]);
171347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[6] = _mm_unpacklo_epi16(s[14], s[15]);
171447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[7] = _mm_unpackhi_epi16(s[14], s[15]);
171547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
171647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[0] = _mm_madd_epi16(u[0], k__cospi_p04_p28);
171747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[1] = _mm_madd_epi16(u[1], k__cospi_p04_p28);
171847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[2] = _mm_madd_epi16(u[0], k__cospi_p28_m04);
171947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[3] = _mm_madd_epi16(u[1], k__cospi_p28_m04);
172047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[4] = _mm_madd_epi16(u[2], k__cospi_p20_p12);
172147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[5] = _mm_madd_epi16(u[3], k__cospi_p20_p12);
172247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[6] = _mm_madd_epi16(u[2], k__cospi_p12_m20);
172347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[7] = _mm_madd_epi16(u[3], k__cospi_p12_m20);
172447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[8] = _mm_madd_epi16(u[4], k__cospi_m28_p04);
172547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[9] = _mm_madd_epi16(u[5], k__cospi_m28_p04);
172647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[10] = _mm_madd_epi16(u[4], k__cospi_p04_p28);
172747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[11] = _mm_madd_epi16(u[5], k__cospi_p04_p28);
172847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[12] = _mm_madd_epi16(u[6], k__cospi_m12_p20);
172947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[13] = _mm_madd_epi16(u[7], k__cospi_m12_p20);
173047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[14] = _mm_madd_epi16(u[6], k__cospi_p20_p12);
173147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[15] = _mm_madd_epi16(u[7], k__cospi_p20_p12);
173247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
173347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[0] = _mm_add_epi32(v[0], v[8]);
173447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[1] = _mm_add_epi32(v[1], v[9]);
173547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[2] = _mm_add_epi32(v[2], v[10]);
173647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[3] = _mm_add_epi32(v[3], v[11]);
173747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[4] = _mm_add_epi32(v[4], v[12]);
173847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[5] = _mm_add_epi32(v[5], v[13]);
173947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[6] = _mm_add_epi32(v[6], v[14]);
174047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[7] = _mm_add_epi32(v[7], v[15]);
174147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[8] = _mm_sub_epi32(v[0], v[8]);
174247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[9] = _mm_sub_epi32(v[1], v[9]);
174347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[10] = _mm_sub_epi32(v[2], v[10]);
174447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[11] = _mm_sub_epi32(v[3], v[11]);
174547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[12] = _mm_sub_epi32(v[4], v[12]);
174647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[13] = _mm_sub_epi32(v[5], v[13]);
174747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[14] = _mm_sub_epi32(v[6], v[14]);
174847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[15] = _mm_sub_epi32(v[7], v[15]);
174947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
175047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
175147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
175247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
175347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
175447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
175547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
175647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
175747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
175847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[8] = _mm_add_epi32(u[8], k__DCT_CONST_ROUNDING);
175947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[9] = _mm_add_epi32(u[9], k__DCT_CONST_ROUNDING);
176047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
176147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
176247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
176347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
176447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
176547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
176647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
176747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
176847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
176947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
177047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
177147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[4] = _mm_srai_epi32(v[4], DCT_CONST_BITS);
177247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[5] = _mm_srai_epi32(v[5], DCT_CONST_BITS);
177347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[6] = _mm_srai_epi32(v[6], DCT_CONST_BITS);
177447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[7] = _mm_srai_epi32(v[7], DCT_CONST_BITS);
177547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[8] = _mm_srai_epi32(v[8], DCT_CONST_BITS);
177647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[9] = _mm_srai_epi32(v[9], DCT_CONST_BITS);
177747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[10] = _mm_srai_epi32(v[10], DCT_CONST_BITS);
177847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[11] = _mm_srai_epi32(v[11], DCT_CONST_BITS);
177947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[12] = _mm_srai_epi32(v[12], DCT_CONST_BITS);
178047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[13] = _mm_srai_epi32(v[13], DCT_CONST_BITS);
178147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[14] = _mm_srai_epi32(v[14], DCT_CONST_BITS);
178247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[15] = _mm_srai_epi32(v[15], DCT_CONST_BITS);
178347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
178447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[0] = _mm_add_epi16(s[0], s[4]);
178547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[1] = _mm_add_epi16(s[1], s[5]);
178647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[2] = _mm_add_epi16(s[2], s[6]);
178747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[3] = _mm_add_epi16(s[3], s[7]);
178847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[4] = _mm_sub_epi16(s[0], s[4]);
178947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[5] = _mm_sub_epi16(s[1], s[5]);
179047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[6] = _mm_sub_epi16(s[2], s[6]);
179147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[7] = _mm_sub_epi16(s[3], s[7]);
179247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[8] = _mm_packs_epi32(u[0], u[1]);
179347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[9] = _mm_packs_epi32(u[2], u[3]);
179447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[10] = _mm_packs_epi32(u[4], u[5]);
179547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[11] = _mm_packs_epi32(u[6], u[7]);
179647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[12] = _mm_packs_epi32(u[8], u[9]);
179747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[13] = _mm_packs_epi32(u[10], u[11]);
179847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[14] = _mm_packs_epi32(u[12], u[13]);
179947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  x[15] = _mm_packs_epi32(u[14], u[15]);
180047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
180147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  // stage 3
180247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[0] = _mm_unpacklo_epi16(x[4], x[5]);
180347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[1] = _mm_unpackhi_epi16(x[4], x[5]);
180447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[2] = _mm_unpacklo_epi16(x[6], x[7]);
180547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[3] = _mm_unpackhi_epi16(x[6], x[7]);
180647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[4] = _mm_unpacklo_epi16(x[12], x[13]);
180747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[5] = _mm_unpackhi_epi16(x[12], x[13]);
180847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[6] = _mm_unpacklo_epi16(x[14], x[15]);
180947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[7] = _mm_unpackhi_epi16(x[14], x[15]);
181047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
181147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[0] = _mm_madd_epi16(u[0], k__cospi_p08_p24);
181247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[1] = _mm_madd_epi16(u[1], k__cospi_p08_p24);
181347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[2] = _mm_madd_epi16(u[0], k__cospi_p24_m08);
181447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[3] = _mm_madd_epi16(u[1], k__cospi_p24_m08);
181547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[4] = _mm_madd_epi16(u[2], k__cospi_m24_p08);
181647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[5] = _mm_madd_epi16(u[3], k__cospi_m24_p08);
181747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[6] = _mm_madd_epi16(u[2], k__cospi_p08_p24);
181847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[7] = _mm_madd_epi16(u[3], k__cospi_p08_p24);
181947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[8] = _mm_madd_epi16(u[4], k__cospi_p08_p24);
182047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[9] = _mm_madd_epi16(u[5], k__cospi_p08_p24);
182147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[10] = _mm_madd_epi16(u[4], k__cospi_p24_m08);
182247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[11] = _mm_madd_epi16(u[5], k__cospi_p24_m08);
182347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[12] = _mm_madd_epi16(u[6], k__cospi_m24_p08);
182447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[13] = _mm_madd_epi16(u[7], k__cospi_m24_p08);
182547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[14] = _mm_madd_epi16(u[6], k__cospi_p08_p24);
182647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  v[15] = _mm_madd_epi16(u[7], k__cospi_p08_p24);
182747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
182847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[0] = _mm_add_epi32(v[0], v[4]);
182947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[1] = _mm_add_epi32(v[1], v[5]);
183047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[2] = _mm_add_epi32(v[2], v[6]);
183147265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[3] = _mm_add_epi32(v[3], v[7]);
183247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[4] = _mm_sub_epi32(v[0], v[4]);
183347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[5] = _mm_sub_epi32(v[1], v[5]);
183447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[6] = _mm_sub_epi32(v[2], v[6]);
183547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[7] = _mm_sub_epi32(v[3], v[7]);
183647265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[8] = _mm_add_epi32(v[8], v[12]);
183747265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[9] = _mm_add_epi32(v[9], v[13]);
183847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[10] = _mm_add_epi32(v[10], v[14]);
183947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[11] = _mm_add_epi32(v[11], v[15]);
184047265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  u[