1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-dwconv/unipass-sse-mul16.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 Google LLC
6 //
7 // This source code is licensed under the BSD-style license found in the
8 // LICENSE file in the root directory of this source tree.
9
10 #include <assert.h>
11
12 #include <smmintrin.h>
13
14 #include <xnnpack/dwconv.h>
15
16
xnn_qs8_dwconv_minmax_ukernel_up8x9__sse41_mul16(size_t channels,size_t output_width,const int8_t ** input,const void * weights,int8_t * output,size_t input_stride,size_t output_increment,size_t input_offset,const int8_t * zero,const union xnn_qs8_gemm_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qs8_dwconv_minmax_ukernel_up8x9__sse41_mul16(
18 size_t channels,
19 size_t output_width,
20 const int8_t** input,
21 const void* weights,
22 int8_t* output,
23 size_t input_stride,
24 size_t output_increment,
25 size_t input_offset,
26 const int8_t* zero,
27 const union xnn_qs8_gemm_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
28 {
29 assert(channels != 0);
30 assert(output_width != 0);
31
32 do {
33 const int8_t* i0 = input[0];
34 assert(i0 != NULL);
35 if XNN_UNPREDICTABLE(i0 != zero) {
36 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
37 }
38 const int8_t* i1 = input[1];
39 assert(i1 != NULL);
40 if XNN_UNPREDICTABLE(i1 != zero) {
41 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
42 }
43 const int8_t* i2 = input[2];
44 assert(i2 != NULL);
45 if XNN_UNPREDICTABLE(i2 != zero) {
46 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
47 }
48 const int8_t* i3 = input[3];
49 assert(i3 != NULL);
50 if XNN_UNPREDICTABLE(i3 != zero) {
51 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
52 }
53 const int8_t* i4 = input[4];
54 assert(i4 != NULL);
55 if XNN_UNPREDICTABLE(i4 != zero) {
56 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
57 }
58 const int8_t* i5 = input[5];
59 assert(i5 != NULL);
60 if XNN_UNPREDICTABLE(i5 != zero) {
61 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
62 }
63 const int8_t* i6 = input[6];
64 assert(i6 != NULL);
65 if XNN_UNPREDICTABLE(i6 != zero) {
66 i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
67 }
68 const int8_t* i7 = input[7];
69 assert(i7 != NULL);
70 if XNN_UNPREDICTABLE(i7 != zero) {
71 i7 = (const int8_t*) ((uintptr_t) i7 + input_offset);
72 }
73 const int8_t* i8 = input[8];
74 assert(i8 != NULL);
75 if XNN_UNPREDICTABLE(i8 != zero) {
76 i8 = (const int8_t*) ((uintptr_t) i8 + input_offset);
77 }
78 input = (const int8_t**) ((uintptr_t) input + input_stride);
79
80 size_t c = channels;
81 const void* w = weights;
82 for (; c >= 8; c -= 8) {
83 __m128i vacc0123 = _mm_loadu_si128((const __m128i*) w);
84 __m128i vacc4567 = _mm_loadu_si128((const __m128i*) ((uintptr_t) w + 4 * sizeof(int32_t)));
85
86
87 const __m128i vi0x01234567 = _mm_loadl_epi64((const __m128i*) i0);
88 const __m128i vxi0x01234567 = _mm_cvtepi8_epi16(vi0x01234567);
89 const __m128i vk0x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 0 * sizeof(int8_t)));
90 const __m128i vxk0x01234567 = _mm_cvtepi8_epi16(vk0x01234567);
91 i0 += 8;
92
93
94 const __m128i vp0x01234567lo = _mm_mullo_epi16(vxi0x01234567, vxk0x01234567);
95 const __m128i vp0x01234567hi = _mm_mulhi_epi16(vxi0x01234567, vxk0x01234567);
96
97 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp0x01234567lo, vp0x01234567hi));
98 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp0x01234567lo, vp0x01234567hi));
99
100 const __m128i vi1x01234567 = _mm_loadl_epi64((const __m128i*) i1);
101 const __m128i vxi1x01234567 = _mm_cvtepi8_epi16(vi1x01234567);
102 const __m128i vk1x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 8 * sizeof(int8_t)));
103 const __m128i vxk1x01234567 = _mm_cvtepi8_epi16(vk1x01234567);
104 i1 += 8;
105
106
107 const __m128i vp1x01234567lo = _mm_mullo_epi16(vxi1x01234567, vxk1x01234567);
108 const __m128i vp1x01234567hi = _mm_mulhi_epi16(vxi1x01234567, vxk1x01234567);
109
110 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp1x01234567lo, vp1x01234567hi));
111 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp1x01234567lo, vp1x01234567hi));
112
113 const __m128i vi2x01234567 = _mm_loadl_epi64((const __m128i*) i2);
114 const __m128i vxi2x01234567 = _mm_cvtepi8_epi16(vi2x01234567);
115 const __m128i vk2x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 16 * sizeof(int8_t)));
116 const __m128i vxk2x01234567 = _mm_cvtepi8_epi16(vk2x01234567);
117 i2 += 8;
118
119
120 const __m128i vp2x01234567lo = _mm_mullo_epi16(vxi2x01234567, vxk2x01234567);
121 const __m128i vp2x01234567hi = _mm_mulhi_epi16(vxi2x01234567, vxk2x01234567);
122
123 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp2x01234567lo, vp2x01234567hi));
124 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp2x01234567lo, vp2x01234567hi));
125
126 const __m128i vi3x01234567 = _mm_loadl_epi64((const __m128i*) i3);
127 const __m128i vxi3x01234567 = _mm_cvtepi8_epi16(vi3x01234567);
128 const __m128i vk3x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 24 * sizeof(int8_t)));
129 const __m128i vxk3x01234567 = _mm_cvtepi8_epi16(vk3x01234567);
130 i3 += 8;
131
132
133 const __m128i vp3x01234567lo = _mm_mullo_epi16(vxi3x01234567, vxk3x01234567);
134 const __m128i vp3x01234567hi = _mm_mulhi_epi16(vxi3x01234567, vxk3x01234567);
135
136 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp3x01234567lo, vp3x01234567hi));
137 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp3x01234567lo, vp3x01234567hi));
138
139 const __m128i vi4x01234567 = _mm_loadl_epi64((const __m128i*) i4);
140 const __m128i vxi4x01234567 = _mm_cvtepi8_epi16(vi4x01234567);
141 const __m128i vk4x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 32 * sizeof(int8_t)));
142 const __m128i vxk4x01234567 = _mm_cvtepi8_epi16(vk4x01234567);
143 i4 += 8;
144
145
146 const __m128i vp4x01234567lo = _mm_mullo_epi16(vxi4x01234567, vxk4x01234567);
147 const __m128i vp4x01234567hi = _mm_mulhi_epi16(vxi4x01234567, vxk4x01234567);
148
149 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp4x01234567lo, vp4x01234567hi));
150 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp4x01234567lo, vp4x01234567hi));
151
152 const __m128i vi5x01234567 = _mm_loadl_epi64((const __m128i*) i5);
153 const __m128i vxi5x01234567 = _mm_cvtepi8_epi16(vi5x01234567);
154 const __m128i vk5x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 40 * sizeof(int8_t)));
155 const __m128i vxk5x01234567 = _mm_cvtepi8_epi16(vk5x01234567);
156 i5 += 8;
157
158
159 const __m128i vp5x01234567lo = _mm_mullo_epi16(vxi5x01234567, vxk5x01234567);
160 const __m128i vp5x01234567hi = _mm_mulhi_epi16(vxi5x01234567, vxk5x01234567);
161
162 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp5x01234567lo, vp5x01234567hi));
163 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp5x01234567lo, vp5x01234567hi));
164
165 const __m128i vi6x01234567 = _mm_loadl_epi64((const __m128i*) i6);
166 const __m128i vxi6x01234567 = _mm_cvtepi8_epi16(vi6x01234567);
167 const __m128i vk6x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 48 * sizeof(int8_t)));
168 const __m128i vxk6x01234567 = _mm_cvtepi8_epi16(vk6x01234567);
169 i6 += 8;
170
171
172 const __m128i vp6x01234567lo = _mm_mullo_epi16(vxi6x01234567, vxk6x01234567);
173 const __m128i vp6x01234567hi = _mm_mulhi_epi16(vxi6x01234567, vxk6x01234567);
174
175 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp6x01234567lo, vp6x01234567hi));
176 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp6x01234567lo, vp6x01234567hi));
177
178 const __m128i vi7x01234567 = _mm_loadl_epi64((const __m128i*) i7);
179 const __m128i vxi7x01234567 = _mm_cvtepi8_epi16(vi7x01234567);
180 const __m128i vk7x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 56 * sizeof(int8_t)));
181 const __m128i vxk7x01234567 = _mm_cvtepi8_epi16(vk7x01234567);
182 i7 += 8;
183
184
185 const __m128i vp7x01234567lo = _mm_mullo_epi16(vxi7x01234567, vxk7x01234567);
186 const __m128i vp7x01234567hi = _mm_mulhi_epi16(vxi7x01234567, vxk7x01234567);
187
188 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp7x01234567lo, vp7x01234567hi));
189 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp7x01234567lo, vp7x01234567hi));
190
191 const __m128i vi8x01234567 = _mm_loadl_epi64((const __m128i*) i8);
192 const __m128i vxi8x01234567 = _mm_cvtepi8_epi16(vi8x01234567);
193 const __m128i vk8x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 64 * sizeof(int8_t)));
194 const __m128i vxk8x01234567 = _mm_cvtepi8_epi16(vk8x01234567);
195 i8 += 8;
196
197
198 const __m128i vp8x01234567lo = _mm_mullo_epi16(vxi8x01234567, vxk8x01234567);
199 const __m128i vp8x01234567hi = _mm_mulhi_epi16(vxi8x01234567, vxk8x01234567);
200
201 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp8x01234567lo, vp8x01234567hi));
202 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp8x01234567lo, vp8x01234567hi));
203
204 w = (const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 72 * sizeof(int8_t));
205
206 const __m128i vmultiplier = _mm_load_si128((const __m128i*) params->sse2.multiplier);
207 const __m128i vrounding = _mm_load_si128((const __m128i*) params->sse2.rounding);
208
209 const __m128i vacc13 = _mm_shuffle_epi32(vacc0123, _MM_SHUFFLE(3, 3, 1, 1));
210 const __m128i vprod02 = _mm_add_epi64(_mm_mul_epi32(vacc0123, vmultiplier), vrounding);
211 const __m128i vprod13 = _mm_add_epi64(_mm_mul_epi32(vacc13, vmultiplier), vrounding);
212 const __m128i vacc57 = _mm_shuffle_epi32(vacc4567, _MM_SHUFFLE(3, 3, 1, 1));
213 const __m128i vprod46 = _mm_add_epi64(_mm_mul_epi32(vacc4567, vmultiplier), vrounding);
214 const __m128i vprod57 = _mm_add_epi64(_mm_mul_epi32(vacc57, vmultiplier), vrounding);
215
216 const __m128i vq31prod02 = _mm_srli_epi64(vprod02, 31);
217 const __m128i vq31prod13 = _mm_add_epi64(vprod13, vprod13);
218 const __m128i vq31prod46 = _mm_srli_epi64(vprod46, 31);
219 const __m128i vq31prod57 = _mm_add_epi64(vprod57, vprod57);
220
221 const __m128i vq31prod0123 = _mm_blend_epi16(vq31prod02, vq31prod13, 0xCC);
222 const __m128i vq31prod4567 = _mm_blend_epi16(vq31prod46, vq31prod57, 0xCC);
223
224 const __m128i vremainder_mask = _mm_load_si128((const __m128i*) params->sse2.remainder_mask);
225 const __m128i vrem0123 =
226 _mm_add_epi32(_mm_and_si128(vq31prod0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vq31prod0123));
227 const __m128i vrem4567 =
228 _mm_add_epi32(_mm_and_si128(vq31prod4567, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vq31prod4567));
229
230 const __m128i vremainder_threshold = _mm_load_si128((const __m128i*) params->sse2.remainder_threshold);
231 const __m128i vshift = _mm_load_si128((const __m128i*) params->sse2.shift);
232 vacc0123 =
233 _mm_sub_epi32(_mm_sra_epi32(vq31prod0123, vshift), _mm_cmpgt_epi32(vrem0123, vremainder_threshold));
234 vacc4567 =
235 _mm_sub_epi32(_mm_sra_epi32(vq31prod4567, vshift), _mm_cmpgt_epi32(vrem4567, vremainder_threshold));
236
237 const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse2.output_zero_point);
238 __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
239
240 const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse2.output_min);
241 const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse2.output_max);
242 vout01234567 = _mm_min_epi16(_mm_max_epi16(vout01234567, voutput_min), voutput_max);
243
244 __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567);
245
246 _mm_storel_epi64((__m128i*) output, vout0123456701234567);
247 output += 8;
248 }
249 if XNN_UNLIKELY(c != 0) {
250 {
251 __m128i vacc0123 = _mm_loadu_si128((const __m128i*) w);
252 __m128i vacc4567 = _mm_loadu_si128((const __m128i*) ((uintptr_t) w + 4 * sizeof(int32_t)));
253
254
255 const __m128i vi0x01234567 = _mm_loadl_epi64((const __m128i*) i0);
256 const __m128i vxi0x01234567 = _mm_cvtepi8_epi16(vi0x01234567);
257 const __m128i vk0x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 0 * sizeof(int8_t)));
258 const __m128i vxk0x01234567 = _mm_cvtepi8_epi16(vk0x01234567);
259
260
261 const __m128i vp0x01234567lo = _mm_mullo_epi16(vxi0x01234567, vxk0x01234567);
262 const __m128i vp0x01234567hi = _mm_mulhi_epi16(vxi0x01234567, vxk0x01234567);
263
264 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp0x01234567lo, vp0x01234567hi));
265 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp0x01234567lo, vp0x01234567hi));
266
267 const __m128i vi1x01234567 = _mm_loadl_epi64((const __m128i*) i1);
268 const __m128i vxi1x01234567 = _mm_cvtepi8_epi16(vi1x01234567);
269 const __m128i vk1x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 8 * sizeof(int8_t)));
270 const __m128i vxk1x01234567 = _mm_cvtepi8_epi16(vk1x01234567);
271
272
273 const __m128i vp1x01234567lo = _mm_mullo_epi16(vxi1x01234567, vxk1x01234567);
274 const __m128i vp1x01234567hi = _mm_mulhi_epi16(vxi1x01234567, vxk1x01234567);
275
276 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp1x01234567lo, vp1x01234567hi));
277 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp1x01234567lo, vp1x01234567hi));
278
279 const __m128i vi2x01234567 = _mm_loadl_epi64((const __m128i*) i2);
280 const __m128i vxi2x01234567 = _mm_cvtepi8_epi16(vi2x01234567);
281 const __m128i vk2x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 16 * sizeof(int8_t)));
282 const __m128i vxk2x01234567 = _mm_cvtepi8_epi16(vk2x01234567);
283
284
285 const __m128i vp2x01234567lo = _mm_mullo_epi16(vxi2x01234567, vxk2x01234567);
286 const __m128i vp2x01234567hi = _mm_mulhi_epi16(vxi2x01234567, vxk2x01234567);
287
288 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp2x01234567lo, vp2x01234567hi));
289 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp2x01234567lo, vp2x01234567hi));
290
291 const __m128i vi3x01234567 = _mm_loadl_epi64((const __m128i*) i3);
292 const __m128i vxi3x01234567 = _mm_cvtepi8_epi16(vi3x01234567);
293 const __m128i vk3x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 24 * sizeof(int8_t)));
294 const __m128i vxk3x01234567 = _mm_cvtepi8_epi16(vk3x01234567);
295
296
297 const __m128i vp3x01234567lo = _mm_mullo_epi16(vxi3x01234567, vxk3x01234567);
298 const __m128i vp3x01234567hi = _mm_mulhi_epi16(vxi3x01234567, vxk3x01234567);
299
300 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp3x01234567lo, vp3x01234567hi));
301 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp3x01234567lo, vp3x01234567hi));
302
303 const __m128i vi4x01234567 = _mm_loadl_epi64((const __m128i*) i4);
304 const __m128i vxi4x01234567 = _mm_cvtepi8_epi16(vi4x01234567);
305 const __m128i vk4x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 32 * sizeof(int8_t)));
306 const __m128i vxk4x01234567 = _mm_cvtepi8_epi16(vk4x01234567);
307
308
309 const __m128i vp4x01234567lo = _mm_mullo_epi16(vxi4x01234567, vxk4x01234567);
310 const __m128i vp4x01234567hi = _mm_mulhi_epi16(vxi4x01234567, vxk4x01234567);
311
312 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp4x01234567lo, vp4x01234567hi));
313 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp4x01234567lo, vp4x01234567hi));
314
315 const __m128i vi5x01234567 = _mm_loadl_epi64((const __m128i*) i5);
316 const __m128i vxi5x01234567 = _mm_cvtepi8_epi16(vi5x01234567);
317 const __m128i vk5x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 40 * sizeof(int8_t)));
318 const __m128i vxk5x01234567 = _mm_cvtepi8_epi16(vk5x01234567);
319
320
321 const __m128i vp5x01234567lo = _mm_mullo_epi16(vxi5x01234567, vxk5x01234567);
322 const __m128i vp5x01234567hi = _mm_mulhi_epi16(vxi5x01234567, vxk5x01234567);
323
324 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp5x01234567lo, vp5x01234567hi));
325 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp5x01234567lo, vp5x01234567hi));
326
327 const __m128i vi6x01234567 = _mm_loadl_epi64((const __m128i*) i6);
328 const __m128i vxi6x01234567 = _mm_cvtepi8_epi16(vi6x01234567);
329 const __m128i vk6x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 48 * sizeof(int8_t)));
330 const __m128i vxk6x01234567 = _mm_cvtepi8_epi16(vk6x01234567);
331
332
333 const __m128i vp6x01234567lo = _mm_mullo_epi16(vxi6x01234567, vxk6x01234567);
334 const __m128i vp6x01234567hi = _mm_mulhi_epi16(vxi6x01234567, vxk6x01234567);
335
336 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp6x01234567lo, vp6x01234567hi));
337 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp6x01234567lo, vp6x01234567hi));
338
339 const __m128i vi7x01234567 = _mm_loadl_epi64((const __m128i*) i7);
340 const __m128i vxi7x01234567 = _mm_cvtepi8_epi16(vi7x01234567);
341 const __m128i vk7x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 56 * sizeof(int8_t)));
342 const __m128i vxk7x01234567 = _mm_cvtepi8_epi16(vk7x01234567);
343
344
345 const __m128i vp7x01234567lo = _mm_mullo_epi16(vxi7x01234567, vxk7x01234567);
346 const __m128i vp7x01234567hi = _mm_mulhi_epi16(vxi7x01234567, vxk7x01234567);
347
348 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp7x01234567lo, vp7x01234567hi));
349 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp7x01234567lo, vp7x01234567hi));
350
351 const __m128i vi8x01234567 = _mm_loadl_epi64((const __m128i*) i8);
352 const __m128i vxi8x01234567 = _mm_cvtepi8_epi16(vi8x01234567);
353 const __m128i vk8x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 64 * sizeof(int8_t)));
354 const __m128i vxk8x01234567 = _mm_cvtepi8_epi16(vk8x01234567);
355
356
357 const __m128i vp8x01234567lo = _mm_mullo_epi16(vxi8x01234567, vxk8x01234567);
358 const __m128i vp8x01234567hi = _mm_mulhi_epi16(vxi8x01234567, vxk8x01234567);
359
360 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp8x01234567lo, vp8x01234567hi));
361 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp8x01234567lo, vp8x01234567hi));
362
363
364 const __m128i vmultiplier = _mm_load_si128((const __m128i*) params->sse2.multiplier);
365 const __m128i vrounding = _mm_load_si128((const __m128i*) params->sse2.rounding);
366
367 const __m128i vacc13 = _mm_shuffle_epi32(vacc0123, _MM_SHUFFLE(3, 3, 1, 1));
368 const __m128i vacc57 = _mm_shuffle_epi32(vacc4567, _MM_SHUFFLE(3, 3, 1, 1));
369
370 const __m128i vprod02 = _mm_add_epi64(_mm_mul_epi32(vacc0123, vmultiplier), vrounding);
371 const __m128i vprod46 = _mm_add_epi64(_mm_mul_epi32(vacc4567, vmultiplier), vrounding);
372
373 const __m128i vprod13 = _mm_add_epi64(_mm_mul_epi32(vacc13, vmultiplier), vrounding);
374 const __m128i vprod57 = _mm_add_epi64(_mm_mul_epi32(vacc57, vmultiplier), vrounding);
375
376 const __m128i vq31prod02 = _mm_srli_epi64(vprod02, 31);
377 const __m128i vq31prod13 = _mm_add_epi64(vprod13, vprod13);
378 const __m128i vq31prod46 = _mm_srli_epi64(vprod46, 31);
379 const __m128i vq31prod57 = _mm_add_epi64(vprod57, vprod57);
380
381 const __m128i vq31prod0123 = _mm_blend_epi16(vq31prod02, vq31prod13, 0xCC);
382 const __m128i vq31prod4567 = _mm_blend_epi16(vq31prod46, vq31prod57, 0xCC);
383
384 const __m128i vremainder_mask = _mm_load_si128((const __m128i*) params->sse2.remainder_mask);
385 const __m128i vrem0123 =
386 _mm_add_epi32(_mm_and_si128(vq31prod0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vq31prod0123));
387 const __m128i vrem4567 =
388 _mm_add_epi32(_mm_and_si128(vq31prod4567, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vq31prod4567));
389
390 const __m128i vremainder_threshold = _mm_load_si128((const __m128i*) params->sse2.remainder_threshold);
391 const __m128i vshift = _mm_load_si128((const __m128i*) params->sse2.shift);
392 vacc0123 =
393 _mm_sub_epi32(_mm_sra_epi32(vq31prod0123, vshift), _mm_cmpgt_epi32(vrem0123, vremainder_threshold));
394 vacc4567 =
395 _mm_sub_epi32(_mm_sra_epi32(vq31prod4567, vshift), _mm_cmpgt_epi32(vrem4567, vremainder_threshold));
396
397 const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse2.output_zero_point);
398 __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
399
400 const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse2.output_min);
401 const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse2.output_max);
402 vout01234567 = _mm_min_epi16(_mm_max_epi16(vout01234567, voutput_min), voutput_max);
403
404 __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567);
405
406 if (c & 4) {
407 *((uint32_t*) output) = (uint32_t) _mm_cvtsi128_si32(vout0123456701234567);
408 vout0123456701234567 = _mm_srli_epi64(vout0123456701234567, 32);
409 output += 4;
410 }
411 if (c & 2) {
412 *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(vout0123456701234567, 0);
413 vout0123456701234567 = _mm_srli_epi32(vout0123456701234567, 16);
414 output += 2;
415 }
416 if (c & 1) {
417 *output = (int8_t) _mm_extract_epi8(vout0123456701234567, 0);
418 output += 1;
419 }
420 }
421 }
422
423 output = (int8_t*) ((uintptr_t) output + output_increment);
424 } while (--output_width != 0);
425 }
426