1*dfc6aa5cSAndroid Build Coastguard Worker /*
2*dfc6aa5cSAndroid Build Coastguard Worker * jidctred-neon.c - reduced-size IDCT (Arm Neon)
3*dfc6aa5cSAndroid Build Coastguard Worker *
4*dfc6aa5cSAndroid Build Coastguard Worker * Copyright (C) 2020, Arm Limited. All Rights Reserved.
5*dfc6aa5cSAndroid Build Coastguard Worker * Copyright (C) 2020, D. R. Commander. All Rights Reserved.
6*dfc6aa5cSAndroid Build Coastguard Worker *
7*dfc6aa5cSAndroid Build Coastguard Worker * This software is provided 'as-is', without any express or implied
8*dfc6aa5cSAndroid Build Coastguard Worker * warranty. In no event will the authors be held liable for any damages
9*dfc6aa5cSAndroid Build Coastguard Worker * arising from the use of this software.
10*dfc6aa5cSAndroid Build Coastguard Worker *
11*dfc6aa5cSAndroid Build Coastguard Worker * Permission is granted to anyone to use this software for any purpose,
12*dfc6aa5cSAndroid Build Coastguard Worker * including commercial applications, and to alter it and redistribute it
13*dfc6aa5cSAndroid Build Coastguard Worker * freely, subject to the following restrictions:
14*dfc6aa5cSAndroid Build Coastguard Worker *
15*dfc6aa5cSAndroid Build Coastguard Worker * 1. The origin of this software must not be misrepresented; you must not
16*dfc6aa5cSAndroid Build Coastguard Worker * claim that you wrote the original software. If you use this software
17*dfc6aa5cSAndroid Build Coastguard Worker * in a product, an acknowledgment in the product documentation would be
18*dfc6aa5cSAndroid Build Coastguard Worker * appreciated but is not required.
19*dfc6aa5cSAndroid Build Coastguard Worker * 2. Altered source versions must be plainly marked as such, and must not be
20*dfc6aa5cSAndroid Build Coastguard Worker * misrepresented as being the original software.
21*dfc6aa5cSAndroid Build Coastguard Worker * 3. This notice may not be removed or altered from any source distribution.
22*dfc6aa5cSAndroid Build Coastguard Worker */
23*dfc6aa5cSAndroid Build Coastguard Worker
24*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_INTERNALS
25*dfc6aa5cSAndroid Build Coastguard Worker #include "../../jinclude.h"
26*dfc6aa5cSAndroid Build Coastguard Worker #include "../../jpeglib.h"
27*dfc6aa5cSAndroid Build Coastguard Worker #include "../../jsimd.h"
28*dfc6aa5cSAndroid Build Coastguard Worker #include "../../jdct.h"
29*dfc6aa5cSAndroid Build Coastguard Worker #include "../../jsimddct.h"
30*dfc6aa5cSAndroid Build Coastguard Worker #include "../jsimd.h"
31*dfc6aa5cSAndroid Build Coastguard Worker #include "align.h"
32*dfc6aa5cSAndroid Build Coastguard Worker #include "neon-compat.h"
33*dfc6aa5cSAndroid Build Coastguard Worker
34*dfc6aa5cSAndroid Build Coastguard Worker #include <arm_neon.h>
35*dfc6aa5cSAndroid Build Coastguard Worker
36*dfc6aa5cSAndroid Build Coastguard Worker
37*dfc6aa5cSAndroid Build Coastguard Worker #define CONST_BITS 13
38*dfc6aa5cSAndroid Build Coastguard Worker #define PASS1_BITS 2
39*dfc6aa5cSAndroid Build Coastguard Worker
40*dfc6aa5cSAndroid Build Coastguard Worker #define F_0_211 1730
41*dfc6aa5cSAndroid Build Coastguard Worker #define F_0_509 4176
42*dfc6aa5cSAndroid Build Coastguard Worker #define F_0_601 4926
43*dfc6aa5cSAndroid Build Coastguard Worker #define F_0_720 5906
44*dfc6aa5cSAndroid Build Coastguard Worker #define F_0_765 6270
45*dfc6aa5cSAndroid Build Coastguard Worker #define F_0_850 6967
46*dfc6aa5cSAndroid Build Coastguard Worker #define F_0_899 7373
47*dfc6aa5cSAndroid Build Coastguard Worker #define F_1_061 8697
48*dfc6aa5cSAndroid Build Coastguard Worker #define F_1_272 10426
49*dfc6aa5cSAndroid Build Coastguard Worker #define F_1_451 11893
50*dfc6aa5cSAndroid Build Coastguard Worker #define F_1_847 15137
51*dfc6aa5cSAndroid Build Coastguard Worker #define F_2_172 17799
52*dfc6aa5cSAndroid Build Coastguard Worker #define F_2_562 20995
53*dfc6aa5cSAndroid Build Coastguard Worker #define F_3_624 29692
54*dfc6aa5cSAndroid Build Coastguard Worker
55*dfc6aa5cSAndroid Build Coastguard Worker
56*dfc6aa5cSAndroid Build Coastguard Worker /* jsimd_idct_2x2_neon() is an inverse DCT function that produces reduced-size
57*dfc6aa5cSAndroid Build Coastguard Worker * 2x2 output from an 8x8 DCT block. It uses the same calculations and
58*dfc6aa5cSAndroid Build Coastguard Worker * produces exactly the same output as IJG's original jpeg_idct_2x2() function
59*dfc6aa5cSAndroid Build Coastguard Worker * from jpeg-6b, which can be found in jidctred.c.
60*dfc6aa5cSAndroid Build Coastguard Worker *
61*dfc6aa5cSAndroid Build Coastguard Worker * Scaled integer constants are used to avoid floating-point arithmetic:
62*dfc6aa5cSAndroid Build Coastguard Worker * 0.720959822 = 5906 * 2^-13
63*dfc6aa5cSAndroid Build Coastguard Worker * 0.850430095 = 6967 * 2^-13
64*dfc6aa5cSAndroid Build Coastguard Worker * 1.272758580 = 10426 * 2^-13
65*dfc6aa5cSAndroid Build Coastguard Worker * 3.624509785 = 29692 * 2^-13
66*dfc6aa5cSAndroid Build Coastguard Worker *
67*dfc6aa5cSAndroid Build Coastguard Worker * See jidctred.c for further details of the 2x2 IDCT algorithm. Where
68*dfc6aa5cSAndroid Build Coastguard Worker * possible, the variable names and comments here in jsimd_idct_2x2_neon()
69*dfc6aa5cSAndroid Build Coastguard Worker * match up with those in jpeg_idct_2x2().
70*dfc6aa5cSAndroid Build Coastguard Worker */
71*dfc6aa5cSAndroid Build Coastguard Worker
72*dfc6aa5cSAndroid Build Coastguard Worker ALIGN(16) static const int16_t jsimd_idct_2x2_neon_consts[] = {
73*dfc6aa5cSAndroid Build Coastguard Worker -F_0_720, F_0_850, -F_1_272, F_3_624
74*dfc6aa5cSAndroid Build Coastguard Worker };
75*dfc6aa5cSAndroid Build Coastguard Worker
jsimd_idct_2x2_neon(void * dct_table,JCOEFPTR coef_block,JSAMPARRAY output_buf,JDIMENSION output_col)76*dfc6aa5cSAndroid Build Coastguard Worker void jsimd_idct_2x2_neon(void *dct_table, JCOEFPTR coef_block,
77*dfc6aa5cSAndroid Build Coastguard Worker JSAMPARRAY output_buf, JDIMENSION output_col)
78*dfc6aa5cSAndroid Build Coastguard Worker {
79*dfc6aa5cSAndroid Build Coastguard Worker ISLOW_MULT_TYPE *quantptr = dct_table;
80*dfc6aa5cSAndroid Build Coastguard Worker
81*dfc6aa5cSAndroid Build Coastguard Worker /* Load DCT coefficients. */
82*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t row0 = vld1q_s16(coef_block + 0 * DCTSIZE);
83*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t row1 = vld1q_s16(coef_block + 1 * DCTSIZE);
84*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t row3 = vld1q_s16(coef_block + 3 * DCTSIZE);
85*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t row5 = vld1q_s16(coef_block + 5 * DCTSIZE);
86*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t row7 = vld1q_s16(coef_block + 7 * DCTSIZE);
87*dfc6aa5cSAndroid Build Coastguard Worker
88*dfc6aa5cSAndroid Build Coastguard Worker /* Load quantization table values. */
89*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t quant_row0 = vld1q_s16(quantptr + 0 * DCTSIZE);
90*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t quant_row1 = vld1q_s16(quantptr + 1 * DCTSIZE);
91*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t quant_row3 = vld1q_s16(quantptr + 3 * DCTSIZE);
92*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t quant_row5 = vld1q_s16(quantptr + 5 * DCTSIZE);
93*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t quant_row7 = vld1q_s16(quantptr + 7 * DCTSIZE);
94*dfc6aa5cSAndroid Build Coastguard Worker
95*dfc6aa5cSAndroid Build Coastguard Worker /* Dequantize DCT coefficients. */
96*dfc6aa5cSAndroid Build Coastguard Worker row0 = vmulq_s16(row0, quant_row0);
97*dfc6aa5cSAndroid Build Coastguard Worker row1 = vmulq_s16(row1, quant_row1);
98*dfc6aa5cSAndroid Build Coastguard Worker row3 = vmulq_s16(row3, quant_row3);
99*dfc6aa5cSAndroid Build Coastguard Worker row5 = vmulq_s16(row5, quant_row5);
100*dfc6aa5cSAndroid Build Coastguard Worker row7 = vmulq_s16(row7, quant_row7);
101*dfc6aa5cSAndroid Build Coastguard Worker
102*dfc6aa5cSAndroid Build Coastguard Worker /* Load IDCT conversion constants. */
103*dfc6aa5cSAndroid Build Coastguard Worker const int16x4_t consts = vld1_s16(jsimd_idct_2x2_neon_consts);
104*dfc6aa5cSAndroid Build Coastguard Worker
105*dfc6aa5cSAndroid Build Coastguard Worker /* Pass 1: process columns from input, put results in vectors row0 and
106*dfc6aa5cSAndroid Build Coastguard Worker * row1.
107*dfc6aa5cSAndroid Build Coastguard Worker */
108*dfc6aa5cSAndroid Build Coastguard Worker
109*dfc6aa5cSAndroid Build Coastguard Worker /* Even part */
110*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp10_l = vshll_n_s16(vget_low_s16(row0), CONST_BITS + 2);
111*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp10_h = vshll_n_s16(vget_high_s16(row0), CONST_BITS + 2);
112*dfc6aa5cSAndroid Build Coastguard Worker
113*dfc6aa5cSAndroid Build Coastguard Worker /* Odd part */
114*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp0_l = vmull_lane_s16(vget_low_s16(row1), consts, 3);
115*dfc6aa5cSAndroid Build Coastguard Worker tmp0_l = vmlal_lane_s16(tmp0_l, vget_low_s16(row3), consts, 2);
116*dfc6aa5cSAndroid Build Coastguard Worker tmp0_l = vmlal_lane_s16(tmp0_l, vget_low_s16(row5), consts, 1);
117*dfc6aa5cSAndroid Build Coastguard Worker tmp0_l = vmlal_lane_s16(tmp0_l, vget_low_s16(row7), consts, 0);
118*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp0_h = vmull_lane_s16(vget_high_s16(row1), consts, 3);
119*dfc6aa5cSAndroid Build Coastguard Worker tmp0_h = vmlal_lane_s16(tmp0_h, vget_high_s16(row3), consts, 2);
120*dfc6aa5cSAndroid Build Coastguard Worker tmp0_h = vmlal_lane_s16(tmp0_h, vget_high_s16(row5), consts, 1);
121*dfc6aa5cSAndroid Build Coastguard Worker tmp0_h = vmlal_lane_s16(tmp0_h, vget_high_s16(row7), consts, 0);
122*dfc6aa5cSAndroid Build Coastguard Worker
123*dfc6aa5cSAndroid Build Coastguard Worker /* Final output stage: descale and narrow to 16-bit. */
124*dfc6aa5cSAndroid Build Coastguard Worker row0 = vcombine_s16(vrshrn_n_s32(vaddq_s32(tmp10_l, tmp0_l), CONST_BITS),
125*dfc6aa5cSAndroid Build Coastguard Worker vrshrn_n_s32(vaddq_s32(tmp10_h, tmp0_h), CONST_BITS));
126*dfc6aa5cSAndroid Build Coastguard Worker row1 = vcombine_s16(vrshrn_n_s32(vsubq_s32(tmp10_l, tmp0_l), CONST_BITS),
127*dfc6aa5cSAndroid Build Coastguard Worker vrshrn_n_s32(vsubq_s32(tmp10_h, tmp0_h), CONST_BITS));
128*dfc6aa5cSAndroid Build Coastguard Worker
129*dfc6aa5cSAndroid Build Coastguard Worker /* Transpose two rows, ready for second pass. */
130*dfc6aa5cSAndroid Build Coastguard Worker int16x8x2_t cols_0246_1357 = vtrnq_s16(row0, row1);
131*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t cols_0246 = cols_0246_1357.val[0];
132*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t cols_1357 = cols_0246_1357.val[1];
133*dfc6aa5cSAndroid Build Coastguard Worker /* Duplicate columns such that each is accessible in its own vector. */
134*dfc6aa5cSAndroid Build Coastguard Worker int32x4x2_t cols_1155_3377 = vtrnq_s32(vreinterpretq_s32_s16(cols_1357),
135*dfc6aa5cSAndroid Build Coastguard Worker vreinterpretq_s32_s16(cols_1357));
136*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t cols_1155 = vreinterpretq_s16_s32(cols_1155_3377.val[0]);
137*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t cols_3377 = vreinterpretq_s16_s32(cols_1155_3377.val[1]);
138*dfc6aa5cSAndroid Build Coastguard Worker
139*dfc6aa5cSAndroid Build Coastguard Worker /* Pass 2: process two rows, store to output array. */
140*dfc6aa5cSAndroid Build Coastguard Worker
141*dfc6aa5cSAndroid Build Coastguard Worker /* Even part: we're only interested in col0; the top half of tmp10 is "don't
142*dfc6aa5cSAndroid Build Coastguard Worker * care."
143*dfc6aa5cSAndroid Build Coastguard Worker */
144*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp10 = vshll_n_s16(vget_low_s16(cols_0246), CONST_BITS + 2);
145*dfc6aa5cSAndroid Build Coastguard Worker
146*dfc6aa5cSAndroid Build Coastguard Worker /* Odd part: we're only interested in the bottom half of tmp0. */
147*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp0 = vmull_lane_s16(vget_low_s16(cols_1155), consts, 3);
148*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmlal_lane_s16(tmp0, vget_low_s16(cols_3377), consts, 2);
149*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmlal_lane_s16(tmp0, vget_high_s16(cols_1155), consts, 1);
150*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmlal_lane_s16(tmp0, vget_high_s16(cols_3377), consts, 0);
151*dfc6aa5cSAndroid Build Coastguard Worker
152*dfc6aa5cSAndroid Build Coastguard Worker /* Final output stage: descale and clamp to range [0-255]. */
153*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t output_s16 = vcombine_s16(vaddhn_s32(tmp10, tmp0),
154*dfc6aa5cSAndroid Build Coastguard Worker vsubhn_s32(tmp10, tmp0));
155*dfc6aa5cSAndroid Build Coastguard Worker output_s16 = vrsraq_n_s16(vdupq_n_s16(CENTERJSAMPLE), output_s16,
156*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS + PASS1_BITS + 3 + 2 - 16);
157*dfc6aa5cSAndroid Build Coastguard Worker /* Narrow to 8-bit and convert to unsigned. */
158*dfc6aa5cSAndroid Build Coastguard Worker uint8x8_t output_u8 = vqmovun_s16(output_s16);
159*dfc6aa5cSAndroid Build Coastguard Worker
160*dfc6aa5cSAndroid Build Coastguard Worker /* Store 2x2 block to memory. */
161*dfc6aa5cSAndroid Build Coastguard Worker vst1_lane_u8(output_buf[0] + output_col, output_u8, 0);
162*dfc6aa5cSAndroid Build Coastguard Worker vst1_lane_u8(output_buf[1] + output_col, output_u8, 1);
163*dfc6aa5cSAndroid Build Coastguard Worker vst1_lane_u8(output_buf[0] + output_col + 1, output_u8, 4);
164*dfc6aa5cSAndroid Build Coastguard Worker vst1_lane_u8(output_buf[1] + output_col + 1, output_u8, 5);
165*dfc6aa5cSAndroid Build Coastguard Worker }
166*dfc6aa5cSAndroid Build Coastguard Worker
167*dfc6aa5cSAndroid Build Coastguard Worker
168*dfc6aa5cSAndroid Build Coastguard Worker /* jsimd_idct_4x4_neon() is an inverse DCT function that produces reduced-size
169*dfc6aa5cSAndroid Build Coastguard Worker * 4x4 output from an 8x8 DCT block. It uses the same calculations and
170*dfc6aa5cSAndroid Build Coastguard Worker * produces exactly the same output as IJG's original jpeg_idct_4x4() function
171*dfc6aa5cSAndroid Build Coastguard Worker * from jpeg-6b, which can be found in jidctred.c.
172*dfc6aa5cSAndroid Build Coastguard Worker *
173*dfc6aa5cSAndroid Build Coastguard Worker * Scaled integer constants are used to avoid floating-point arithmetic:
174*dfc6aa5cSAndroid Build Coastguard Worker * 0.211164243 = 1730 * 2^-13
175*dfc6aa5cSAndroid Build Coastguard Worker * 0.509795579 = 4176 * 2^-13
176*dfc6aa5cSAndroid Build Coastguard Worker * 0.601344887 = 4926 * 2^-13
177*dfc6aa5cSAndroid Build Coastguard Worker * 0.765366865 = 6270 * 2^-13
178*dfc6aa5cSAndroid Build Coastguard Worker * 0.899976223 = 7373 * 2^-13
179*dfc6aa5cSAndroid Build Coastguard Worker * 1.061594337 = 8697 * 2^-13
180*dfc6aa5cSAndroid Build Coastguard Worker * 1.451774981 = 11893 * 2^-13
181*dfc6aa5cSAndroid Build Coastguard Worker * 1.847759065 = 15137 * 2^-13
182*dfc6aa5cSAndroid Build Coastguard Worker * 2.172734803 = 17799 * 2^-13
183*dfc6aa5cSAndroid Build Coastguard Worker * 2.562915447 = 20995 * 2^-13
184*dfc6aa5cSAndroid Build Coastguard Worker *
185*dfc6aa5cSAndroid Build Coastguard Worker * See jidctred.c for further details of the 4x4 IDCT algorithm. Where
186*dfc6aa5cSAndroid Build Coastguard Worker * possible, the variable names and comments here in jsimd_idct_4x4_neon()
187*dfc6aa5cSAndroid Build Coastguard Worker * match up with those in jpeg_idct_4x4().
188*dfc6aa5cSAndroid Build Coastguard Worker */
189*dfc6aa5cSAndroid Build Coastguard Worker
190*dfc6aa5cSAndroid Build Coastguard Worker ALIGN(16) static const int16_t jsimd_idct_4x4_neon_consts[] = {
191*dfc6aa5cSAndroid Build Coastguard Worker F_1_847, -F_0_765, -F_0_211, F_1_451,
192*dfc6aa5cSAndroid Build Coastguard Worker -F_2_172, F_1_061, -F_0_509, -F_0_601,
193*dfc6aa5cSAndroid Build Coastguard Worker F_0_899, F_2_562, 0, 0
194*dfc6aa5cSAndroid Build Coastguard Worker };
195*dfc6aa5cSAndroid Build Coastguard Worker
jsimd_idct_4x4_neon(void * dct_table,JCOEFPTR coef_block,JSAMPARRAY output_buf,JDIMENSION output_col)196*dfc6aa5cSAndroid Build Coastguard Worker void jsimd_idct_4x4_neon(void *dct_table, JCOEFPTR coef_block,
197*dfc6aa5cSAndroid Build Coastguard Worker JSAMPARRAY output_buf, JDIMENSION output_col)
198*dfc6aa5cSAndroid Build Coastguard Worker {
199*dfc6aa5cSAndroid Build Coastguard Worker ISLOW_MULT_TYPE *quantptr = dct_table;
200*dfc6aa5cSAndroid Build Coastguard Worker
201*dfc6aa5cSAndroid Build Coastguard Worker /* Load DCT coefficients. */
202*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t row0 = vld1q_s16(coef_block + 0 * DCTSIZE);
203*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t row1 = vld1q_s16(coef_block + 1 * DCTSIZE);
204*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t row2 = vld1q_s16(coef_block + 2 * DCTSIZE);
205*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t row3 = vld1q_s16(coef_block + 3 * DCTSIZE);
206*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t row5 = vld1q_s16(coef_block + 5 * DCTSIZE);
207*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t row6 = vld1q_s16(coef_block + 6 * DCTSIZE);
208*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t row7 = vld1q_s16(coef_block + 7 * DCTSIZE);
209*dfc6aa5cSAndroid Build Coastguard Worker
210*dfc6aa5cSAndroid Build Coastguard Worker /* Load quantization table values for DC coefficients. */
211*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t quant_row0 = vld1q_s16(quantptr + 0 * DCTSIZE);
212*dfc6aa5cSAndroid Build Coastguard Worker /* Dequantize DC coefficients. */
213*dfc6aa5cSAndroid Build Coastguard Worker row0 = vmulq_s16(row0, quant_row0);
214*dfc6aa5cSAndroid Build Coastguard Worker
215*dfc6aa5cSAndroid Build Coastguard Worker /* Construct bitmap to test if all AC coefficients are 0. */
216*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t bitmap = vorrq_s16(row1, row2);
217*dfc6aa5cSAndroid Build Coastguard Worker bitmap = vorrq_s16(bitmap, row3);
218*dfc6aa5cSAndroid Build Coastguard Worker bitmap = vorrq_s16(bitmap, row5);
219*dfc6aa5cSAndroid Build Coastguard Worker bitmap = vorrq_s16(bitmap, row6);
220*dfc6aa5cSAndroid Build Coastguard Worker bitmap = vorrq_s16(bitmap, row7);
221*dfc6aa5cSAndroid Build Coastguard Worker
222*dfc6aa5cSAndroid Build Coastguard Worker int64_t left_ac_bitmap = vgetq_lane_s64(vreinterpretq_s64_s16(bitmap), 0);
223*dfc6aa5cSAndroid Build Coastguard Worker int64_t right_ac_bitmap = vgetq_lane_s64(vreinterpretq_s64_s16(bitmap), 1);
224*dfc6aa5cSAndroid Build Coastguard Worker
225*dfc6aa5cSAndroid Build Coastguard Worker /* Load constants for IDCT computation. */
226*dfc6aa5cSAndroid Build Coastguard Worker #ifdef HAVE_VLD1_S16_X3
227*dfc6aa5cSAndroid Build Coastguard Worker const int16x4x3_t consts = vld1_s16_x3(jsimd_idct_4x4_neon_consts);
228*dfc6aa5cSAndroid Build Coastguard Worker #else
229*dfc6aa5cSAndroid Build Coastguard Worker /* GCC does not currently support the intrinsic vld1_<type>_x3(). */
230*dfc6aa5cSAndroid Build Coastguard Worker const int16x4_t consts1 = vld1_s16(jsimd_idct_4x4_neon_consts);
231*dfc6aa5cSAndroid Build Coastguard Worker const int16x4_t consts2 = vld1_s16(jsimd_idct_4x4_neon_consts + 4);
232*dfc6aa5cSAndroid Build Coastguard Worker const int16x4_t consts3 = vld1_s16(jsimd_idct_4x4_neon_consts + 8);
233*dfc6aa5cSAndroid Build Coastguard Worker const int16x4x3_t consts = { { consts1, consts2, consts3 } };
234*dfc6aa5cSAndroid Build Coastguard Worker #endif
235*dfc6aa5cSAndroid Build Coastguard Worker
236*dfc6aa5cSAndroid Build Coastguard Worker if (left_ac_bitmap == 0 && right_ac_bitmap == 0) {
237*dfc6aa5cSAndroid Build Coastguard Worker /* All AC coefficients are zero.
238*dfc6aa5cSAndroid Build Coastguard Worker * Compute DC values and duplicate into row vectors 0, 1, 2, and 3.
239*dfc6aa5cSAndroid Build Coastguard Worker */
240*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t dcval = vshlq_n_s16(row0, PASS1_BITS);
241*dfc6aa5cSAndroid Build Coastguard Worker row0 = dcval;
242*dfc6aa5cSAndroid Build Coastguard Worker row1 = dcval;
243*dfc6aa5cSAndroid Build Coastguard Worker row2 = dcval;
244*dfc6aa5cSAndroid Build Coastguard Worker row3 = dcval;
245*dfc6aa5cSAndroid Build Coastguard Worker } else if (left_ac_bitmap == 0) {
246*dfc6aa5cSAndroid Build Coastguard Worker /* AC coefficients are zero for columns 0, 1, 2, and 3.
247*dfc6aa5cSAndroid Build Coastguard Worker * Compute DC values for these columns.
248*dfc6aa5cSAndroid Build Coastguard Worker */
249*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t dcval = vshl_n_s16(vget_low_s16(row0), PASS1_BITS);
250*dfc6aa5cSAndroid Build Coastguard Worker
251*dfc6aa5cSAndroid Build Coastguard Worker /* Commence regular IDCT computation for columns 4, 5, 6, and 7. */
252*dfc6aa5cSAndroid Build Coastguard Worker
253*dfc6aa5cSAndroid Build Coastguard Worker /* Load quantization table. */
254*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t quant_row1 = vld1_s16(quantptr + 1 * DCTSIZE + 4);
255*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t quant_row2 = vld1_s16(quantptr + 2 * DCTSIZE + 4);
256*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t quant_row3 = vld1_s16(quantptr + 3 * DCTSIZE + 4);
257*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t quant_row5 = vld1_s16(quantptr + 5 * DCTSIZE + 4);
258*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t quant_row6 = vld1_s16(quantptr + 6 * DCTSIZE + 4);
259*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t quant_row7 = vld1_s16(quantptr + 7 * DCTSIZE + 4);
260*dfc6aa5cSAndroid Build Coastguard Worker
261*dfc6aa5cSAndroid Build Coastguard Worker /* Even part */
262*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp0 = vshll_n_s16(vget_high_s16(row0), CONST_BITS + 1);
263*dfc6aa5cSAndroid Build Coastguard Worker
264*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t z2 = vmul_s16(vget_high_s16(row2), quant_row2);
265*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t z3 = vmul_s16(vget_high_s16(row6), quant_row6);
266*dfc6aa5cSAndroid Build Coastguard Worker
267*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp2 = vmull_lane_s16(z2, consts.val[0], 0);
268*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmlal_lane_s16(tmp2, z3, consts.val[0], 1);
269*dfc6aa5cSAndroid Build Coastguard Worker
270*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp10 = vaddq_s32(tmp0, tmp2);
271*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp12 = vsubq_s32(tmp0, tmp2);
272*dfc6aa5cSAndroid Build Coastguard Worker
273*dfc6aa5cSAndroid Build Coastguard Worker /* Odd part */
274*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t z1 = vmul_s16(vget_high_s16(row7), quant_row7);
275*dfc6aa5cSAndroid Build Coastguard Worker z2 = vmul_s16(vget_high_s16(row5), quant_row5);
276*dfc6aa5cSAndroid Build Coastguard Worker z3 = vmul_s16(vget_high_s16(row3), quant_row3);
277*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t z4 = vmul_s16(vget_high_s16(row1), quant_row1);
278*dfc6aa5cSAndroid Build Coastguard Worker
279*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmull_lane_s16(z1, consts.val[0], 2);
280*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmlal_lane_s16(tmp0, z2, consts.val[0], 3);
281*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmlal_lane_s16(tmp0, z3, consts.val[1], 0);
282*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmlal_lane_s16(tmp0, z4, consts.val[1], 1);
283*dfc6aa5cSAndroid Build Coastguard Worker
284*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmull_lane_s16(z1, consts.val[1], 2);
285*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmlal_lane_s16(tmp2, z2, consts.val[1], 3);
286*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmlal_lane_s16(tmp2, z3, consts.val[2], 0);
287*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmlal_lane_s16(tmp2, z4, consts.val[2], 1);
288*dfc6aa5cSAndroid Build Coastguard Worker
289*dfc6aa5cSAndroid Build Coastguard Worker /* Final output stage: descale and narrow to 16-bit. */
290*dfc6aa5cSAndroid Build Coastguard Worker row0 = vcombine_s16(dcval, vrshrn_n_s32(vaddq_s32(tmp10, tmp2),
291*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1));
292*dfc6aa5cSAndroid Build Coastguard Worker row3 = vcombine_s16(dcval, vrshrn_n_s32(vsubq_s32(tmp10, tmp2),
293*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1));
294*dfc6aa5cSAndroid Build Coastguard Worker row1 = vcombine_s16(dcval, vrshrn_n_s32(vaddq_s32(tmp12, tmp0),
295*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1));
296*dfc6aa5cSAndroid Build Coastguard Worker row2 = vcombine_s16(dcval, vrshrn_n_s32(vsubq_s32(tmp12, tmp0),
297*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1));
298*dfc6aa5cSAndroid Build Coastguard Worker } else if (right_ac_bitmap == 0) {
299*dfc6aa5cSAndroid Build Coastguard Worker /* AC coefficients are zero for columns 4, 5, 6, and 7.
300*dfc6aa5cSAndroid Build Coastguard Worker * Compute DC values for these columns.
301*dfc6aa5cSAndroid Build Coastguard Worker */
302*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t dcval = vshl_n_s16(vget_high_s16(row0), PASS1_BITS);
303*dfc6aa5cSAndroid Build Coastguard Worker
304*dfc6aa5cSAndroid Build Coastguard Worker /* Commence regular IDCT computation for columns 0, 1, 2, and 3. */
305*dfc6aa5cSAndroid Build Coastguard Worker
306*dfc6aa5cSAndroid Build Coastguard Worker /* Load quantization table. */
307*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t quant_row1 = vld1_s16(quantptr + 1 * DCTSIZE);
308*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t quant_row2 = vld1_s16(quantptr + 2 * DCTSIZE);
309*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t quant_row3 = vld1_s16(quantptr + 3 * DCTSIZE);
310*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t quant_row5 = vld1_s16(quantptr + 5 * DCTSIZE);
311*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t quant_row6 = vld1_s16(quantptr + 6 * DCTSIZE);
312*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t quant_row7 = vld1_s16(quantptr + 7 * DCTSIZE);
313*dfc6aa5cSAndroid Build Coastguard Worker
314*dfc6aa5cSAndroid Build Coastguard Worker /* Even part */
315*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp0 = vshll_n_s16(vget_low_s16(row0), CONST_BITS + 1);
316*dfc6aa5cSAndroid Build Coastguard Worker
317*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t z2 = vmul_s16(vget_low_s16(row2), quant_row2);
318*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t z3 = vmul_s16(vget_low_s16(row6), quant_row6);
319*dfc6aa5cSAndroid Build Coastguard Worker
320*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp2 = vmull_lane_s16(z2, consts.val[0], 0);
321*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmlal_lane_s16(tmp2, z3, consts.val[0], 1);
322*dfc6aa5cSAndroid Build Coastguard Worker
323*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp10 = vaddq_s32(tmp0, tmp2);
324*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp12 = vsubq_s32(tmp0, tmp2);
325*dfc6aa5cSAndroid Build Coastguard Worker
326*dfc6aa5cSAndroid Build Coastguard Worker /* Odd part */
327*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t z1 = vmul_s16(vget_low_s16(row7), quant_row7);
328*dfc6aa5cSAndroid Build Coastguard Worker z2 = vmul_s16(vget_low_s16(row5), quant_row5);
329*dfc6aa5cSAndroid Build Coastguard Worker z3 = vmul_s16(vget_low_s16(row3), quant_row3);
330*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t z4 = vmul_s16(vget_low_s16(row1), quant_row1);
331*dfc6aa5cSAndroid Build Coastguard Worker
332*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmull_lane_s16(z1, consts.val[0], 2);
333*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmlal_lane_s16(tmp0, z2, consts.val[0], 3);
334*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmlal_lane_s16(tmp0, z3, consts.val[1], 0);
335*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmlal_lane_s16(tmp0, z4, consts.val[1], 1);
336*dfc6aa5cSAndroid Build Coastguard Worker
337*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmull_lane_s16(z1, consts.val[1], 2);
338*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmlal_lane_s16(tmp2, z2, consts.val[1], 3);
339*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmlal_lane_s16(tmp2, z3, consts.val[2], 0);
340*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmlal_lane_s16(tmp2, z4, consts.val[2], 1);
341*dfc6aa5cSAndroid Build Coastguard Worker
342*dfc6aa5cSAndroid Build Coastguard Worker /* Final output stage: descale and narrow to 16-bit. */
343*dfc6aa5cSAndroid Build Coastguard Worker row0 = vcombine_s16(vrshrn_n_s32(vaddq_s32(tmp10, tmp2),
344*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1), dcval);
345*dfc6aa5cSAndroid Build Coastguard Worker row3 = vcombine_s16(vrshrn_n_s32(vsubq_s32(tmp10, tmp2),
346*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1), dcval);
347*dfc6aa5cSAndroid Build Coastguard Worker row1 = vcombine_s16(vrshrn_n_s32(vaddq_s32(tmp12, tmp0),
348*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1), dcval);
349*dfc6aa5cSAndroid Build Coastguard Worker row2 = vcombine_s16(vrshrn_n_s32(vsubq_s32(tmp12, tmp0),
350*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1), dcval);
351*dfc6aa5cSAndroid Build Coastguard Worker } else {
352*dfc6aa5cSAndroid Build Coastguard Worker /* All AC coefficients are non-zero; full IDCT calculation required. */
353*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t quant_row1 = vld1q_s16(quantptr + 1 * DCTSIZE);
354*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t quant_row2 = vld1q_s16(quantptr + 2 * DCTSIZE);
355*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t quant_row3 = vld1q_s16(quantptr + 3 * DCTSIZE);
356*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t quant_row5 = vld1q_s16(quantptr + 5 * DCTSIZE);
357*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t quant_row6 = vld1q_s16(quantptr + 6 * DCTSIZE);
358*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t quant_row7 = vld1q_s16(quantptr + 7 * DCTSIZE);
359*dfc6aa5cSAndroid Build Coastguard Worker
360*dfc6aa5cSAndroid Build Coastguard Worker /* Even part */
361*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp0_l = vshll_n_s16(vget_low_s16(row0), CONST_BITS + 1);
362*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp0_h = vshll_n_s16(vget_high_s16(row0), CONST_BITS + 1);
363*dfc6aa5cSAndroid Build Coastguard Worker
364*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t z2 = vmulq_s16(row2, quant_row2);
365*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t z3 = vmulq_s16(row6, quant_row6);
366*dfc6aa5cSAndroid Build Coastguard Worker
367*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp2_l = vmull_lane_s16(vget_low_s16(z2), consts.val[0], 0);
368*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp2_h = vmull_lane_s16(vget_high_s16(z2), consts.val[0], 0);
369*dfc6aa5cSAndroid Build Coastguard Worker tmp2_l = vmlal_lane_s16(tmp2_l, vget_low_s16(z3), consts.val[0], 1);
370*dfc6aa5cSAndroid Build Coastguard Worker tmp2_h = vmlal_lane_s16(tmp2_h, vget_high_s16(z3), consts.val[0], 1);
371*dfc6aa5cSAndroid Build Coastguard Worker
372*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp10_l = vaddq_s32(tmp0_l, tmp2_l);
373*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp10_h = vaddq_s32(tmp0_h, tmp2_h);
374*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp12_l = vsubq_s32(tmp0_l, tmp2_l);
375*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp12_h = vsubq_s32(tmp0_h, tmp2_h);
376*dfc6aa5cSAndroid Build Coastguard Worker
377*dfc6aa5cSAndroid Build Coastguard Worker /* Odd part */
378*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t z1 = vmulq_s16(row7, quant_row7);
379*dfc6aa5cSAndroid Build Coastguard Worker z2 = vmulq_s16(row5, quant_row5);
380*dfc6aa5cSAndroid Build Coastguard Worker z3 = vmulq_s16(row3, quant_row3);
381*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t z4 = vmulq_s16(row1, quant_row1);
382*dfc6aa5cSAndroid Build Coastguard Worker
383*dfc6aa5cSAndroid Build Coastguard Worker tmp0_l = vmull_lane_s16(vget_low_s16(z1), consts.val[0], 2);
384*dfc6aa5cSAndroid Build Coastguard Worker tmp0_l = vmlal_lane_s16(tmp0_l, vget_low_s16(z2), consts.val[0], 3);
385*dfc6aa5cSAndroid Build Coastguard Worker tmp0_l = vmlal_lane_s16(tmp0_l, vget_low_s16(z3), consts.val[1], 0);
386*dfc6aa5cSAndroid Build Coastguard Worker tmp0_l = vmlal_lane_s16(tmp0_l, vget_low_s16(z4), consts.val[1], 1);
387*dfc6aa5cSAndroid Build Coastguard Worker tmp0_h = vmull_lane_s16(vget_high_s16(z1), consts.val[0], 2);
388*dfc6aa5cSAndroid Build Coastguard Worker tmp0_h = vmlal_lane_s16(tmp0_h, vget_high_s16(z2), consts.val[0], 3);
389*dfc6aa5cSAndroid Build Coastguard Worker tmp0_h = vmlal_lane_s16(tmp0_h, vget_high_s16(z3), consts.val[1], 0);
390*dfc6aa5cSAndroid Build Coastguard Worker tmp0_h = vmlal_lane_s16(tmp0_h, vget_high_s16(z4), consts.val[1], 1);
391*dfc6aa5cSAndroid Build Coastguard Worker
392*dfc6aa5cSAndroid Build Coastguard Worker tmp2_l = vmull_lane_s16(vget_low_s16(z1), consts.val[1], 2);
393*dfc6aa5cSAndroid Build Coastguard Worker tmp2_l = vmlal_lane_s16(tmp2_l, vget_low_s16(z2), consts.val[1], 3);
394*dfc6aa5cSAndroid Build Coastguard Worker tmp2_l = vmlal_lane_s16(tmp2_l, vget_low_s16(z3), consts.val[2], 0);
395*dfc6aa5cSAndroid Build Coastguard Worker tmp2_l = vmlal_lane_s16(tmp2_l, vget_low_s16(z4), consts.val[2], 1);
396*dfc6aa5cSAndroid Build Coastguard Worker tmp2_h = vmull_lane_s16(vget_high_s16(z1), consts.val[1], 2);
397*dfc6aa5cSAndroid Build Coastguard Worker tmp2_h = vmlal_lane_s16(tmp2_h, vget_high_s16(z2), consts.val[1], 3);
398*dfc6aa5cSAndroid Build Coastguard Worker tmp2_h = vmlal_lane_s16(tmp2_h, vget_high_s16(z3), consts.val[2], 0);
399*dfc6aa5cSAndroid Build Coastguard Worker tmp2_h = vmlal_lane_s16(tmp2_h, vget_high_s16(z4), consts.val[2], 1);
400*dfc6aa5cSAndroid Build Coastguard Worker
401*dfc6aa5cSAndroid Build Coastguard Worker /* Final output stage: descale and narrow to 16-bit. */
402*dfc6aa5cSAndroid Build Coastguard Worker row0 = vcombine_s16(vrshrn_n_s32(vaddq_s32(tmp10_l, tmp2_l),
403*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1),
404*dfc6aa5cSAndroid Build Coastguard Worker vrshrn_n_s32(vaddq_s32(tmp10_h, tmp2_h),
405*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1));
406*dfc6aa5cSAndroid Build Coastguard Worker row3 = vcombine_s16(vrshrn_n_s32(vsubq_s32(tmp10_l, tmp2_l),
407*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1),
408*dfc6aa5cSAndroid Build Coastguard Worker vrshrn_n_s32(vsubq_s32(tmp10_h, tmp2_h),
409*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1));
410*dfc6aa5cSAndroid Build Coastguard Worker row1 = vcombine_s16(vrshrn_n_s32(vaddq_s32(tmp12_l, tmp0_l),
411*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1),
412*dfc6aa5cSAndroid Build Coastguard Worker vrshrn_n_s32(vaddq_s32(tmp12_h, tmp0_h),
413*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1));
414*dfc6aa5cSAndroid Build Coastguard Worker row2 = vcombine_s16(vrshrn_n_s32(vsubq_s32(tmp12_l, tmp0_l),
415*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1),
416*dfc6aa5cSAndroid Build Coastguard Worker vrshrn_n_s32(vsubq_s32(tmp12_h, tmp0_h),
417*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS - PASS1_BITS + 1));
418*dfc6aa5cSAndroid Build Coastguard Worker }
419*dfc6aa5cSAndroid Build Coastguard Worker
420*dfc6aa5cSAndroid Build Coastguard Worker /* Transpose 8x4 block to perform IDCT on rows in second pass. */
421*dfc6aa5cSAndroid Build Coastguard Worker int16x8x2_t row_01 = vtrnq_s16(row0, row1);
422*dfc6aa5cSAndroid Build Coastguard Worker int16x8x2_t row_23 = vtrnq_s16(row2, row3);
423*dfc6aa5cSAndroid Build Coastguard Worker
424*dfc6aa5cSAndroid Build Coastguard Worker int32x4x2_t cols_0426 = vtrnq_s32(vreinterpretq_s32_s16(row_01.val[0]),
425*dfc6aa5cSAndroid Build Coastguard Worker vreinterpretq_s32_s16(row_23.val[0]));
426*dfc6aa5cSAndroid Build Coastguard Worker int32x4x2_t cols_1537 = vtrnq_s32(vreinterpretq_s32_s16(row_01.val[1]),
427*dfc6aa5cSAndroid Build Coastguard Worker vreinterpretq_s32_s16(row_23.val[1]));
428*dfc6aa5cSAndroid Build Coastguard Worker
429*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t col0 = vreinterpret_s16_s32(vget_low_s32(cols_0426.val[0]));
430*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t col1 = vreinterpret_s16_s32(vget_low_s32(cols_1537.val[0]));
431*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t col2 = vreinterpret_s16_s32(vget_low_s32(cols_0426.val[1]));
432*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t col3 = vreinterpret_s16_s32(vget_low_s32(cols_1537.val[1]));
433*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t col5 = vreinterpret_s16_s32(vget_high_s32(cols_1537.val[0]));
434*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t col6 = vreinterpret_s16_s32(vget_high_s32(cols_0426.val[1]));
435*dfc6aa5cSAndroid Build Coastguard Worker int16x4_t col7 = vreinterpret_s16_s32(vget_high_s32(cols_1537.val[1]));
436*dfc6aa5cSAndroid Build Coastguard Worker
437*dfc6aa5cSAndroid Build Coastguard Worker /* Commence second pass of IDCT. */
438*dfc6aa5cSAndroid Build Coastguard Worker
439*dfc6aa5cSAndroid Build Coastguard Worker /* Even part */
440*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp0 = vshll_n_s16(col0, CONST_BITS + 1);
441*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp2 = vmull_lane_s16(col2, consts.val[0], 0);
442*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmlal_lane_s16(tmp2, col6, consts.val[0], 1);
443*dfc6aa5cSAndroid Build Coastguard Worker
444*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp10 = vaddq_s32(tmp0, tmp2);
445*dfc6aa5cSAndroid Build Coastguard Worker int32x4_t tmp12 = vsubq_s32(tmp0, tmp2);
446*dfc6aa5cSAndroid Build Coastguard Worker
447*dfc6aa5cSAndroid Build Coastguard Worker /* Odd part */
448*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmull_lane_s16(col7, consts.val[0], 2);
449*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmlal_lane_s16(tmp0, col5, consts.val[0], 3);
450*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmlal_lane_s16(tmp0, col3, consts.val[1], 0);
451*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = vmlal_lane_s16(tmp0, col1, consts.val[1], 1);
452*dfc6aa5cSAndroid Build Coastguard Worker
453*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmull_lane_s16(col7, consts.val[1], 2);
454*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmlal_lane_s16(tmp2, col5, consts.val[1], 3);
455*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmlal_lane_s16(tmp2, col3, consts.val[2], 0);
456*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = vmlal_lane_s16(tmp2, col1, consts.val[2], 1);
457*dfc6aa5cSAndroid Build Coastguard Worker
458*dfc6aa5cSAndroid Build Coastguard Worker /* Final output stage: descale and clamp to range [0-255]. */
459*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t output_cols_02 = vcombine_s16(vaddhn_s32(tmp10, tmp2),
460*dfc6aa5cSAndroid Build Coastguard Worker vsubhn_s32(tmp12, tmp0));
461*dfc6aa5cSAndroid Build Coastguard Worker int16x8_t output_cols_13 = vcombine_s16(vaddhn_s32(tmp12, tmp0),
462*dfc6aa5cSAndroid Build Coastguard Worker vsubhn_s32(tmp10, tmp2));
463*dfc6aa5cSAndroid Build Coastguard Worker output_cols_02 = vrsraq_n_s16(vdupq_n_s16(CENTERJSAMPLE), output_cols_02,
464*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS + PASS1_BITS + 3 + 1 - 16);
465*dfc6aa5cSAndroid Build Coastguard Worker output_cols_13 = vrsraq_n_s16(vdupq_n_s16(CENTERJSAMPLE), output_cols_13,
466*dfc6aa5cSAndroid Build Coastguard Worker CONST_BITS + PASS1_BITS + 3 + 1 - 16);
467*dfc6aa5cSAndroid Build Coastguard Worker /* Narrow to 8-bit and convert to unsigned while zipping 8-bit elements.
468*dfc6aa5cSAndroid Build Coastguard Worker * An interleaving store completes the transpose.
469*dfc6aa5cSAndroid Build Coastguard Worker */
470*dfc6aa5cSAndroid Build Coastguard Worker uint8x8x2_t output_0123 = vzip_u8(vqmovun_s16(output_cols_02),
471*dfc6aa5cSAndroid Build Coastguard Worker vqmovun_s16(output_cols_13));
472*dfc6aa5cSAndroid Build Coastguard Worker uint16x4x2_t output_01_23 = { {
473*dfc6aa5cSAndroid Build Coastguard Worker vreinterpret_u16_u8(output_0123.val[0]),
474*dfc6aa5cSAndroid Build Coastguard Worker vreinterpret_u16_u8(output_0123.val[1])
475*dfc6aa5cSAndroid Build Coastguard Worker } };
476*dfc6aa5cSAndroid Build Coastguard Worker
477*dfc6aa5cSAndroid Build Coastguard Worker /* Store 4x4 block to memory. */
478*dfc6aa5cSAndroid Build Coastguard Worker JSAMPROW outptr0 = output_buf[0] + output_col;
479*dfc6aa5cSAndroid Build Coastguard Worker JSAMPROW outptr1 = output_buf[1] + output_col;
480*dfc6aa5cSAndroid Build Coastguard Worker JSAMPROW outptr2 = output_buf[2] + output_col;
481*dfc6aa5cSAndroid Build Coastguard Worker JSAMPROW outptr3 = output_buf[3] + output_col;
482*dfc6aa5cSAndroid Build Coastguard Worker vst2_lane_u16((uint16_t *)outptr0, output_01_23, 0);
483*dfc6aa5cSAndroid Build Coastguard Worker vst2_lane_u16((uint16_t *)outptr1, output_01_23, 1);
484*dfc6aa5cSAndroid Build Coastguard Worker vst2_lane_u16((uint16_t *)outptr2, output_01_23, 2);
485*dfc6aa5cSAndroid Build Coastguard Worker vst2_lane_u16((uint16_t *)outptr3, output_01_23, 3);
486*dfc6aa5cSAndroid Build Coastguard Worker }
487