/src/aom/av1/common/x86/convolve_sse2.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2017, 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/av1_rtcd.h" |
15 | | |
16 | | #include "aom_dsp/aom_dsp_common.h" |
17 | | #include "aom_dsp/aom_filter.h" |
18 | | #include "aom_dsp/x86/convolve_common_intrin.h" |
19 | | #include "av1/common/convolve.h" |
20 | | |
21 | | static INLINE void prepare_coeffs(const InterpFilterParams *const filter_params, |
22 | | const int subpel_q4, |
23 | 0 | __m128i *const coeffs /* [4] */) { |
24 | 0 | const int16_t *const y_filter = av1_get_interp_filter_subpel_kernel( |
25 | 0 | filter_params, subpel_q4 & SUBPEL_MASK); |
26 | 0 | const __m128i coeffs_y = _mm_loadu_si128((__m128i *)y_filter); |
27 | | // coeffs 0 1 0 1 2 3 2 3 |
28 | 0 | const __m128i tmp_0 = _mm_unpacklo_epi32(coeffs_y, coeffs_y); |
29 | | // coeffs 4 5 4 5 6 7 6 7 |
30 | 0 | const __m128i tmp_1 = _mm_unpackhi_epi32(coeffs_y, coeffs_y); |
31 | |
|
32 | 0 | coeffs[0] = _mm_unpacklo_epi64(tmp_0, tmp_0); // coeffs 0 1 0 1 0 1 0 1 |
33 | 0 | coeffs[1] = _mm_unpackhi_epi64(tmp_0, tmp_0); // coeffs 2 3 2 3 2 3 2 3 |
34 | 0 | coeffs[2] = _mm_unpacklo_epi64(tmp_1, tmp_1); // coeffs 4 5 4 5 4 5 4 5 |
35 | 0 | coeffs[3] = _mm_unpackhi_epi64(tmp_1, tmp_1); // coeffs 6 7 6 7 6 7 6 7 |
36 | 0 | } |
37 | | |
38 | | static INLINE __m128i convolve(const __m128i *const s, |
39 | 0 | const __m128i *const coeffs) { |
40 | 0 | const __m128i d0 = _mm_madd_epi16(s[0], coeffs[0]); |
41 | 0 | const __m128i d1 = _mm_madd_epi16(s[1], coeffs[1]); |
42 | 0 | const __m128i d2 = _mm_madd_epi16(s[2], coeffs[2]); |
43 | 0 | const __m128i d3 = _mm_madd_epi16(s[3], coeffs[3]); |
44 | 0 | const __m128i d = _mm_add_epi32(_mm_add_epi32(d0, d1), _mm_add_epi32(d2, d3)); |
45 | 0 | return d; |
46 | 0 | } |
47 | | |
48 | | static INLINE __m128i convolve_lo_x(const __m128i *const s, |
49 | 0 | const __m128i *const coeffs) { |
50 | 0 | __m128i ss[4]; |
51 | 0 | ss[0] = _mm_unpacklo_epi8(s[0], _mm_setzero_si128()); |
52 | 0 | ss[1] = _mm_unpacklo_epi8(s[1], _mm_setzero_si128()); |
53 | 0 | ss[2] = _mm_unpacklo_epi8(s[2], _mm_setzero_si128()); |
54 | 0 | ss[3] = _mm_unpacklo_epi8(s[3], _mm_setzero_si128()); |
55 | 0 | return convolve(ss, coeffs); |
56 | 0 | } |
57 | | |
58 | | static INLINE __m128i convolve_lo_y(const __m128i *const s, |
59 | 0 | const __m128i *const coeffs) { |
60 | 0 | __m128i ss[4]; |
61 | 0 | ss[0] = _mm_unpacklo_epi8(s[0], _mm_setzero_si128()); |
62 | 0 | ss[1] = _mm_unpacklo_epi8(s[2], _mm_setzero_si128()); |
63 | 0 | ss[2] = _mm_unpacklo_epi8(s[4], _mm_setzero_si128()); |
64 | 0 | ss[3] = _mm_unpacklo_epi8(s[6], _mm_setzero_si128()); |
65 | 0 | return convolve(ss, coeffs); |
66 | 0 | } |
67 | | |
68 | | static INLINE __m128i convolve_hi_y(const __m128i *const s, |
69 | 0 | const __m128i *const coeffs) { |
70 | 0 | __m128i ss[4]; |
71 | 0 | ss[0] = _mm_unpackhi_epi8(s[0], _mm_setzero_si128()); |
72 | 0 | ss[1] = _mm_unpackhi_epi8(s[2], _mm_setzero_si128()); |
73 | 0 | ss[2] = _mm_unpackhi_epi8(s[4], _mm_setzero_si128()); |
74 | 0 | ss[3] = _mm_unpackhi_epi8(s[6], _mm_setzero_si128()); |
75 | 0 | return convolve(ss, coeffs); |
76 | 0 | } |
77 | | |
78 | | void av1_convolve_y_sr_12tap_sse2(const uint8_t *src, int src_stride, |
79 | | uint8_t *dst, int dst_stride, int w, int h, |
80 | | const InterpFilterParams *filter_params_y, |
81 | 0 | int subpel_y_qn) { |
82 | 0 | const int fo_vert = filter_params_y->taps / 2 - 1; |
83 | 0 | const uint8_t *src_ptr = src - fo_vert * src_stride; |
84 | 0 | const __m128i round_const = _mm_set1_epi32((1 << FILTER_BITS) >> 1); |
85 | 0 | const __m128i round_shift = _mm_cvtsi32_si128(FILTER_BITS); |
86 | 0 | __m128i coeffs[6]; |
87 | |
|
88 | 0 | prepare_coeffs_12tap(filter_params_y, subpel_y_qn, coeffs); |
89 | |
|
90 | 0 | int j = 0; |
91 | 0 | do { |
92 | 0 | __m128i s[12], src10, res_lo, res_hi; |
93 | 0 | __m128i res_lo_round, res_hi_round, res16, res; |
94 | 0 | const uint8_t *data = &src_ptr[j]; |
95 | |
|
96 | 0 | src10 = _mm_loadl_epi64((__m128i *)(data + 10 * src_stride)); |
97 | 0 | s[0] = |
98 | 0 | _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i *)(data + 0 * src_stride)), |
99 | 0 | _mm_loadl_epi64((__m128i *)(data + 1 * src_stride))); |
100 | 0 | s[1] = |
101 | 0 | _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i *)(data + 1 * src_stride)), |
102 | 0 | _mm_loadl_epi64((__m128i *)(data + 2 * src_stride))); |
103 | 0 | s[2] = |
104 | 0 | _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i *)(data + 2 * src_stride)), |
105 | 0 | _mm_loadl_epi64((__m128i *)(data + 3 * src_stride))); |
106 | 0 | s[3] = |
107 | 0 | _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i *)(data + 3 * src_stride)), |
108 | 0 | _mm_loadl_epi64((__m128i *)(data + 4 * src_stride))); |
109 | 0 | s[4] = |
110 | 0 | _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i *)(data + 4 * src_stride)), |
111 | 0 | _mm_loadl_epi64((__m128i *)(data + 5 * src_stride))); |
112 | 0 | s[5] = |
113 | 0 | _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i *)(data + 5 * src_stride)), |
114 | 0 | _mm_loadl_epi64((__m128i *)(data + 6 * src_stride))); |
115 | 0 | s[6] = |
116 | 0 | _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i *)(data + 6 * src_stride)), |
117 | 0 | _mm_loadl_epi64((__m128i *)(data + 7 * src_stride))); |
118 | 0 | s[7] = |
119 | 0 | _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i *)(data + 7 * src_stride)), |
120 | 0 | _mm_loadl_epi64((__m128i *)(data + 8 * src_stride))); |
121 | 0 | s[8] = |
122 | 0 | _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i *)(data + 8 * src_stride)), |
123 | 0 | _mm_loadl_epi64((__m128i *)(data + 9 * src_stride))); |
124 | 0 | s[9] = _mm_unpacklo_epi8( |
125 | 0 | _mm_loadl_epi64((__m128i *)(data + 9 * src_stride)), src10); |
126 | |
|
127 | 0 | int i = 0; |
128 | 0 | do { |
129 | 0 | data = &src_ptr[i * src_stride + j]; |
130 | 0 | s[10] = _mm_unpacklo_epi8( |
131 | 0 | src10, _mm_loadl_epi64((__m128i *)(data + 11 * src_stride))); |
132 | 0 | src10 = _mm_loadl_epi64((__m128i *)(data + 12 * src_stride)); |
133 | 0 | s[11] = _mm_unpacklo_epi8( |
134 | 0 | _mm_loadl_epi64((__m128i *)(data + 11 * src_stride)), src10); |
135 | |
|
136 | 0 | res_lo = convolve_lo_y_12tap(s, coeffs); // Filter low index pixels |
137 | 0 | res_hi = convolve_hi_y_12tap(s, coeffs); // Filter high index pixels |
138 | |
|
139 | 0 | res_lo_round = |
140 | 0 | _mm_sra_epi32(_mm_add_epi32(res_lo, round_const), round_shift); |
141 | 0 | res_hi_round = |
142 | 0 | _mm_sra_epi32(_mm_add_epi32(res_hi, round_const), round_shift); |
143 | |
|
144 | 0 | res16 = _mm_packs_epi32(res_lo_round, res_hi_round); |
145 | 0 | res = _mm_packus_epi16(res16, res16); |
146 | |
|
147 | 0 | _mm_storel_epi64((__m128i *)(dst + i * dst_stride + j), res); |
148 | 0 | i++; |
149 | |
|
150 | 0 | res_lo = convolve_lo_y_12tap(s + 1, coeffs); // Filter low index pixels |
151 | 0 | res_hi = convolve_hi_y_12tap(s + 1, coeffs); // Filter high index pixels |
152 | |
|
153 | 0 | res_lo_round = |
154 | 0 | _mm_sra_epi32(_mm_add_epi32(res_lo, round_const), round_shift); |
155 | 0 | res_hi_round = |
156 | 0 | _mm_sra_epi32(_mm_add_epi32(res_hi, round_const), round_shift); |
157 | |
|
158 | 0 | res16 = _mm_packs_epi32(res_lo_round, res_hi_round); |
159 | 0 | res = _mm_packus_epi16(res16, res16); |
160 | |
|
161 | 0 | _mm_storel_epi64((__m128i *)(dst + i * dst_stride + j), res); |
162 | 0 | i++; |
163 | |
|
164 | 0 | s[0] = s[2]; |
165 | 0 | s[1] = s[3]; |
166 | 0 | s[2] = s[4]; |
167 | 0 | s[3] = s[5]; |
168 | 0 | s[4] = s[6]; |
169 | 0 | s[5] = s[7]; |
170 | 0 | s[6] = s[8]; |
171 | 0 | s[7] = s[9]; |
172 | 0 | s[8] = s[10]; |
173 | 0 | s[9] = s[11]; |
174 | 0 | } while (i < h); |
175 | 0 | j += 8; |
176 | 0 | } while (j < w); |
177 | 0 | } |
178 | | |
179 | | void av1_convolve_y_sr_sse2(const uint8_t *src, int src_stride, uint8_t *dst, |
180 | | int dst_stride, int w, int h, |
181 | | const InterpFilterParams *filter_params_y, |
182 | 0 | const int subpel_y_qn) { |
183 | 0 | if (filter_params_y->taps > 8) { |
184 | 0 | if (w < 8) { |
185 | 0 | av1_convolve_y_sr_c(src, src_stride, dst, dst_stride, w, h, |
186 | 0 | filter_params_y, subpel_y_qn); |
187 | 0 | } else { |
188 | 0 | av1_convolve_y_sr_12tap_sse2(src, src_stride, dst, dst_stride, w, h, |
189 | 0 | filter_params_y, subpel_y_qn); |
190 | 0 | } |
191 | 0 | } else { |
192 | 0 | const int fo_vert = filter_params_y->taps / 2 - 1; |
193 | 0 | const uint8_t *src_ptr = src - fo_vert * src_stride; |
194 | 0 | const __m128i round_const = _mm_set1_epi32((1 << FILTER_BITS) >> 1); |
195 | 0 | const __m128i round_shift = _mm_cvtsi32_si128(FILTER_BITS); |
196 | 0 | __m128i coeffs[4]; |
197 | |
|
198 | 0 | prepare_coeffs(filter_params_y, subpel_y_qn, coeffs); |
199 | |
|
200 | 0 | if (w <= 4) { |
201 | 0 | __m128i s[8], src6, res, res_round, res16; |
202 | 0 | int res_int; |
203 | 0 | src6 = _mm_cvtsi32_si128(*(int *)(src_ptr + 6 * src_stride)); |
204 | 0 | s[0] = _mm_unpacklo_epi8( |
205 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 0 * src_stride)), |
206 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 1 * src_stride))); |
207 | 0 | s[1] = _mm_unpacklo_epi8( |
208 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 1 * src_stride)), |
209 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 2 * src_stride))); |
210 | 0 | s[2] = _mm_unpacklo_epi8( |
211 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 2 * src_stride)), |
212 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 3 * src_stride))); |
213 | 0 | s[3] = _mm_unpacklo_epi8( |
214 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 3 * src_stride)), |
215 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 4 * src_stride))); |
216 | 0 | s[4] = _mm_unpacklo_epi8( |
217 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 4 * src_stride)), |
218 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 5 * src_stride))); |
219 | 0 | s[5] = _mm_unpacklo_epi8( |
220 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 5 * src_stride)), src6); |
221 | |
|
222 | 0 | do { |
223 | 0 | s[6] = _mm_unpacklo_epi8( |
224 | 0 | src6, _mm_cvtsi32_si128(*(int *)(src_ptr + 7 * src_stride))); |
225 | 0 | src6 = _mm_cvtsi32_si128(*(int *)(src_ptr + 8 * src_stride)); |
226 | 0 | s[7] = _mm_unpacklo_epi8( |
227 | 0 | _mm_cvtsi32_si128(*(int *)(src_ptr + 7 * src_stride)), src6); |
228 | |
|
229 | 0 | res = convolve_lo_y(s + 0, coeffs); |
230 | 0 | res_round = _mm_sra_epi32(_mm_add_epi32(res, round_const), round_shift); |
231 | 0 | res16 = _mm_packs_epi32(res_round, res_round); |
232 | 0 | res_int = _mm_cvtsi128_si32(_mm_packus_epi16(res16, res16)); |
233 | |
|
234 | 0 | if (w == 2) |
235 | 0 | *(uint16_t *)dst = (uint16_t)res_int; |
236 | 0 | else |
237 | 0 | *(int *)dst = res_int; |
238 | |
|
239 | 0 | src_ptr += src_stride; |
240 | 0 | dst += dst_stride; |
241 | |
|
242 | 0 | res = convolve_lo_y(s + 1, coeffs); |
243 | 0 | res_round = _mm_sra_epi32(_mm_add_epi32(res, round_const), round_shift); |
244 | 0 | res16 = _mm_packs_epi32(res_round, res_round); |
245 | 0 | res_int = _mm_cvtsi128_si32(_mm_packus_epi16(res16, res16)); |
246 | |
|
247 | 0 | if (w == 2) |
248 | 0 | *(uint16_t *)dst = (uint16_t)res_int; |
249 | 0 | else |
250 | 0 | *(int *)dst = res_int; |
251 | |
|
252 | 0 | src_ptr += src_stride; |
253 | 0 | dst += dst_stride; |
254 | |
|
255 | 0 | s[0] = s[2]; |
256 | 0 | s[1] = s[3]; |
257 | 0 | s[2] = s[4]; |
258 | 0 | s[3] = s[5]; |
259 | 0 | s[4] = s[6]; |
260 | 0 | s[5] = s[7]; |
261 | 0 | h -= 2; |
262 | 0 | } while (h); |
263 | 0 | } else { |
264 | 0 | assert(!(w % 8)); |
265 | 0 | int j = 0; |
266 | 0 | do { |
267 | 0 | __m128i s[8], src6, res_lo, res_hi; |
268 | 0 | __m128i res_lo_round, res_hi_round, res16, res; |
269 | 0 | const uint8_t *data = &src_ptr[j]; |
270 | |
|
271 | 0 | src6 = _mm_loadl_epi64((__m128i *)(data + 6 * src_stride)); |
272 | 0 | s[0] = _mm_unpacklo_epi8( |
273 | 0 | _mm_loadl_epi64((__m128i *)(data + 0 * src_stride)), |
274 | 0 | _mm_loadl_epi64((__m128i *)(data + 1 * src_stride))); |
275 | 0 | s[1] = _mm_unpacklo_epi8( |
276 | 0 | _mm_loadl_epi64((__m128i *)(data + 1 * src_stride)), |
277 | 0 | _mm_loadl_epi64((__m128i *)(data + 2 * src_stride))); |
278 | 0 | s[2] = _mm_unpacklo_epi8( |
279 | 0 | _mm_loadl_epi64((__m128i *)(data + 2 * src_stride)), |
280 | 0 | _mm_loadl_epi64((__m128i *)(data + 3 * src_stride))); |
281 | 0 | s[3] = _mm_unpacklo_epi8( |
282 | 0 | _mm_loadl_epi64((__m128i *)(data + 3 * src_stride)), |
283 | 0 | _mm_loadl_epi64((__m128i *)(data + 4 * src_stride))); |
284 | 0 | s[4] = _mm_unpacklo_epi8( |
285 | 0 | _mm_loadl_epi64((__m128i *)(data + 4 * src_stride)), |
286 | 0 | _mm_loadl_epi64((__m128i *)(data + 5 * src_stride))); |
287 | 0 | s[5] = _mm_unpacklo_epi8( |
288 | 0 | _mm_loadl_epi64((__m128i *)(data + 5 * src_stride)), src6); |
289 | |
|
290 | 0 | int i = 0; |
291 | 0 | do { |
292 | 0 | data = &src_ptr[i * src_stride + j]; |
293 | 0 | s[6] = _mm_unpacklo_epi8( |
294 | 0 | src6, _mm_loadl_epi64((__m128i *)(data + 7 * src_stride))); |
295 | 0 | src6 = _mm_loadl_epi64((__m128i *)(data + 8 * src_stride)); |
296 | 0 | s[7] = _mm_unpacklo_epi8( |
297 | 0 | _mm_loadl_epi64((__m128i *)(data + 7 * src_stride)), src6); |
298 | |
|
299 | 0 | res_lo = convolve_lo_y(s, coeffs); // Filter low index pixels |
300 | 0 | res_hi = convolve_hi_y(s, coeffs); // Filter high index pixels |
301 | |
|
302 | 0 | res_lo_round = |
303 | 0 | _mm_sra_epi32(_mm_add_epi32(res_lo, round_const), round_shift); |
304 | 0 | res_hi_round = |
305 | 0 | _mm_sra_epi32(_mm_add_epi32(res_hi, round_const), round_shift); |
306 | |
|
307 | 0 | res16 = _mm_packs_epi32(res_lo_round, res_hi_round); |
308 | 0 | res = _mm_packus_epi16(res16, res16); |
309 | |
|
310 | 0 | _mm_storel_epi64((__m128i *)(dst + i * dst_stride + j), res); |
311 | 0 | i++; |
312 | |
|
313 | 0 | res_lo = convolve_lo_y(s + 1, coeffs); // Filter low index pixels |
314 | 0 | res_hi = convolve_hi_y(s + 1, coeffs); // Filter high index pixels |
315 | |
|
316 | 0 | res_lo_round = |
317 | 0 | _mm_sra_epi32(_mm_add_epi32(res_lo, round_const), round_shift); |
318 | 0 | res_hi_round = |
319 | 0 | _mm_sra_epi32(_mm_add_epi32(res_hi, round_const), round_shift); |
320 | |
|
321 | 0 | res16 = _mm_packs_epi32(res_lo_round, res_hi_round); |
322 | 0 | res = _mm_packus_epi16(res16, res16); |
323 | |
|
324 | 0 | _mm_storel_epi64((__m128i *)(dst + i * dst_stride + j), res); |
325 | 0 | i++; |
326 | |
|
327 | 0 | s[0] = s[2]; |
328 | 0 | s[1] = s[3]; |
329 | 0 | s[2] = s[4]; |
330 | 0 | s[3] = s[5]; |
331 | 0 | s[4] = s[6]; |
332 | 0 | s[5] = s[7]; |
333 | 0 | } while (i < h); |
334 | 0 | j += 8; |
335 | 0 | } while (j < w); |
336 | 0 | } |
337 | 0 | } |
338 | 0 | } |
339 | | |
340 | | void av1_convolve_x_sr_12tap_sse2(const uint8_t *src, int src_stride, |
341 | | uint8_t *dst, int dst_stride, int w, int h, |
342 | | const InterpFilterParams *filter_params_x, |
343 | | int subpel_x_qn, |
344 | 0 | ConvolveParams *conv_params) { |
345 | 0 | const int fo_horiz = filter_params_x->taps / 2 - 1; |
346 | 0 | const uint8_t *src_ptr = src - fo_horiz; |
347 | 0 | const int bits = FILTER_BITS - conv_params->round_0; |
348 | 0 | const __m128i round_0_const = |
349 | 0 | _mm_set1_epi32((1 << conv_params->round_0) >> 1); |
350 | 0 | const __m128i round_const = _mm_set1_epi32((1 << bits) >> 1); |
351 | 0 | const __m128i round_0_shift = _mm_cvtsi32_si128(conv_params->round_0); |
352 | 0 | const __m128i round_shift = _mm_cvtsi32_si128(bits); |
353 | 0 | const __m128i zero = _mm_setzero_si128(); |
354 | 0 | __m128i coeffs[6]; |
355 | |
|
356 | 0 | assert(bits >= 0); |
357 | 0 | assert((FILTER_BITS - conv_params->round_1) >= 0 || |
358 | 0 | ((conv_params->round_0 + conv_params->round_1) == 2 * FILTER_BITS)); |
359 | | |
360 | 0 | prepare_coeffs_12tap(filter_params_x, subpel_x_qn, coeffs); |
361 | |
|
362 | 0 | int i = 0; |
363 | 0 | do { |
364 | 0 | int j = 0; |
365 | 0 | do { |
366 | 0 | const __m128i data = |
367 | 0 | _mm_loadu_si128((__m128i *)&src_ptr[i * src_stride + j]); |
368 | 0 | __m128i s[4]; |
369 | |
|
370 | 0 | s[0] = _mm_unpacklo_epi16(data, _mm_srli_si128(data, 1)); |
371 | 0 | s[1] = |
372 | 0 | _mm_unpacklo_epi16(_mm_srli_si128(data, 2), _mm_srli_si128(data, 3)); |
373 | 0 | s[2] = |
374 | 0 | _mm_unpacklo_epi16(_mm_srli_si128(data, 4), _mm_srli_si128(data, 5)); |
375 | 0 | s[3] = |
376 | 0 | _mm_unpacklo_epi16(_mm_srli_si128(data, 6), _mm_srli_si128(data, 7)); |
377 | |
|
378 | 0 | const __m128i res32 = convolve_lo_x_12tap(s, coeffs, zero); |
379 | |
|
380 | 0 | __m128i res32_round = |
381 | 0 | _mm_sra_epi32(_mm_add_epi32(res32, round_0_const), round_0_shift); |
382 | 0 | res32_round = |
383 | 0 | _mm_sra_epi32(_mm_add_epi32(res32_round, round_const), round_shift); |
384 | |
|
385 | 0 | const __m128i res16 = _mm_packs_epi32(res32_round, zero); |
386 | 0 | const __m128i res = _mm_packus_epi16(res16, zero); |
387 | |
|
388 | 0 | const int val = _mm_cvtsi128_si32(res); |
389 | 0 | memcpy((dst + i * dst_stride + j), &val, sizeof(val)); |
390 | 0 | j += 4; |
391 | 0 | } while (j < w); |
392 | 0 | } while (++i < h); |
393 | 0 | } |
394 | | |
395 | | void av1_convolve_x_sr_sse2(const uint8_t *src, int src_stride, uint8_t *dst, |
396 | | int dst_stride, int w, int h, |
397 | | const InterpFilterParams *filter_params_x, |
398 | | const int subpel_x_qn, |
399 | 0 | ConvolveParams *conv_params) { |
400 | 0 | if (filter_params_x->taps > 8) { |
401 | 0 | if (w < 4) { |
402 | 0 | av1_convolve_x_sr_c(src, src_stride, dst, dst_stride, w, h, |
403 | 0 | filter_params_x, subpel_x_qn, conv_params); |
404 | 0 | } else { |
405 | 0 | av1_convolve_x_sr_12tap_sse2(src, src_stride, dst, dst_stride, w, h, |
406 | 0 | filter_params_x, subpel_x_qn, conv_params); |
407 | 0 | } |
408 | 0 | } else { |
409 | 0 | const int fo_horiz = filter_params_x->taps / 2 - 1; |
410 | 0 | const uint8_t *src_ptr = src - fo_horiz; |
411 | 0 | const int bits = FILTER_BITS - conv_params->round_0; |
412 | 0 | const __m128i round_0_const = |
413 | 0 | _mm_set1_epi32((1 << conv_params->round_0) >> 1); |
414 | 0 | const __m128i round_const = _mm_set1_epi32((1 << bits) >> 1); |
415 | 0 | const __m128i round_0_shift = _mm_cvtsi32_si128(conv_params->round_0); |
416 | 0 | const __m128i round_shift = _mm_cvtsi32_si128(bits); |
417 | 0 | __m128i coeffs[4]; |
418 | |
|
419 | 0 | assert(bits >= 0); |
420 | 0 | assert((FILTER_BITS - conv_params->round_1) >= 0 || |
421 | 0 | ((conv_params->round_0 + conv_params->round_1) == 2 * FILTER_BITS)); |
422 | | |
423 | 0 | prepare_coeffs(filter_params_x, subpel_x_qn, coeffs); |
424 | |
|
425 | 0 | if (w <= 4) { |
426 | 0 | do { |
427 | 0 | const __m128i data = _mm_loadu_si128((__m128i *)src_ptr); |
428 | 0 | __m128i s[4]; |
429 | |
|
430 | 0 | s[0] = _mm_unpacklo_epi8(data, _mm_srli_si128(data, 1)); |
431 | 0 | s[1] = |
432 | 0 | _mm_unpacklo_epi8(_mm_srli_si128(data, 2), _mm_srli_si128(data, 3)); |
433 | 0 | s[2] = |
434 | 0 | _mm_unpacklo_epi8(_mm_srli_si128(data, 4), _mm_srli_si128(data, 5)); |
435 | 0 | s[3] = |
436 | 0 | _mm_unpacklo_epi8(_mm_srli_si128(data, 6), _mm_srli_si128(data, 7)); |
437 | 0 | const __m128i res_lo = convolve_lo_x(s, coeffs); |
438 | 0 | __m128i res_lo_round = |
439 | 0 | _mm_sra_epi32(_mm_add_epi32(res_lo, round_0_const), round_0_shift); |
440 | 0 | res_lo_round = _mm_sra_epi32(_mm_add_epi32(res_lo_round, round_const), |
441 | 0 | round_shift); |
442 | |
|
443 | 0 | const __m128i res16 = _mm_packs_epi32(res_lo_round, res_lo_round); |
444 | 0 | const __m128i res = _mm_packus_epi16(res16, res16); |
445 | |
|
446 | 0 | int r = _mm_cvtsi128_si32(res); |
447 | 0 | if (w == 2) |
448 | 0 | *(uint16_t *)dst = (uint16_t)r; |
449 | 0 | else |
450 | 0 | *(int *)dst = r; |
451 | |
|
452 | 0 | src_ptr += src_stride; |
453 | 0 | dst += dst_stride; |
454 | 0 | } while (--h); |
455 | 0 | } else { |
456 | 0 | assert(!(w % 8)); |
457 | 0 | int i = 0; |
458 | 0 | do { |
459 | 0 | int j = 0; |
460 | 0 | do { |
461 | 0 | const __m128i data = |
462 | 0 | _mm_loadu_si128((__m128i *)&src_ptr[i * src_stride + j]); |
463 | 0 | __m128i s[4]; |
464 | | |
465 | | // Filter even-index pixels |
466 | 0 | s[0] = data; |
467 | 0 | s[1] = _mm_srli_si128(data, 2); |
468 | 0 | s[2] = _mm_srli_si128(data, 4); |
469 | 0 | s[3] = _mm_srli_si128(data, 6); |
470 | 0 | const __m128i res_even = convolve_lo_x(s, coeffs); |
471 | | |
472 | | // Filter odd-index pixels |
473 | 0 | s[0] = _mm_srli_si128(data, 1); |
474 | 0 | s[1] = _mm_srli_si128(data, 3); |
475 | 0 | s[2] = _mm_srli_si128(data, 5); |
476 | 0 | s[3] = _mm_srli_si128(data, 7); |
477 | 0 | const __m128i res_odd = convolve_lo_x(s, coeffs); |
478 | | |
479 | | // Rearrange pixels back into the order 0 ... 7 |
480 | 0 | const __m128i res_lo = _mm_unpacklo_epi32(res_even, res_odd); |
481 | 0 | const __m128i res_hi = _mm_unpackhi_epi32(res_even, res_odd); |
482 | 0 | __m128i res_lo_round = _mm_sra_epi32( |
483 | 0 | _mm_add_epi32(res_lo, round_0_const), round_0_shift); |
484 | 0 | res_lo_round = _mm_sra_epi32(_mm_add_epi32(res_lo_round, round_const), |
485 | 0 | round_shift); |
486 | 0 | __m128i res_hi_round = _mm_sra_epi32( |
487 | 0 | _mm_add_epi32(res_hi, round_0_const), round_0_shift); |
488 | 0 | res_hi_round = _mm_sra_epi32(_mm_add_epi32(res_hi_round, round_const), |
489 | 0 | round_shift); |
490 | |
|
491 | 0 | const __m128i res16 = _mm_packs_epi32(res_lo_round, res_hi_round); |
492 | 0 | const __m128i res = _mm_packus_epi16(res16, res16); |
493 | |
|
494 | 0 | _mm_storel_epi64((__m128i *)(dst + i * dst_stride + j), res); |
495 | 0 | j += 8; |
496 | 0 | } while (j < w); |
497 | 0 | } while (++i < h); |
498 | 0 | } |
499 | 0 | } |
500 | 0 | } |