1 /*
2 * Copyright (c) 2018, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12 #include "warp_plane_neon.h"
13
horizontal_filter_4x1_f4(const uint8x16_t in,int sx,int alpha)14 static AOM_FORCE_INLINE int16x8_t horizontal_filter_4x1_f4(const uint8x16_t in,
15 int sx, int alpha) {
16 const int32x4_t add_const = vdupq_n_s32(1 << (8 + FILTER_BITS - 1));
17
18 // Loading the 8 filter taps
19 int16x8_t f[4];
20 load_filters_4(f, sx, alpha);
21
22 int16x8_t in16_lo = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(in)));
23 int16x8_t in16_hi = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(in)));
24
25 int16x8_t m0 = vmulq_s16(f[0], in16_lo);
26 int16x8_t m1 = vmulq_s16(f[1], vextq_s16(in16_lo, in16_hi, 1));
27 int16x8_t m2 = vmulq_s16(f[2], vextq_s16(in16_lo, in16_hi, 2));
28 int16x8_t m3 = vmulq_s16(f[3], vextq_s16(in16_lo, in16_hi, 3));
29
30 int32x4_t m0123_pairs[] = { vpaddlq_s16(m0), vpaddlq_s16(m1), vpaddlq_s16(m2),
31 vpaddlq_s16(m3) };
32
33 int32x4_t tmp_res_low = horizontal_add_4d_s32x4(m0123_pairs);
34
35 tmp_res_low = vaddq_s32(tmp_res_low, add_const);
36
37 uint16x8_t res =
38 vcombine_u16(vqrshrun_n_s32(tmp_res_low, ROUND0_BITS), vdup_n_u16(0));
39 return vreinterpretq_s16_u16(res);
40 }
41
horizontal_filter_8x1_f8(const uint8x16_t in,int sx,int alpha)42 static AOM_FORCE_INLINE int16x8_t horizontal_filter_8x1_f8(const uint8x16_t in,
43 int sx, int alpha) {
44 const int32x4_t add_const = vdupq_n_s32(1 << (8 + FILTER_BITS - 1));
45
46 // Loading the 8 filter taps
47 int16x8_t f[8];
48 load_filters_8(f, sx, alpha);
49
50 int16x8_t in16_lo = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(in)));
51 int16x8_t in16_hi = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(in)));
52
53 int16x8_t m0 = vmulq_s16(f[0], in16_lo);
54 int16x8_t m1 = vmulq_s16(f[1], vextq_s16(in16_lo, in16_hi, 1));
55 int16x8_t m2 = vmulq_s16(f[2], vextq_s16(in16_lo, in16_hi, 2));
56 int16x8_t m3 = vmulq_s16(f[3], vextq_s16(in16_lo, in16_hi, 3));
57 int16x8_t m4 = vmulq_s16(f[4], vextq_s16(in16_lo, in16_hi, 4));
58 int16x8_t m5 = vmulq_s16(f[5], vextq_s16(in16_lo, in16_hi, 5));
59 int16x8_t m6 = vmulq_s16(f[6], vextq_s16(in16_lo, in16_hi, 6));
60 int16x8_t m7 = vmulq_s16(f[7], vextq_s16(in16_lo, in16_hi, 7));
61
62 int32x4_t m0123_pairs[] = { vpaddlq_s16(m0), vpaddlq_s16(m1), vpaddlq_s16(m2),
63 vpaddlq_s16(m3) };
64 int32x4_t m4567_pairs[] = { vpaddlq_s16(m4), vpaddlq_s16(m5), vpaddlq_s16(m6),
65 vpaddlq_s16(m7) };
66
67 int32x4_t tmp_res_low = horizontal_add_4d_s32x4(m0123_pairs);
68 int32x4_t tmp_res_high = horizontal_add_4d_s32x4(m4567_pairs);
69
70 tmp_res_low = vaddq_s32(tmp_res_low, add_const);
71 tmp_res_high = vaddq_s32(tmp_res_high, add_const);
72
73 uint16x8_t res = vcombine_u16(vqrshrun_n_s32(tmp_res_low, ROUND0_BITS),
74 vqrshrun_n_s32(tmp_res_high, ROUND0_BITS));
75 return vreinterpretq_s16_u16(res);
76 }
77
horizontal_filter_4x1_f1(const uint8x16_t in,int sx)78 static AOM_FORCE_INLINE int16x8_t horizontal_filter_4x1_f1(const uint8x16_t in,
79 int sx) {
80 const int32x4_t add_const = vdupq_n_s32(1 << (8 + FILTER_BITS - 1));
81
82 int16x8_t f_s16 =
83 vld1q_s16((int16_t *)(av1_warped_filter + (sx >> WARPEDDIFF_PREC_BITS)));
84
85 int16x8_t in16_lo = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(in)));
86 int16x8_t in16_hi = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(in)));
87
88 int16x8_t m0 = vmulq_s16(f_s16, in16_lo);
89 int16x8_t m1 = vmulq_s16(f_s16, vextq_s16(in16_lo, in16_hi, 1));
90 int16x8_t m2 = vmulq_s16(f_s16, vextq_s16(in16_lo, in16_hi, 2));
91 int16x8_t m3 = vmulq_s16(f_s16, vextq_s16(in16_lo, in16_hi, 3));
92
93 int32x4_t m0123_pairs[] = { vpaddlq_s16(m0), vpaddlq_s16(m1), vpaddlq_s16(m2),
94 vpaddlq_s16(m3) };
95
96 int32x4_t tmp_res_low = horizontal_add_4d_s32x4(m0123_pairs);
97
98 tmp_res_low = vaddq_s32(tmp_res_low, add_const);
99
100 uint16x8_t res =
101 vcombine_u16(vqrshrun_n_s32(tmp_res_low, ROUND0_BITS), vdup_n_u16(0));
102 return vreinterpretq_s16_u16(res);
103 }
104
horizontal_filter_8x1_f1(const uint8x16_t in,int sx)105 static AOM_FORCE_INLINE int16x8_t horizontal_filter_8x1_f1(const uint8x16_t in,
106 int sx) {
107 const int32x4_t add_const = vdupq_n_s32(1 << (8 + FILTER_BITS - 1));
108
109 int16x8_t f_s16 =
110 vld1q_s16((int16_t *)(av1_warped_filter + (sx >> WARPEDDIFF_PREC_BITS)));
111
112 int16x8_t in16_lo = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(in)));
113 int16x8_t in16_hi = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(in)));
114
115 int16x8_t m0 = vmulq_s16(f_s16, in16_lo);
116 int16x8_t m1 = vmulq_s16(f_s16, vextq_s16(in16_lo, in16_hi, 1));
117 int16x8_t m2 = vmulq_s16(f_s16, vextq_s16(in16_lo, in16_hi, 2));
118 int16x8_t m3 = vmulq_s16(f_s16, vextq_s16(in16_lo, in16_hi, 3));
119 int16x8_t m4 = vmulq_s16(f_s16, vextq_s16(in16_lo, in16_hi, 4));
120 int16x8_t m5 = vmulq_s16(f_s16, vextq_s16(in16_lo, in16_hi, 5));
121 int16x8_t m6 = vmulq_s16(f_s16, vextq_s16(in16_lo, in16_hi, 6));
122 int16x8_t m7 = vmulq_s16(f_s16, vextq_s16(in16_lo, in16_hi, 7));
123
124 int32x4_t m0123_pairs[] = { vpaddlq_s16(m0), vpaddlq_s16(m1), vpaddlq_s16(m2),
125 vpaddlq_s16(m3) };
126 int32x4_t m4567_pairs[] = { vpaddlq_s16(m4), vpaddlq_s16(m5), vpaddlq_s16(m6),
127 vpaddlq_s16(m7) };
128
129 int32x4_t tmp_res_low = horizontal_add_4d_s32x4(m0123_pairs);
130 int32x4_t tmp_res_high = horizontal_add_4d_s32x4(m4567_pairs);
131
132 tmp_res_low = vaddq_s32(tmp_res_low, add_const);
133 tmp_res_high = vaddq_s32(tmp_res_high, add_const);
134
135 uint16x8_t res = vcombine_u16(vqrshrun_n_s32(tmp_res_low, ROUND0_BITS),
136 vqrshrun_n_s32(tmp_res_high, ROUND0_BITS));
137 return vreinterpretq_s16_u16(res);
138 }
139
vertical_filter_4x1_f1(const int16x8_t * src,int32x4_t * res,int sy)140 static AOM_FORCE_INLINE void vertical_filter_4x1_f1(const int16x8_t *src,
141 int32x4_t *res, int sy) {
142 int16x4_t s0 = vget_low_s16(src[0]);
143 int16x4_t s1 = vget_low_s16(src[1]);
144 int16x4_t s2 = vget_low_s16(src[2]);
145 int16x4_t s3 = vget_low_s16(src[3]);
146 int16x4_t s4 = vget_low_s16(src[4]);
147 int16x4_t s5 = vget_low_s16(src[5]);
148 int16x4_t s6 = vget_low_s16(src[6]);
149 int16x4_t s7 = vget_low_s16(src[7]);
150
151 int16x8_t f =
152 vld1q_s16((int16_t *)(av1_warped_filter + (sy >> WARPEDDIFF_PREC_BITS)));
153
154 int32x4_t m0123 = vmull_lane_s16(s0, vget_low_s16(f), 0);
155 m0123 = vmlal_lane_s16(m0123, s1, vget_low_s16(f), 1);
156 m0123 = vmlal_lane_s16(m0123, s2, vget_low_s16(f), 2);
157 m0123 = vmlal_lane_s16(m0123, s3, vget_low_s16(f), 3);
158 m0123 = vmlal_lane_s16(m0123, s4, vget_high_s16(f), 0);
159 m0123 = vmlal_lane_s16(m0123, s5, vget_high_s16(f), 1);
160 m0123 = vmlal_lane_s16(m0123, s6, vget_high_s16(f), 2);
161 m0123 = vmlal_lane_s16(m0123, s7, vget_high_s16(f), 3);
162
163 *res = m0123;
164 }
165
vertical_filter_4x1_f4(const int16x8_t * src,int32x4_t * res,int sy,int gamma)166 static AOM_FORCE_INLINE void vertical_filter_4x1_f4(const int16x8_t *src,
167 int32x4_t *res, int sy,
168 int gamma) {
169 int16x8_t s0, s1, s2, s3;
170 transpose_elems_s16_4x8(
171 vget_low_s16(src[0]), vget_low_s16(src[1]), vget_low_s16(src[2]),
172 vget_low_s16(src[3]), vget_low_s16(src[4]), vget_low_s16(src[5]),
173 vget_low_s16(src[6]), vget_low_s16(src[7]), &s0, &s1, &s2, &s3);
174
175 int16x8_t f[4];
176 load_filters_4(f, sy, gamma);
177
178 int32x4_t m0 = vmull_s16(vget_low_s16(s0), vget_low_s16(f[0]));
179 m0 = vmlal_s16(m0, vget_high_s16(s0), vget_high_s16(f[0]));
180 int32x4_t m1 = vmull_s16(vget_low_s16(s1), vget_low_s16(f[1]));
181 m1 = vmlal_s16(m1, vget_high_s16(s1), vget_high_s16(f[1]));
182 int32x4_t m2 = vmull_s16(vget_low_s16(s2), vget_low_s16(f[2]));
183 m2 = vmlal_s16(m2, vget_high_s16(s2), vget_high_s16(f[2]));
184 int32x4_t m3 = vmull_s16(vget_low_s16(s3), vget_low_s16(f[3]));
185 m3 = vmlal_s16(m3, vget_high_s16(s3), vget_high_s16(f[3]));
186
187 int32x4_t m0123_pairs[] = { m0, m1, m2, m3 };
188
189 *res = horizontal_add_4d_s32x4(m0123_pairs);
190 }
191
vertical_filter_8x1_f1(const int16x8_t * src,int32x4_t * res_low,int32x4_t * res_high,int sy)192 static AOM_FORCE_INLINE void vertical_filter_8x1_f1(const int16x8_t *src,
193 int32x4_t *res_low,
194 int32x4_t *res_high,
195 int sy) {
196 int16x8_t s0 = src[0];
197 int16x8_t s1 = src[1];
198 int16x8_t s2 = src[2];
199 int16x8_t s3 = src[3];
200 int16x8_t s4 = src[4];
201 int16x8_t s5 = src[5];
202 int16x8_t s6 = src[6];
203 int16x8_t s7 = src[7];
204
205 int16x8_t f =
206 vld1q_s16((int16_t *)(av1_warped_filter + (sy >> WARPEDDIFF_PREC_BITS)));
207
208 int32x4_t m0123 = vmull_lane_s16(vget_low_s16(s0), vget_low_s16(f), 0);
209 m0123 = vmlal_lane_s16(m0123, vget_low_s16(s1), vget_low_s16(f), 1);
210 m0123 = vmlal_lane_s16(m0123, vget_low_s16(s2), vget_low_s16(f), 2);
211 m0123 = vmlal_lane_s16(m0123, vget_low_s16(s3), vget_low_s16(f), 3);
212 m0123 = vmlal_lane_s16(m0123, vget_low_s16(s4), vget_high_s16(f), 0);
213 m0123 = vmlal_lane_s16(m0123, vget_low_s16(s5), vget_high_s16(f), 1);
214 m0123 = vmlal_lane_s16(m0123, vget_low_s16(s6), vget_high_s16(f), 2);
215 m0123 = vmlal_lane_s16(m0123, vget_low_s16(s7), vget_high_s16(f), 3);
216
217 int32x4_t m4567 = vmull_lane_s16(vget_high_s16(s0), vget_low_s16(f), 0);
218 m4567 = vmlal_lane_s16(m4567, vget_high_s16(s1), vget_low_s16(f), 1);
219 m4567 = vmlal_lane_s16(m4567, vget_high_s16(s2), vget_low_s16(f), 2);
220 m4567 = vmlal_lane_s16(m4567, vget_high_s16(s3), vget_low_s16(f), 3);
221 m4567 = vmlal_lane_s16(m4567, vget_high_s16(s4), vget_high_s16(f), 0);
222 m4567 = vmlal_lane_s16(m4567, vget_high_s16(s5), vget_high_s16(f), 1);
223 m4567 = vmlal_lane_s16(m4567, vget_high_s16(s6), vget_high_s16(f), 2);
224 m4567 = vmlal_lane_s16(m4567, vget_high_s16(s7), vget_high_s16(f), 3);
225
226 *res_low = m0123;
227 *res_high = m4567;
228 }
229
vertical_filter_8x1_f8(const int16x8_t * src,int32x4_t * res_low,int32x4_t * res_high,int sy,int gamma)230 static AOM_FORCE_INLINE void vertical_filter_8x1_f8(const int16x8_t *src,
231 int32x4_t *res_low,
232 int32x4_t *res_high, int sy,
233 int gamma) {
234 int16x8_t s0 = src[0];
235 int16x8_t s1 = src[1];
236 int16x8_t s2 = src[2];
237 int16x8_t s3 = src[3];
238 int16x8_t s4 = src[4];
239 int16x8_t s5 = src[5];
240 int16x8_t s6 = src[6];
241 int16x8_t s7 = src[7];
242 transpose_elems_inplace_s16_8x8(&s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7);
243
244 int16x8_t f[8];
245 load_filters_8(f, sy, gamma);
246
247 int32x4_t m0 = vmull_s16(vget_low_s16(s0), vget_low_s16(f[0]));
248 m0 = vmlal_s16(m0, vget_high_s16(s0), vget_high_s16(f[0]));
249 int32x4_t m1 = vmull_s16(vget_low_s16(s1), vget_low_s16(f[1]));
250 m1 = vmlal_s16(m1, vget_high_s16(s1), vget_high_s16(f[1]));
251 int32x4_t m2 = vmull_s16(vget_low_s16(s2), vget_low_s16(f[2]));
252 m2 = vmlal_s16(m2, vget_high_s16(s2), vget_high_s16(f[2]));
253 int32x4_t m3 = vmull_s16(vget_low_s16(s3), vget_low_s16(f[3]));
254 m3 = vmlal_s16(m3, vget_high_s16(s3), vget_high_s16(f[3]));
255 int32x4_t m4 = vmull_s16(vget_low_s16(s4), vget_low_s16(f[4]));
256 m4 = vmlal_s16(m4, vget_high_s16(s4), vget_high_s16(f[4]));
257 int32x4_t m5 = vmull_s16(vget_low_s16(s5), vget_low_s16(f[5]));
258 m5 = vmlal_s16(m5, vget_high_s16(s5), vget_high_s16(f[5]));
259 int32x4_t m6 = vmull_s16(vget_low_s16(s6), vget_low_s16(f[6]));
260 m6 = vmlal_s16(m6, vget_high_s16(s6), vget_high_s16(f[6]));
261 int32x4_t m7 = vmull_s16(vget_low_s16(s7), vget_low_s16(f[7]));
262 m7 = vmlal_s16(m7, vget_high_s16(s7), vget_high_s16(f[7]));
263
264 int32x4_t m0123_pairs[] = { m0, m1, m2, m3 };
265 int32x4_t m4567_pairs[] = { m4, m5, m6, m7 };
266
267 *res_low = horizontal_add_4d_s32x4(m0123_pairs);
268 *res_high = horizontal_add_4d_s32x4(m4567_pairs);
269 }
270
av1_warp_affine_neon(const int32_t * mat,const uint8_t * ref,int width,int height,int stride,uint8_t * pred,int p_col,int p_row,int p_width,int p_height,int p_stride,int subsampling_x,int subsampling_y,ConvolveParams * conv_params,int16_t alpha,int16_t beta,int16_t gamma,int16_t delta)271 void av1_warp_affine_neon(const int32_t *mat, const uint8_t *ref, int width,
272 int height, int stride, uint8_t *pred, int p_col,
273 int p_row, int p_width, int p_height, int p_stride,
274 int subsampling_x, int subsampling_y,
275 ConvolveParams *conv_params, int16_t alpha,
276 int16_t beta, int16_t gamma, int16_t delta) {
277 av1_warp_affine_common(mat, ref, width, height, stride, pred, p_col, p_row,
278 p_width, p_height, p_stride, subsampling_x,
279 subsampling_y, conv_params, alpha, beta, gamma, delta);
280 }
281