]> granicus.if.org Git - libvpx/blob - vpx_dsp/arm/idct32x32_135_add_neon.c
ppc: Add vpx_sadnxmx4d_vsx for n,m = {8, 16, 32 ,64}
[libvpx] / vpx_dsp / arm / idct32x32_135_add_neon.c
1 /*
2  *  Copyright (c) 2016 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 <arm_neon.h>
12
13 #include "./vpx_config.h"
14 #include "./vpx_dsp_rtcd.h"
15 #include "vpx_dsp/arm/idct_neon.h"
16 #include "vpx_dsp/arm/transpose_neon.h"
17 #include "vpx_dsp/txfm_common.h"
18
19 static INLINE void load_8x8_s16(const tran_low_t *input, int16x8_t *const in0,
20                                 int16x8_t *const in1, int16x8_t *const in2,
21                                 int16x8_t *const in3, int16x8_t *const in4,
22                                 int16x8_t *const in5, int16x8_t *const in6,
23                                 int16x8_t *const in7) {
24   *in0 = load_tran_low_to_s16q(input);
25   input += 32;
26   *in1 = load_tran_low_to_s16q(input);
27   input += 32;
28   *in2 = load_tran_low_to_s16q(input);
29   input += 32;
30   *in3 = load_tran_low_to_s16q(input);
31   input += 32;
32   *in4 = load_tran_low_to_s16q(input);
33   input += 32;
34   *in5 = load_tran_low_to_s16q(input);
35   input += 32;
36   *in6 = load_tran_low_to_s16q(input);
37   input += 32;
38   *in7 = load_tran_low_to_s16q(input);
39 }
40
41 static INLINE void load_4x8_s16(const tran_low_t *input, int16x4_t *const in0,
42                                 int16x4_t *const in1, int16x4_t *const in2,
43                                 int16x4_t *const in3, int16x4_t *const in4,
44                                 int16x4_t *const in5, int16x4_t *const in6,
45                                 int16x4_t *const in7) {
46   *in0 = load_tran_low_to_s16d(input);
47   input += 32;
48   *in1 = load_tran_low_to_s16d(input);
49   input += 32;
50   *in2 = load_tran_low_to_s16d(input);
51   input += 32;
52   *in3 = load_tran_low_to_s16d(input);
53   input += 32;
54   *in4 = load_tran_low_to_s16d(input);
55   input += 32;
56   *in5 = load_tran_low_to_s16d(input);
57   input += 32;
58   *in6 = load_tran_low_to_s16d(input);
59   input += 32;
60   *in7 = load_tran_low_to_s16d(input);
61 }
62
63 // Only for the first pass of the  _135_ variant. Since it only uses values from
64 // the top left 16x16 it can safely assume all the remaining values are 0 and
65 // skip an awful lot of calculations. In fact, only the first 12 columns make
66 // the cut. None of the elements in the 13th, 14th, 15th or 16th columns are
67 // used so it skips any calls to input[12|13|14|15] too.
68 // In C this does a single row of 32 for each call. Here it transposes the top
69 // left 12x8 to allow using SIMD.
70
71 // vp9/common/vp9_scan.c:vp9_default_iscan_32x32 arranges the first 135 non-zero
72 // coefficients as follows:
73 //      0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15
74 //  0   0   2   5  10  17  25  38  47  62  83 101 121
75 //  1   1   4   8  15  22  30  45  58  74  92 112 133
76 //  2   3   7  12  18  28  36  52  64  82 102 118
77 //  3   6  11  16  23  31  43  60  73  90 109 126
78 //  4   9  14  19  29  37  50  65  78  98 116 134
79 //  5  13  20  26  35  44  54  72  85 105 123
80 //  6  21  27  33  42  53  63  80  94 113 132
81 //  7  24  32  39  48  57  71  88 104 120
82 //  8  34  40  46  56  68  81  96 111 130
83 //  9  41  49  55  67  77  91 107 124
84 // 10  51  59  66  76  89  99 119 131
85 // 11  61  69  75  87 100 114 129
86 // 12  70  79  86  97 108 122
87 // 13  84  93 103 110 125
88 // 14  98 106 115 127
89 // 15 117 128
90 void vpx_idct32_12_neon(const tran_low_t *const input, int16_t *output) {
91   int16x4_t tmp[8];
92   int16x8_t in[12], s1[32], s2[32], s3[32], s4[32], s5[32], s6[32], s7[32];
93
94   load_8x8_s16(input, &in[0], &in[1], &in[2], &in[3], &in[4], &in[5], &in[6],
95                &in[7]);
96   transpose_s16_8x8(&in[0], &in[1], &in[2], &in[3], &in[4], &in[5], &in[6],
97                     &in[7]);
98
99   load_4x8_s16(input + 8, &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5],
100                &tmp[6], &tmp[7]);
101   transpose_s16_4x8(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6],
102                     tmp[7], &in[8], &in[9], &in[10], &in[11]);
103
104   // stage 1
105   s1[16] = multiply_shift_and_narrow_s16(in[1], cospi_31_64);
106   s1[31] = multiply_shift_and_narrow_s16(in[1], cospi_1_64);
107
108   s1[18] = multiply_shift_and_narrow_s16(in[9], cospi_23_64);
109   s1[29] = multiply_shift_and_narrow_s16(in[9], cospi_9_64);
110
111   s1[19] = multiply_shift_and_narrow_s16(in[7], -cospi_25_64);
112   s1[28] = multiply_shift_and_narrow_s16(in[7], cospi_7_64);
113
114   s1[20] = multiply_shift_and_narrow_s16(in[5], cospi_27_64);
115   s1[27] = multiply_shift_and_narrow_s16(in[5], cospi_5_64);
116
117   s1[21] = multiply_shift_and_narrow_s16(in[11], -cospi_21_64);
118   s1[26] = multiply_shift_and_narrow_s16(in[11], cospi_11_64);
119
120   s1[23] = multiply_shift_and_narrow_s16(in[3], -cospi_29_64);
121   s1[24] = multiply_shift_and_narrow_s16(in[3], cospi_3_64);
122
123   // stage 2
124   s2[8] = multiply_shift_and_narrow_s16(in[2], cospi_30_64);
125   s2[15] = multiply_shift_and_narrow_s16(in[2], cospi_2_64);
126
127   s2[10] = multiply_shift_and_narrow_s16(in[10], cospi_22_64);
128   s2[13] = multiply_shift_and_narrow_s16(in[10], cospi_10_64);
129
130   s2[11] = multiply_shift_and_narrow_s16(in[6], -cospi_26_64);
131   s2[12] = multiply_shift_and_narrow_s16(in[6], cospi_6_64);
132
133   s2[18] = vsubq_s16(s1[19], s1[18]);
134   s2[19] = vaddq_s16(s1[18], s1[19]);
135   s2[20] = vaddq_s16(s1[20], s1[21]);
136   s2[21] = vsubq_s16(s1[20], s1[21]);
137   s2[26] = vsubq_s16(s1[27], s1[26]);
138   s2[27] = vaddq_s16(s1[26], s1[27]);
139   s2[28] = vaddq_s16(s1[28], s1[29]);
140   s2[29] = vsubq_s16(s1[28], s1[29]);
141
142   // stage 3
143   s3[4] = multiply_shift_and_narrow_s16(in[4], cospi_28_64);
144   s3[7] = multiply_shift_and_narrow_s16(in[4], cospi_4_64);
145
146   s3[10] = vsubq_s16(s2[11], s2[10]);
147   s3[11] = vaddq_s16(s2[10], s2[11]);
148   s3[12] = vaddq_s16(s2[12], s2[13]);
149   s3[13] = vsubq_s16(s2[12], s2[13]);
150
151   s3[17] = multiply_accumulate_shift_and_narrow_s16(s1[16], -cospi_4_64, s1[31],
152                                                     cospi_28_64);
153   s3[30] = multiply_accumulate_shift_and_narrow_s16(s1[16], cospi_28_64, s1[31],
154                                                     cospi_4_64);
155
156   s3[18] = multiply_accumulate_shift_and_narrow_s16(s2[18], -cospi_28_64,
157                                                     s2[29], -cospi_4_64);
158   s3[29] = multiply_accumulate_shift_and_narrow_s16(s2[18], -cospi_4_64, s2[29],
159                                                     cospi_28_64);
160
161   s3[21] = multiply_accumulate_shift_and_narrow_s16(s2[21], -cospi_20_64,
162                                                     s2[26], cospi_12_64);
163   s3[26] = multiply_accumulate_shift_and_narrow_s16(s2[21], cospi_12_64, s2[26],
164                                                     cospi_20_64);
165
166   s3[22] = multiply_accumulate_shift_and_narrow_s16(s1[23], -cospi_12_64,
167                                                     s1[24], -cospi_20_64);
168   s3[25] = multiply_accumulate_shift_and_narrow_s16(s1[23], -cospi_20_64,
169                                                     s1[24], cospi_12_64);
170
171   // stage 4
172   s4[0] = multiply_shift_and_narrow_s16(in[0], cospi_16_64);
173   s4[2] = multiply_shift_and_narrow_s16(in[8], cospi_24_64);
174   s4[3] = multiply_shift_and_narrow_s16(in[8], cospi_8_64);
175
176   s4[9] = multiply_accumulate_shift_and_narrow_s16(s2[8], -cospi_8_64, s2[15],
177                                                    cospi_24_64);
178   s4[14] = multiply_accumulate_shift_and_narrow_s16(s2[8], cospi_24_64, s2[15],
179                                                     cospi_8_64);
180
181   s4[10] = multiply_accumulate_shift_and_narrow_s16(s3[10], -cospi_24_64,
182                                                     s3[13], -cospi_8_64);
183   s4[13] = multiply_accumulate_shift_and_narrow_s16(s3[10], -cospi_8_64, s3[13],
184                                                     cospi_24_64);
185
186   s4[16] = vaddq_s16(s1[16], s2[19]);
187   s4[17] = vaddq_s16(s3[17], s3[18]);
188   s4[18] = vsubq_s16(s3[17], s3[18]);
189   s4[19] = vsubq_s16(s1[16], s2[19]);
190   s4[20] = vsubq_s16(s1[23], s2[20]);
191   s4[21] = vsubq_s16(s3[22], s3[21]);
192   s4[22] = vaddq_s16(s3[21], s3[22]);
193   s4[23] = vaddq_s16(s2[20], s1[23]);
194   s4[24] = vaddq_s16(s1[24], s2[27]);
195   s4[25] = vaddq_s16(s3[25], s3[26]);
196   s4[26] = vsubq_s16(s3[25], s3[26]);
197   s4[27] = vsubq_s16(s1[24], s2[27]);
198   s4[28] = vsubq_s16(s1[31], s2[28]);
199   s4[29] = vsubq_s16(s3[30], s3[29]);
200   s4[30] = vaddq_s16(s3[29], s3[30]);
201   s4[31] = vaddq_s16(s2[28], s1[31]);
202
203   // stage 5
204   s5[0] = vaddq_s16(s4[0], s4[3]);
205   s5[1] = vaddq_s16(s4[0], s4[2]);
206   s5[2] = vsubq_s16(s4[0], s4[2]);
207   s5[3] = vsubq_s16(s4[0], s4[3]);
208
209   s5[5] = sub_multiply_shift_and_narrow_s16(s3[7], s3[4], cospi_16_64);
210   s5[6] = add_multiply_shift_and_narrow_s16(s3[4], s3[7], cospi_16_64);
211
212   s5[8] = vaddq_s16(s2[8], s3[11]);
213   s5[9] = vaddq_s16(s4[9], s4[10]);
214   s5[10] = vsubq_s16(s4[9], s4[10]);
215   s5[11] = vsubq_s16(s2[8], s3[11]);
216   s5[12] = vsubq_s16(s2[15], s3[12]);
217   s5[13] = vsubq_s16(s4[14], s4[13]);
218   s5[14] = vaddq_s16(s4[13], s4[14]);
219   s5[15] = vaddq_s16(s2[15], s3[12]);
220
221   s5[18] = multiply_accumulate_shift_and_narrow_s16(s4[18], -cospi_8_64, s4[29],
222                                                     cospi_24_64);
223   s5[29] = multiply_accumulate_shift_and_narrow_s16(s4[18], cospi_24_64, s4[29],
224                                                     cospi_8_64);
225
226   s5[19] = multiply_accumulate_shift_and_narrow_s16(s4[19], -cospi_8_64, s4[28],
227                                                     cospi_24_64);
228   s5[28] = multiply_accumulate_shift_and_narrow_s16(s4[19], cospi_24_64, s4[28],
229                                                     cospi_8_64);
230
231   s5[20] = multiply_accumulate_shift_and_narrow_s16(s4[20], -cospi_24_64,
232                                                     s4[27], -cospi_8_64);
233   s5[27] = multiply_accumulate_shift_and_narrow_s16(s4[20], -cospi_8_64, s4[27],
234                                                     cospi_24_64);
235
236   s5[21] = multiply_accumulate_shift_and_narrow_s16(s4[21], -cospi_24_64,
237                                                     s4[26], -cospi_8_64);
238   s5[26] = multiply_accumulate_shift_and_narrow_s16(s4[21], -cospi_8_64, s4[26],
239                                                     cospi_24_64);
240
241   // stage 6
242   s6[0] = vaddq_s16(s5[0], s3[7]);
243   s6[1] = vaddq_s16(s5[1], s5[6]);
244   s6[2] = vaddq_s16(s5[2], s5[5]);
245   s6[3] = vaddq_s16(s5[3], s3[4]);
246   s6[4] = vsubq_s16(s5[3], s3[4]);
247   s6[5] = vsubq_s16(s5[2], s5[5]);
248   s6[6] = vsubq_s16(s5[1], s5[6]);
249   s6[7] = vsubq_s16(s5[0], s3[7]);
250
251   s6[10] = sub_multiply_shift_and_narrow_s16(s5[13], s5[10], cospi_16_64);
252   s6[13] = add_multiply_shift_and_narrow_s16(s5[10], s5[13], cospi_16_64);
253
254   s6[11] = sub_multiply_shift_and_narrow_s16(s5[12], s5[11], cospi_16_64);
255   s6[12] = add_multiply_shift_and_narrow_s16(s5[11], s5[12], cospi_16_64);
256
257   s6[16] = vaddq_s16(s4[16], s4[23]);
258   s6[17] = vaddq_s16(s4[17], s4[22]);
259   s6[18] = vaddq_s16(s5[18], s5[21]);
260   s6[19] = vaddq_s16(s5[19], s5[20]);
261   s6[20] = vsubq_s16(s5[19], s5[20]);
262   s6[21] = vsubq_s16(s5[18], s5[21]);
263   s6[22] = vsubq_s16(s4[17], s4[22]);
264   s6[23] = vsubq_s16(s4[16], s4[23]);
265
266   s6[24] = vsubq_s16(s4[31], s4[24]);
267   s6[25] = vsubq_s16(s4[30], s4[25]);
268   s6[26] = vsubq_s16(s5[29], s5[26]);
269   s6[27] = vsubq_s16(s5[28], s5[27]);
270   s6[28] = vaddq_s16(s5[27], s5[28]);
271   s6[29] = vaddq_s16(s5[26], s5[29]);
272   s6[30] = vaddq_s16(s4[25], s4[30]);
273   s6[31] = vaddq_s16(s4[24], s4[31]);
274
275   // stage 7
276   s7[0] = vaddq_s16(s6[0], s5[15]);
277   s7[1] = vaddq_s16(s6[1], s5[14]);
278   s7[2] = vaddq_s16(s6[2], s6[13]);
279   s7[3] = vaddq_s16(s6[3], s6[12]);
280   s7[4] = vaddq_s16(s6[4], s6[11]);
281   s7[5] = vaddq_s16(s6[5], s6[10]);
282   s7[6] = vaddq_s16(s6[6], s5[9]);
283   s7[7] = vaddq_s16(s6[7], s5[8]);
284   s7[8] = vsubq_s16(s6[7], s5[8]);
285   s7[9] = vsubq_s16(s6[6], s5[9]);
286   s7[10] = vsubq_s16(s6[5], s6[10]);
287   s7[11] = vsubq_s16(s6[4], s6[11]);
288   s7[12] = vsubq_s16(s6[3], s6[12]);
289   s7[13] = vsubq_s16(s6[2], s6[13]);
290   s7[14] = vsubq_s16(s6[1], s5[14]);
291   s7[15] = vsubq_s16(s6[0], s5[15]);
292
293   s7[20] = sub_multiply_shift_and_narrow_s16(s6[27], s6[20], cospi_16_64);
294   s7[27] = add_multiply_shift_and_narrow_s16(s6[20], s6[27], cospi_16_64);
295
296   s7[21] = sub_multiply_shift_and_narrow_s16(s6[26], s6[21], cospi_16_64);
297   s7[26] = add_multiply_shift_and_narrow_s16(s6[21], s6[26], cospi_16_64);
298
299   s7[22] = sub_multiply_shift_and_narrow_s16(s6[25], s6[22], cospi_16_64);
300   s7[25] = add_multiply_shift_and_narrow_s16(s6[22], s6[25], cospi_16_64);
301
302   s7[23] = sub_multiply_shift_and_narrow_s16(s6[24], s6[23], cospi_16_64);
303   s7[24] = add_multiply_shift_and_narrow_s16(s6[23], s6[24], cospi_16_64);
304
305   // final stage
306   vst1q_s16(output, vaddq_s16(s7[0], s6[31]));
307   output += 16;
308   vst1q_s16(output, vaddq_s16(s7[1], s6[30]));
309   output += 16;
310   vst1q_s16(output, vaddq_s16(s7[2], s6[29]));
311   output += 16;
312   vst1q_s16(output, vaddq_s16(s7[3], s6[28]));
313   output += 16;
314   vst1q_s16(output, vaddq_s16(s7[4], s7[27]));
315   output += 16;
316   vst1q_s16(output, vaddq_s16(s7[5], s7[26]));
317   output += 16;
318   vst1q_s16(output, vaddq_s16(s7[6], s7[25]));
319   output += 16;
320   vst1q_s16(output, vaddq_s16(s7[7], s7[24]));
321   output += 16;
322
323   vst1q_s16(output, vaddq_s16(s7[8], s7[23]));
324   output += 16;
325   vst1q_s16(output, vaddq_s16(s7[9], s7[22]));
326   output += 16;
327   vst1q_s16(output, vaddq_s16(s7[10], s7[21]));
328   output += 16;
329   vst1q_s16(output, vaddq_s16(s7[11], s7[20]));
330   output += 16;
331   vst1q_s16(output, vaddq_s16(s7[12], s6[19]));
332   output += 16;
333   vst1q_s16(output, vaddq_s16(s7[13], s6[18]));
334   output += 16;
335   vst1q_s16(output, vaddq_s16(s7[14], s6[17]));
336   output += 16;
337   vst1q_s16(output, vaddq_s16(s7[15], s6[16]));
338   output += 16;
339
340   vst1q_s16(output, vsubq_s16(s7[15], s6[16]));
341   output += 16;
342   vst1q_s16(output, vsubq_s16(s7[14], s6[17]));
343   output += 16;
344   vst1q_s16(output, vsubq_s16(s7[13], s6[18]));
345   output += 16;
346   vst1q_s16(output, vsubq_s16(s7[12], s6[19]));
347   output += 16;
348   vst1q_s16(output, vsubq_s16(s7[11], s7[20]));
349   output += 16;
350   vst1q_s16(output, vsubq_s16(s7[10], s7[21]));
351   output += 16;
352   vst1q_s16(output, vsubq_s16(s7[9], s7[22]));
353   output += 16;
354   vst1q_s16(output, vsubq_s16(s7[8], s7[23]));
355   output += 16;
356
357   vst1q_s16(output, vsubq_s16(s7[7], s7[24]));
358   output += 16;
359   vst1q_s16(output, vsubq_s16(s7[6], s7[25]));
360   output += 16;
361   vst1q_s16(output, vsubq_s16(s7[5], s7[26]));
362   output += 16;
363   vst1q_s16(output, vsubq_s16(s7[4], s7[27]));
364   output += 16;
365   vst1q_s16(output, vsubq_s16(s7[3], s6[28]));
366   output += 16;
367   vst1q_s16(output, vsubq_s16(s7[2], s6[29]));
368   output += 16;
369   vst1q_s16(output, vsubq_s16(s7[1], s6[30]));
370   output += 16;
371   vst1q_s16(output, vsubq_s16(s7[0], s6[31]));
372 }
373
374 void vpx_idct32_16_neon(const int16_t *const input, void *const output,
375                         const int stride, const int highbd_flag) {
376   int16x8_t in[16], s1[32], s2[32], s3[32], s4[32], s5[32], s6[32], s7[32],
377       out[32];
378
379   load_and_transpose_s16_8x8(input, 16, &in[0], &in[1], &in[2], &in[3], &in[4],
380                              &in[5], &in[6], &in[7]);
381
382   load_and_transpose_s16_8x8(input + 8, 16, &in[8], &in[9], &in[10], &in[11],
383                              &in[12], &in[13], &in[14], &in[15]);
384
385   // stage 1
386   s1[16] = multiply_shift_and_narrow_s16(in[1], cospi_31_64);
387   s1[31] = multiply_shift_and_narrow_s16(in[1], cospi_1_64);
388
389   s1[17] = multiply_shift_and_narrow_s16(in[15], -cospi_17_64);
390   s1[30] = multiply_shift_and_narrow_s16(in[15], cospi_15_64);
391
392   s1[18] = multiply_shift_and_narrow_s16(in[9], cospi_23_64);
393   s1[29] = multiply_shift_and_narrow_s16(in[9], cospi_9_64);
394
395   s1[19] = multiply_shift_and_narrow_s16(in[7], -cospi_25_64);
396   s1[28] = multiply_shift_and_narrow_s16(in[7], cospi_7_64);
397
398   s1[20] = multiply_shift_and_narrow_s16(in[5], cospi_27_64);
399   s1[27] = multiply_shift_and_narrow_s16(in[5], cospi_5_64);
400
401   s1[21] = multiply_shift_and_narrow_s16(in[11], -cospi_21_64);
402   s1[26] = multiply_shift_and_narrow_s16(in[11], cospi_11_64);
403
404   s1[22] = multiply_shift_and_narrow_s16(in[13], cospi_19_64);
405   s1[25] = multiply_shift_and_narrow_s16(in[13], cospi_13_64);
406
407   s1[23] = multiply_shift_and_narrow_s16(in[3], -cospi_29_64);
408   s1[24] = multiply_shift_and_narrow_s16(in[3], cospi_3_64);
409
410   // stage 2
411   s2[8] = multiply_shift_and_narrow_s16(in[2], cospi_30_64);
412   s2[15] = multiply_shift_and_narrow_s16(in[2], cospi_2_64);
413
414   s2[9] = multiply_shift_and_narrow_s16(in[14], -cospi_18_64);
415   s2[14] = multiply_shift_and_narrow_s16(in[14], cospi_14_64);
416
417   s2[10] = multiply_shift_and_narrow_s16(in[10], cospi_22_64);
418   s2[13] = multiply_shift_and_narrow_s16(in[10], cospi_10_64);
419
420   s2[11] = multiply_shift_and_narrow_s16(in[6], -cospi_26_64);
421   s2[12] = multiply_shift_and_narrow_s16(in[6], cospi_6_64);
422
423   s2[16] = vaddq_s16(s1[16], s1[17]);
424   s2[17] = vsubq_s16(s1[16], s1[17]);
425   s2[18] = vsubq_s16(s1[19], s1[18]);
426   s2[19] = vaddq_s16(s1[18], s1[19]);
427   s2[20] = vaddq_s16(s1[20], s1[21]);
428   s2[21] = vsubq_s16(s1[20], s1[21]);
429   s2[22] = vsubq_s16(s1[23], s1[22]);
430   s2[23] = vaddq_s16(s1[22], s1[23]);
431   s2[24] = vaddq_s16(s1[24], s1[25]);
432   s2[25] = vsubq_s16(s1[24], s1[25]);
433   s2[26] = vsubq_s16(s1[27], s1[26]);
434   s2[27] = vaddq_s16(s1[26], s1[27]);
435   s2[28] = vaddq_s16(s1[28], s1[29]);
436   s2[29] = vsubq_s16(s1[28], s1[29]);
437   s2[30] = vsubq_s16(s1[31], s1[30]);
438   s2[31] = vaddq_s16(s1[30], s1[31]);
439
440   // stage 3
441   s3[4] = multiply_shift_and_narrow_s16(in[4], cospi_28_64);
442   s3[7] = multiply_shift_and_narrow_s16(in[4], cospi_4_64);
443
444   s3[5] = multiply_shift_and_narrow_s16(in[12], -cospi_20_64);
445   s3[6] = multiply_shift_and_narrow_s16(in[12], cospi_12_64);
446
447   s3[8] = vaddq_s16(s2[8], s2[9]);
448   s3[9] = vsubq_s16(s2[8], s2[9]);
449   s3[10] = vsubq_s16(s2[11], s2[10]);
450   s3[11] = vaddq_s16(s2[10], s2[11]);
451   s3[12] = vaddq_s16(s2[12], s2[13]);
452   s3[13] = vsubq_s16(s2[12], s2[13]);
453   s3[14] = vsubq_s16(s2[15], s2[14]);
454   s3[15] = vaddq_s16(s2[14], s2[15]);
455
456   s3[17] = multiply_accumulate_shift_and_narrow_s16(s2[17], -cospi_4_64, s2[30],
457                                                     cospi_28_64);
458   s3[30] = multiply_accumulate_shift_and_narrow_s16(s2[17], cospi_28_64, s2[30],
459                                                     cospi_4_64);
460
461   s3[18] = multiply_accumulate_shift_and_narrow_s16(s2[18], -cospi_28_64,
462                                                     s2[29], -cospi_4_64);
463   s3[29] = multiply_accumulate_shift_and_narrow_s16(s2[18], -cospi_4_64, s2[29],
464                                                     cospi_28_64);
465
466   s3[21] = multiply_accumulate_shift_and_narrow_s16(s2[21], -cospi_20_64,
467                                                     s2[26], cospi_12_64);
468   s3[26] = multiply_accumulate_shift_and_narrow_s16(s2[21], cospi_12_64, s2[26],
469                                                     cospi_20_64);
470
471   s3[22] = multiply_accumulate_shift_and_narrow_s16(s2[22], -cospi_12_64,
472                                                     s2[25], -cospi_20_64);
473   s3[25] = multiply_accumulate_shift_and_narrow_s16(s2[22], -cospi_20_64,
474                                                     s2[25], cospi_12_64);
475
476   // stage 4
477   s4[0] = multiply_shift_and_narrow_s16(in[0], cospi_16_64);
478   s4[2] = multiply_shift_and_narrow_s16(in[8], cospi_24_64);
479   s4[3] = multiply_shift_and_narrow_s16(in[8], cospi_8_64);
480
481   s4[4] = vaddq_s16(s3[4], s3[5]);
482   s4[5] = vsubq_s16(s3[4], s3[5]);
483   s4[6] = vsubq_s16(s3[7], s3[6]);
484   s4[7] = vaddq_s16(s3[6], s3[7]);
485
486   s4[9] = multiply_accumulate_shift_and_narrow_s16(s3[9], -cospi_8_64, s3[14],
487                                                    cospi_24_64);
488   s4[14] = multiply_accumulate_shift_and_narrow_s16(s3[9], cospi_24_64, s3[14],
489                                                     cospi_8_64);
490
491   s4[10] = multiply_accumulate_shift_and_narrow_s16(s3[10], -cospi_24_64,
492                                                     s3[13], -cospi_8_64);
493   s4[13] = multiply_accumulate_shift_and_narrow_s16(s3[10], -cospi_8_64, s3[13],
494                                                     cospi_24_64);
495
496   s4[16] = vaddq_s16(s2[16], s2[19]);
497   s4[17] = vaddq_s16(s3[17], s3[18]);
498   s4[18] = vsubq_s16(s3[17], s3[18]);
499   s4[19] = vsubq_s16(s2[16], s2[19]);
500   s4[20] = vsubq_s16(s2[23], s2[20]);
501   s4[21] = vsubq_s16(s3[22], s3[21]);
502   s4[22] = vaddq_s16(s3[21], s3[22]);
503   s4[23] = vaddq_s16(s2[20], s2[23]);
504   s4[24] = vaddq_s16(s2[24], s2[27]);
505   s4[25] = vaddq_s16(s3[25], s3[26]);
506   s4[26] = vsubq_s16(s3[25], s3[26]);
507   s4[27] = vsubq_s16(s2[24], s2[27]);
508   s4[28] = vsubq_s16(s2[31], s2[28]);
509   s4[29] = vsubq_s16(s3[30], s3[29]);
510   s4[30] = vaddq_s16(s3[29], s3[30]);
511   s4[31] = vaddq_s16(s2[28], s2[31]);
512
513   // stage 5
514   s5[0] = vaddq_s16(s4[0], s4[3]);
515   s5[1] = vaddq_s16(s4[0], s4[2]);
516   s5[2] = vsubq_s16(s4[0], s4[2]);
517   s5[3] = vsubq_s16(s4[0], s4[3]);
518
519   s5[5] = sub_multiply_shift_and_narrow_s16(s4[6], s4[5], cospi_16_64);
520   s5[6] = add_multiply_shift_and_narrow_s16(s4[5], s4[6], cospi_16_64);
521
522   s5[8] = vaddq_s16(s3[8], s3[11]);
523   s5[9] = vaddq_s16(s4[9], s4[10]);
524   s5[10] = vsubq_s16(s4[9], s4[10]);
525   s5[11] = vsubq_s16(s3[8], s3[11]);
526   s5[12] = vsubq_s16(s3[15], s3[12]);
527   s5[13] = vsubq_s16(s4[14], s4[13]);
528   s5[14] = vaddq_s16(s4[13], s4[14]);
529   s5[15] = vaddq_s16(s3[15], s3[12]);
530
531   s5[18] = multiply_accumulate_shift_and_narrow_s16(s4[18], -cospi_8_64, s4[29],
532                                                     cospi_24_64);
533   s5[29] = multiply_accumulate_shift_and_narrow_s16(s4[18], cospi_24_64, s4[29],
534                                                     cospi_8_64);
535
536   s5[19] = multiply_accumulate_shift_and_narrow_s16(s4[19], -cospi_8_64, s4[28],
537                                                     cospi_24_64);
538   s5[28] = multiply_accumulate_shift_and_narrow_s16(s4[19], cospi_24_64, s4[28],
539                                                     cospi_8_64);
540
541   s5[20] = multiply_accumulate_shift_and_narrow_s16(s4[20], -cospi_24_64,
542                                                     s4[27], -cospi_8_64);
543   s5[27] = multiply_accumulate_shift_and_narrow_s16(s4[20], -cospi_8_64, s4[27],
544                                                     cospi_24_64);
545
546   s5[21] = multiply_accumulate_shift_and_narrow_s16(s4[21], -cospi_24_64,
547                                                     s4[26], -cospi_8_64);
548   s5[26] = multiply_accumulate_shift_and_narrow_s16(s4[21], -cospi_8_64, s4[26],
549                                                     cospi_24_64);
550
551   // stage 6
552   s6[0] = vaddq_s16(s5[0], s4[7]);
553   s6[1] = vaddq_s16(s5[1], s5[6]);
554   s6[2] = vaddq_s16(s5[2], s5[5]);
555   s6[3] = vaddq_s16(s5[3], s4[4]);
556   s6[4] = vsubq_s16(s5[3], s4[4]);
557   s6[5] = vsubq_s16(s5[2], s5[5]);
558   s6[6] = vsubq_s16(s5[1], s5[6]);
559   s6[7] = vsubq_s16(s5[0], s4[7]);
560
561   s6[10] = sub_multiply_shift_and_narrow_s16(s5[13], s5[10], cospi_16_64);
562   s6[13] = add_multiply_shift_and_narrow_s16(s5[10], s5[13], cospi_16_64);
563
564   s6[11] = sub_multiply_shift_and_narrow_s16(s5[12], s5[11], cospi_16_64);
565   s6[12] = add_multiply_shift_and_narrow_s16(s5[11], s5[12], cospi_16_64);
566
567   s6[16] = vaddq_s16(s4[16], s4[23]);
568   s6[17] = vaddq_s16(s4[17], s4[22]);
569   s6[18] = vaddq_s16(s5[18], s5[21]);
570   s6[19] = vaddq_s16(s5[19], s5[20]);
571   s6[20] = vsubq_s16(s5[19], s5[20]);
572   s6[21] = vsubq_s16(s5[18], s5[21]);
573   s6[22] = vsubq_s16(s4[17], s4[22]);
574   s6[23] = vsubq_s16(s4[16], s4[23]);
575   s6[24] = vsubq_s16(s4[31], s4[24]);
576   s6[25] = vsubq_s16(s4[30], s4[25]);
577   s6[26] = vsubq_s16(s5[29], s5[26]);
578   s6[27] = vsubq_s16(s5[28], s5[27]);
579   s6[28] = vaddq_s16(s5[27], s5[28]);
580   s6[29] = vaddq_s16(s5[26], s5[29]);
581   s6[30] = vaddq_s16(s4[25], s4[30]);
582   s6[31] = vaddq_s16(s4[24], s4[31]);
583
584   // stage 7
585   s7[0] = vaddq_s16(s6[0], s5[15]);
586   s7[1] = vaddq_s16(s6[1], s5[14]);
587   s7[2] = vaddq_s16(s6[2], s6[13]);
588   s7[3] = vaddq_s16(s6[3], s6[12]);
589   s7[4] = vaddq_s16(s6[4], s6[11]);
590   s7[5] = vaddq_s16(s6[5], s6[10]);
591   s7[6] = vaddq_s16(s6[6], s5[9]);
592   s7[7] = vaddq_s16(s6[7], s5[8]);
593   s7[8] = vsubq_s16(s6[7], s5[8]);
594   s7[9] = vsubq_s16(s6[6], s5[9]);
595   s7[10] = vsubq_s16(s6[5], s6[10]);
596   s7[11] = vsubq_s16(s6[4], s6[11]);
597   s7[12] = vsubq_s16(s6[3], s6[12]);
598   s7[13] = vsubq_s16(s6[2], s6[13]);
599   s7[14] = vsubq_s16(s6[1], s5[14]);
600   s7[15] = vsubq_s16(s6[0], s5[15]);
601
602   s7[20] = sub_multiply_shift_and_narrow_s16(s6[27], s6[20], cospi_16_64);
603   s7[27] = add_multiply_shift_and_narrow_s16(s6[20], s6[27], cospi_16_64);
604
605   s7[21] = sub_multiply_shift_and_narrow_s16(s6[26], s6[21], cospi_16_64);
606   s7[26] = add_multiply_shift_and_narrow_s16(s6[21], s6[26], cospi_16_64);
607
608   s7[22] = sub_multiply_shift_and_narrow_s16(s6[25], s6[22], cospi_16_64);
609   s7[25] = add_multiply_shift_and_narrow_s16(s6[22], s6[25], cospi_16_64);
610
611   s7[23] = sub_multiply_shift_and_narrow_s16(s6[24], s6[23], cospi_16_64);
612   s7[24] = add_multiply_shift_and_narrow_s16(s6[23], s6[24], cospi_16_64);
613
614   // final stage
615   out[0] = final_add(s7[0], s6[31]);
616   out[1] = final_add(s7[1], s6[30]);
617   out[2] = final_add(s7[2], s6[29]);
618   out[3] = final_add(s7[3], s6[28]);
619   out[4] = final_add(s7[4], s7[27]);
620   out[5] = final_add(s7[5], s7[26]);
621   out[6] = final_add(s7[6], s7[25]);
622   out[7] = final_add(s7[7], s7[24]);
623   out[8] = final_add(s7[8], s7[23]);
624   out[9] = final_add(s7[9], s7[22]);
625   out[10] = final_add(s7[10], s7[21]);
626   out[11] = final_add(s7[11], s7[20]);
627   out[12] = final_add(s7[12], s6[19]);
628   out[13] = final_add(s7[13], s6[18]);
629   out[14] = final_add(s7[14], s6[17]);
630   out[15] = final_add(s7[15], s6[16]);
631   out[16] = final_sub(s7[15], s6[16]);
632   out[17] = final_sub(s7[14], s6[17]);
633   out[18] = final_sub(s7[13], s6[18]);
634   out[19] = final_sub(s7[12], s6[19]);
635   out[20] = final_sub(s7[11], s7[20]);
636   out[21] = final_sub(s7[10], s7[21]);
637   out[22] = final_sub(s7[9], s7[22]);
638   out[23] = final_sub(s7[8], s7[23]);
639   out[24] = final_sub(s7[7], s7[24]);
640   out[25] = final_sub(s7[6], s7[25]);
641   out[26] = final_sub(s7[5], s7[26]);
642   out[27] = final_sub(s7[4], s7[27]);
643   out[28] = final_sub(s7[3], s6[28]);
644   out[29] = final_sub(s7[2], s6[29]);
645   out[30] = final_sub(s7[1], s6[30]);
646   out[31] = final_sub(s7[0], s6[31]);
647
648   if (highbd_flag) {
649     highbd_add_and_store_bd8(out, output, stride);
650   } else {
651     uint8_t *const outputT = (uint8_t *)output;
652     add_and_store_u8_s16(out[0], out[1], out[2], out[3], out[4], out[5], out[6],
653                          out[7], outputT, stride);
654     add_and_store_u8_s16(out[8], out[9], out[10], out[11], out[12], out[13],
655                          out[14], out[15], outputT + (8 * stride), stride);
656     add_and_store_u8_s16(out[16], out[17], out[18], out[19], out[20], out[21],
657                          out[22], out[23], outputT + (16 * stride), stride);
658     add_and_store_u8_s16(out[24], out[25], out[26], out[27], out[28], out[29],
659                          out[30], out[31], outputT + (24 * stride), stride);
660   }
661 }
662
663 void vpx_idct32x32_135_add_neon(const tran_low_t *input, uint8_t *dest,
664                                 int stride) {
665   int i;
666   int16_t temp[32 * 16];
667   int16_t *t = temp;
668
669   vpx_idct32_12_neon(input, temp);
670   vpx_idct32_12_neon(input + 32 * 8, temp + 8);
671
672   for (i = 0; i < 32; i += 8) {
673     vpx_idct32_16_neon(t, dest, stride, 0);
674     t += (16 * 8);
675     dest += 8;
676   }
677 }