/src/aom/av1/common/x86/jnt_convolve_sse2.c
Line | Count | Source (jump to first uncovered line) |
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 <emmintrin.h> |
13 | | |
14 | | #include "config/aom_dsp_rtcd.h" |
15 | | |
16 | | #include "aom_dsp/aom_filter.h" |
17 | | #include "aom_dsp/x86/convolve_sse2.h" |
18 | | |
19 | | void av1_dist_wtd_convolve_x_sse2(const uint8_t *src, int src_stride, |
20 | | uint8_t *dst0, int dst_stride0, int w, int h, |
21 | | const InterpFilterParams *filter_params_x, |
22 | | const int subpel_x_qn, |
23 | 0 | ConvolveParams *conv_params) { |
24 | 0 | const int bd = 8; |
25 | 0 | CONV_BUF_TYPE *dst = conv_params->dst; |
26 | 0 | const int dst_stride = conv_params->dst_stride; |
27 | 0 | const int fo_horiz = filter_params_x->taps / 2 - 1; |
28 | 0 | const uint8_t *src_ptr = src - fo_horiz; |
29 | 0 | const int bits = FILTER_BITS - conv_params->round_1; |
30 | 0 | const __m128i left_shift = _mm_cvtsi32_si128(bits); |
31 | 0 | const __m128i round_const = _mm_set1_epi32((1 << conv_params->round_0) >> 1); |
32 | 0 | const __m128i round_shift = _mm_cvtsi32_si128(conv_params->round_0); |
33 | 0 | const int w0 = conv_params->fwd_offset; |
34 | 0 | const int w1 = conv_params->bck_offset; |
35 | 0 | const __m128i wt0 = _mm_set1_epi16(w0); |
36 | 0 | const __m128i wt1 = _mm_set1_epi16(w1); |
37 | 0 | const __m128i wt = _mm_unpacklo_epi16(wt0, wt1); |
38 | 0 | const int do_average = conv_params->do_average; |
39 | 0 | const int use_dist_wtd_comp_avg = conv_params->use_dist_wtd_comp_avg; |
40 | 0 | const int offset_0 = |
41 | 0 | bd + 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
42 | 0 | const int offset = (1 << offset_0) + (1 << (offset_0 - 1)); |
43 | 0 | const __m128i offset_const = _mm_set1_epi16(offset); |
44 | 0 | const int rounding_shift = |
45 | 0 | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
46 | 0 | const __m128i rounding_const = _mm_set1_epi16((1 << rounding_shift) >> 1); |
47 | 0 | __m128i coeffs[4]; |
48 | |
|
49 | 0 | prepare_coeffs(filter_params_x, subpel_x_qn, coeffs); |
50 | |
|
51 | 0 | if (w == 4) { |
52 | 0 | do { |
53 | 0 | const __m128i data = _mm_loadu_si128((__m128i *)src_ptr); |
54 | 0 | __m128i s[4]; |
55 | |
|
56 | 0 | s[0] = _mm_unpacklo_epi8(data, _mm_srli_si128(data, 1)); |
57 | 0 | s[1] = |
58 | 0 | _mm_unpacklo_epi8(_mm_srli_si128(data, 2), _mm_srli_si128(data, 3)); |
59 | 0 | s[2] = |
60 | 0 | _mm_unpacklo_epi8(_mm_srli_si128(data, 4), _mm_srli_si128(data, 5)); |
61 | 0 | s[3] = |
62 | 0 | _mm_unpacklo_epi8(_mm_srli_si128(data, 6), _mm_srli_si128(data, 7)); |
63 | 0 | const __m128i res_lo = convolve_lo_x(s, coeffs); |
64 | 0 | const __m128i res_lo_round = |
65 | 0 | _mm_sra_epi32(_mm_add_epi32(res_lo, round_const), round_shift); |
66 | 0 | const __m128i res_lo_shift = _mm_sll_epi32(res_lo_round, left_shift); |
67 | |
|
68 | 0 | const __m128i res_16b = _mm_packs_epi32(res_lo_shift, res_lo_shift); |
69 | 0 | const __m128i res_unsigned = _mm_add_epi16(res_16b, offset_const); |
70 | | |
71 | | // Accumulate values into the destination buffer |
72 | 0 | if (do_average) { |
73 | 0 | const __m128i data_ref_0 = _mm_loadu_si128((__m128i *)dst); |
74 | |
|
75 | 0 | const __m128i comp_avg_res = |
76 | 0 | comp_avg(&data_ref_0, &res_unsigned, &wt, use_dist_wtd_comp_avg); |
77 | |
|
78 | 0 | const __m128i round_result = convolve_rounding( |
79 | 0 | &comp_avg_res, &offset_const, &rounding_const, rounding_shift); |
80 | |
|
81 | 0 | const __m128i res_8 = _mm_packus_epi16(round_result, round_result); |
82 | 0 | *(int *)(&dst0[0]) = _mm_cvtsi128_si32(res_8); |
83 | 0 | } else { |
84 | 0 | _mm_store_si128((__m128i *)(&dst[0]), res_unsigned); |
85 | 0 | } |
86 | 0 | src_ptr += src_stride; |
87 | 0 | dst += dst_stride; |
88 | 0 | dst0 += dst_stride0; |
89 | 0 | } while (--h); |
90 | 0 | } else { |
91 | 0 | assert(!(w % 8)); |
92 | 0 | int i = 0; |
93 | 0 | do { |
94 | 0 | int j = 0; |
95 | 0 | do { |
96 | 0 | const __m128i data = |
97 | 0 | _mm_loadu_si128((__m128i *)&src_ptr[i * src_stride + j]); |
98 | 0 | __m128i s[4]; |
99 | | |
100 | | // Filter even-index pixels |
101 | 0 | s[0] = data; |
102 | 0 | s[1] = _mm_srli_si128(data, 2); |
103 | 0 | s[2] = _mm_srli_si128(data, 4); |
104 | 0 | s[3] = _mm_srli_si128(data, 6); |
105 | 0 | const __m128i res_even = convolve_lo_x(s, coeffs); |
106 | | |
107 | | // Filter odd-index pixels |
108 | 0 | s[0] = _mm_srli_si128(data, 1); |
109 | 0 | s[1] = _mm_srli_si128(data, 3); |
110 | 0 | s[2] = _mm_srli_si128(data, 5); |
111 | 0 | s[3] = _mm_srli_si128(data, 7); |
112 | 0 | const __m128i res_odd = convolve_lo_x(s, coeffs); |
113 | | |
114 | | // Rearrange pixels back into the order 0 ... 7 |
115 | 0 | const __m128i res_lo = _mm_unpacklo_epi32(res_even, res_odd); |
116 | 0 | const __m128i res_hi = _mm_unpackhi_epi32(res_even, res_odd); |
117 | 0 | const __m128i res_lo_round = |
118 | 0 | _mm_sra_epi32(_mm_add_epi32(res_lo, round_const), round_shift); |
119 | 0 | const __m128i res_hi_round = |
120 | 0 | _mm_sra_epi32(_mm_add_epi32(res_hi, round_const), round_shift); |
121 | 0 | const __m128i res_lo_shift = _mm_sll_epi32(res_lo_round, left_shift); |
122 | 0 | const __m128i res_hi_shift = _mm_sll_epi32(res_hi_round, left_shift); |
123 | |
|
124 | 0 | const __m128i res_16b = _mm_packs_epi32(res_lo_shift, res_hi_shift); |
125 | 0 | const __m128i res_unsigned = _mm_add_epi16(res_16b, offset_const); |
126 | | |
127 | | // Accumulate values into the destination buffer |
128 | 0 | if (do_average) { |
129 | 0 | const __m128i data_ref_0 = |
130 | 0 | _mm_loadu_si128((__m128i *)(&dst[i * dst_stride + j])); |
131 | |
|
132 | 0 | const __m128i comp_avg_res = |
133 | 0 | comp_avg(&data_ref_0, &res_unsigned, &wt, use_dist_wtd_comp_avg); |
134 | |
|
135 | 0 | const __m128i round_result = convolve_rounding( |
136 | 0 | &comp_avg_res, &offset_const, &rounding_const, rounding_shift); |
137 | |
|
138 | 0 | const __m128i res_8 = _mm_packus_epi16(round_result, round_result); |
139 | 0 | _mm_storel_epi64((__m128i *)(&dst0[i * dst_stride0 + j]), res_8); |
140 | 0 | } else { |
141 | 0 | _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_unsigned); |
142 | 0 | } |
143 | 0 | j += 8; |
144 | 0 | } while (j < w); |
145 | 0 | } while (++i < h); |
146 | 0 | } |
147 | 0 | } |
148 | | |
149 | | void av1_dist_wtd_convolve_y_sse2(const uint8_t *src, int src_stride, |
150 | | uint8_t *dst0, int dst_stride0, int w, int h, |
151 | | const InterpFilterParams *filter_params_y, |
152 | | const int subpel_y_qn, |
153 | 0 | ConvolveParams *conv_params) { |
154 | 0 | const int bd = 8; |
155 | 0 | CONV_BUF_TYPE *dst = conv_params->dst; |
156 | 0 | const int dst_stride = conv_params->dst_stride; |
157 | 0 | const int fo_vert = filter_params_y->taps / 2 - 1; |
158 | 0 | const uint8_t *src_ptr = src - fo_vert * src_stride; |
159 | 0 | const int bits = FILTER_BITS - conv_params->round_0; |
160 | 0 | const __m128i left_shift = _mm_cvtsi32_si128(bits); |
161 | 0 | const __m128i wt0 = _mm_set1_epi16(conv_params->fwd_offset); |
162 | 0 | const __m128i wt1 = _mm_set1_epi16(conv_params->bck_offset); |
163 | 0 | const __m128i wt = _mm_unpacklo_epi16(wt0, wt1); |
164 | 0 | const int do_average = conv_params->do_average; |
165 | 0 | const int use_dist_wtd_comp_avg = conv_params->use_dist_wtd_comp_avg; |
166 | 0 | const int offset_0 = |
167 | 0 | bd + 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
168 | 0 | const int offset = (1 << offset_0) + (1 << (offset_0 - 1)); |
169 | 0 | const __m128i offset_const = _mm_set1_epi16(offset); |
170 | 0 | const int rounding_shift = |
171 | 0 | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
172 | 0 | const __m128i rounding_const = _mm_set1_epi16((1 << rounding_shift) >> 1); |
173 | 0 | const __m128i round_const = _mm_set1_epi32((1 << conv_params->round_1) >> 1); |
174 | 0 | const __m128i round_shift = _mm_cvtsi32_si128(conv_params->round_1); |
175 | 0 | __m128i coeffs[4]; |
176 | |
|
177 | 0 | prepare_coeffs(filter_params_y, subpel_y_qn, coeffs); |
178 | |
|
179 | 0 | if (w == 4) { |
180 | 0 | __m128i s[8], src6, res, res_shift; |
181 | 0 | src6 = _mm_cvtsi32_si128(*(int *)(src_ptr + 6 * src_stride)); |
182 | 0 | s[0] = _mm_unpacklo_epi8( |
183 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 0 * src_stride)), |
184 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 1 * src_stride))); |
185 | 0 | s[1] = _mm_unpacklo_epi8( |
186 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 1 * src_stride)), |
187 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 2 * src_stride))); |
188 | 0 | s[2] = _mm_unpacklo_epi8( |
189 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 2 * src_stride)), |
190 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 3 * src_stride))); |
191 | 0 | s[3] = _mm_unpacklo_epi8( |
192 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 3 * src_stride)), |
193 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 4 * src_stride))); |
194 | 0 | s[4] = _mm_unpacklo_epi8( |
195 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 4 * src_stride)), |
196 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 5 * src_stride))); |
197 | 0 | s[5] = _mm_unpacklo_epi8( |
198 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 5 * src_stride)), src6); |
199 | |
|
200 | 0 | do { |
201 | 0 | s[6] = _mm_unpacklo_epi8( |
202 | 0 | src6, _mm_cvtsi32_si128(*(int *)(src_ptr + 7 * src_stride))); |
203 | 0 | src6 = _mm_cvtsi32_si128(*(int *)(src_ptr + 8 * src_stride)); |
204 | 0 | s[7] = _mm_unpacklo_epi8( |
205 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 7 * src_stride)), src6); |
206 | |
|
207 | 0 | res = convolve_lo_y(s + 0, coeffs); |
208 | 0 | res_shift = _mm_sll_epi32(res, left_shift); |
209 | 0 | res_shift = |
210 | 0 | _mm_sra_epi32(_mm_add_epi32(res_shift, round_const), round_shift); |
211 | |
|
212 | 0 | __m128i res_16b = _mm_packs_epi32(res_shift, res_shift); |
213 | 0 | __m128i res_unsigned = _mm_add_epi16(res_16b, offset_const); |
214 | | |
215 | | // Accumulate values into the destination buffer |
216 | 0 | if (do_average) { |
217 | 0 | const __m128i data_ref_0 = _mm_loadu_si128((__m128i *)dst); |
218 | |
|
219 | 0 | const __m128i comp_avg_res = |
220 | 0 | comp_avg(&data_ref_0, &res_unsigned, &wt, use_dist_wtd_comp_avg); |
221 | |
|
222 | 0 | const __m128i round_result = convolve_rounding( |
223 | 0 | &comp_avg_res, &offset_const, &rounding_const, rounding_shift); |
224 | |
|
225 | 0 | const __m128i res_8 = _mm_packus_epi16(round_result, round_result); |
226 | 0 | *(int *)(&dst0[0]) = _mm_cvtsi128_si32(res_8); |
227 | |
|
228 | 0 | } else { |
229 | 0 | _mm_store_si128((__m128i *)dst, res_unsigned); |
230 | 0 | } |
231 | |
|
232 | 0 | src_ptr += src_stride; |
233 | 0 | dst += dst_stride; |
234 | 0 | dst0 += dst_stride0; |
235 | |
|
236 | 0 | res = convolve_lo_y(s + 1, coeffs); |
237 | 0 | res_shift = _mm_sll_epi32(res, left_shift); |
238 | 0 | res_shift = |
239 | 0 | _mm_sra_epi32(_mm_add_epi32(res_shift, round_const), round_shift); |
240 | |
|
241 | 0 | res_16b = _mm_packs_epi32(res_shift, res_shift); |
242 | 0 | res_unsigned = _mm_add_epi16(res_16b, offset_const); |
243 | | |
244 | | // Accumulate values into the destination buffer |
245 | 0 | if (do_average) { |
246 | 0 | const __m128i data_ref_0 = _mm_loadu_si128((__m128i *)dst); |
247 | |
|
248 | 0 | const __m128i comp_avg_res = |
249 | 0 | comp_avg(&data_ref_0, &res_unsigned, &wt, use_dist_wtd_comp_avg); |
250 | |
|
251 | 0 | const __m128i round_result = convolve_rounding( |
252 | 0 | &comp_avg_res, &offset_const, &rounding_const, rounding_shift); |
253 | |
|
254 | 0 | const __m128i res_8 = _mm_packus_epi16(round_result, round_result); |
255 | 0 | *(int *)(&dst0[0]) = _mm_cvtsi128_si32(res_8); |
256 | |
|
257 | 0 | } else { |
258 | 0 | _mm_store_si128((__m128i *)dst, res_unsigned); |
259 | 0 | } |
260 | |
|
261 | 0 | src_ptr += src_stride; |
262 | 0 | dst += dst_stride; |
263 | 0 | dst0 += dst_stride0; |
264 | |
|
265 | 0 | s[0] = s[2]; |
266 | 0 | s[1] = s[3]; |
267 | 0 | s[2] = s[4]; |
268 | 0 | s[3] = s[5]; |
269 | 0 | s[4] = s[6]; |
270 | 0 | s[5] = s[7]; |
271 | 0 | h -= 2; |
272 | 0 | } while (h); |
273 | 0 | } else { |
274 | 0 | assert(!(w % 8)); |
275 | 0 | int j = 0; |
276 | 0 | do { |
277 | 0 | __m128i s[8], src6, res_lo, res_hi, res_lo_shift, res_hi_shift; |
278 | 0 | const uint8_t *data = &src_ptr[j]; |
279 | |
|
280 | 0 | src6 = _mm_loadl_epi64((__m128i *)(data + 6 * src_stride)); |
281 | 0 | s[0] = _mm_unpacklo_epi8( |
282 | 0 | _mm_loadl_epi64((__m128i *)(data + 0 * src_stride)), |
283 | 0 | _mm_loadl_epi64((__m128i *)(data + 1 * src_stride))); |
284 | 0 | s[1] = _mm_unpacklo_epi8( |
285 | 0 | _mm_loadl_epi64((__m128i *)(data + 1 * src_stride)), |
286 | 0 | _mm_loadl_epi64((__m128i *)(data + 2 * src_stride))); |
287 | 0 | s[2] = _mm_unpacklo_epi8( |
288 | 0 | _mm_loadl_epi64((__m128i *)(data + 2 * src_stride)), |
289 | 0 | _mm_loadl_epi64((__m128i *)(data + 3 * src_stride))); |
290 | 0 | s[3] = _mm_unpacklo_epi8( |
291 | 0 | _mm_loadl_epi64((__m128i *)(data + 3 * src_stride)), |
292 | 0 | _mm_loadl_epi64((__m128i *)(data + 4 * src_stride))); |
293 | 0 | s[4] = _mm_unpacklo_epi8( |
294 | 0 | _mm_loadl_epi64((__m128i *)(data + 4 * src_stride)), |
295 | 0 | _mm_loadl_epi64((__m128i *)(data + 5 * src_stride))); |
296 | 0 | s[5] = _mm_unpacklo_epi8( |
297 | 0 | _mm_loadl_epi64((__m128i *)(data + 5 * src_stride)), src6); |
298 | |
|
299 | 0 | int i = 0; |
300 | 0 | do { |
301 | 0 | data = &src_ptr[i * src_stride + j]; |
302 | 0 | s[6] = _mm_unpacklo_epi8( |
303 | 0 | src6, _mm_loadl_epi64((__m128i *)(data + 7 * src_stride))); |
304 | 0 | src6 = _mm_loadl_epi64((__m128i *)(data + 8 * src_stride)); |
305 | 0 | s[7] = _mm_unpacklo_epi8( |
306 | 0 | _mm_loadl_epi64((__m128i *)(data + 7 * src_stride)), src6); |
307 | |
|
308 | 0 | res_lo = convolve_lo_y(s, coeffs); // Filter low index pixels |
309 | 0 | res_hi = convolve_hi_y(s, coeffs); // Filter high index pixels |
310 | 0 | res_lo_shift = _mm_sll_epi32(res_lo, left_shift); |
311 | 0 | res_hi_shift = _mm_sll_epi32(res_hi, left_shift); |
312 | 0 | res_lo_shift = _mm_sra_epi32(_mm_add_epi32(res_lo_shift, round_const), |
313 | 0 | round_shift); |
314 | 0 | res_hi_shift = _mm_sra_epi32(_mm_add_epi32(res_hi_shift, round_const), |
315 | 0 | round_shift); |
316 | |
|
317 | 0 | __m128i res_16b = _mm_packs_epi32(res_lo_shift, res_hi_shift); |
318 | 0 | __m128i res_unsigned = _mm_add_epi16(res_16b, offset_const); |
319 | | |
320 | | // Accumulate values into the destination buffer |
321 | 0 | if (do_average) { |
322 | 0 | const __m128i data_ref_0 = |
323 | 0 | _mm_loadu_si128((__m128i *)(&dst[i * dst_stride + j])); |
324 | |
|
325 | 0 | const __m128i comp_avg_res = |
326 | 0 | comp_avg(&data_ref_0, &res_unsigned, &wt, use_dist_wtd_comp_avg); |
327 | |
|
328 | 0 | const __m128i round_result = convolve_rounding( |
329 | 0 | &comp_avg_res, &offset_const, &rounding_const, rounding_shift); |
330 | |
|
331 | 0 | const __m128i res_8 = _mm_packus_epi16(round_result, round_result); |
332 | 0 | _mm_storel_epi64((__m128i *)(&dst0[i * dst_stride0 + j]), res_8); |
333 | 0 | } else { |
334 | 0 | _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_unsigned); |
335 | 0 | } |
336 | 0 | i++; |
337 | |
|
338 | 0 | res_lo = convolve_lo_y(s + 1, coeffs); // Filter low index pixels |
339 | 0 | res_hi = convolve_hi_y(s + 1, coeffs); // Filter high index pixels |
340 | 0 | res_lo_shift = _mm_sll_epi32(res_lo, left_shift); |
341 | 0 | res_hi_shift = _mm_sll_epi32(res_hi, left_shift); |
342 | 0 | res_lo_shift = _mm_sra_epi32(_mm_add_epi32(res_lo_shift, round_const), |
343 | 0 | round_shift); |
344 | 0 | res_hi_shift = _mm_sra_epi32(_mm_add_epi32(res_hi_shift, round_const), |
345 | 0 | round_shift); |
346 | 0 | res_16b = _mm_packs_epi32(res_lo_shift, res_hi_shift); |
347 | 0 | res_unsigned = _mm_add_epi16(res_16b, offset_const); |
348 | | |
349 | | // Accumulate values into the destination buffer |
350 | 0 | if (do_average) { |
351 | 0 | __m128i data_ref_0 = |
352 | 0 | _mm_loadu_si128((__m128i *)(&dst[i * dst_stride + j])); |
353 | |
|
354 | 0 | const __m128i comp_avg_res = |
355 | 0 | comp_avg(&data_ref_0, &res_unsigned, &wt, use_dist_wtd_comp_avg); |
356 | |
|
357 | 0 | const __m128i round_result = convolve_rounding( |
358 | 0 | &comp_avg_res, &offset_const, &rounding_const, rounding_shift); |
359 | |
|
360 | 0 | const __m128i res_8 = _mm_packus_epi16(round_result, round_result); |
361 | 0 | _mm_storel_epi64((__m128i *)(&dst0[i * dst_stride0 + j]), res_8); |
362 | 0 | } else { |
363 | 0 | _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_unsigned); |
364 | 0 | } |
365 | 0 | i++; |
366 | |
|
367 | 0 | s[0] = s[2]; |
368 | 0 | s[1] = s[3]; |
369 | 0 | s[2] = s[4]; |
370 | 0 | s[3] = s[5]; |
371 | 0 | s[4] = s[6]; |
372 | 0 | s[5] = s[7]; |
373 | 0 | } while (i < h); |
374 | 0 | j += 8; |
375 | 0 | } while (j < w); |
376 | 0 | } |
377 | 0 | } |
378 | | |
379 | | void av1_dist_wtd_convolve_2d_sse2(const uint8_t *src, int src_stride, |
380 | | uint8_t *dst0, int dst_stride0, int w, int h, |
381 | | const InterpFilterParams *filter_params_x, |
382 | | const InterpFilterParams *filter_params_y, |
383 | | const int subpel_x_qn, const int subpel_y_qn, |
384 | 0 | ConvolveParams *conv_params) { |
385 | 0 | CONV_BUF_TYPE *dst = conv_params->dst; |
386 | 0 | int dst_stride = conv_params->dst_stride; |
387 | 0 | const int bd = 8; |
388 | |
|
389 | 0 | DECLARE_ALIGNED(16, int16_t, |
390 | 0 | im_block[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) * MAX_SB_SIZE]); |
391 | 0 | int im_h = h + filter_params_y->taps - 1; |
392 | 0 | int im_stride = MAX_SB_SIZE; |
393 | 0 | int i, j; |
394 | 0 | const int fo_vert = filter_params_y->taps / 2 - 1; |
395 | 0 | const int fo_horiz = filter_params_x->taps / 2 - 1; |
396 | 0 | const int do_average = conv_params->do_average; |
397 | 0 | const int use_dist_wtd_comp_avg = conv_params->use_dist_wtd_comp_avg; |
398 | 0 | const uint8_t *const src_ptr = src - fo_vert * src_stride - fo_horiz; |
399 | |
|
400 | 0 | const __m128i zero = _mm_setzero_si128(); |
401 | |
|
402 | 0 | const int w0 = conv_params->fwd_offset; |
403 | 0 | const int w1 = conv_params->bck_offset; |
404 | 0 | const __m128i wt0 = _mm_set1_epi16(w0); |
405 | 0 | const __m128i wt1 = _mm_set1_epi16(w1); |
406 | 0 | const __m128i wt = _mm_unpacklo_epi16(wt0, wt1); |
407 | |
|
408 | 0 | const int offset_0 = |
409 | 0 | bd + 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
410 | 0 | const int offset = (1 << offset_0) + (1 << (offset_0 - 1)); |
411 | 0 | const __m128i offset_const = _mm_set1_epi16(offset); |
412 | 0 | const int rounding_shift = |
413 | 0 | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
414 | 0 | const __m128i rounding_const = _mm_set1_epi16((1 << rounding_shift) >> 1); |
415 | | |
416 | | /* Horizontal filter */ |
417 | 0 | { |
418 | 0 | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
419 | 0 | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
420 | 0 | const __m128i coeffs_x = _mm_loadu_si128((__m128i *)x_filter); |
421 | | |
422 | | // coeffs 0 1 0 1 2 3 2 3 |
423 | 0 | const __m128i tmp_0 = _mm_unpacklo_epi32(coeffs_x, coeffs_x); |
424 | | // coeffs 4 5 4 5 6 7 6 7 |
425 | 0 | const __m128i tmp_1 = _mm_unpackhi_epi32(coeffs_x, coeffs_x); |
426 | | |
427 | | // coeffs 0 1 0 1 0 1 0 1 |
428 | 0 | const __m128i coeff_01 = _mm_unpacklo_epi64(tmp_0, tmp_0); |
429 | | // coeffs 2 3 2 3 2 3 2 3 |
430 | 0 | const __m128i coeff_23 = _mm_unpackhi_epi64(tmp_0, tmp_0); |
431 | | // coeffs 4 5 4 5 4 5 4 5 |
432 | 0 | const __m128i coeff_45 = _mm_unpacklo_epi64(tmp_1, tmp_1); |
433 | | // coeffs 6 7 6 7 6 7 6 7 |
434 | 0 | const __m128i coeff_67 = _mm_unpackhi_epi64(tmp_1, tmp_1); |
435 | |
|
436 | 0 | const __m128i round_const = _mm_set1_epi32( |
437 | 0 | ((1 << conv_params->round_0) >> 1) + (1 << (bd + FILTER_BITS - 1))); |
438 | 0 | const __m128i round_shift = _mm_cvtsi32_si128(conv_params->round_0); |
439 | |
|
440 | 0 | for (i = 0; i < im_h; ++i) { |
441 | 0 | for (j = 0; j < w; j += 8) { |
442 | 0 | __m128i temp_lo, temp_hi; |
443 | 0 | const __m128i data = |
444 | 0 | _mm_loadu_si128((__m128i *)&src_ptr[i * src_stride + j]); |
445 | |
|
446 | 0 | const __m128i src_lo = _mm_unpacklo_epi8(data, zero); |
447 | 0 | const __m128i src_hi = _mm_unpackhi_epi8(data, zero); |
448 | | |
449 | | // Filter even-index pixels |
450 | 0 | const __m128i res_0 = _mm_madd_epi16(src_lo, coeff_01); |
451 | 0 | temp_lo = _mm_srli_si128(src_lo, 4); |
452 | 0 | temp_hi = _mm_slli_si128(src_hi, 12); |
453 | 0 | const __m128i src_2 = _mm_or_si128(temp_hi, temp_lo); |
454 | 0 | const __m128i res_2 = _mm_madd_epi16(src_2, coeff_23); |
455 | 0 | temp_lo = _mm_srli_si128(src_lo, 8); |
456 | 0 | temp_hi = _mm_slli_si128(src_hi, 8); |
457 | 0 | const __m128i src_4 = _mm_or_si128(temp_hi, temp_lo); |
458 | 0 | const __m128i res_4 = _mm_madd_epi16(src_4, coeff_45); |
459 | 0 | temp_lo = _mm_srli_si128(src_lo, 12); |
460 | 0 | temp_hi = _mm_slli_si128(src_hi, 4); |
461 | 0 | const __m128i src_6 = _mm_or_si128(temp_hi, temp_lo); |
462 | 0 | const __m128i res_6 = _mm_madd_epi16(src_6, coeff_67); |
463 | |
|
464 | 0 | __m128i res_even = _mm_add_epi32(_mm_add_epi32(res_0, res_4), |
465 | 0 | _mm_add_epi32(res_2, res_6)); |
466 | 0 | res_even = |
467 | 0 | _mm_sra_epi32(_mm_add_epi32(res_even, round_const), round_shift); |
468 | | |
469 | | // Filter odd-index pixels |
470 | 0 | temp_lo = _mm_srli_si128(src_lo, 2); |
471 | 0 | temp_hi = _mm_slli_si128(src_hi, 14); |
472 | 0 | const __m128i src_1 = _mm_or_si128(temp_hi, temp_lo); |
473 | 0 | const __m128i res_1 = _mm_madd_epi16(src_1, coeff_01); |
474 | 0 | temp_lo = _mm_srli_si128(src_lo, 6); |
475 | 0 | temp_hi = _mm_slli_si128(src_hi, 10); |
476 | 0 | const __m128i src_3 = _mm_or_si128(temp_hi, temp_lo); |
477 | 0 | const __m128i res_3 = _mm_madd_epi16(src_3, coeff_23); |
478 | 0 | temp_lo = _mm_srli_si128(src_lo, 10); |
479 | 0 | temp_hi = _mm_slli_si128(src_hi, 6); |
480 | 0 | const __m128i src_5 = _mm_or_si128(temp_hi, temp_lo); |
481 | 0 | const __m128i res_5 = _mm_madd_epi16(src_5, coeff_45); |
482 | 0 | temp_lo = _mm_srli_si128(src_lo, 14); |
483 | 0 | temp_hi = _mm_slli_si128(src_hi, 2); |
484 | 0 | const __m128i src_7 = _mm_or_si128(temp_hi, temp_lo); |
485 | 0 | const __m128i res_7 = _mm_madd_epi16(src_7, coeff_67); |
486 | |
|
487 | 0 | __m128i res_odd = _mm_add_epi32(_mm_add_epi32(res_1, res_5), |
488 | 0 | _mm_add_epi32(res_3, res_7)); |
489 | 0 | res_odd = |
490 | 0 | _mm_sra_epi32(_mm_add_epi32(res_odd, round_const), round_shift); |
491 | | |
492 | | // Pack in the column order 0, 2, 4, 6, 1, 3, 5, 7 |
493 | 0 | __m128i res = _mm_packs_epi32(res_even, res_odd); |
494 | 0 | _mm_store_si128((__m128i *)&im_block[i * im_stride + j], res); |
495 | 0 | } |
496 | 0 | } |
497 | 0 | } |
498 | | |
499 | | /* Vertical filter */ |
500 | 0 | { |
501 | 0 | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
502 | 0 | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
503 | 0 | const __m128i coeffs_y = _mm_loadu_si128((__m128i *)y_filter); |
504 | | |
505 | | // coeffs 0 1 0 1 2 3 2 3 |
506 | 0 | const __m128i tmp_0 = _mm_unpacklo_epi32(coeffs_y, coeffs_y); |
507 | | // coeffs 4 5 4 5 6 7 6 7 |
508 | 0 | const __m128i tmp_1 = _mm_unpackhi_epi32(coeffs_y, coeffs_y); |
509 | | |
510 | | // coeffs 0 1 0 1 0 1 0 1 |
511 | 0 | const __m128i coeff_01 = _mm_unpacklo_epi64(tmp_0, tmp_0); |
512 | | // coeffs 2 3 2 3 2 3 2 3 |
513 | 0 | const __m128i coeff_23 = _mm_unpackhi_epi64(tmp_0, tmp_0); |
514 | | // coeffs 4 5 4 5 4 5 4 5 |
515 | 0 | const __m128i coeff_45 = _mm_unpacklo_epi64(tmp_1, tmp_1); |
516 | | // coeffs 6 7 6 7 6 7 6 7 |
517 | 0 | const __m128i coeff_67 = _mm_unpackhi_epi64(tmp_1, tmp_1); |
518 | |
|
519 | 0 | const __m128i round_const = _mm_set1_epi32( |
520 | 0 | ((1 << conv_params->round_1) >> 1) - |
521 | 0 | (1 << (bd + 2 * FILTER_BITS - conv_params->round_0 - 1))); |
522 | 0 | const __m128i round_shift = _mm_cvtsi32_si128(conv_params->round_1); |
523 | |
|
524 | 0 | for (i = 0; i < h; ++i) { |
525 | 0 | for (j = 0; j < w; j += 8) { |
526 | | // Filter even-index pixels |
527 | 0 | const int16_t *data = &im_block[i * im_stride + j]; |
528 | 0 | const __m128i src_0 = |
529 | 0 | _mm_unpacklo_epi16(*(__m128i *)(data + 0 * im_stride), |
530 | 0 | *(__m128i *)(data + 1 * im_stride)); |
531 | 0 | const __m128i src_2 = |
532 | 0 | _mm_unpacklo_epi16(*(__m128i *)(data + 2 * im_stride), |
533 | 0 | *(__m128i *)(data + 3 * im_stride)); |
534 | 0 | const __m128i src_4 = |
535 | 0 | _mm_unpacklo_epi16(*(__m128i *)(data + 4 * im_stride), |
536 | 0 | *(__m128i *)(data + 5 * im_stride)); |
537 | 0 | const __m128i src_6 = |
538 | 0 | _mm_unpacklo_epi16(*(__m128i *)(data + 6 * im_stride), |
539 | 0 | *(__m128i *)(data + 7 * im_stride)); |
540 | |
|
541 | 0 | const __m128i res_0 = _mm_madd_epi16(src_0, coeff_01); |
542 | 0 | const __m128i res_2 = _mm_madd_epi16(src_2, coeff_23); |
543 | 0 | const __m128i res_4 = _mm_madd_epi16(src_4, coeff_45); |
544 | 0 | const __m128i res_6 = _mm_madd_epi16(src_6, coeff_67); |
545 | |
|
546 | 0 | const __m128i res_even = _mm_add_epi32(_mm_add_epi32(res_0, res_2), |
547 | 0 | _mm_add_epi32(res_4, res_6)); |
548 | | |
549 | | // Filter odd-index pixels |
550 | 0 | const __m128i src_1 = |
551 | 0 | _mm_unpackhi_epi16(*(__m128i *)(data + 0 * im_stride), |
552 | 0 | *(__m128i *)(data + 1 * im_stride)); |
553 | 0 | const __m128i src_3 = |
554 | 0 | _mm_unpackhi_epi16(*(__m128i *)(data + 2 * im_stride), |
555 | 0 | *(__m128i *)(data + 3 * im_stride)); |
556 | 0 | const __m128i src_5 = |
557 | 0 | _mm_unpackhi_epi16(*(__m128i *)(data + 4 * im_stride), |
558 | 0 | *(__m128i *)(data + 5 * im_stride)); |
559 | 0 | const __m128i src_7 = |
560 | 0 | _mm_unpackhi_epi16(*(__m128i *)(data + 6 * im_stride), |
561 | 0 | *(__m128i *)(data + 7 * im_stride)); |
562 | |
|
563 | 0 | const __m128i res_1 = _mm_madd_epi16(src_1, coeff_01); |
564 | 0 | const __m128i res_3 = _mm_madd_epi16(src_3, coeff_23); |
565 | 0 | const __m128i res_5 = _mm_madd_epi16(src_5, coeff_45); |
566 | 0 | const __m128i res_7 = _mm_madd_epi16(src_7, coeff_67); |
567 | |
|
568 | 0 | const __m128i res_odd = _mm_add_epi32(_mm_add_epi32(res_1, res_3), |
569 | 0 | _mm_add_epi32(res_5, res_7)); |
570 | | |
571 | | // Rearrange pixels back into the order 0 ... 7 |
572 | 0 | const __m128i res_lo = _mm_unpacklo_epi32(res_even, res_odd); |
573 | 0 | const __m128i res_hi = _mm_unpackhi_epi32(res_even, res_odd); |
574 | |
|
575 | 0 | const __m128i res_lo_round = |
576 | 0 | _mm_sra_epi32(_mm_add_epi32(res_lo, round_const), round_shift); |
577 | 0 | const __m128i res_hi_round = |
578 | 0 | _mm_sra_epi32(_mm_add_epi32(res_hi, round_const), round_shift); |
579 | |
|
580 | 0 | const __m128i res_16b = _mm_packs_epi32(res_lo_round, res_hi_round); |
581 | 0 | const __m128i res_unsigned = _mm_add_epi16(res_16b, offset_const); |
582 | | |
583 | | // Accumulate values into the destination buffer |
584 | 0 | if (do_average) { |
585 | 0 | const __m128i data_ref_0 = |
586 | 0 | _mm_loadu_si128((__m128i *)(&dst[i * dst_stride + j])); |
587 | |
|
588 | 0 | const __m128i comp_avg_res = |
589 | 0 | comp_avg(&data_ref_0, &res_unsigned, &wt, use_dist_wtd_comp_avg); |
590 | |
|
591 | 0 | const __m128i round_result = convolve_rounding( |
592 | 0 | &comp_avg_res, &offset_const, &rounding_const, rounding_shift); |
593 | |
|
594 | 0 | const __m128i res_8 = _mm_packus_epi16(round_result, round_result); |
595 | |
|
596 | 0 | if (w > 4) |
597 | 0 | _mm_storel_epi64((__m128i *)(&dst0[i * dst_stride0 + j]), res_8); |
598 | 0 | else |
599 | 0 | *(int *)(&dst0[i * dst_stride0 + j]) = _mm_cvtsi128_si32(res_8); |
600 | 0 | } else { |
601 | 0 | _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_unsigned); |
602 | 0 | } |
603 | 0 | } |
604 | 0 | } |
605 | 0 | } |
606 | 0 | } |