Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: source/libvpx/vp9/encoder/x86/vp9_dct_ssse3.c

Issue 756673003: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #if defined(_MSC_VER) && _MSC_VER <= 1500
12 // Need to include math.h before calling tmmintrin.h/intrin.h
13 // in certain versions of MSVS.
14 #include <math.h>
15 #endif
16 #include <tmmintrin.h> // SSSE3
17 #include "vp9/common/x86/vp9_idct_intrin_sse2.h"
18
19 void vp9_fdct8x8_quant_ssse3(const int16_t *input, int stride,
20 int16_t* coeff_ptr, intptr_t n_coeffs,
21 int skip_block, const int16_t* zbin_ptr,
22 const int16_t* round_ptr, const int16_t* quant_ptr,
23 const int16_t* quant_shift_ptr,
24 int16_t* qcoeff_ptr,
25 int16_t* dqcoeff_ptr, const int16_t* dequant_ptr,
26 int zbin_oq_value, uint16_t* eob_ptr,
27 const int16_t* scan_ptr,
28 const int16_t* iscan_ptr) {
29 __m128i zero;
30 int pass;
31 // Constants
32 // When we use them, in one case, they are all the same. In all others
33 // it's a pair of them that we need to repeat four times. This is done
34 // by constructing the 32 bit constant corresponding to that pair.
35 const __m128i k__dual_p16_p16 = dual_set_epi16(23170, 23170);
36 const __m128i k__cospi_p16_p16 = _mm_set1_epi16((int16_t)cospi_16_64);
37 const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
38 const __m128i k__cospi_p24_p08 = pair_set_epi16(cospi_24_64, cospi_8_64);
39 const __m128i k__cospi_m08_p24 = pair_set_epi16(-cospi_8_64, cospi_24_64);
40 const __m128i k__cospi_p28_p04 = pair_set_epi16(cospi_28_64, cospi_4_64);
41 const __m128i k__cospi_m04_p28 = pair_set_epi16(-cospi_4_64, cospi_28_64);
42 const __m128i k__cospi_p12_p20 = pair_set_epi16(cospi_12_64, cospi_20_64);
43 const __m128i k__cospi_m20_p12 = pair_set_epi16(-cospi_20_64, cospi_12_64);
44 const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
45 // Load input
46 __m128i in0 = _mm_load_si128((const __m128i *)(input + 0 * stride));
47 __m128i in1 = _mm_load_si128((const __m128i *)(input + 1 * stride));
48 __m128i in2 = _mm_load_si128((const __m128i *)(input + 2 * stride));
49 __m128i in3 = _mm_load_si128((const __m128i *)(input + 3 * stride));
50 __m128i in4 = _mm_load_si128((const __m128i *)(input + 4 * stride));
51 __m128i in5 = _mm_load_si128((const __m128i *)(input + 5 * stride));
52 __m128i in6 = _mm_load_si128((const __m128i *)(input + 6 * stride));
53 __m128i in7 = _mm_load_si128((const __m128i *)(input + 7 * stride));
54 __m128i *in[8];
55 int index = 0;
56
57 (void)scan_ptr;
58 (void)zbin_ptr;
59 (void)quant_shift_ptr;
60 (void)zbin_oq_value;
61 (void)coeff_ptr;
62
63 // Pre-condition input (shift by two)
64 in0 = _mm_slli_epi16(in0, 2);
65 in1 = _mm_slli_epi16(in1, 2);
66 in2 = _mm_slli_epi16(in2, 2);
67 in3 = _mm_slli_epi16(in3, 2);
68 in4 = _mm_slli_epi16(in4, 2);
69 in5 = _mm_slli_epi16(in5, 2);
70 in6 = _mm_slli_epi16(in6, 2);
71 in7 = _mm_slli_epi16(in7, 2);
72
73 in[0] = &in0;
74 in[1] = &in1;
75 in[2] = &in2;
76 in[3] = &in3;
77 in[4] = &in4;
78 in[5] = &in5;
79 in[6] = &in6;
80 in[7] = &in7;
81
82 // We do two passes, first the columns, then the rows. The results of the
83 // first pass are transposed so that the same column code can be reused. The
84 // results of the second pass are also transposed so that the rows (processed
85 // as columns) are put back in row positions.
86 for (pass = 0; pass < 2; pass++) {
87 // To store results of each pass before the transpose.
88 __m128i res0, res1, res2, res3, res4, res5, res6, res7;
89 // Add/subtract
90 const __m128i q0 = _mm_add_epi16(in0, in7);
91 const __m128i q1 = _mm_add_epi16(in1, in6);
92 const __m128i q2 = _mm_add_epi16(in2, in5);
93 const __m128i q3 = _mm_add_epi16(in3, in4);
94 const __m128i q4 = _mm_sub_epi16(in3, in4);
95 const __m128i q5 = _mm_sub_epi16(in2, in5);
96 const __m128i q6 = _mm_sub_epi16(in1, in6);
97 const __m128i q7 = _mm_sub_epi16(in0, in7);
98 // Work on first four results
99 {
100 // Add/subtract
101 const __m128i r0 = _mm_add_epi16(q0, q3);
102 const __m128i r1 = _mm_add_epi16(q1, q2);
103 const __m128i r2 = _mm_sub_epi16(q1, q2);
104 const __m128i r3 = _mm_sub_epi16(q0, q3);
105 // Interleave to do the multiply by constants which gets us into 32bits
106 const __m128i t0 = _mm_add_epi16(r0, r1);
107 const __m128i t1 = _mm_sub_epi16(r0, r1);
108 const __m128i t2 = _mm_unpacklo_epi16(r2, r3);
109 const __m128i t3 = _mm_unpackhi_epi16(r2, r3);
110
111 const __m128i u0 = _mm_mulhrs_epi16(t0, k__dual_p16_p16);
112 const __m128i u1 = _mm_mulhrs_epi16(t1, k__dual_p16_p16);
113 const __m128i u4 = _mm_madd_epi16(t2, k__cospi_p24_p08);
114 const __m128i u5 = _mm_madd_epi16(t3, k__cospi_p24_p08);
115 const __m128i u6 = _mm_madd_epi16(t2, k__cospi_m08_p24);
116 const __m128i u7 = _mm_madd_epi16(t3, k__cospi_m08_p24);
117 // dct_const_round_shift
118 const __m128i v4 = _mm_add_epi32(u4, k__DCT_CONST_ROUNDING);
119 const __m128i v5 = _mm_add_epi32(u5, k__DCT_CONST_ROUNDING);
120 const __m128i v6 = _mm_add_epi32(u6, k__DCT_CONST_ROUNDING);
121 const __m128i v7 = _mm_add_epi32(u7, k__DCT_CONST_ROUNDING);
122 const __m128i w4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
123 const __m128i w5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
124 const __m128i w6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
125 const __m128i w7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
126 // Combine
127 res0 = u0;
128 res4 = u1;
129 res2 = _mm_packs_epi32(w4, w5);
130 res6 = _mm_packs_epi32(w6, w7);
131 }
132 // Work on next four results
133 if (pass == 1) {
134 // Interleave to do the multiply by constants which gets us into 32bits
135 const __m128i d0 = _mm_unpacklo_epi16(q6, q5);
136 const __m128i d1 = _mm_unpackhi_epi16(q6, q5);
137 const __m128i e0 = _mm_madd_epi16(d0, k__cospi_p16_m16);
138 const __m128i e1 = _mm_madd_epi16(d1, k__cospi_p16_m16);
139 const __m128i e2 = _mm_madd_epi16(d0, k__cospi_p16_p16);
140 const __m128i e3 = _mm_madd_epi16(d1, k__cospi_p16_p16);
141 // dct_const_round_shift
142 const __m128i f0 = _mm_add_epi32(e0, k__DCT_CONST_ROUNDING);
143 const __m128i f1 = _mm_add_epi32(e1, k__DCT_CONST_ROUNDING);
144 const __m128i f2 = _mm_add_epi32(e2, k__DCT_CONST_ROUNDING);
145 const __m128i f3 = _mm_add_epi32(e3, k__DCT_CONST_ROUNDING);
146 const __m128i s0 = _mm_srai_epi32(f0, DCT_CONST_BITS);
147 const __m128i s1 = _mm_srai_epi32(f1, DCT_CONST_BITS);
148 const __m128i s2 = _mm_srai_epi32(f2, DCT_CONST_BITS);
149 const __m128i s3 = _mm_srai_epi32(f3, DCT_CONST_BITS);
150 // Combine
151 const __m128i r0 = _mm_packs_epi32(s0, s1);
152 const __m128i r1 = _mm_packs_epi32(s2, s3);
153 // Add/subtract
154 const __m128i x0 = _mm_add_epi16(q4, r0);
155 const __m128i x1 = _mm_sub_epi16(q4, r0);
156 const __m128i x2 = _mm_sub_epi16(q7, r1);
157 const __m128i x3 = _mm_add_epi16(q7, r1);
158 // Interleave to do the multiply by constants which gets us into 32bits
159 const __m128i t0 = _mm_unpacklo_epi16(x0, x3);
160 const __m128i t1 = _mm_unpackhi_epi16(x0, x3);
161 const __m128i t2 = _mm_unpacklo_epi16(x1, x2);
162 const __m128i t3 = _mm_unpackhi_epi16(x1, x2);
163 const __m128i u0 = _mm_madd_epi16(t0, k__cospi_p28_p04);
164 const __m128i u1 = _mm_madd_epi16(t1, k__cospi_p28_p04);
165 const __m128i u2 = _mm_madd_epi16(t0, k__cospi_m04_p28);
166 const __m128i u3 = _mm_madd_epi16(t1, k__cospi_m04_p28);
167 const __m128i u4 = _mm_madd_epi16(t2, k__cospi_p12_p20);
168 const __m128i u5 = _mm_madd_epi16(t3, k__cospi_p12_p20);
169 const __m128i u6 = _mm_madd_epi16(t2, k__cospi_m20_p12);
170 const __m128i u7 = _mm_madd_epi16(t3, k__cospi_m20_p12);
171 // dct_const_round_shift
172 const __m128i v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING);
173 const __m128i v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING);
174 const __m128i v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING);
175 const __m128i v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING);
176 const __m128i v4 = _mm_add_epi32(u4, k__DCT_CONST_ROUNDING);
177 const __m128i v5 = _mm_add_epi32(u5, k__DCT_CONST_ROUNDING);
178 const __m128i v6 = _mm_add_epi32(u6, k__DCT_CONST_ROUNDING);
179 const __m128i v7 = _mm_add_epi32(u7, k__DCT_CONST_ROUNDING);
180 const __m128i w0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
181 const __m128i w1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
182 const __m128i w2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
183 const __m128i w3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
184 const __m128i w4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
185 const __m128i w5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
186 const __m128i w6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
187 const __m128i w7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
188 // Combine
189 res1 = _mm_packs_epi32(w0, w1);
190 res7 = _mm_packs_epi32(w2, w3);
191 res5 = _mm_packs_epi32(w4, w5);
192 res3 = _mm_packs_epi32(w6, w7);
193 } else {
194 // Interleave to do the multiply by constants which gets us into 32bits
195 const __m128i d0 = _mm_sub_epi16(q6, q5);
196 const __m128i d1 = _mm_add_epi16(q6, q5);
197 const __m128i r0 = _mm_mulhrs_epi16(d0, k__dual_p16_p16);
198 const __m128i r1 = _mm_mulhrs_epi16(d1, k__dual_p16_p16);
199 // Add/subtract
200 const __m128i x0 = _mm_add_epi16(q4, r0);
201 const __m128i x1 = _mm_sub_epi16(q4, r0);
202 const __m128i x2 = _mm_sub_epi16(q7, r1);
203 const __m128i x3 = _mm_add_epi16(q7, r1);
204 // Interleave to do the multiply by constants which gets us into 32bits
205 const __m128i t0 = _mm_unpacklo_epi16(x0, x3);
206 const __m128i t1 = _mm_unpackhi_epi16(x0, x3);
207 const __m128i t2 = _mm_unpacklo_epi16(x1, x2);
208 const __m128i t3 = _mm_unpackhi_epi16(x1, x2);
209 const __m128i u0 = _mm_madd_epi16(t0, k__cospi_p28_p04);
210 const __m128i u1 = _mm_madd_epi16(t1, k__cospi_p28_p04);
211 const __m128i u2 = _mm_madd_epi16(t0, k__cospi_m04_p28);
212 const __m128i u3 = _mm_madd_epi16(t1, k__cospi_m04_p28);
213 const __m128i u4 = _mm_madd_epi16(t2, k__cospi_p12_p20);
214 const __m128i u5 = _mm_madd_epi16(t3, k__cospi_p12_p20);
215 const __m128i u6 = _mm_madd_epi16(t2, k__cospi_m20_p12);
216 const __m128i u7 = _mm_madd_epi16(t3, k__cospi_m20_p12);
217 // dct_const_round_shift
218 const __m128i v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING);
219 const __m128i v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING);
220 const __m128i v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING);
221 const __m128i v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING);
222 const __m128i v4 = _mm_add_epi32(u4, k__DCT_CONST_ROUNDING);
223 const __m128i v5 = _mm_add_epi32(u5, k__DCT_CONST_ROUNDING);
224 const __m128i v6 = _mm_add_epi32(u6, k__DCT_CONST_ROUNDING);
225 const __m128i v7 = _mm_add_epi32(u7, k__DCT_CONST_ROUNDING);
226 const __m128i w0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
227 const __m128i w1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
228 const __m128i w2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
229 const __m128i w3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
230 const __m128i w4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
231 const __m128i w5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
232 const __m128i w6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
233 const __m128i w7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
234 // Combine
235 res1 = _mm_packs_epi32(w0, w1);
236 res7 = _mm_packs_epi32(w2, w3);
237 res5 = _mm_packs_epi32(w4, w5);
238 res3 = _mm_packs_epi32(w6, w7);
239 }
240 // Transpose the 8x8.
241 {
242 // 00 01 02 03 04 05 06 07
243 // 10 11 12 13 14 15 16 17
244 // 20 21 22 23 24 25 26 27
245 // 30 31 32 33 34 35 36 37
246 // 40 41 42 43 44 45 46 47
247 // 50 51 52 53 54 55 56 57
248 // 60 61 62 63 64 65 66 67
249 // 70 71 72 73 74 75 76 77
250 const __m128i tr0_0 = _mm_unpacklo_epi16(res0, res1);
251 const __m128i tr0_1 = _mm_unpacklo_epi16(res2, res3);
252 const __m128i tr0_2 = _mm_unpackhi_epi16(res0, res1);
253 const __m128i tr0_3 = _mm_unpackhi_epi16(res2, res3);
254 const __m128i tr0_4 = _mm_unpacklo_epi16(res4, res5);
255 const __m128i tr0_5 = _mm_unpacklo_epi16(res6, res7);
256 const __m128i tr0_6 = _mm_unpackhi_epi16(res4, res5);
257 const __m128i tr0_7 = _mm_unpackhi_epi16(res6, res7);
258 // 00 10 01 11 02 12 03 13
259 // 20 30 21 31 22 32 23 33
260 // 04 14 05 15 06 16 07 17
261 // 24 34 25 35 26 36 27 37
262 // 40 50 41 51 42 52 43 53
263 // 60 70 61 71 62 72 63 73
264 // 54 54 55 55 56 56 57 57
265 // 64 74 65 75 66 76 67 77
266 const __m128i tr1_0 = _mm_unpacklo_epi32(tr0_0, tr0_1);
267 const __m128i tr1_1 = _mm_unpacklo_epi32(tr0_2, tr0_3);
268 const __m128i tr1_2 = _mm_unpackhi_epi32(tr0_0, tr0_1);
269 const __m128i tr1_3 = _mm_unpackhi_epi32(tr0_2, tr0_3);
270 const __m128i tr1_4 = _mm_unpacklo_epi32(tr0_4, tr0_5);
271 const __m128i tr1_5 = _mm_unpacklo_epi32(tr0_6, tr0_7);
272 const __m128i tr1_6 = _mm_unpackhi_epi32(tr0_4, tr0_5);
273 const __m128i tr1_7 = _mm_unpackhi_epi32(tr0_6, tr0_7);
274 // 00 10 20 30 01 11 21 31
275 // 40 50 60 70 41 51 61 71
276 // 02 12 22 32 03 13 23 33
277 // 42 52 62 72 43 53 63 73
278 // 04 14 24 34 05 15 21 36
279 // 44 54 64 74 45 55 61 76
280 // 06 16 26 36 07 17 27 37
281 // 46 56 66 76 47 57 67 77
282 in0 = _mm_unpacklo_epi64(tr1_0, tr1_4);
283 in1 = _mm_unpackhi_epi64(tr1_0, tr1_4);
284 in2 = _mm_unpacklo_epi64(tr1_2, tr1_6);
285 in3 = _mm_unpackhi_epi64(tr1_2, tr1_6);
286 in4 = _mm_unpacklo_epi64(tr1_1, tr1_5);
287 in5 = _mm_unpackhi_epi64(tr1_1, tr1_5);
288 in6 = _mm_unpacklo_epi64(tr1_3, tr1_7);
289 in7 = _mm_unpackhi_epi64(tr1_3, tr1_7);
290 // 00 10 20 30 40 50 60 70
291 // 01 11 21 31 41 51 61 71
292 // 02 12 22 32 42 52 62 72
293 // 03 13 23 33 43 53 63 73
294 // 04 14 24 34 44 54 64 74
295 // 05 15 25 35 45 55 65 75
296 // 06 16 26 36 46 56 66 76
297 // 07 17 27 37 47 57 67 77
298 }
299 }
300 // Post-condition output and store it
301 {
302 // Post-condition (division by two)
303 // division of two 16 bits signed numbers using shifts
304 // n / 2 = (n - (n >> 15)) >> 1
305 const __m128i sign_in0 = _mm_srai_epi16(in0, 15);
306 const __m128i sign_in1 = _mm_srai_epi16(in1, 15);
307 const __m128i sign_in2 = _mm_srai_epi16(in2, 15);
308 const __m128i sign_in3 = _mm_srai_epi16(in3, 15);
309 const __m128i sign_in4 = _mm_srai_epi16(in4, 15);
310 const __m128i sign_in5 = _mm_srai_epi16(in5, 15);
311 const __m128i sign_in6 = _mm_srai_epi16(in6, 15);
312 const __m128i sign_in7 = _mm_srai_epi16(in7, 15);
313 in0 = _mm_sub_epi16(in0, sign_in0);
314 in1 = _mm_sub_epi16(in1, sign_in1);
315 in2 = _mm_sub_epi16(in2, sign_in2);
316 in3 = _mm_sub_epi16(in3, sign_in3);
317 in4 = _mm_sub_epi16(in4, sign_in4);
318 in5 = _mm_sub_epi16(in5, sign_in5);
319 in6 = _mm_sub_epi16(in6, sign_in6);
320 in7 = _mm_sub_epi16(in7, sign_in7);
321 in0 = _mm_srai_epi16(in0, 1);
322 in1 = _mm_srai_epi16(in1, 1);
323 in2 = _mm_srai_epi16(in2, 1);
324 in3 = _mm_srai_epi16(in3, 1);
325 in4 = _mm_srai_epi16(in4, 1);
326 in5 = _mm_srai_epi16(in5, 1);
327 in6 = _mm_srai_epi16(in6, 1);
328 in7 = _mm_srai_epi16(in7, 1);
329 }
330
331 iscan_ptr += n_coeffs;
332 qcoeff_ptr += n_coeffs;
333 dqcoeff_ptr += n_coeffs;
334 n_coeffs = -n_coeffs;
335 zero = _mm_setzero_si128();
336
337 if (!skip_block) {
338 __m128i eob;
339 __m128i round, quant, dequant;
340 {
341 __m128i coeff0, coeff1;
342
343 // Setup global values
344 {
345 round = _mm_load_si128((const __m128i*)round_ptr);
346 quant = _mm_load_si128((const __m128i*)quant_ptr);
347 dequant = _mm_load_si128((const __m128i*)dequant_ptr);
348 }
349
350 {
351 __m128i coeff0_sign, coeff1_sign;
352 __m128i qcoeff0, qcoeff1;
353 __m128i qtmp0, qtmp1;
354 // Do DC and first 15 AC
355 coeff0 = *in[0];
356 coeff1 = *in[1];
357
358 // Poor man's sign extract
359 coeff0_sign = _mm_srai_epi16(coeff0, 15);
360 coeff1_sign = _mm_srai_epi16(coeff1, 15);
361 qcoeff0 = _mm_xor_si128(coeff0, coeff0_sign);
362 qcoeff1 = _mm_xor_si128(coeff1, coeff1_sign);
363 qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
364 qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
365
366 qcoeff0 = _mm_adds_epi16(qcoeff0, round);
367 round = _mm_unpackhi_epi64(round, round);
368 qcoeff1 = _mm_adds_epi16(qcoeff1, round);
369 qtmp0 = _mm_mulhi_epi16(qcoeff0, quant);
370 quant = _mm_unpackhi_epi64(quant, quant);
371 qtmp1 = _mm_mulhi_epi16(qcoeff1, quant);
372
373 // Reinsert signs
374 qcoeff0 = _mm_xor_si128(qtmp0, coeff0_sign);
375 qcoeff1 = _mm_xor_si128(qtmp1, coeff1_sign);
376 qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
377 qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
378
379 _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), qcoeff0);
380 _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, qcoeff1);
381
382 coeff0 = _mm_mullo_epi16(qcoeff0, dequant);
383 dequant = _mm_unpackhi_epi64(dequant, dequant);
384 coeff1 = _mm_mullo_epi16(qcoeff1, dequant);
385
386 _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), coeff0);
387 _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, coeff1);
388 }
389
390 {
391 // Scan for eob
392 __m128i zero_coeff0, zero_coeff1;
393 __m128i nzero_coeff0, nzero_coeff1;
394 __m128i iscan0, iscan1;
395 __m128i eob1;
396 zero_coeff0 = _mm_cmpeq_epi16(coeff0, zero);
397 zero_coeff1 = _mm_cmpeq_epi16(coeff1, zero);
398 nzero_coeff0 = _mm_cmpeq_epi16(zero_coeff0, zero);
399 nzero_coeff1 = _mm_cmpeq_epi16(zero_coeff1, zero);
400 iscan0 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs));
401 iscan1 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs) + 1);
402 // Add one to convert from indices to counts
403 iscan0 = _mm_sub_epi16(iscan0, nzero_coeff0);
404 iscan1 = _mm_sub_epi16(iscan1, nzero_coeff1);
405 eob = _mm_and_si128(iscan0, nzero_coeff0);
406 eob1 = _mm_and_si128(iscan1, nzero_coeff1);
407 eob = _mm_max_epi16(eob, eob1);
408 }
409 n_coeffs += 8 * 2;
410 }
411
412 // AC only loop
413 index = 2;
414 while (n_coeffs < 0) {
415 __m128i coeff0, coeff1;
416 {
417 __m128i coeff0_sign, coeff1_sign;
418 __m128i qcoeff0, qcoeff1;
419 __m128i qtmp0, qtmp1;
420
421 coeff0 = *in[index];
422 coeff1 = *in[index + 1];
423
424 // Poor man's sign extract
425 coeff0_sign = _mm_srai_epi16(coeff0, 15);
426 coeff1_sign = _mm_srai_epi16(coeff1, 15);
427 qcoeff0 = _mm_xor_si128(coeff0, coeff0_sign);
428 qcoeff1 = _mm_xor_si128(coeff1, coeff1_sign);
429 qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
430 qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
431
432 qcoeff0 = _mm_adds_epi16(qcoeff0, round);
433 qcoeff1 = _mm_adds_epi16(qcoeff1, round);
434 qtmp0 = _mm_mulhi_epi16(qcoeff0, quant);
435 qtmp1 = _mm_mulhi_epi16(qcoeff1, quant);
436
437 // Reinsert signs
438 qcoeff0 = _mm_xor_si128(qtmp0, coeff0_sign);
439 qcoeff1 = _mm_xor_si128(qtmp1, coeff1_sign);
440 qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
441 qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
442
443 _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), qcoeff0);
444 _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, qcoeff1);
445
446 coeff0 = _mm_mullo_epi16(qcoeff0, dequant);
447 coeff1 = _mm_mullo_epi16(qcoeff1, dequant);
448
449 _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), coeff0);
450 _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, coeff1);
451 }
452
453 {
454 // Scan for eob
455 __m128i zero_coeff0, zero_coeff1;
456 __m128i nzero_coeff0, nzero_coeff1;
457 __m128i iscan0, iscan1;
458 __m128i eob0, eob1;
459 zero_coeff0 = _mm_cmpeq_epi16(coeff0, zero);
460 zero_coeff1 = _mm_cmpeq_epi16(coeff1, zero);
461 nzero_coeff0 = _mm_cmpeq_epi16(zero_coeff0, zero);
462 nzero_coeff1 = _mm_cmpeq_epi16(zero_coeff1, zero);
463 iscan0 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs));
464 iscan1 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs) + 1);
465 // Add one to convert from indices to counts
466 iscan0 = _mm_sub_epi16(iscan0, nzero_coeff0);
467 iscan1 = _mm_sub_epi16(iscan1, nzero_coeff1);
468 eob0 = _mm_and_si128(iscan0, nzero_coeff0);
469 eob1 = _mm_and_si128(iscan1, nzero_coeff1);
470 eob0 = _mm_max_epi16(eob0, eob1);
471 eob = _mm_max_epi16(eob, eob0);
472 }
473 n_coeffs += 8 * 2;
474 index += 2;
475 }
476
477 // Accumulate EOB
478 {
479 __m128i eob_shuffled;
480 eob_shuffled = _mm_shuffle_epi32(eob, 0xe);
481 eob = _mm_max_epi16(eob, eob_shuffled);
482 eob_shuffled = _mm_shufflelo_epi16(eob, 0xe);
483 eob = _mm_max_epi16(eob, eob_shuffled);
484 eob_shuffled = _mm_shufflelo_epi16(eob, 0x1);
485 eob = _mm_max_epi16(eob, eob_shuffled);
486 *eob_ptr = _mm_extract_epi16(eob, 1);
487 }
488 } else {
489 do {
490 _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), zero);
491 _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, zero);
492 _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), zero);
493 _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, zero);
494 n_coeffs += 8 * 2;
495 } while (n_coeffs < 0);
496 *eob_ptr = 0;
497 }
498 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/x86/vp9_dct_sse2.c ('k') | source/libvpx/vp9/encoder/x86/vp9_denoiser_sse2.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698