• 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 <arm_neon.h>
12 
13 #include "./vpx_config.h"
14 #include "./vpx_dsp_rtcd.h"
15 #include "vpx/vpx_integer.h"
16 
17 //------------------------------------------------------------------------------
18 // DC 4x4
19 
dc_sum_4(const uint8_t * ref)20 static INLINE uint16x4_t dc_sum_4(const uint8_t *ref) {
21   const uint8x8_t ref_u8 = vld1_u8(ref);
22   const uint16x4_t p0 = vpaddl_u8(ref_u8);
23   return vpadd_u16(p0, p0);
24 }
25 
dc_store_4x4(uint8_t * dst,ptrdiff_t stride,const uint8x8_t dc)26 static INLINE void dc_store_4x4(uint8_t *dst, ptrdiff_t stride,
27                                 const uint8x8_t dc) {
28   const uint8x8_t dc_dup = vdup_lane_u8(dc, 0);
29   int i;
30   for (i = 0; i < 4; ++i, dst += stride) {
31     vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(dc_dup), 0);
32   }
33 }
34 
vpx_dc_predictor_4x4_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)35 void vpx_dc_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
36                                const uint8_t *above, const uint8_t *left) {
37   const uint8x8_t a = vld1_u8(above);
38   const uint8x8_t l = vld1_u8(left);
39   const uint16x8_t al = vaddl_u8(a, l);
40   uint16x4_t sum;
41   uint8x8_t dc;
42   sum = vpadd_u16(vget_low_u16(al), vget_low_u16(al));
43   sum = vpadd_u16(sum, sum);
44   dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 3));
45   dc_store_4x4(dst, stride, dc);
46 }
47 
vpx_dc_left_predictor_4x4_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)48 void vpx_dc_left_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
49                                     const uint8_t *above, const uint8_t *left) {
50   const uint16x4_t sum = dc_sum_4(left);
51   const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 2));
52   (void)above;
53   dc_store_4x4(dst, stride, dc);
54 }
55 
vpx_dc_top_predictor_4x4_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)56 void vpx_dc_top_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
57                                    const uint8_t *above, const uint8_t *left) {
58   const uint16x4_t sum = dc_sum_4(above);
59   const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 2));
60   (void)left;
61   dc_store_4x4(dst, stride, dc);
62 }
63 
vpx_dc_128_predictor_4x4_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)64 void vpx_dc_128_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
65                                    const uint8_t *above, const uint8_t *left) {
66   const uint8x8_t dc = vdup_n_u8(0x80);
67   (void)above;
68   (void)left;
69   dc_store_4x4(dst, stride, dc);
70 }
71 
72 //------------------------------------------------------------------------------
73 // DC 8x8
74 
dc_sum_8(const uint8_t * ref)75 static INLINE uint16x4_t dc_sum_8(const uint8_t *ref) {
76   const uint8x8_t ref_u8 = vld1_u8(ref);
77   uint16x4_t sum = vpaddl_u8(ref_u8);
78   sum = vpadd_u16(sum, sum);
79   return vpadd_u16(sum, sum);
80 }
81 
dc_store_8x8(uint8_t * dst,ptrdiff_t stride,const uint8x8_t dc)82 static INLINE void dc_store_8x8(uint8_t *dst, ptrdiff_t stride,
83                                 const uint8x8_t dc) {
84   const uint8x8_t dc_dup = vdup_lane_u8(dc, 0);
85   int i;
86   for (i = 0; i < 8; ++i, dst += stride) {
87     vst1_u8(dst, dc_dup);
88   }
89 }
90 
vpx_dc_predictor_8x8_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)91 void vpx_dc_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
92                                const uint8_t *above, const uint8_t *left) {
93   const uint8x8_t above_u8 = vld1_u8(above);
94   const uint8x8_t left_u8 = vld1_u8(left);
95   const uint8x16_t above_and_left = vcombine_u8(above_u8, left_u8);
96   const uint16x8_t p0 = vpaddlq_u8(above_and_left);
97   uint16x4_t sum = vadd_u16(vget_low_u16(p0), vget_high_u16(p0));
98   uint8x8_t dc;
99   sum = vpadd_u16(sum, sum);
100   sum = vpadd_u16(sum, sum);
101   dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 4));
102   dc_store_8x8(dst, stride, dc);
103 }
104 
vpx_dc_left_predictor_8x8_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)105 void vpx_dc_left_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
106                                     const uint8_t *above, const uint8_t *left) {
107   const uint16x4_t sum = dc_sum_8(left);
108   const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 3));
109   (void)above;
110   dc_store_8x8(dst, stride, dc);
111 }
112 
vpx_dc_top_predictor_8x8_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)113 void vpx_dc_top_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
114                                    const uint8_t *above, const uint8_t *left) {
115   const uint16x4_t sum = dc_sum_8(above);
116   const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 3));
117   (void)left;
118   dc_store_8x8(dst, stride, dc);
119 }
120 
vpx_dc_128_predictor_8x8_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)121 void vpx_dc_128_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
122                                    const uint8_t *above, const uint8_t *left) {
123   const uint8x8_t dc = vdup_n_u8(0x80);
124   (void)above;
125   (void)left;
126   dc_store_8x8(dst, stride, dc);
127 }
128 
129 //------------------------------------------------------------------------------
130 // DC 16x16
131 
dc_sum_16(const uint8_t * ref)132 static INLINE uint16x4_t dc_sum_16(const uint8_t *ref) {
133   const uint8x16_t ref_u8 = vld1q_u8(ref);
134   const uint16x8_t p0 = vpaddlq_u8(ref_u8);
135   uint16x4_t sum = vadd_u16(vget_low_u16(p0), vget_high_u16(p0));
136   sum = vpadd_u16(sum, sum);
137   return vpadd_u16(sum, sum);
138 }
139 
dc_store_16x16(uint8_t * dst,ptrdiff_t stride,const uint8x8_t dc)140 static INLINE void dc_store_16x16(uint8_t *dst, ptrdiff_t stride,
141                                   const uint8x8_t dc) {
142   const uint8x16_t dc_dup = vdupq_lane_u8(dc, 0);
143   int i;
144   for (i = 0; i < 16; ++i, dst += stride) {
145     vst1q_u8(dst, dc_dup);
146   }
147 }
148 
vpx_dc_predictor_16x16_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)149 void vpx_dc_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
150                                  const uint8_t *above, const uint8_t *left) {
151   const uint8x16_t ref0 = vld1q_u8(above);
152   const uint8x16_t ref1 = vld1q_u8(left);
153   const uint16x8_t p0 = vpaddlq_u8(ref0);
154   const uint16x8_t p1 = vpaddlq_u8(ref1);
155   const uint16x8_t p2 = vaddq_u16(p0, p1);
156   uint16x4_t sum = vadd_u16(vget_low_u16(p2), vget_high_u16(p2));
157   uint8x8_t dc;
158   sum = vpadd_u16(sum, sum);
159   sum = vpadd_u16(sum, sum);
160   dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 5));
161   dc_store_16x16(dst, stride, dc);
162 }
163 
vpx_dc_left_predictor_16x16_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)164 void vpx_dc_left_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
165                                       const uint8_t *above,
166                                       const uint8_t *left) {
167   const uint16x4_t sum = dc_sum_16(left);
168   const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 4));
169   (void)above;
170   dc_store_16x16(dst, stride, dc);
171 }
172 
vpx_dc_top_predictor_16x16_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)173 void vpx_dc_top_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
174                                      const uint8_t *above,
175                                      const uint8_t *left) {
176   const uint16x4_t sum = dc_sum_16(above);
177   const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 4));
178   (void)left;
179   dc_store_16x16(dst, stride, dc);
180 }
181 
vpx_dc_128_predictor_16x16_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)182 void vpx_dc_128_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
183                                      const uint8_t *above,
184                                      const uint8_t *left) {
185   const uint8x8_t dc = vdup_n_u8(0x80);
186   (void)above;
187   (void)left;
188   dc_store_16x16(dst, stride, dc);
189 }
190 
191 //------------------------------------------------------------------------------
192 // DC 32x32
193 
dc_sum_32(const uint8_t * ref)194 static INLINE uint16x4_t dc_sum_32(const uint8_t *ref) {
195   const uint8x16x2_t r = vld2q_u8(ref);
196   const uint16x8_t p0 = vpaddlq_u8(r.val[0]);
197   const uint16x8_t p1 = vpaddlq_u8(r.val[1]);
198   const uint16x8_t p2 = vaddq_u16(p0, p1);
199   uint16x4_t sum = vadd_u16(vget_low_u16(p2), vget_high_u16(p2));
200   sum = vpadd_u16(sum, sum);
201   return vpadd_u16(sum, sum);
202 }
203 
dc_store_32x32(uint8_t * dst,ptrdiff_t stride,const uint8x8_t dc)204 static INLINE void dc_store_32x32(uint8_t *dst, ptrdiff_t stride,
205                                   const uint8x8_t dc) {
206   uint8x16x2_t dc_dup;
207   int i;
208   dc_dup.val[0] = dc_dup.val[1] = vdupq_lane_u8(dc, 0);
209 
210   for (i = 0; i < 32; ++i, dst += stride) {
211     vst2q_u8(dst, dc_dup);
212   }
213 }
214 
vpx_dc_predictor_32x32_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)215 void vpx_dc_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
216                                  const uint8_t *above, const uint8_t *left) {
217   const uint8x16x2_t a = vld2q_u8(above);
218   const uint8x16x2_t l = vld2q_u8(left);
219   const uint16x8_t pa0 = vpaddlq_u8(a.val[0]);
220   const uint16x8_t pl0 = vpaddlq_u8(l.val[0]);
221   const uint16x8_t pa1 = vpaddlq_u8(a.val[1]);
222   const uint16x8_t pl1 = vpaddlq_u8(l.val[1]);
223   const uint16x8_t pa = vaddq_u16(pa0, pa1);
224   const uint16x8_t pl = vaddq_u16(pl0, pl1);
225   const uint16x8_t pal = vaddq_u16(pa, pl);
226   uint16x4_t sum = vadd_u16(vget_low_u16(pal), vget_high_u16(pal));
227   uint8x8_t dc;
228   sum = vpadd_u16(sum, sum);
229   sum = vpadd_u16(sum, sum);
230   dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 6));
231   dc_store_32x32(dst, stride, dc);
232 }
233 
vpx_dc_left_predictor_32x32_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)234 void vpx_dc_left_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
235                                       const uint8_t *above,
236                                       const uint8_t *left) {
237   const uint16x4_t sum = dc_sum_32(left);
238   const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 5));
239   (void)above;
240   dc_store_32x32(dst, stride, dc);
241 }
242 
vpx_dc_top_predictor_32x32_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)243 void vpx_dc_top_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
244                                      const uint8_t *above,
245                                      const uint8_t *left) {
246   const uint16x4_t sum = dc_sum_32(above);
247   const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 5));
248   (void)left;
249   dc_store_32x32(dst, stride, dc);
250 }
251 
vpx_dc_128_predictor_32x32_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)252 void vpx_dc_128_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
253                                      const uint8_t *above,
254                                      const uint8_t *left) {
255   const uint8x8_t dc = vdup_n_u8(0x80);
256   (void)above;
257   (void)left;
258   dc_store_32x32(dst, stride, dc);
259 }
260 
261 // -----------------------------------------------------------------------------
262 
vpx_d45_predictor_4x4_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)263 void vpx_d45_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
264                                 const uint8_t *above, const uint8_t *left) {
265   const uint8x8_t ABCDEFGH = vld1_u8(above);
266   const uint64x1_t A1 = vshr_n_u64(vreinterpret_u64_u8(ABCDEFGH), 8);
267   const uint64x1_t A2 = vshr_n_u64(vreinterpret_u64_u8(ABCDEFGH), 16);
268   const uint8x8_t BCDEFGH0 = vreinterpret_u8_u64(A1);
269   const uint8x8_t CDEFGH00 = vreinterpret_u8_u64(A2);
270   const uint8x8_t avg1 = vhadd_u8(ABCDEFGH, CDEFGH00);
271   const uint8x8_t avg2 = vrhadd_u8(avg1, BCDEFGH0);
272   const uint64x1_t avg2_u64 = vreinterpret_u64_u8(avg2);
273   const uint32x2_t r0 = vreinterpret_u32_u8(avg2);
274   const uint32x2_t r1 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 8));
275   const uint32x2_t r2 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 16));
276   const uint32x2_t r3 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 24));
277   (void)left;
278   vst1_lane_u32((uint32_t *)(dst + 0 * stride), r0, 0);
279   vst1_lane_u32((uint32_t *)(dst + 1 * stride), r1, 0);
280   vst1_lane_u32((uint32_t *)(dst + 2 * stride), r2, 0);
281   vst1_lane_u32((uint32_t *)(dst + 3 * stride), r3, 0);
282   vst1_lane_u8(dst + 3 * stride + 3, ABCDEFGH, 7);
283 }
284 
d45_store_8(uint8_t ** dst,const ptrdiff_t stride,const uint8x8_t above_right,uint8x8_t * row)285 static INLINE void d45_store_8(uint8_t **dst, const ptrdiff_t stride,
286                                const uint8x8_t above_right, uint8x8_t *row) {
287   *row = vext_u8(*row, above_right, 1);
288   vst1_u8(*dst, *row);
289   *dst += stride;
290 }
291 
vpx_d45_predictor_8x8_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)292 void vpx_d45_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
293                                 const uint8_t *above, const uint8_t *left) {
294   const uint8x8_t A0 = vld1_u8(above);
295   const uint8x8_t above_right = vdup_lane_u8(A0, 7);
296   const uint8x8_t A1 = vext_u8(A0, above_right, 1);
297   const uint8x8_t A2 = vext_u8(A0, above_right, 2);
298   const uint8x8_t avg1 = vhadd_u8(A0, A2);
299   uint8x8_t row = vrhadd_u8(avg1, A1);
300   (void)left;
301 
302   vst1_u8(dst, row);
303   dst += stride;
304   d45_store_8(&dst, stride, above_right, &row);
305   d45_store_8(&dst, stride, above_right, &row);
306   d45_store_8(&dst, stride, above_right, &row);
307   d45_store_8(&dst, stride, above_right, &row);
308   d45_store_8(&dst, stride, above_right, &row);
309   d45_store_8(&dst, stride, above_right, &row);
310   vst1_u8(dst, above_right);
311 }
312 
d45_store_16(uint8_t ** dst,const ptrdiff_t stride,const uint8x16_t above_right,uint8x16_t * row)313 static INLINE void d45_store_16(uint8_t **dst, const ptrdiff_t stride,
314                                 const uint8x16_t above_right, uint8x16_t *row) {
315   *row = vextq_u8(*row, above_right, 1);
316   vst1q_u8(*dst, *row);
317   *dst += stride;
318 }
319 
vpx_d45_predictor_16x16_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)320 void vpx_d45_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
321                                   const uint8_t *above, const uint8_t *left) {
322   const uint8x16_t A0 = vld1q_u8(above);
323   const uint8x16_t above_right = vdupq_lane_u8(vget_high_u8(A0), 7);
324   const uint8x16_t A1 = vextq_u8(A0, above_right, 1);
325   const uint8x16_t A2 = vextq_u8(A0, above_right, 2);
326   const uint8x16_t avg1 = vhaddq_u8(A0, A2);
327   uint8x16_t row = vrhaddq_u8(avg1, A1);
328   (void)left;
329 
330   vst1q_u8(dst, row);
331   dst += stride;
332   d45_store_16(&dst, stride, above_right, &row);
333   d45_store_16(&dst, stride, above_right, &row);
334   d45_store_16(&dst, stride, above_right, &row);
335   d45_store_16(&dst, stride, above_right, &row);
336   d45_store_16(&dst, stride, above_right, &row);
337   d45_store_16(&dst, stride, above_right, &row);
338   d45_store_16(&dst, stride, above_right, &row);
339   d45_store_16(&dst, stride, above_right, &row);
340   d45_store_16(&dst, stride, above_right, &row);
341   d45_store_16(&dst, stride, above_right, &row);
342   d45_store_16(&dst, stride, above_right, &row);
343   d45_store_16(&dst, stride, above_right, &row);
344   d45_store_16(&dst, stride, above_right, &row);
345   d45_store_16(&dst, stride, above_right, &row);
346   vst1q_u8(dst, above_right);
347 }
348 
vpx_d45_predictor_32x32_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)349 void vpx_d45_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
350                                   const uint8_t *above, const uint8_t *left) {
351   const uint8x16_t A0_0 = vld1q_u8(above);
352   const uint8x16_t A0_1 = vld1q_u8(above + 16);
353   const uint8x16_t above_right = vdupq_lane_u8(vget_high_u8(A0_1), 7);
354   const uint8x16_t A1_0 = vld1q_u8(above + 1);
355   const uint8x16_t A1_1 = vld1q_u8(above + 17);
356   const uint8x16_t A2_0 = vld1q_u8(above + 2);
357   const uint8x16_t A2_1 = vld1q_u8(above + 18);
358   const uint8x16_t avg_0 = vhaddq_u8(A0_0, A2_0);
359   const uint8x16_t avg_1 = vhaddq_u8(A0_1, A2_1);
360   uint8x16_t row_0 = vrhaddq_u8(avg_0, A1_0);
361   uint8x16_t row_1 = vrhaddq_u8(avg_1, A1_1);
362   int i;
363   (void)left;
364 
365   vst1q_u8(dst, row_0);
366   dst += 16;
367   vst1q_u8(dst, row_1);
368   dst += stride - 16;
369 
370   for (i = 0; i < 30; ++i) {
371     row_0 = vextq_u8(row_0, row_1, 1);
372     row_1 = vextq_u8(row_1, above_right, 1);
373     vst1q_u8(dst, row_0);
374     dst += 16;
375     vst1q_u8(dst, row_1);
376     dst += stride - 16;
377   }
378 
379   vst1q_u8(dst, above_right);
380   dst += 16;
381   vst1q_u8(dst, row_1);
382 }
383 
384 // -----------------------------------------------------------------------------
385 
vpx_d135_predictor_4x4_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)386 void vpx_d135_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
387                                  const uint8_t *above, const uint8_t *left) {
388   const uint8x8_t XA0123 = vld1_u8(above - 1);
389   const uint8x8_t L0123 = vld1_u8(left);
390   const uint8x8_t L3210 = vrev64_u8(L0123);
391   const uint8x8_t L3210XA012 = vext_u8(L3210, XA0123, 4);
392   const uint8x8_t L210XA0123 = vext_u8(L3210, XA0123, 5);
393   const uint8x8_t L10XA0123_ =
394       vreinterpret_u8_u64(vshr_n_u64(vreinterpret_u64_u8(L210XA0123), 8));
395   const uint8x8_t avg1 = vhadd_u8(L10XA0123_, L3210XA012);
396   const uint8x8_t avg2 = vrhadd_u8(avg1, L210XA0123);
397   const uint64x1_t avg2_u64 = vreinterpret_u64_u8(avg2);
398   const uint32x2_t r3 = vreinterpret_u32_u8(avg2);
399   const uint32x2_t r2 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 8));
400   const uint32x2_t r1 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 16));
401   const uint32x2_t r0 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 24));
402   vst1_lane_u32((uint32_t *)dst, r0, 0);
403   dst += stride;
404   vst1_lane_u32((uint32_t *)dst, r1, 0);
405   dst += stride;
406   vst1_lane_u32((uint32_t *)dst, r2, 0);
407   dst += stride;
408   vst1_lane_u32((uint32_t *)dst, r3, 0);
409 }
410 
vpx_d135_predictor_8x8_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)411 void vpx_d135_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
412                                  const uint8_t *above, const uint8_t *left) {
413   const uint8x8_t XA0123456 = vld1_u8(above - 1);
414   const uint8x8_t A01234567 = vld1_u8(above);
415   const uint8x8_t A1234567_ = vld1_u8(above + 1);
416   const uint8x8_t L01234567 = vld1_u8(left);
417   const uint8x8_t L76543210 = vrev64_u8(L01234567);
418   const uint8x8_t L6543210X = vext_u8(L76543210, XA0123456, 1);
419   const uint8x8_t L543210XA0 = vext_u8(L76543210, XA0123456, 2);
420   const uint8x16_t L76543210XA0123456 = vcombine_u8(L76543210, XA0123456);
421   const uint8x16_t L6543210XA01234567 = vcombine_u8(L6543210X, A01234567);
422   const uint8x16_t L543210XA01234567_ = vcombine_u8(L543210XA0, A1234567_);
423   const uint8x16_t avg = vhaddq_u8(L76543210XA0123456, L543210XA01234567_);
424   const uint8x16_t row = vrhaddq_u8(avg, L6543210XA01234567);
425   const uint8x8_t row_0 = vget_low_u8(row);
426   const uint8x8_t row_1 = vget_high_u8(row);
427   const uint8x8_t r0 = vext_u8(row_0, row_1, 7);
428   const uint8x8_t r1 = vext_u8(row_0, row_1, 6);
429   const uint8x8_t r2 = vext_u8(row_0, row_1, 5);
430   const uint8x8_t r3 = vext_u8(row_0, row_1, 4);
431   const uint8x8_t r4 = vext_u8(row_0, row_1, 3);
432   const uint8x8_t r5 = vext_u8(row_0, row_1, 2);
433   const uint8x8_t r6 = vext_u8(row_0, row_1, 1);
434 
435   vst1_u8(dst, r0);
436   dst += stride;
437   vst1_u8(dst, r1);
438   dst += stride;
439   vst1_u8(dst, r2);
440   dst += stride;
441   vst1_u8(dst, r3);
442   dst += stride;
443   vst1_u8(dst, r4);
444   dst += stride;
445   vst1_u8(dst, r5);
446   dst += stride;
447   vst1_u8(dst, r6);
448   dst += stride;
449   vst1_u8(dst, row_0);
450 }
451 
d135_store_16x8(uint8_t ** dst,const ptrdiff_t stride,const uint8x16_t row_0,const uint8x16_t row_1,const uint8x16_t row_2,const uint8x16_t row_3,const uint8x16_t row_4,const uint8x16_t row_5,const uint8x16_t row_6,const uint8x16_t row_7)452 static INLINE void d135_store_16x8(
453     uint8_t **dst, const ptrdiff_t stride, const uint8x16_t row_0,
454     const uint8x16_t row_1, const uint8x16_t row_2, const uint8x16_t row_3,
455     const uint8x16_t row_4, const uint8x16_t row_5, const uint8x16_t row_6,
456     const uint8x16_t row_7) {
457   vst1q_u8(*dst, row_0);
458   *dst += stride;
459   vst1q_u8(*dst, row_1);
460   *dst += stride;
461   vst1q_u8(*dst, row_2);
462   *dst += stride;
463   vst1q_u8(*dst, row_3);
464   *dst += stride;
465   vst1q_u8(*dst, row_4);
466   *dst += stride;
467   vst1q_u8(*dst, row_5);
468   *dst += stride;
469   vst1q_u8(*dst, row_6);
470   *dst += stride;
471   vst1q_u8(*dst, row_7);
472   *dst += stride;
473 }
474 
vpx_d135_predictor_16x16_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)475 void vpx_d135_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
476                                    const uint8_t *above, const uint8_t *left) {
477   const uint8x16_t XA0123456789abcde = vld1q_u8(above - 1);
478   const uint8x16_t A0123456789abcdef = vld1q_u8(above);
479   const uint8x16_t A123456789abcdef_ = vld1q_u8(above + 1);
480   const uint8x16_t L0123456789abcdef = vld1q_u8(left);
481   const uint8x8_t L76543210 = vrev64_u8(vget_low_u8(L0123456789abcdef));
482   const uint8x8_t Lfedcba98 = vrev64_u8(vget_high_u8(L0123456789abcdef));
483   const uint8x16_t Lfedcba9876543210 = vcombine_u8(Lfedcba98, L76543210);
484   const uint8x16_t Ledcba9876543210X =
485       vextq_u8(Lfedcba9876543210, XA0123456789abcde, 1);
486   const uint8x16_t Ldcba9876543210XA0 =
487       vextq_u8(Lfedcba9876543210, XA0123456789abcde, 2);
488   const uint8x16_t avg_0 = vhaddq_u8(Lfedcba9876543210, Ldcba9876543210XA0);
489   const uint8x16_t avg_1 = vhaddq_u8(XA0123456789abcde, A123456789abcdef_);
490   const uint8x16_t row_0 = vrhaddq_u8(avg_0, Ledcba9876543210X);
491   const uint8x16_t row_1 = vrhaddq_u8(avg_1, A0123456789abcdef);
492   const uint8x16_t r_0 = vextq_u8(row_0, row_1, 15);
493   const uint8x16_t r_1 = vextq_u8(row_0, row_1, 14);
494   const uint8x16_t r_2 = vextq_u8(row_0, row_1, 13);
495   const uint8x16_t r_3 = vextq_u8(row_0, row_1, 12);
496   const uint8x16_t r_4 = vextq_u8(row_0, row_1, 11);
497   const uint8x16_t r_5 = vextq_u8(row_0, row_1, 10);
498   const uint8x16_t r_6 = vextq_u8(row_0, row_1, 9);
499   const uint8x16_t r_7 = vcombine_u8(vget_high_u8(row_0), vget_low_u8(row_1));
500   const uint8x16_t r_8 = vextq_u8(row_0, row_1, 7);
501   const uint8x16_t r_9 = vextq_u8(row_0, row_1, 6);
502   const uint8x16_t r_a = vextq_u8(row_0, row_1, 5);
503   const uint8x16_t r_b = vextq_u8(row_0, row_1, 4);
504   const uint8x16_t r_c = vextq_u8(row_0, row_1, 3);
505   const uint8x16_t r_d = vextq_u8(row_0, row_1, 2);
506   const uint8x16_t r_e = vextq_u8(row_0, row_1, 1);
507 
508   d135_store_16x8(&dst, stride, r_0, r_1, r_2, r_3, r_4, r_5, r_6, r_7);
509   d135_store_16x8(&dst, stride, r_8, r_9, r_a, r_b, r_c, r_d, r_e, row_0);
510 }
511 
d135_store_32x2(uint8_t ** dst,const ptrdiff_t stride,const uint8x16_t row_0,const uint8x16_t row_1,const uint8x16_t row_2)512 static INLINE void d135_store_32x2(uint8_t **dst, const ptrdiff_t stride,
513                                    const uint8x16_t row_0,
514                                    const uint8x16_t row_1,
515                                    const uint8x16_t row_2) {
516   uint8_t *dst2 = *dst;
517   vst1q_u8(dst2, row_1);
518   dst2 += 16;
519   vst1q_u8(dst2, row_2);
520   dst2 += 16 * stride - 16;
521   vst1q_u8(dst2, row_0);
522   dst2 += 16;
523   vst1q_u8(dst2, row_1);
524   *dst += stride;
525 }
526 
vpx_d135_predictor_32x32_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)527 void vpx_d135_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
528                                    const uint8_t *above, const uint8_t *left) {
529   const uint8x16_t LL0123456789abcdef = vld1q_u8(left + 16);
530   const uint8x16_t LU0123456789abcdef = vld1q_u8(left);
531   const uint8x8_t LL76543210 = vrev64_u8(vget_low_u8(LL0123456789abcdef));
532   const uint8x8_t LU76543210 = vrev64_u8(vget_low_u8(LU0123456789abcdef));
533   const uint8x8_t LLfedcba98 = vrev64_u8(vget_high_u8(LL0123456789abcdef));
534   const uint8x8_t LUfedcba98 = vrev64_u8(vget_high_u8(LU0123456789abcdef));
535   const uint8x16_t LLfedcba9876543210 = vcombine_u8(LLfedcba98, LL76543210);
536   const uint8x16_t LUfedcba9876543210 = vcombine_u8(LUfedcba98, LU76543210);
537   const uint8x16_t LLedcba9876543210Uf =
538       vextq_u8(LLfedcba9876543210, LUfedcba9876543210, 1);
539   const uint8x16_t LLdcba9876543210Ufe =
540       vextq_u8(LLfedcba9876543210, LUfedcba9876543210, 2);
541   const uint8x16_t avg_0 = vhaddq_u8(LLfedcba9876543210, LLdcba9876543210Ufe);
542   const uint8x16_t row_0 = vrhaddq_u8(avg_0, LLedcba9876543210Uf);
543 
544   const uint8x16_t XAL0123456789abcde = vld1q_u8(above - 1);
545   const uint8x16_t LUedcba9876543210X =
546       vextq_u8(LUfedcba9876543210, XAL0123456789abcde, 1);
547   const uint8x16_t LUdcba9876543210XA0 =
548       vextq_u8(LUfedcba9876543210, XAL0123456789abcde, 2);
549   const uint8x16_t avg_1 = vhaddq_u8(LUfedcba9876543210, LUdcba9876543210XA0);
550   const uint8x16_t row_1 = vrhaddq_u8(avg_1, LUedcba9876543210X);
551 
552   const uint8x16_t AL0123456789abcdef = vld1q_u8(above);
553   const uint8x16_t AL123456789abcdefg = vld1q_u8(above + 1);
554   const uint8x16_t ALfR0123456789abcde = vld1q_u8(above + 15);
555   const uint8x16_t AR0123456789abcdef = vld1q_u8(above + 16);
556   const uint8x16_t AR123456789abcdef_ = vld1q_u8(above + 17);
557   const uint8x16_t avg_2 = vhaddq_u8(XAL0123456789abcde, AL123456789abcdefg);
558   const uint8x16_t row_2 = vrhaddq_u8(avg_2, AL0123456789abcdef);
559   const uint8x16_t avg_3 = vhaddq_u8(ALfR0123456789abcde, AR123456789abcdef_);
560   const uint8x16_t row_3 = vrhaddq_u8(avg_3, AR0123456789abcdef);
561 
562   {
563     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 15);
564     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 15);
565     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 15);
566     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
567   }
568 
569   {
570     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 14);
571     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 14);
572     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 14);
573     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
574   }
575 
576   {
577     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 13);
578     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 13);
579     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 13);
580     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
581   }
582 
583   {
584     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 12);
585     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 12);
586     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 12);
587     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
588   }
589 
590   {
591     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 11);
592     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 11);
593     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 11);
594     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
595   }
596 
597   {
598     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 10);
599     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 10);
600     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 10);
601     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
602   }
603 
604   {
605     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 9);
606     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 9);
607     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 9);
608     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
609   }
610 
611   {
612     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 8);
613     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 8);
614     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 8);
615     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
616   }
617 
618   {
619     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 7);
620     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 7);
621     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 7);
622     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
623   }
624 
625   {
626     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 6);
627     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 6);
628     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 6);
629     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
630   }
631 
632   {
633     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 5);
634     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 5);
635     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 5);
636     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
637   }
638 
639   {
640     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 4);
641     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 4);
642     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 4);
643     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
644   }
645 
646   {
647     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 3);
648     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 3);
649     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 3);
650     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
651   }
652 
653   {
654     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 2);
655     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 2);
656     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 2);
657     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
658   }
659 
660   {
661     const uint8x16_t r_0 = vextq_u8(row_0, row_1, 1);
662     const uint8x16_t r_1 = vextq_u8(row_1, row_2, 1);
663     const uint8x16_t r_2 = vextq_u8(row_2, row_3, 1);
664     d135_store_32x2(&dst, stride, r_0, r_1, r_2);
665   }
666 
667   d135_store_32x2(&dst, stride, row_0, row_1, row_2);
668 }
669 
670 #if !HAVE_NEON_ASM
671 
vpx_v_predictor_4x4_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)672 void vpx_v_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
673                               const uint8_t *above, const uint8_t *left) {
674   const uint32_t d = *(const uint32_t *)above;
675   int i;
676   (void)left;
677 
678   for (i = 0; i < 4; i++, dst += stride) {
679     *(uint32_t *)dst = d;
680   }
681 }
682 
vpx_v_predictor_8x8_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)683 void vpx_v_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
684                               const uint8_t *above, const uint8_t *left) {
685   const uint8x8_t d = vld1_u8(above);
686   int i;
687   (void)left;
688 
689   for (i = 0; i < 8; i++, dst += stride) {
690     vst1_u8(dst, d);
691   }
692 }
693 
vpx_v_predictor_16x16_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)694 void vpx_v_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
695                                 const uint8_t *above, const uint8_t *left) {
696   const uint8x16_t d = vld1q_u8(above);
697   int i;
698   (void)left;
699 
700   for (i = 0; i < 16; i++, dst += stride) {
701     vst1q_u8(dst, d);
702   }
703 }
704 
vpx_v_predictor_32x32_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)705 void vpx_v_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
706                                 const uint8_t *above, const uint8_t *left) {
707   const uint8x16_t d0 = vld1q_u8(above);
708   const uint8x16_t d1 = vld1q_u8(above + 16);
709   int i;
710   (void)left;
711 
712   for (i = 0; i < 32; i++) {
713     // Note: performance was worse using vst2q_u8 under gcc-4.9 & clang-3.8.
714     // clang-3.8 unrolled the loop fully with no filler so the cause is likely
715     // the latency of the instruction.
716     vst1q_u8(dst, d0);
717     dst += 16;
718     vst1q_u8(dst, d1);
719     dst += stride - 16;
720   }
721 }
722 
723 // -----------------------------------------------------------------------------
724 
vpx_h_predictor_4x4_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)725 void vpx_h_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
726                               const uint8_t *above, const uint8_t *left) {
727   const uint32x2_t zero = vdup_n_u32(0);
728   const uint8x8_t left_u8 =
729       vreinterpret_u8_u32(vld1_lane_u32((const uint32_t *)left, zero, 0));
730   uint8x8_t d;
731   (void)above;
732 
733   d = vdup_lane_u8(left_u8, 0);
734   vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d), 0);
735   dst += stride;
736   d = vdup_lane_u8(left_u8, 1);
737   vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d), 0);
738   dst += stride;
739   d = vdup_lane_u8(left_u8, 2);
740   vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d), 0);
741   dst += stride;
742   d = vdup_lane_u8(left_u8, 3);
743   vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d), 0);
744 }
745 
vpx_h_predictor_8x8_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)746 void vpx_h_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
747                               const uint8_t *above, const uint8_t *left) {
748   const uint8x8_t left_u8 = vld1_u8(left);
749   uint8x8_t d;
750   (void)above;
751 
752   d = vdup_lane_u8(left_u8, 0);
753   vst1_u8(dst, d);
754   dst += stride;
755   d = vdup_lane_u8(left_u8, 1);
756   vst1_u8(dst, d);
757   dst += stride;
758   d = vdup_lane_u8(left_u8, 2);
759   vst1_u8(dst, d);
760   dst += stride;
761   d = vdup_lane_u8(left_u8, 3);
762   vst1_u8(dst, d);
763   dst += stride;
764   d = vdup_lane_u8(left_u8, 4);
765   vst1_u8(dst, d);
766   dst += stride;
767   d = vdup_lane_u8(left_u8, 5);
768   vst1_u8(dst, d);
769   dst += stride;
770   d = vdup_lane_u8(left_u8, 6);
771   vst1_u8(dst, d);
772   dst += stride;
773   d = vdup_lane_u8(left_u8, 7);
774   vst1_u8(dst, d);
775 }
776 
h_store_16x8(uint8_t ** dst,const ptrdiff_t stride,const uint8x8_t left)777 static INLINE void h_store_16x8(uint8_t **dst, const ptrdiff_t stride,
778                                 const uint8x8_t left) {
779   const uint8x16_t row_0 = vdupq_lane_u8(left, 0);
780   const uint8x16_t row_1 = vdupq_lane_u8(left, 1);
781   const uint8x16_t row_2 = vdupq_lane_u8(left, 2);
782   const uint8x16_t row_3 = vdupq_lane_u8(left, 3);
783   const uint8x16_t row_4 = vdupq_lane_u8(left, 4);
784   const uint8x16_t row_5 = vdupq_lane_u8(left, 5);
785   const uint8x16_t row_6 = vdupq_lane_u8(left, 6);
786   const uint8x16_t row_7 = vdupq_lane_u8(left, 7);
787 
788   vst1q_u8(*dst, row_0);
789   *dst += stride;
790   vst1q_u8(*dst, row_1);
791   *dst += stride;
792   vst1q_u8(*dst, row_2);
793   *dst += stride;
794   vst1q_u8(*dst, row_3);
795   *dst += stride;
796   vst1q_u8(*dst, row_4);
797   *dst += stride;
798   vst1q_u8(*dst, row_5);
799   *dst += stride;
800   vst1q_u8(*dst, row_6);
801   *dst += stride;
802   vst1q_u8(*dst, row_7);
803   *dst += stride;
804 }
805 
vpx_h_predictor_16x16_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)806 void vpx_h_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
807                                 const uint8_t *above, const uint8_t *left) {
808   const uint8x16_t left_u8q = vld1q_u8(left);
809   (void)above;
810 
811   h_store_16x8(&dst, stride, vget_low_u8(left_u8q));
812   h_store_16x8(&dst, stride, vget_high_u8(left_u8q));
813 }
814 
h_store_32x8(uint8_t ** dst,const ptrdiff_t stride,const uint8x8_t left)815 static INLINE void h_store_32x8(uint8_t **dst, const ptrdiff_t stride,
816                                 const uint8x8_t left) {
817   const uint8x16_t row_0 = vdupq_lane_u8(left, 0);
818   const uint8x16_t row_1 = vdupq_lane_u8(left, 1);
819   const uint8x16_t row_2 = vdupq_lane_u8(left, 2);
820   const uint8x16_t row_3 = vdupq_lane_u8(left, 3);
821   const uint8x16_t row_4 = vdupq_lane_u8(left, 4);
822   const uint8x16_t row_5 = vdupq_lane_u8(left, 5);
823   const uint8x16_t row_6 = vdupq_lane_u8(left, 6);
824   const uint8x16_t row_7 = vdupq_lane_u8(left, 7);
825 
826   vst1q_u8(*dst, row_0);  // Note clang-3.8 produced poor code w/vst2q_u8
827   *dst += 16;
828   vst1q_u8(*dst, row_0);
829   *dst += stride - 16;
830   vst1q_u8(*dst, row_1);
831   *dst += 16;
832   vst1q_u8(*dst, row_1);
833   *dst += stride - 16;
834   vst1q_u8(*dst, row_2);
835   *dst += 16;
836   vst1q_u8(*dst, row_2);
837   *dst += stride - 16;
838   vst1q_u8(*dst, row_3);
839   *dst += 16;
840   vst1q_u8(*dst, row_3);
841   *dst += stride - 16;
842   vst1q_u8(*dst, row_4);
843   *dst += 16;
844   vst1q_u8(*dst, row_4);
845   *dst += stride - 16;
846   vst1q_u8(*dst, row_5);
847   *dst += 16;
848   vst1q_u8(*dst, row_5);
849   *dst += stride - 16;
850   vst1q_u8(*dst, row_6);
851   *dst += 16;
852   vst1q_u8(*dst, row_6);
853   *dst += stride - 16;
854   vst1q_u8(*dst, row_7);
855   *dst += 16;
856   vst1q_u8(*dst, row_7);
857   *dst += stride - 16;
858 }
859 
vpx_h_predictor_32x32_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)860 void vpx_h_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
861                                 const uint8_t *above, const uint8_t *left) {
862   int i;
863   (void)above;
864 
865   for (i = 0; i < 2; i++, left += 16) {
866     const uint8x16_t left_u8 = vld1q_u8(left);
867     h_store_32x8(&dst, stride, vget_low_u8(left_u8));
868     h_store_32x8(&dst, stride, vget_high_u8(left_u8));
869   }
870 }
871 
872 // -----------------------------------------------------------------------------
873 
convert_u8_to_s16(uint8x8_t v)874 static INLINE int16x8_t convert_u8_to_s16(uint8x8_t v) {
875   return vreinterpretq_s16_u16(vmovl_u8(v));
876 }
877 
vpx_tm_predictor_4x4_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)878 void vpx_tm_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride,
879                                const uint8_t *above, const uint8_t *left) {
880   const uint8x8_t top_left = vld1_dup_u8(above - 1);
881   const uint8x8_t left_u8 = vld1_u8(left);
882   const uint8x8_t above_u8 = vld1_u8(above);
883   const int16x4_t left_s16 = vget_low_s16(convert_u8_to_s16(left_u8));
884   int16x8_t sub, sum;
885   uint32x2_t d;
886 
887   sub = vreinterpretq_s16_u16(vsubl_u8(above_u8, top_left));
888   // Avoid vcombine_s16() which generates lots of redundant code with clang-3.8.
889   sub = vreinterpretq_s16_s64(
890       vdupq_lane_s64(vreinterpret_s64_s16(vget_low_s16(sub)), 0));
891 
892   sum = vcombine_s16(vdup_lane_s16(left_s16, 0), vdup_lane_s16(left_s16, 1));
893   sum = vaddq_s16(sum, sub);
894   d = vreinterpret_u32_u8(vqmovun_s16(sum));
895   vst1_lane_u32((uint32_t *)dst, d, 0);
896   dst += stride;
897   vst1_lane_u32((uint32_t *)dst, d, 1);
898   dst += stride;
899 
900   sum = vcombine_s16(vdup_lane_s16(left_s16, 2), vdup_lane_s16(left_s16, 3));
901   sum = vaddq_s16(sum, sub);
902   d = vreinterpret_u32_u8(vqmovun_s16(sum));
903   vst1_lane_u32((uint32_t *)dst, d, 0);
904   dst += stride;
905   vst1_lane_u32((uint32_t *)dst, d, 1);
906 }
907 
tm_8_kernel(uint8_t ** dst,const ptrdiff_t stride,const int16x8_t left_dup,const int16x8_t sub)908 static INLINE void tm_8_kernel(uint8_t **dst, const ptrdiff_t stride,
909                                const int16x8_t left_dup, const int16x8_t sub) {
910   const int16x8_t sum = vaddq_s16(left_dup, sub);
911   const uint8x8_t d = vqmovun_s16(sum);
912   vst1_u8(*dst, d);
913   *dst += stride;
914 }
915 
vpx_tm_predictor_8x8_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)916 void vpx_tm_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride,
917                                const uint8_t *above, const uint8_t *left) {
918   const uint8x8_t top_left = vld1_dup_u8(above - 1);
919   const uint8x8_t above_u8 = vld1_u8(above);
920   const uint8x8_t left_u8 = vld1_u8(left);
921   const int16x8_t left_s16q = convert_u8_to_s16(left_u8);
922   const int16x8_t sub = vreinterpretq_s16_u16(vsubl_u8(above_u8, top_left));
923   int16x4_t left_s16d = vget_low_s16(left_s16q);
924   int i;
925 
926   for (i = 0; i < 2; i++, left_s16d = vget_high_s16(left_s16q)) {
927     int16x8_t left_dup;
928 
929     left_dup = vdupq_lane_s16(left_s16d, 0);
930     tm_8_kernel(&dst, stride, left_dup, sub);
931     left_dup = vdupq_lane_s16(left_s16d, 1);
932     tm_8_kernel(&dst, stride, left_dup, sub);
933     left_dup = vdupq_lane_s16(left_s16d, 2);
934     tm_8_kernel(&dst, stride, left_dup, sub);
935     left_dup = vdupq_lane_s16(left_s16d, 3);
936     tm_8_kernel(&dst, stride, left_dup, sub);
937   }
938 }
939 
tm_16_kernel(uint8_t ** dst,const ptrdiff_t stride,const int16x8_t left_dup,const int16x8_t sub0,const int16x8_t sub1)940 static INLINE void tm_16_kernel(uint8_t **dst, const ptrdiff_t stride,
941                                 const int16x8_t left_dup, const int16x8_t sub0,
942                                 const int16x8_t sub1) {
943   const int16x8_t sum0 = vaddq_s16(left_dup, sub0);
944   const int16x8_t sum1 = vaddq_s16(left_dup, sub1);
945   const uint8x8_t d0 = vqmovun_s16(sum0);
946   const uint8x8_t d1 = vqmovun_s16(sum1);
947   vst1_u8(*dst, d0);
948   *dst += 8;
949   vst1_u8(*dst, d1);
950   *dst += stride - 8;
951 }
952 
vpx_tm_predictor_16x16_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)953 void vpx_tm_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride,
954                                  const uint8_t *above, const uint8_t *left) {
955   const uint8x16_t top_left = vld1q_dup_u8(above - 1);
956   const uint8x16_t above_u8 = vld1q_u8(above);
957   const int16x8_t sub0 = vreinterpretq_s16_u16(
958       vsubl_u8(vget_low_u8(above_u8), vget_low_u8(top_left)));
959   const int16x8_t sub1 = vreinterpretq_s16_u16(
960       vsubl_u8(vget_high_u8(above_u8), vget_high_u8(top_left)));
961   int16x8_t left_dup;
962   int i;
963 
964   for (i = 0; i < 2; i++, left += 8) {
965     const uint8x8_t left_u8 = vld1_u8(left);
966     const int16x8_t left_s16q = convert_u8_to_s16(left_u8);
967     const int16x4_t left_low = vget_low_s16(left_s16q);
968     const int16x4_t left_high = vget_high_s16(left_s16q);
969 
970     left_dup = vdupq_lane_s16(left_low, 0);
971     tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
972     left_dup = vdupq_lane_s16(left_low, 1);
973     tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
974     left_dup = vdupq_lane_s16(left_low, 2);
975     tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
976     left_dup = vdupq_lane_s16(left_low, 3);
977     tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
978 
979     left_dup = vdupq_lane_s16(left_high, 0);
980     tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
981     left_dup = vdupq_lane_s16(left_high, 1);
982     tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
983     left_dup = vdupq_lane_s16(left_high, 2);
984     tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
985     left_dup = vdupq_lane_s16(left_high, 3);
986     tm_16_kernel(&dst, stride, left_dup, sub0, sub1);
987   }
988 }
989 
tm_32_kernel(uint8_t ** dst,const ptrdiff_t stride,const int16x8_t left_dup,const int16x8_t sub0,const int16x8_t sub1,const int16x8_t sub2,const int16x8_t sub3)990 static INLINE void tm_32_kernel(uint8_t **dst, const ptrdiff_t stride,
991                                 const int16x8_t left_dup, const int16x8_t sub0,
992                                 const int16x8_t sub1, const int16x8_t sub2,
993                                 const int16x8_t sub3) {
994   const int16x8_t sum0 = vaddq_s16(left_dup, sub0);
995   const int16x8_t sum1 = vaddq_s16(left_dup, sub1);
996   const int16x8_t sum2 = vaddq_s16(left_dup, sub2);
997   const int16x8_t sum3 = vaddq_s16(left_dup, sub3);
998   const uint8x8_t d0 = vqmovun_s16(sum0);
999   const uint8x8_t d1 = vqmovun_s16(sum1);
1000   const uint8x8_t d2 = vqmovun_s16(sum2);
1001   const uint8x8_t d3 = vqmovun_s16(sum3);
1002 
1003   vst1q_u8(*dst, vcombine_u8(d0, d1));
1004   *dst += 16;
1005   vst1q_u8(*dst, vcombine_u8(d2, d3));
1006   *dst += stride - 16;
1007 }
1008 
vpx_tm_predictor_32x32_neon(uint8_t * dst,ptrdiff_t stride,const uint8_t * above,const uint8_t * left)1009 void vpx_tm_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride,
1010                                  const uint8_t *above, const uint8_t *left) {
1011   const uint8x16_t top_left = vld1q_dup_u8(above - 1);
1012   const uint8x16_t above_low = vld1q_u8(above);
1013   const uint8x16_t above_high = vld1q_u8(above + 16);
1014   const int16x8_t sub0 = vreinterpretq_s16_u16(
1015       vsubl_u8(vget_low_u8(above_low), vget_low_u8(top_left)));
1016   const int16x8_t sub1 = vreinterpretq_s16_u16(
1017       vsubl_u8(vget_high_u8(above_low), vget_high_u8(top_left)));
1018   const int16x8_t sub2 = vreinterpretq_s16_u16(
1019       vsubl_u8(vget_low_u8(above_high), vget_low_u8(top_left)));
1020   const int16x8_t sub3 = vreinterpretq_s16_u16(
1021       vsubl_u8(vget_high_u8(above_high), vget_high_u8(top_left)));
1022   int16x8_t left_dup;
1023   int i, j;
1024 
1025   for (j = 0; j < 4; j++, left += 8) {
1026     const uint8x8_t left_u8 = vld1_u8(left);
1027     const int16x8_t left_s16q = convert_u8_to_s16(left_u8);
1028     int16x4_t left_s16d = vget_low_s16(left_s16q);
1029     for (i = 0; i < 2; i++, left_s16d = vget_high_s16(left_s16q)) {
1030       left_dup = vdupq_lane_s16(left_s16d, 0);
1031       tm_32_kernel(&dst, stride, left_dup, sub0, sub1, sub2, sub3);
1032       left_dup = vdupq_lane_s16(left_s16d, 1);
1033       tm_32_kernel(&dst, stride, left_dup, sub0, sub1, sub2, sub3);
1034       left_dup = vdupq_lane_s16(left_s16d, 2);
1035       tm_32_kernel(&dst, stride, left_dup, sub0, sub1, sub2, sub3);
1036       left_dup = vdupq_lane_s16(left_s16d, 3);
1037       tm_32_kernel(&dst, stride, left_dup, sub0, sub1, sub2, sub3);
1038     }
1039   }
1040 }
1041 #endif  // !HAVE_NEON_ASM
1042