• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <assert.h>
12 #include <tmmintrin.h>  // SSSE3
13 
14 #include "./vp9_rtcd.h"
15 #include "./vpx_config.h"
16 #include "vpx_dsp/vpx_dsp_common.h"
17 #include "vpx_dsp/x86/bitdepth_conversion_sse2.h"
18 #include "vpx_dsp/x86/inv_txfm_sse2.h"
19 #include "vpx_dsp/x86/txfm_common_sse2.h"
20 
vp9_fdct8x8_quant_ssse3(const int16_t * input,int stride,tran_low_t * coeff_ptr,intptr_t n_coeffs,int skip_block,const int16_t * round_ptr,const int16_t * quant_ptr,tran_low_t * qcoeff_ptr,tran_low_t * dqcoeff_ptr,const int16_t * dequant_ptr,uint16_t * eob_ptr,const int16_t * scan,const int16_t * iscan)21 void vp9_fdct8x8_quant_ssse3(const int16_t *input, int stride,
22                              tran_low_t *coeff_ptr, intptr_t n_coeffs,
23                              int skip_block, const int16_t *round_ptr,
24                              const int16_t *quant_ptr, tran_low_t *qcoeff_ptr,
25                              tran_low_t *dqcoeff_ptr,
26                              const int16_t *dequant_ptr, uint16_t *eob_ptr,
27                              const int16_t *scan, const int16_t *iscan) {
28   __m128i zero;
29   int pass;
30 
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(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;
58   (void)coeff_ptr;
59 
60   // Pre-condition input (shift by two)
61   in0 = _mm_slli_epi16(in0, 2);
62   in1 = _mm_slli_epi16(in1, 2);
63   in2 = _mm_slli_epi16(in2, 2);
64   in3 = _mm_slli_epi16(in3, 2);
65   in4 = _mm_slli_epi16(in4, 2);
66   in5 = _mm_slli_epi16(in5, 2);
67   in6 = _mm_slli_epi16(in6, 2);
68   in7 = _mm_slli_epi16(in7, 2);
69 
70   in[0] = &in0;
71   in[1] = &in1;
72   in[2] = &in2;
73   in[3] = &in3;
74   in[4] = &in4;
75   in[5] = &in5;
76   in[6] = &in6;
77   in[7] = &in7;
78 
79   // We do two passes, first the columns, then the rows. The results of the
80   // first pass are transposed so that the same column code can be reused. The
81   // results of the second pass are also transposed so that the rows (processed
82   // as columns) are put back in row positions.
83   for (pass = 0; pass < 2; pass++) {
84     // To store results of each pass before the transpose.
85     __m128i res0, res1, res2, res3, res4, res5, res6, res7;
86     // Add/subtract
87     const __m128i q0 = _mm_add_epi16(in0, in7);
88     const __m128i q1 = _mm_add_epi16(in1, in6);
89     const __m128i q2 = _mm_add_epi16(in2, in5);
90     const __m128i q3 = _mm_add_epi16(in3, in4);
91     const __m128i q4 = _mm_sub_epi16(in3, in4);
92     const __m128i q5 = _mm_sub_epi16(in2, in5);
93     const __m128i q6 = _mm_sub_epi16(in1, in6);
94     const __m128i q7 = _mm_sub_epi16(in0, in7);
95     // Work on first four results
96     {
97       // Add/subtract
98       const __m128i r0 = _mm_add_epi16(q0, q3);
99       const __m128i r1 = _mm_add_epi16(q1, q2);
100       const __m128i r2 = _mm_sub_epi16(q1, q2);
101       const __m128i r3 = _mm_sub_epi16(q0, q3);
102       // Interleave to do the multiply by constants which gets us into 32bits
103       const __m128i t0 = _mm_unpacklo_epi16(r0, r1);
104       const __m128i t1 = _mm_unpackhi_epi16(r0, r1);
105       const __m128i t2 = _mm_unpacklo_epi16(r2, r3);
106       const __m128i t3 = _mm_unpackhi_epi16(r2, r3);
107 
108       const __m128i u0 = _mm_madd_epi16(t0, k__cospi_p16_p16);
109       const __m128i u1 = _mm_madd_epi16(t1, k__cospi_p16_p16);
110       const __m128i u2 = _mm_madd_epi16(t0, k__cospi_p16_m16);
111       const __m128i u3 = _mm_madd_epi16(t1, k__cospi_p16_m16);
112 
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 
119       const __m128i v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING);
120       const __m128i v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING);
121       const __m128i v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING);
122       const __m128i v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING);
123 
124       const __m128i v4 = _mm_add_epi32(u4, k__DCT_CONST_ROUNDING);
125       const __m128i v5 = _mm_add_epi32(u5, k__DCT_CONST_ROUNDING);
126       const __m128i v6 = _mm_add_epi32(u6, k__DCT_CONST_ROUNDING);
127       const __m128i v7 = _mm_add_epi32(u7, k__DCT_CONST_ROUNDING);
128 
129       const __m128i w0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
130       const __m128i w1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
131       const __m128i w2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
132       const __m128i w3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
133 
134       const __m128i w4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
135       const __m128i w5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
136       const __m128i w6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
137       const __m128i w7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
138       // Combine
139 
140       res0 = _mm_packs_epi32(w0, w1);
141       res4 = _mm_packs_epi32(w2, w3);
142       res2 = _mm_packs_epi32(w4, w5);
143       res6 = _mm_packs_epi32(w6, w7);
144     }
145     // Work on next four results
146     {
147       // Interleave to do the multiply by constants which gets us into 32bits
148       const __m128i d0 = _mm_sub_epi16(q6, q5);
149       const __m128i d1 = _mm_add_epi16(q6, q5);
150       const __m128i r0 = _mm_mulhrs_epi16(d0, k__dual_p16_p16);
151       const __m128i r1 = _mm_mulhrs_epi16(d1, k__dual_p16_p16);
152 
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     }
194     // Transpose the 8x8.
195     {
196       // 00 01 02 03 04 05 06 07
197       // 10 11 12 13 14 15 16 17
198       // 20 21 22 23 24 25 26 27
199       // 30 31 32 33 34 35 36 37
200       // 40 41 42 43 44 45 46 47
201       // 50 51 52 53 54 55 56 57
202       // 60 61 62 63 64 65 66 67
203       // 70 71 72 73 74 75 76 77
204       const __m128i tr0_0 = _mm_unpacklo_epi16(res0, res1);
205       const __m128i tr0_1 = _mm_unpacklo_epi16(res2, res3);
206       const __m128i tr0_2 = _mm_unpackhi_epi16(res0, res1);
207       const __m128i tr0_3 = _mm_unpackhi_epi16(res2, res3);
208       const __m128i tr0_4 = _mm_unpacklo_epi16(res4, res5);
209       const __m128i tr0_5 = _mm_unpacklo_epi16(res6, res7);
210       const __m128i tr0_6 = _mm_unpackhi_epi16(res4, res5);
211       const __m128i tr0_7 = _mm_unpackhi_epi16(res6, res7);
212       // 00 10 01 11 02 12 03 13
213       // 20 30 21 31 22 32 23 33
214       // 04 14 05 15 06 16 07 17
215       // 24 34 25 35 26 36 27 37
216       // 40 50 41 51 42 52 43 53
217       // 60 70 61 71 62 72 63 73
218       // 54 54 55 55 56 56 57 57
219       // 64 74 65 75 66 76 67 77
220       const __m128i tr1_0 = _mm_unpacklo_epi32(tr0_0, tr0_1);
221       const __m128i tr1_1 = _mm_unpacklo_epi32(tr0_2, tr0_3);
222       const __m128i tr1_2 = _mm_unpackhi_epi32(tr0_0, tr0_1);
223       const __m128i tr1_3 = _mm_unpackhi_epi32(tr0_2, tr0_3);
224       const __m128i tr1_4 = _mm_unpacklo_epi32(tr0_4, tr0_5);
225       const __m128i tr1_5 = _mm_unpacklo_epi32(tr0_6, tr0_7);
226       const __m128i tr1_6 = _mm_unpackhi_epi32(tr0_4, tr0_5);
227       const __m128i tr1_7 = _mm_unpackhi_epi32(tr0_6, tr0_7);
228       // 00 10 20 30 01 11 21 31
229       // 40 50 60 70 41 51 61 71
230       // 02 12 22 32 03 13 23 33
231       // 42 52 62 72 43 53 63 73
232       // 04 14 24 34 05 15 21 36
233       // 44 54 64 74 45 55 61 76
234       // 06 16 26 36 07 17 27 37
235       // 46 56 66 76 47 57 67 77
236       in0 = _mm_unpacklo_epi64(tr1_0, tr1_4);
237       in1 = _mm_unpackhi_epi64(tr1_0, tr1_4);
238       in2 = _mm_unpacklo_epi64(tr1_2, tr1_6);
239       in3 = _mm_unpackhi_epi64(tr1_2, tr1_6);
240       in4 = _mm_unpacklo_epi64(tr1_1, tr1_5);
241       in5 = _mm_unpackhi_epi64(tr1_1, tr1_5);
242       in6 = _mm_unpacklo_epi64(tr1_3, tr1_7);
243       in7 = _mm_unpackhi_epi64(tr1_3, tr1_7);
244       // 00 10 20 30 40 50 60 70
245       // 01 11 21 31 41 51 61 71
246       // 02 12 22 32 42 52 62 72
247       // 03 13 23 33 43 53 63 73
248       // 04 14 24 34 44 54 64 74
249       // 05 15 25 35 45 55 65 75
250       // 06 16 26 36 46 56 66 76
251       // 07 17 27 37 47 57 67 77
252     }
253   }
254   // Post-condition output and store it
255   {
256     // Post-condition (division by two)
257     //    division of two 16 bits signed numbers using shifts
258     //    n / 2 = (n - (n >> 15)) >> 1
259     const __m128i sign_in0 = _mm_srai_epi16(in0, 15);
260     const __m128i sign_in1 = _mm_srai_epi16(in1, 15);
261     const __m128i sign_in2 = _mm_srai_epi16(in2, 15);
262     const __m128i sign_in3 = _mm_srai_epi16(in3, 15);
263     const __m128i sign_in4 = _mm_srai_epi16(in4, 15);
264     const __m128i sign_in5 = _mm_srai_epi16(in5, 15);
265     const __m128i sign_in6 = _mm_srai_epi16(in6, 15);
266     const __m128i sign_in7 = _mm_srai_epi16(in7, 15);
267     in0 = _mm_sub_epi16(in0, sign_in0);
268     in1 = _mm_sub_epi16(in1, sign_in1);
269     in2 = _mm_sub_epi16(in2, sign_in2);
270     in3 = _mm_sub_epi16(in3, sign_in3);
271     in4 = _mm_sub_epi16(in4, sign_in4);
272     in5 = _mm_sub_epi16(in5, sign_in5);
273     in6 = _mm_sub_epi16(in6, sign_in6);
274     in7 = _mm_sub_epi16(in7, sign_in7);
275     in0 = _mm_srai_epi16(in0, 1);
276     in1 = _mm_srai_epi16(in1, 1);
277     in2 = _mm_srai_epi16(in2, 1);
278     in3 = _mm_srai_epi16(in3, 1);
279     in4 = _mm_srai_epi16(in4, 1);
280     in5 = _mm_srai_epi16(in5, 1);
281     in6 = _mm_srai_epi16(in6, 1);
282     in7 = _mm_srai_epi16(in7, 1);
283   }
284 
285   iscan += n_coeffs;
286   qcoeff_ptr += n_coeffs;
287   dqcoeff_ptr += n_coeffs;
288   n_coeffs = -n_coeffs;
289   zero = _mm_setzero_si128();
290 
291   if (!skip_block) {
292     __m128i eob;
293     __m128i round, quant, dequant, thr;
294     int16_t nzflag;
295     {
296       __m128i coeff0, coeff1;
297 
298       // Setup global values
299       {
300         round = _mm_load_si128((const __m128i *)round_ptr);
301         quant = _mm_load_si128((const __m128i *)quant_ptr);
302         dequant = _mm_load_si128((const __m128i *)dequant_ptr);
303       }
304 
305       {
306         __m128i coeff0_sign, coeff1_sign;
307         __m128i qcoeff0, qcoeff1;
308         __m128i qtmp0, qtmp1;
309         // Do DC and first 15 AC
310         coeff0 = *in[0];
311         coeff1 = *in[1];
312 
313         // Poor man's sign extract
314         coeff0_sign = _mm_srai_epi16(coeff0, 15);
315         coeff1_sign = _mm_srai_epi16(coeff1, 15);
316         qcoeff0 = _mm_xor_si128(coeff0, coeff0_sign);
317         qcoeff1 = _mm_xor_si128(coeff1, coeff1_sign);
318         qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
319         qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
320 
321         qcoeff0 = _mm_adds_epi16(qcoeff0, round);
322         round = _mm_unpackhi_epi64(round, round);
323         qcoeff1 = _mm_adds_epi16(qcoeff1, round);
324         qtmp0 = _mm_mulhi_epi16(qcoeff0, quant);
325         quant = _mm_unpackhi_epi64(quant, quant);
326         qtmp1 = _mm_mulhi_epi16(qcoeff1, quant);
327 
328         // Reinsert signs
329         qcoeff0 = _mm_xor_si128(qtmp0, coeff0_sign);
330         qcoeff1 = _mm_xor_si128(qtmp1, coeff1_sign);
331         qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
332         qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
333 
334         store_tran_low(qcoeff0, qcoeff_ptr + n_coeffs);
335         store_tran_low(qcoeff1, qcoeff_ptr + n_coeffs + 8);
336 
337         coeff0 = _mm_mullo_epi16(qcoeff0, dequant);
338         dequant = _mm_unpackhi_epi64(dequant, dequant);
339         coeff1 = _mm_mullo_epi16(qcoeff1, dequant);
340 
341         store_tran_low(coeff0, dqcoeff_ptr + n_coeffs);
342         store_tran_low(coeff1, dqcoeff_ptr + n_coeffs + 8);
343       }
344 
345       {
346         // Scan for eob
347         __m128i zero_coeff0, zero_coeff1;
348         __m128i nzero_coeff0, nzero_coeff1;
349         __m128i iscan0, iscan1;
350         __m128i eob1;
351         zero_coeff0 = _mm_cmpeq_epi16(coeff0, zero);
352         zero_coeff1 = _mm_cmpeq_epi16(coeff1, zero);
353         nzero_coeff0 = _mm_cmpeq_epi16(zero_coeff0, zero);
354         nzero_coeff1 = _mm_cmpeq_epi16(zero_coeff1, zero);
355         iscan0 = _mm_load_si128((const __m128i *)(iscan + n_coeffs));
356         iscan1 = _mm_load_si128((const __m128i *)(iscan + n_coeffs) + 1);
357         // Add one to convert from indices to counts
358         iscan0 = _mm_sub_epi16(iscan0, nzero_coeff0);
359         iscan1 = _mm_sub_epi16(iscan1, nzero_coeff1);
360         eob = _mm_and_si128(iscan0, nzero_coeff0);
361         eob1 = _mm_and_si128(iscan1, nzero_coeff1);
362         eob = _mm_max_epi16(eob, eob1);
363       }
364       n_coeffs += 8 * 2;
365     }
366 
367     // AC only loop
368     index = 2;
369     thr = _mm_srai_epi16(dequant, 1);
370     while (n_coeffs < 0) {
371       __m128i coeff0, coeff1;
372       {
373         __m128i coeff0_sign, coeff1_sign;
374         __m128i qcoeff0, qcoeff1;
375         __m128i qtmp0, qtmp1;
376 
377         assert(index < (int)(sizeof(in) / sizeof(in[0])) - 1);
378         coeff0 = *in[index];
379         coeff1 = *in[index + 1];
380 
381         // Poor man's sign extract
382         coeff0_sign = _mm_srai_epi16(coeff0, 15);
383         coeff1_sign = _mm_srai_epi16(coeff1, 15);
384         qcoeff0 = _mm_xor_si128(coeff0, coeff0_sign);
385         qcoeff1 = _mm_xor_si128(coeff1, coeff1_sign);
386         qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
387         qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
388 
389         nzflag = _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff0, thr)) |
390                  _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff1, thr));
391 
392         if (nzflag) {
393           qcoeff0 = _mm_adds_epi16(qcoeff0, round);
394           qcoeff1 = _mm_adds_epi16(qcoeff1, round);
395           qtmp0 = _mm_mulhi_epi16(qcoeff0, quant);
396           qtmp1 = _mm_mulhi_epi16(qcoeff1, quant);
397 
398           // Reinsert signs
399           qcoeff0 = _mm_xor_si128(qtmp0, coeff0_sign);
400           qcoeff1 = _mm_xor_si128(qtmp1, coeff1_sign);
401           qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
402           qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
403 
404           store_tran_low(qcoeff0, qcoeff_ptr + n_coeffs);
405           store_tran_low(qcoeff1, qcoeff_ptr + n_coeffs + 8);
406 
407           coeff0 = _mm_mullo_epi16(qcoeff0, dequant);
408           coeff1 = _mm_mullo_epi16(qcoeff1, dequant);
409 
410           store_tran_low(coeff0, dqcoeff_ptr + n_coeffs);
411           store_tran_low(coeff1, dqcoeff_ptr + n_coeffs + 8);
412         } else {
413           // Maybe a more efficient way to store 0?
414           store_zero_tran_low(qcoeff_ptr + n_coeffs);
415           store_zero_tran_low(qcoeff_ptr + n_coeffs + 8);
416 
417           store_zero_tran_low(dqcoeff_ptr + n_coeffs);
418           store_zero_tran_low(dqcoeff_ptr + n_coeffs + 8);
419         }
420       }
421 
422       if (nzflag) {
423         // Scan for eob
424         __m128i zero_coeff0, zero_coeff1;
425         __m128i nzero_coeff0, nzero_coeff1;
426         __m128i iscan0, iscan1;
427         __m128i eob0, eob1;
428         zero_coeff0 = _mm_cmpeq_epi16(coeff0, zero);
429         zero_coeff1 = _mm_cmpeq_epi16(coeff1, zero);
430         nzero_coeff0 = _mm_cmpeq_epi16(zero_coeff0, zero);
431         nzero_coeff1 = _mm_cmpeq_epi16(zero_coeff1, zero);
432         iscan0 = _mm_load_si128((const __m128i *)(iscan + n_coeffs));
433         iscan1 = _mm_load_si128((const __m128i *)(iscan + n_coeffs) + 1);
434         // Add one to convert from indices to counts
435         iscan0 = _mm_sub_epi16(iscan0, nzero_coeff0);
436         iscan1 = _mm_sub_epi16(iscan1, nzero_coeff1);
437         eob0 = _mm_and_si128(iscan0, nzero_coeff0);
438         eob1 = _mm_and_si128(iscan1, nzero_coeff1);
439         eob0 = _mm_max_epi16(eob0, eob1);
440         eob = _mm_max_epi16(eob, eob0);
441       }
442       n_coeffs += 8 * 2;
443       index += 2;
444     }
445 
446     // Accumulate EOB
447     {
448       __m128i eob_shuffled;
449       eob_shuffled = _mm_shuffle_epi32(eob, 0xe);
450       eob = _mm_max_epi16(eob, eob_shuffled);
451       eob_shuffled = _mm_shufflelo_epi16(eob, 0xe);
452       eob = _mm_max_epi16(eob, eob_shuffled);
453       eob_shuffled = _mm_shufflelo_epi16(eob, 0x1);
454       eob = _mm_max_epi16(eob, eob_shuffled);
455       *eob_ptr = _mm_extract_epi16(eob, 1);
456     }
457   } else {
458     do {
459       store_zero_tran_low(dqcoeff_ptr + n_coeffs);
460       store_zero_tran_low(dqcoeff_ptr + n_coeffs + 8);
461       store_zero_tran_low(qcoeff_ptr + n_coeffs);
462       store_zero_tran_low(qcoeff_ptr + n_coeffs + 8);
463       n_coeffs += 8 * 2;
464     } while (n_coeffs < 0);
465     *eob_ptr = 0;
466   }
467 }
468