blob: ba6f0573d7f0f489f980f137c0d0b1e3101c0038 [file] [log] [blame]
Marat Dukhan4ed14882021-05-12 17:50:40 -07001// 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 <tmmintrin.h>
13
14#include <xnnpack/dwconv.h>
15
16
Marat Dukhanb07c26a2021-05-24 19:44:51 -070017void xnn_qs8_dwconv_minmax_gemmlowp_ukernel_up8x25__ssse3_mul16(
Marat Dukhan4ed14882021-05-12 17:50:40 -070018 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,
Marat Dukhane3d17bf2021-05-24 22:22:43 -070027 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
Marat Dukhan4ed14882021-05-12 17:50:40 -070028{
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 const int8_t* i9 = input[9];
79 assert(i9 != NULL);
80 if XNN_UNPREDICTABLE(i9 != zero) {
81 i9 = (const int8_t*) ((uintptr_t) i9 + input_offset);
82 }
83 const int8_t* i10 = input[10];
84 assert(i10 != NULL);
85 if XNN_UNPREDICTABLE(i10 != zero) {
86 i10 = (const int8_t*) ((uintptr_t) i10 + input_offset);
87 }
88 const int8_t* i11 = input[11];
89 assert(i11 != NULL);
90 if XNN_UNPREDICTABLE(i11 != zero) {
91 i11 = (const int8_t*) ((uintptr_t) i11 + input_offset);
92 }
93 const int8_t* i12 = input[12];
94 assert(i12 != NULL);
95 if XNN_UNPREDICTABLE(i12 != zero) {
96 i12 = (const int8_t*) ((uintptr_t) i12 + input_offset);
97 }
98 const int8_t* i13 = input[13];
99 assert(i13 != NULL);
100 if XNN_UNPREDICTABLE(i13 != zero) {
101 i13 = (const int8_t*) ((uintptr_t) i13 + input_offset);
102 }
103 const int8_t* i14 = input[14];
104 assert(i14 != NULL);
105 if XNN_UNPREDICTABLE(i14 != zero) {
106 i14 = (const int8_t*) ((uintptr_t) i14 + input_offset);
107 }
108 const int8_t* i15 = input[15];
109 assert(i15 != NULL);
110 if XNN_UNPREDICTABLE(i15 != zero) {
111 i15 = (const int8_t*) ((uintptr_t) i15 + input_offset);
112 }
113 const int8_t* i16 = input[16];
114 assert(i16 != NULL);
115 if XNN_UNPREDICTABLE(i16 != zero) {
116 i16 = (const int8_t*) ((uintptr_t) i16 + input_offset);
117 }
118 const int8_t* i17 = input[17];
119 assert(i17 != NULL);
120 if XNN_UNPREDICTABLE(i17 != zero) {
121 i17 = (const int8_t*) ((uintptr_t) i17 + input_offset);
122 }
123 const int8_t* i18 = input[18];
124 assert(i18 != NULL);
125 if XNN_UNPREDICTABLE(i18 != zero) {
126 i18 = (const int8_t*) ((uintptr_t) i18 + input_offset);
127 }
128 const int8_t* i19 = input[19];
129 assert(i19 != NULL);
130 if XNN_UNPREDICTABLE(i19 != zero) {
131 i19 = (const int8_t*) ((uintptr_t) i19 + input_offset);
132 }
133 const int8_t* i20 = input[20];
134 assert(i20 != NULL);
135 if XNN_UNPREDICTABLE(i20 != zero) {
136 i20 = (const int8_t*) ((uintptr_t) i20 + input_offset);
137 }
138 const int8_t* i21 = input[21];
139 assert(i21 != NULL);
140 if XNN_UNPREDICTABLE(i21 != zero) {
141 i21 = (const int8_t*) ((uintptr_t) i21 + input_offset);
142 }
143 const int8_t* i22 = input[22];
144 assert(i22 != NULL);
145 if XNN_UNPREDICTABLE(i22 != zero) {
146 i22 = (const int8_t*) ((uintptr_t) i22 + input_offset);
147 }
148 const int8_t* i23 = input[23];
149 assert(i23 != NULL);
150 if XNN_UNPREDICTABLE(i23 != zero) {
151 i23 = (const int8_t*) ((uintptr_t) i23 + input_offset);
152 }
153 const int8_t* i24 = input[24];
154 assert(i24 != NULL);
155 if XNN_UNPREDICTABLE(i24 != zero) {
156 i24 = (const int8_t*) ((uintptr_t) i24 + input_offset);
157 }
158 input = (const int8_t**) ((uintptr_t) input + input_stride);
159
160 size_t c = channels;
161 const void* w = weights;
162 for (; c >= 8; c -= 8) {
163 __m128i vacc0123 = _mm_loadu_si128((const __m128i*) w);
Marat Dukhane5eee462021-07-01 19:34:39 -0700164 __m128i vacc4567 = _mm_loadu_si128((const __m128i*) ((const int32_t*) w + 4));
Marat Dukhan4ed14882021-05-12 17:50:40 -0700165
166
167 const __m128i vi0x01234567 = _mm_loadl_epi64((const __m128i*) i0);
168 const __m128i vk0x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 0 * sizeof(int8_t)));
169 i0 += 8;
170
Marat Dukhane5eee462021-07-01 19:34:39 -0700171 const __m128i vxi0x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi0x01234567, vi0x01234567), 8);
172 const __m128i vxk0x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk0x01234567, vk0x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700173
174 const __m128i vp0x01234567lo = _mm_mullo_epi16(vxi0x01234567, vxk0x01234567);
175 const __m128i vp0x01234567hi = _mm_mulhi_epi16(vxi0x01234567, vxk0x01234567);
176
177 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp0x01234567lo, vp0x01234567hi));
178 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp0x01234567lo, vp0x01234567hi));
179
180 const __m128i vi1x01234567 = _mm_loadl_epi64((const __m128i*) i1);
181 const __m128i vk1x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 8 * sizeof(int8_t)));
182 i1 += 8;
183
Marat Dukhane5eee462021-07-01 19:34:39 -0700184 const __m128i vxi1x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi1x01234567, vi1x01234567), 8);
185 const __m128i vxk1x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk1x01234567, vk1x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700186
187 const __m128i vp1x01234567lo = _mm_mullo_epi16(vxi1x01234567, vxk1x01234567);
188 const __m128i vp1x01234567hi = _mm_mulhi_epi16(vxi1x01234567, vxk1x01234567);
189
190 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp1x01234567lo, vp1x01234567hi));
191 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp1x01234567lo, vp1x01234567hi));
192
193 const __m128i vi2x01234567 = _mm_loadl_epi64((const __m128i*) i2);
194 const __m128i vk2x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 16 * sizeof(int8_t)));
195 i2 += 8;
196
Marat Dukhane5eee462021-07-01 19:34:39 -0700197 const __m128i vxi2x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi2x01234567, vi2x01234567), 8);
198 const __m128i vxk2x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk2x01234567, vk2x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700199
200 const __m128i vp2x01234567lo = _mm_mullo_epi16(vxi2x01234567, vxk2x01234567);
201 const __m128i vp2x01234567hi = _mm_mulhi_epi16(vxi2x01234567, vxk2x01234567);
202
203 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp2x01234567lo, vp2x01234567hi));
204 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp2x01234567lo, vp2x01234567hi));
205
206 const __m128i vi3x01234567 = _mm_loadl_epi64((const __m128i*) i3);
207 const __m128i vk3x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 24 * sizeof(int8_t)));
208 i3 += 8;
209
Marat Dukhane5eee462021-07-01 19:34:39 -0700210 const __m128i vxi3x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi3x01234567, vi3x01234567), 8);
211 const __m128i vxk3x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk3x01234567, vk3x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700212
213 const __m128i vp3x01234567lo = _mm_mullo_epi16(vxi3x01234567, vxk3x01234567);
214 const __m128i vp3x01234567hi = _mm_mulhi_epi16(vxi3x01234567, vxk3x01234567);
215
216 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp3x01234567lo, vp3x01234567hi));
217 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp3x01234567lo, vp3x01234567hi));
218
219 const __m128i vi4x01234567 = _mm_loadl_epi64((const __m128i*) i4);
220 const __m128i vk4x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 32 * sizeof(int8_t)));
221 i4 += 8;
222
Marat Dukhane5eee462021-07-01 19:34:39 -0700223 const __m128i vxi4x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi4x01234567, vi4x01234567), 8);
224 const __m128i vxk4x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk4x01234567, vk4x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700225
226 const __m128i vp4x01234567lo = _mm_mullo_epi16(vxi4x01234567, vxk4x01234567);
227 const __m128i vp4x01234567hi = _mm_mulhi_epi16(vxi4x01234567, vxk4x01234567);
228
229 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp4x01234567lo, vp4x01234567hi));
230 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp4x01234567lo, vp4x01234567hi));
231
232 const __m128i vi5x01234567 = _mm_loadl_epi64((const __m128i*) i5);
233 const __m128i vk5x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 40 * sizeof(int8_t)));
234 i5 += 8;
235
Marat Dukhane5eee462021-07-01 19:34:39 -0700236 const __m128i vxi5x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi5x01234567, vi5x01234567), 8);
237 const __m128i vxk5x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk5x01234567, vk5x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700238
239 const __m128i vp5x01234567lo = _mm_mullo_epi16(vxi5x01234567, vxk5x01234567);
240 const __m128i vp5x01234567hi = _mm_mulhi_epi16(vxi5x01234567, vxk5x01234567);
241
242 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp5x01234567lo, vp5x01234567hi));
243 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp5x01234567lo, vp5x01234567hi));
244
245 const __m128i vi6x01234567 = _mm_loadl_epi64((const __m128i*) i6);
246 const __m128i vk6x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 48 * sizeof(int8_t)));
247 i6 += 8;
248
Marat Dukhane5eee462021-07-01 19:34:39 -0700249 const __m128i vxi6x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi6x01234567, vi6x01234567), 8);
250 const __m128i vxk6x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk6x01234567, vk6x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700251
252 const __m128i vp6x01234567lo = _mm_mullo_epi16(vxi6x01234567, vxk6x01234567);
253 const __m128i vp6x01234567hi = _mm_mulhi_epi16(vxi6x01234567, vxk6x01234567);
254
255 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp6x01234567lo, vp6x01234567hi));
256 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp6x01234567lo, vp6x01234567hi));
257
258 const __m128i vi7x01234567 = _mm_loadl_epi64((const __m128i*) i7);
259 const __m128i vk7x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 56 * sizeof(int8_t)));
260 i7 += 8;
261
Marat Dukhane5eee462021-07-01 19:34:39 -0700262 const __m128i vxi7x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi7x01234567, vi7x01234567), 8);
263 const __m128i vxk7x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk7x01234567, vk7x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700264
265 const __m128i vp7x01234567lo = _mm_mullo_epi16(vxi7x01234567, vxk7x01234567);
266 const __m128i vp7x01234567hi = _mm_mulhi_epi16(vxi7x01234567, vxk7x01234567);
267
268 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp7x01234567lo, vp7x01234567hi));
269 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp7x01234567lo, vp7x01234567hi));
270
271 const __m128i vi8x01234567 = _mm_loadl_epi64((const __m128i*) i8);
272 const __m128i vk8x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 64 * sizeof(int8_t)));
273 i8 += 8;
274
Marat Dukhane5eee462021-07-01 19:34:39 -0700275 const __m128i vxi8x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi8x01234567, vi8x01234567), 8);
276 const __m128i vxk8x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk8x01234567, vk8x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700277
278 const __m128i vp8x01234567lo = _mm_mullo_epi16(vxi8x01234567, vxk8x01234567);
279 const __m128i vp8x01234567hi = _mm_mulhi_epi16(vxi8x01234567, vxk8x01234567);
280
281 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp8x01234567lo, vp8x01234567hi));
282 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp8x01234567lo, vp8x01234567hi));
283
284 const __m128i vi9x01234567 = _mm_loadl_epi64((const __m128i*) i9);
285 const __m128i vk9x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 72 * sizeof(int8_t)));
286 i9 += 8;
287
Marat Dukhane5eee462021-07-01 19:34:39 -0700288 const __m128i vxi9x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi9x01234567, vi9x01234567), 8);
289 const __m128i vxk9x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk9x01234567, vk9x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700290
291 const __m128i vp9x01234567lo = _mm_mullo_epi16(vxi9x01234567, vxk9x01234567);
292 const __m128i vp9x01234567hi = _mm_mulhi_epi16(vxi9x01234567, vxk9x01234567);
293
294 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp9x01234567lo, vp9x01234567hi));
295 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp9x01234567lo, vp9x01234567hi));
296
297 const __m128i vi10x01234567 = _mm_loadl_epi64((const __m128i*) i10);
298 const __m128i vk10x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 80 * sizeof(int8_t)));
299 i10 += 8;
300
Marat Dukhane5eee462021-07-01 19:34:39 -0700301 const __m128i vxi10x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi10x01234567, vi10x01234567), 8);
302 const __m128i vxk10x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk10x01234567, vk10x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700303
304 const __m128i vp10x01234567lo = _mm_mullo_epi16(vxi10x01234567, vxk10x01234567);
305 const __m128i vp10x01234567hi = _mm_mulhi_epi16(vxi10x01234567, vxk10x01234567);
306
307 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp10x01234567lo, vp10x01234567hi));
308 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp10x01234567lo, vp10x01234567hi));
309
310 const __m128i vi11x01234567 = _mm_loadl_epi64((const __m128i*) i11);
311 const __m128i vk11x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 88 * sizeof(int8_t)));
312 i11 += 8;
313
Marat Dukhane5eee462021-07-01 19:34:39 -0700314 const __m128i vxi11x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi11x01234567, vi11x01234567), 8);
315 const __m128i vxk11x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk11x01234567, vk11x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700316
317 const __m128i vp11x01234567lo = _mm_mullo_epi16(vxi11x01234567, vxk11x01234567);
318 const __m128i vp11x01234567hi = _mm_mulhi_epi16(vxi11x01234567, vxk11x01234567);
319
320 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp11x01234567lo, vp11x01234567hi));
321 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp11x01234567lo, vp11x01234567hi));
322
323 const __m128i vi12x01234567 = _mm_loadl_epi64((const __m128i*) i12);
324 const __m128i vk12x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 96 * sizeof(int8_t)));
325 i12 += 8;
326
Marat Dukhane5eee462021-07-01 19:34:39 -0700327 const __m128i vxi12x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi12x01234567, vi12x01234567), 8);
328 const __m128i vxk12x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk12x01234567, vk12x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700329
330 const __m128i vp12x01234567lo = _mm_mullo_epi16(vxi12x01234567, vxk12x01234567);
331 const __m128i vp12x01234567hi = _mm_mulhi_epi16(vxi12x01234567, vxk12x01234567);
332
333 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp12x01234567lo, vp12x01234567hi));
334 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp12x01234567lo, vp12x01234567hi));
335
336 const __m128i vi13x01234567 = _mm_loadl_epi64((const __m128i*) i13);
337 const __m128i vk13x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 104 * sizeof(int8_t)));
338 i13 += 8;
339
Marat Dukhane5eee462021-07-01 19:34:39 -0700340 const __m128i vxi13x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi13x01234567, vi13x01234567), 8);
341 const __m128i vxk13x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk13x01234567, vk13x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700342
343 const __m128i vp13x01234567lo = _mm_mullo_epi16(vxi13x01234567, vxk13x01234567);
344 const __m128i vp13x01234567hi = _mm_mulhi_epi16(vxi13x01234567, vxk13x01234567);
345
346 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp13x01234567lo, vp13x01234567hi));
347 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp13x01234567lo, vp13x01234567hi));
348
349 const __m128i vi14x01234567 = _mm_loadl_epi64((const __m128i*) i14);
350 const __m128i vk14x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 112 * sizeof(int8_t)));
351 i14 += 8;
352
Marat Dukhane5eee462021-07-01 19:34:39 -0700353 const __m128i vxi14x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi14x01234567, vi14x01234567), 8);
354 const __m128i vxk14x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk14x01234567, vk14x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700355
356 const __m128i vp14x01234567lo = _mm_mullo_epi16(vxi14x01234567, vxk14x01234567);
357 const __m128i vp14x01234567hi = _mm_mulhi_epi16(vxi14x01234567, vxk14x01234567);
358
359 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp14x01234567lo, vp14x01234567hi));
360 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp14x01234567lo, vp14x01234567hi));
361
362 const __m128i vi15x01234567 = _mm_loadl_epi64((const __m128i*) i15);
363 const __m128i vk15x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 120 * sizeof(int8_t)));
364 i15 += 8;
365
Marat Dukhane5eee462021-07-01 19:34:39 -0700366 const __m128i vxi15x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi15x01234567, vi15x01234567), 8);
367 const __m128i vxk15x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk15x01234567, vk15x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700368
369 const __m128i vp15x01234567lo = _mm_mullo_epi16(vxi15x01234567, vxk15x01234567);
370 const __m128i vp15x01234567hi = _mm_mulhi_epi16(vxi15x01234567, vxk15x01234567);
371
372 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp15x01234567lo, vp15x01234567hi));
373 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp15x01234567lo, vp15x01234567hi));
374
375 const __m128i vi16x01234567 = _mm_loadl_epi64((const __m128i*) i16);
376 const __m128i vk16x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 128 * sizeof(int8_t)));
377 i16 += 8;
378
Marat Dukhane5eee462021-07-01 19:34:39 -0700379 const __m128i vxi16x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi16x01234567, vi16x01234567), 8);
380 const __m128i vxk16x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk16x01234567, vk16x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700381
382 const __m128i vp16x01234567lo = _mm_mullo_epi16(vxi16x01234567, vxk16x01234567);
383 const __m128i vp16x01234567hi = _mm_mulhi_epi16(vxi16x01234567, vxk16x01234567);
384
385 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp16x01234567lo, vp16x01234567hi));
386 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp16x01234567lo, vp16x01234567hi));
387
388 const __m128i vi17x01234567 = _mm_loadl_epi64((const __m128i*) i17);
389 const __m128i vk17x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 136 * sizeof(int8_t)));
390 i17 += 8;
391
Marat Dukhane5eee462021-07-01 19:34:39 -0700392 const __m128i vxi17x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi17x01234567, vi17x01234567), 8);
393 const __m128i vxk17x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk17x01234567, vk17x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700394
395 const __m128i vp17x01234567lo = _mm_mullo_epi16(vxi17x01234567, vxk17x01234567);
396 const __m128i vp17x01234567hi = _mm_mulhi_epi16(vxi17x01234567, vxk17x01234567);
397
398 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp17x01234567lo, vp17x01234567hi));
399 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp17x01234567lo, vp17x01234567hi));
400
401 const __m128i vi18x01234567 = _mm_loadl_epi64((const __m128i*) i18);
402 const __m128i vk18x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 144 * sizeof(int8_t)));
403 i18 += 8;
404
Marat Dukhane5eee462021-07-01 19:34:39 -0700405 const __m128i vxi18x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi18x01234567, vi18x01234567), 8);
406 const __m128i vxk18x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk18x01234567, vk18x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700407
408 const __m128i vp18x01234567lo = _mm_mullo_epi16(vxi18x01234567, vxk18x01234567);
409 const __m128i vp18x01234567hi = _mm_mulhi_epi16(vxi18x01234567, vxk18x01234567);
410
411 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp18x01234567lo, vp18x01234567hi));
412 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp18x01234567lo, vp18x01234567hi));
413
414 const __m128i vi19x01234567 = _mm_loadl_epi64((const __m128i*) i19);
415 const __m128i vk19x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 152 * sizeof(int8_t)));
416 i19 += 8;
417
Marat Dukhane5eee462021-07-01 19:34:39 -0700418 const __m128i vxi19x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi19x01234567, vi19x01234567), 8);
419 const __m128i vxk19x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk19x01234567, vk19x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700420
421 const __m128i vp19x01234567lo = _mm_mullo_epi16(vxi19x01234567, vxk19x01234567);
422 const __m128i vp19x01234567hi = _mm_mulhi_epi16(vxi19x01234567, vxk19x01234567);
423
424 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp19x01234567lo, vp19x01234567hi));
425 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp19x01234567lo, vp19x01234567hi));
426
427 const __m128i vi20x01234567 = _mm_loadl_epi64((const __m128i*) i20);
428 const __m128i vk20x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 160 * sizeof(int8_t)));
429 i20 += 8;
430
Marat Dukhane5eee462021-07-01 19:34:39 -0700431 const __m128i vxi20x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi20x01234567, vi20x01234567), 8);
432 const __m128i vxk20x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk20x01234567, vk20x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700433
434 const __m128i vp20x01234567lo = _mm_mullo_epi16(vxi20x01234567, vxk20x01234567);
435 const __m128i vp20x01234567hi = _mm_mulhi_epi16(vxi20x01234567, vxk20x01234567);
436
437 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp20x01234567lo, vp20x01234567hi));
438 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp20x01234567lo, vp20x01234567hi));
439
440 const __m128i vi21x01234567 = _mm_loadl_epi64((const __m128i*) i21);
441 const __m128i vk21x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 168 * sizeof(int8_t)));
442 i21 += 8;
443
Marat Dukhane5eee462021-07-01 19:34:39 -0700444 const __m128i vxi21x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi21x01234567, vi21x01234567), 8);
445 const __m128i vxk21x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk21x01234567, vk21x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700446
447 const __m128i vp21x01234567lo = _mm_mullo_epi16(vxi21x01234567, vxk21x01234567);
448 const __m128i vp21x01234567hi = _mm_mulhi_epi16(vxi21x01234567, vxk21x01234567);
449
450 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp21x01234567lo, vp21x01234567hi));
451 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp21x01234567lo, vp21x01234567hi));
452
453 const __m128i vi22x01234567 = _mm_loadl_epi64((const __m128i*) i22);
454 const __m128i vk22x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 176 * sizeof(int8_t)));
455 i22 += 8;
456
Marat Dukhane5eee462021-07-01 19:34:39 -0700457 const __m128i vxi22x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi22x01234567, vi22x01234567), 8);
458 const __m128i vxk22x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk22x01234567, vk22x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700459
460 const __m128i vp22x01234567lo = _mm_mullo_epi16(vxi22x01234567, vxk22x01234567);
461 const __m128i vp22x01234567hi = _mm_mulhi_epi16(vxi22x01234567, vxk22x01234567);
462
463 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp22x01234567lo, vp22x01234567hi));
464 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp22x01234567lo, vp22x01234567hi));
465
466 const __m128i vi23x01234567 = _mm_loadl_epi64((const __m128i*) i23);
467 const __m128i vk23x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 184 * sizeof(int8_t)));
468 i23 += 8;
469
Marat Dukhane5eee462021-07-01 19:34:39 -0700470 const __m128i vxi23x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi23x01234567, vi23x01234567), 8);
471 const __m128i vxk23x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk23x01234567, vk23x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700472
473 const __m128i vp23x01234567lo = _mm_mullo_epi16(vxi23x01234567, vxk23x01234567);
474 const __m128i vp23x01234567hi = _mm_mulhi_epi16(vxi23x01234567, vxk23x01234567);
475
476 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp23x01234567lo, vp23x01234567hi));
477 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp23x01234567lo, vp23x01234567hi));
478
479 const __m128i vi24x01234567 = _mm_loadl_epi64((const __m128i*) i24);
480 const __m128i vk24x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 192 * sizeof(int8_t)));
481 i24 += 8;
482
Marat Dukhane5eee462021-07-01 19:34:39 -0700483 const __m128i vxi24x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi24x01234567, vi24x01234567), 8);
484 const __m128i vxk24x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk24x01234567, vk24x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700485
486 const __m128i vp24x01234567lo = _mm_mullo_epi16(vxi24x01234567, vxk24x01234567);
487 const __m128i vp24x01234567hi = _mm_mulhi_epi16(vxi24x01234567, vxk24x01234567);
488
489 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp24x01234567lo, vp24x01234567hi));
490 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp24x01234567lo, vp24x01234567hi));
491
492 w = (const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 200 * sizeof(int8_t));
493
Marat Dukhan9b474cf2021-05-25 16:37:48 -0700494 const __m128i vmultiplier = _mm_load_si128((const __m128i*) params->gemmlowp_sse2.multiplier);
495 const __m128i vrounding = _mm_load_si128((const __m128i*) params->gemmlowp_sse2.rounding);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700496
497 const __m128i vnmask0123 = _mm_cmpgt_epi32(_mm_setzero_si128(), vacc0123);
498 const __m128i vnmask4567 = _mm_cmpgt_epi32(_mm_setzero_si128(), vacc4567);
499
500 const __m128i vabsacc0123 = _mm_abs_epi32(vacc0123);
501 const __m128i vabsacc4567 = _mm_abs_epi32(vacc4567);
502
503 const __m128i vabsacc13 = _mm_shuffle_epi32(vabsacc0123, _MM_SHUFFLE(3, 3, 1, 1));
504 const __m128i vabsprod02 = _mm_mul_epu32(vabsacc0123, vmultiplier);
505 const __m128i vabsprod13 = _mm_mul_epu32(vabsacc13, vmultiplier);
506 const __m128i vabsacc57 = _mm_shuffle_epi32(vabsacc4567, _MM_SHUFFLE(3, 3, 1, 1));
507 const __m128i vabsprod46 = _mm_mul_epu32(vabsacc4567, vmultiplier);
508 const __m128i vabsprod57 = _mm_mul_epu32(vabsacc57, vmultiplier);
509
510 const __m128i vnmask02 = _mm_shuffle_epi32(vnmask0123, _MM_SHUFFLE(2, 2, 0, 0));
511 const __m128i vnmask13 = _mm_shuffle_epi32(vnmask0123, _MM_SHUFFLE(3, 3, 1, 1));
512 const __m128i vnmask46 = _mm_shuffle_epi32(vnmask4567, _MM_SHUFFLE(2, 2, 0, 0));
513 const __m128i vnmask57 = _mm_shuffle_epi32(vnmask4567, _MM_SHUFFLE(3, 3, 1, 1));
514
515 const __m128i vprod02 = _mm_sub_epi64(_mm_xor_si128(vabsprod02, vnmask02), vnmask02);
516 const __m128i vprod13 = _mm_sub_epi64(_mm_xor_si128(vabsprod13, vnmask13), vnmask13);
517 const __m128i vprod46 = _mm_sub_epi64(_mm_xor_si128(vabsprod46, vnmask46), vnmask46);
518 const __m128i vprod57 = _mm_sub_epi64(_mm_xor_si128(vabsprod57, vnmask57), vnmask57);
519
520 const __m128i vq31prod02 = _mm_srli_epi64(_mm_add_epi64(vprod02, vrounding), 31);
521 const __m128i vq31prod13 = _mm_srli_epi64(_mm_add_epi64(vprod13, vrounding), 31);
522 const __m128i vq31prod46 = _mm_srli_epi64(_mm_add_epi64(vprod46, vrounding), 31);
523 const __m128i vq31prod57 = _mm_srli_epi64(_mm_add_epi64(vprod57, vrounding), 31);
524
525 const __m128i vq31prod0213 = _mm_castps_si128(_mm_shuffle_ps(
526 _mm_castsi128_ps(vq31prod02), _mm_castsi128_ps(vq31prod13), _MM_SHUFFLE(2, 0, 2, 0)));
527 const __m128i vq31prod4657 = _mm_castps_si128(_mm_shuffle_ps(
528 _mm_castsi128_ps(vq31prod46), _mm_castsi128_ps(vq31prod57), _MM_SHUFFLE(2, 0, 2, 0)));
529
530 const __m128i vq31prod0123 = _mm_shuffle_epi32(vq31prod0213, _MM_SHUFFLE(3, 1, 2, 0));
531 const __m128i vq31prod4567 = _mm_shuffle_epi32(vq31prod4657, _MM_SHUFFLE(3, 1, 2, 0));
532
Marat Dukhan9b474cf2021-05-25 16:37:48 -0700533 const __m128i vremainder_mask = _mm_load_si128((const __m128i*) params->gemmlowp_sse2.remainder_mask);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700534 const __m128i vrem0123 =
535 _mm_add_epi32(_mm_and_si128(vq31prod0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vq31prod0123));
536 const __m128i vrem4567 =
537 _mm_add_epi32(_mm_and_si128(vq31prod4567, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vq31prod4567));
538
Marat Dukhan9b474cf2021-05-25 16:37:48 -0700539 const __m128i vremainder_threshold = _mm_load_si128((const __m128i*) params->gemmlowp_sse2.remainder_threshold);
540 const __m128i vshift = _mm_loadl_epi64((const __m128i*) params->gemmlowp_sse2.shift);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700541 vacc0123 =
542 _mm_sub_epi32(_mm_sra_epi32(vq31prod0123, vshift), _mm_cmpgt_epi32(vrem0123, vremainder_threshold));
543 vacc4567 =
544 _mm_sub_epi32(_mm_sra_epi32(vq31prod4567, vshift), _mm_cmpgt_epi32(vrem4567, vremainder_threshold));
545
Marat Dukhan9b474cf2021-05-25 16:37:48 -0700546 const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->gemmlowp_sse2.output_zero_point);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700547 __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
548
Marat Dukhan9b474cf2021-05-25 16:37:48 -0700549 const __m128i voutput_min = _mm_load_si128((const __m128i*) params->gemmlowp_sse2.output_min);
Marat Dukhan748fd122021-05-22 20:46:56 -0700550 vout01234567 = _mm_max_epi16(vout01234567, voutput_min);
551
Marat Dukhan9b474cf2021-05-25 16:37:48 -0700552 const __m128i voutput_max = _mm_load_si128((const __m128i*) params->gemmlowp_sse2.output_max);
Marat Dukhan748fd122021-05-22 20:46:56 -0700553 vout01234567 = _mm_min_epi16(vout01234567, voutput_max);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700554
555 __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567);
556
Marat Dukhan748fd122021-05-22 20:46:56 -0700557
Marat Dukhan4ed14882021-05-12 17:50:40 -0700558 _mm_storel_epi64((__m128i*) output, vout0123456701234567);
559 output += 8;
560 }
561 if XNN_UNLIKELY(c != 0) {
562 {
563 __m128i vacc0123 = _mm_loadu_si128((const __m128i*) w);
Marat Dukhane5eee462021-07-01 19:34:39 -0700564 __m128i vacc4567 = _mm_loadu_si128((const __m128i*) ((const int32_t*) w + 4));
Marat Dukhan4ed14882021-05-12 17:50:40 -0700565
566
567 const __m128i vi0x01234567 = _mm_loadl_epi64((const __m128i*) i0);
568 const __m128i vk0x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 0 * sizeof(int8_t)));
569
Marat Dukhane5eee462021-07-01 19:34:39 -0700570 const __m128i vxi0x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi0x01234567, vi0x01234567), 8);
571 const __m128i vxk0x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk0x01234567, vk0x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700572
573 const __m128i vp0x01234567lo = _mm_mullo_epi16(vxi0x01234567, vxk0x01234567);
574 const __m128i vp0x01234567hi = _mm_mulhi_epi16(vxi0x01234567, vxk0x01234567);
575
576 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp0x01234567lo, vp0x01234567hi));
577 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp0x01234567lo, vp0x01234567hi));
578
579 const __m128i vi1x01234567 = _mm_loadl_epi64((const __m128i*) i1);
580 const __m128i vk1x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 8 * sizeof(int8_t)));
581
Marat Dukhane5eee462021-07-01 19:34:39 -0700582 const __m128i vxi1x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi1x01234567, vi1x01234567), 8);
583 const __m128i vxk1x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk1x01234567, vk1x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700584
585 const __m128i vp1x01234567lo = _mm_mullo_epi16(vxi1x01234567, vxk1x01234567);
586 const __m128i vp1x01234567hi = _mm_mulhi_epi16(vxi1x01234567, vxk1x01234567);
587
588 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp1x01234567lo, vp1x01234567hi));
589 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp1x01234567lo, vp1x01234567hi));
590
591 const __m128i vi2x01234567 = _mm_loadl_epi64((const __m128i*) i2);
592 const __m128i vk2x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 16 * sizeof(int8_t)));
593
Marat Dukhane5eee462021-07-01 19:34:39 -0700594 const __m128i vxi2x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi2x01234567, vi2x01234567), 8);
595 const __m128i vxk2x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk2x01234567, vk2x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700596
597 const __m128i vp2x01234567lo = _mm_mullo_epi16(vxi2x01234567, vxk2x01234567);
598 const __m128i vp2x01234567hi = _mm_mulhi_epi16(vxi2x01234567, vxk2x01234567);
599
600 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp2x01234567lo, vp2x01234567hi));
601 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp2x01234567lo, vp2x01234567hi));
602
603 const __m128i vi3x01234567 = _mm_loadl_epi64((const __m128i*) i3);
604 const __m128i vk3x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 24 * sizeof(int8_t)));
605
Marat Dukhane5eee462021-07-01 19:34:39 -0700606 const __m128i vxi3x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi3x01234567, vi3x01234567), 8);
607 const __m128i vxk3x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk3x01234567, vk3x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700608
609 const __m128i vp3x01234567lo = _mm_mullo_epi16(vxi3x01234567, vxk3x01234567);
610 const __m128i vp3x01234567hi = _mm_mulhi_epi16(vxi3x01234567, vxk3x01234567);
611
612 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp3x01234567lo, vp3x01234567hi));
613 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp3x01234567lo, vp3x01234567hi));
614
615 const __m128i vi4x01234567 = _mm_loadl_epi64((const __m128i*) i4);
616 const __m128i vk4x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 32 * sizeof(int8_t)));
617
Marat Dukhane5eee462021-07-01 19:34:39 -0700618 const __m128i vxi4x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi4x01234567, vi4x01234567), 8);
619 const __m128i vxk4x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk4x01234567, vk4x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700620
621 const __m128i vp4x01234567lo = _mm_mullo_epi16(vxi4x01234567, vxk4x01234567);
622 const __m128i vp4x01234567hi = _mm_mulhi_epi16(vxi4x01234567, vxk4x01234567);
623
624 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp4x01234567lo, vp4x01234567hi));
625 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp4x01234567lo, vp4x01234567hi));
626
627 const __m128i vi5x01234567 = _mm_loadl_epi64((const __m128i*) i5);
628 const __m128i vk5x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 40 * sizeof(int8_t)));
629
Marat Dukhane5eee462021-07-01 19:34:39 -0700630 const __m128i vxi5x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi5x01234567, vi5x01234567), 8);
631 const __m128i vxk5x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk5x01234567, vk5x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700632
633 const __m128i vp5x01234567lo = _mm_mullo_epi16(vxi5x01234567, vxk5x01234567);
634 const __m128i vp5x01234567hi = _mm_mulhi_epi16(vxi5x01234567, vxk5x01234567);
635
636 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp5x01234567lo, vp5x01234567hi));
637 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp5x01234567lo, vp5x01234567hi));
638
639 const __m128i vi6x01234567 = _mm_loadl_epi64((const __m128i*) i6);
640 const __m128i vk6x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 48 * sizeof(int8_t)));
641
Marat Dukhane5eee462021-07-01 19:34:39 -0700642 const __m128i vxi6x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi6x01234567, vi6x01234567), 8);
643 const __m128i vxk6x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk6x01234567, vk6x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700644
645 const __m128i vp6x01234567lo = _mm_mullo_epi16(vxi6x01234567, vxk6x01234567);
646 const __m128i vp6x01234567hi = _mm_mulhi_epi16(vxi6x01234567, vxk6x01234567);
647
648 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp6x01234567lo, vp6x01234567hi));
649 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp6x01234567lo, vp6x01234567hi));
650
651 const __m128i vi7x01234567 = _mm_loadl_epi64((const __m128i*) i7);
652 const __m128i vk7x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 56 * sizeof(int8_t)));
653
Marat Dukhane5eee462021-07-01 19:34:39 -0700654 const __m128i vxi7x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi7x01234567, vi7x01234567), 8);
655 const __m128i vxk7x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk7x01234567, vk7x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700656
657 const __m128i vp7x01234567lo = _mm_mullo_epi16(vxi7x01234567, vxk7x01234567);
658 const __m128i vp7x01234567hi = _mm_mulhi_epi16(vxi7x01234567, vxk7x01234567);
659
660 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp7x01234567lo, vp7x01234567hi));
661 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp7x01234567lo, vp7x01234567hi));
662
663 const __m128i vi8x01234567 = _mm_loadl_epi64((const __m128i*) i8);
664 const __m128i vk8x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 64 * sizeof(int8_t)));
665
Marat Dukhane5eee462021-07-01 19:34:39 -0700666 const __m128i vxi8x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi8x01234567, vi8x01234567), 8);
667 const __m128i vxk8x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk8x01234567, vk8x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700668
669 const __m128i vp8x01234567lo = _mm_mullo_epi16(vxi8x01234567, vxk8x01234567);
670 const __m128i vp8x01234567hi = _mm_mulhi_epi16(vxi8x01234567, vxk8x01234567);
671
672 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp8x01234567lo, vp8x01234567hi));
673 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp8x01234567lo, vp8x01234567hi));
674
675 const __m128i vi9x01234567 = _mm_loadl_epi64((const __m128i*) i9);
676 const __m128i vk9x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 72 * sizeof(int8_t)));
677
Marat Dukhane5eee462021-07-01 19:34:39 -0700678 const __m128i vxi9x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi9x01234567, vi9x01234567), 8);
679 const __m128i vxk9x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk9x01234567, vk9x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700680
681 const __m128i vp9x01234567lo = _mm_mullo_epi16(vxi9x01234567, vxk9x01234567);
682 const __m128i vp9x01234567hi = _mm_mulhi_epi16(vxi9x01234567, vxk9x01234567);
683
684 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp9x01234567lo, vp9x01234567hi));
685 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp9x01234567lo, vp9x01234567hi));
686
687 const __m128i vi10x01234567 = _mm_loadl_epi64((const __m128i*) i10);
688 const __m128i vk10x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 80 * sizeof(int8_t)));
689
Marat Dukhane5eee462021-07-01 19:34:39 -0700690 const __m128i vxi10x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi10x01234567, vi10x01234567), 8);
691 const __m128i vxk10x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk10x01234567, vk10x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700692
693 const __m128i vp10x01234567lo = _mm_mullo_epi16(vxi10x01234567, vxk10x01234567);
694 const __m128i vp10x01234567hi = _mm_mulhi_epi16(vxi10x01234567, vxk10x01234567);
695
696 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp10x01234567lo, vp10x01234567hi));
697 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp10x01234567lo, vp10x01234567hi));
698
699 const __m128i vi11x01234567 = _mm_loadl_epi64((const __m128i*) i11);
700 const __m128i vk11x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 88 * sizeof(int8_t)));
701
Marat Dukhane5eee462021-07-01 19:34:39 -0700702 const __m128i vxi11x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi11x01234567, vi11x01234567), 8);
703 const __m128i vxk11x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk11x01234567, vk11x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700704
705 const __m128i vp11x01234567lo = _mm_mullo_epi16(vxi11x01234567, vxk11x01234567);
706 const __m128i vp11x01234567hi = _mm_mulhi_epi16(vxi11x01234567, vxk11x01234567);
707
708 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp11x01234567lo, vp11x01234567hi));
709 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp11x01234567lo, vp11x01234567hi));
710
711 const __m128i vi12x01234567 = _mm_loadl_epi64((const __m128i*) i12);
712 const __m128i vk12x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 96 * sizeof(int8_t)));
713
Marat Dukhane5eee462021-07-01 19:34:39 -0700714 const __m128i vxi12x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi12x01234567, vi12x01234567), 8);
715 const __m128i vxk12x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk12x01234567, vk12x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700716
717 const __m128i vp12x01234567lo = _mm_mullo_epi16(vxi12x01234567, vxk12x01234567);
718 const __m128i vp12x01234567hi = _mm_mulhi_epi16(vxi12x01234567, vxk12x01234567);
719
720 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp12x01234567lo, vp12x01234567hi));
721 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp12x01234567lo, vp12x01234567hi));
722
723 const __m128i vi13x01234567 = _mm_loadl_epi64((const __m128i*) i13);
724 const __m128i vk13x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 104 * sizeof(int8_t)));
725
Marat Dukhane5eee462021-07-01 19:34:39 -0700726 const __m128i vxi13x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi13x01234567, vi13x01234567), 8);
727 const __m128i vxk13x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk13x01234567, vk13x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700728
729 const __m128i vp13x01234567lo = _mm_mullo_epi16(vxi13x01234567, vxk13x01234567);
730 const __m128i vp13x01234567hi = _mm_mulhi_epi16(vxi13x01234567, vxk13x01234567);
731
732 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp13x01234567lo, vp13x01234567hi));
733 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp13x01234567lo, vp13x01234567hi));
734
735 const __m128i vi14x01234567 = _mm_loadl_epi64((const __m128i*) i14);
736 const __m128i vk14x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 112 * sizeof(int8_t)));
737
Marat Dukhane5eee462021-07-01 19:34:39 -0700738 const __m128i vxi14x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi14x01234567, vi14x01234567), 8);
739 const __m128i vxk14x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk14x01234567, vk14x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700740
741 const __m128i vp14x01234567lo = _mm_mullo_epi16(vxi14x01234567, vxk14x01234567);
742 const __m128i vp14x01234567hi = _mm_mulhi_epi16(vxi14x01234567, vxk14x01234567);
743
744 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp14x01234567lo, vp14x01234567hi));
745 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp14x01234567lo, vp14x01234567hi));
746
747 const __m128i vi15x01234567 = _mm_loadl_epi64((const __m128i*) i15);
748 const __m128i vk15x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 120 * sizeof(int8_t)));
749
Marat Dukhane5eee462021-07-01 19:34:39 -0700750 const __m128i vxi15x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi15x01234567, vi15x01234567), 8);
751 const __m128i vxk15x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk15x01234567, vk15x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700752
753 const __m128i vp15x01234567lo = _mm_mullo_epi16(vxi15x01234567, vxk15x01234567);
754 const __m128i vp15x01234567hi = _mm_mulhi_epi16(vxi15x01234567, vxk15x01234567);
755
756 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp15x01234567lo, vp15x01234567hi));
757 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp15x01234567lo, vp15x01234567hi));
758
759 const __m128i vi16x01234567 = _mm_loadl_epi64((const __m128i*) i16);
760 const __m128i vk16x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 128 * sizeof(int8_t)));
761
Marat Dukhane5eee462021-07-01 19:34:39 -0700762 const __m128i vxi16x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi16x01234567, vi16x01234567), 8);
763 const __m128i vxk16x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk16x01234567, vk16x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700764
765 const __m128i vp16x01234567lo = _mm_mullo_epi16(vxi16x01234567, vxk16x01234567);
766 const __m128i vp16x01234567hi = _mm_mulhi_epi16(vxi16x01234567, vxk16x01234567);
767
768 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp16x01234567lo, vp16x01234567hi));
769 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp16x01234567lo, vp16x01234567hi));
770
771 const __m128i vi17x01234567 = _mm_loadl_epi64((const __m128i*) i17);
772 const __m128i vk17x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 136 * sizeof(int8_t)));
773
Marat Dukhane5eee462021-07-01 19:34:39 -0700774 const __m128i vxi17x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi17x01234567, vi17x01234567), 8);
775 const __m128i vxk17x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk17x01234567, vk17x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700776
777 const __m128i vp17x01234567lo = _mm_mullo_epi16(vxi17x01234567, vxk17x01234567);
778 const __m128i vp17x01234567hi = _mm_mulhi_epi16(vxi17x01234567, vxk17x01234567);
779
780 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp17x01234567lo, vp17x01234567hi));
781 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp17x01234567lo, vp17x01234567hi));
782
783 const __m128i vi18x01234567 = _mm_loadl_epi64((const __m128i*) i18);
784 const __m128i vk18x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 144 * sizeof(int8_t)));
785
Marat Dukhane5eee462021-07-01 19:34:39 -0700786 const __m128i vxi18x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi18x01234567, vi18x01234567), 8);
787 const __m128i vxk18x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk18x01234567, vk18x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700788
789 const __m128i vp18x01234567lo = _mm_mullo_epi16(vxi18x01234567, vxk18x01234567);
790 const __m128i vp18x01234567hi = _mm_mulhi_epi16(vxi18x01234567, vxk18x01234567);
791
792 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp18x01234567lo, vp18x01234567hi));
793 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp18x01234567lo, vp18x01234567hi));
794
795 const __m128i vi19x01234567 = _mm_loadl_epi64((const __m128i*) i19);
796 const __m128i vk19x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 152 * sizeof(int8_t)));
797
Marat Dukhane5eee462021-07-01 19:34:39 -0700798 const __m128i vxi19x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi19x01234567, vi19x01234567), 8);
799 const __m128i vxk19x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk19x01234567, vk19x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700800
801 const __m128i vp19x01234567lo = _mm_mullo_epi16(vxi19x01234567, vxk19x01234567);
802 const __m128i vp19x01234567hi = _mm_mulhi_epi16(vxi19x01234567, vxk19x01234567);
803
804 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp19x01234567lo, vp19x01234567hi));
805 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp19x01234567lo, vp19x01234567hi));
806
807 const __m128i vi20x01234567 = _mm_loadl_epi64((const __m128i*) i20);
808 const __m128i vk20x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 160 * sizeof(int8_t)));
809
Marat Dukhane5eee462021-07-01 19:34:39 -0700810 const __m128i vxi20x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi20x01234567, vi20x01234567), 8);
811 const __m128i vxk20x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk20x01234567, vk20x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700812
813 const __m128i vp20x01234567lo = _mm_mullo_epi16(vxi20x01234567, vxk20x01234567);
814 const __m128i vp20x01234567hi = _mm_mulhi_epi16(vxi20x01234567, vxk20x01234567);
815
816 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp20x01234567lo, vp20x01234567hi));
817 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp20x01234567lo, vp20x01234567hi));
818
819 const __m128i vi21x01234567 = _mm_loadl_epi64((const __m128i*) i21);
820 const __m128i vk21x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 168 * sizeof(int8_t)));
821
Marat Dukhane5eee462021-07-01 19:34:39 -0700822 const __m128i vxi21x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi21x01234567, vi21x01234567), 8);
823 const __m128i vxk21x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk21x01234567, vk21x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700824
825 const __m128i vp21x01234567lo = _mm_mullo_epi16(vxi21x01234567, vxk21x01234567);
826 const __m128i vp21x01234567hi = _mm_mulhi_epi16(vxi21x01234567, vxk21x01234567);
827
828 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp21x01234567lo, vp21x01234567hi));
829 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp21x01234567lo, vp21x01234567hi));
830
831 const __m128i vi22x01234567 = _mm_loadl_epi64((const __m128i*) i22);
832 const __m128i vk22x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 176 * sizeof(int8_t)));
833
Marat Dukhane5eee462021-07-01 19:34:39 -0700834 const __m128i vxi22x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi22x01234567, vi22x01234567), 8);
835 const __m128i vxk22x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk22x01234567, vk22x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700836
837 const __m128i vp22x01234567lo = _mm_mullo_epi16(vxi22x01234567, vxk22x01234567);
838 const __m128i vp22x01234567hi = _mm_mulhi_epi16(vxi22x01234567, vxk22x01234567);
839
840 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp22x01234567lo, vp22x01234567hi));
841 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp22x01234567lo, vp22x01234567hi));
842
843 const __m128i vi23x01234567 = _mm_loadl_epi64((const __m128i*) i23);
844 const __m128i vk23x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 184 * sizeof(int8_t)));
845
Marat Dukhane5eee462021-07-01 19:34:39 -0700846 const __m128i vxi23x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi23x01234567, vi23x01234567), 8);
847 const __m128i vxk23x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk23x01234567, vk23x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700848
849 const __m128i vp23x01234567lo = _mm_mullo_epi16(vxi23x01234567, vxk23x01234567);
850 const __m128i vp23x01234567hi = _mm_mulhi_epi16(vxi23x01234567, vxk23x01234567);
851
852 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp23x01234567lo, vp23x01234567hi));
853 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp23x01234567lo, vp23x01234567hi));
854
855 const __m128i vi24x01234567 = _mm_loadl_epi64((const __m128i*) i24);
856 const __m128i vk24x01234567 = _mm_loadl_epi64((const __m128i*) ((uintptr_t) w + 8 * sizeof(int32_t) + 192 * sizeof(int8_t)));
857
Marat Dukhane5eee462021-07-01 19:34:39 -0700858 const __m128i vxi24x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vi24x01234567, vi24x01234567), 8);
859 const __m128i vxk24x01234567 = _mm_srai_epi16(_mm_unpacklo_epi8(vk24x01234567, vk24x01234567), 8);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700860
861 const __m128i vp24x01234567lo = _mm_mullo_epi16(vxi24x01234567, vxk24x01234567);
862 const __m128i vp24x01234567hi = _mm_mulhi_epi16(vxi24x01234567, vxk24x01234567);
863
864 vacc0123 = _mm_add_epi32(vacc0123, _mm_unpacklo_epi16(vp24x01234567lo, vp24x01234567hi));
865 vacc4567 = _mm_add_epi32(vacc4567, _mm_unpackhi_epi16(vp24x01234567lo, vp24x01234567hi));
866
867
Marat Dukhan9b474cf2021-05-25 16:37:48 -0700868 const __m128i vmultiplier = _mm_load_si128((const __m128i*) params->gemmlowp_sse2.multiplier);
869 const __m128i vrounding = _mm_load_si128((const __m128i*) params->gemmlowp_sse2.rounding);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700870
871 const __m128i vnmask0123 = _mm_cmpgt_epi32(_mm_setzero_si128(), vacc0123);
872 const __m128i vnmask4567 = _mm_cmpgt_epi32(_mm_setzero_si128(), vacc4567);
873
874 const __m128i vabsacc0123 = _mm_abs_epi32(vacc0123);
875 const __m128i vabsacc4567 = _mm_abs_epi32(vacc4567);
876
877 const __m128i vabsacc13 = _mm_shuffle_epi32(vabsacc0123, _MM_SHUFFLE(3, 3, 1, 1));
878 const __m128i vabsacc57 = _mm_shuffle_epi32(vabsacc4567, _MM_SHUFFLE(3, 3, 1, 1));
879
880 const __m128i vabsprod02 = _mm_mul_epu32(vabsacc0123, vmultiplier);
881 const __m128i vabsprod13 = _mm_mul_epu32(vabsacc13, vmultiplier);
882 const __m128i vabsprod46 = _mm_mul_epu32(vabsacc4567, vmultiplier);
883 const __m128i vabsprod57 = _mm_mul_epu32(vabsacc57, vmultiplier);
884
885 const __m128i vnmask02 = _mm_shuffle_epi32(vnmask0123, _MM_SHUFFLE(2, 2, 0, 0));
886 const __m128i vnmask13 = _mm_shuffle_epi32(vnmask0123, _MM_SHUFFLE(3, 3, 1, 1));
887 const __m128i vnmask46 = _mm_shuffle_epi32(vnmask4567, _MM_SHUFFLE(2, 2, 0, 0));
888 const __m128i vnmask57 = _mm_shuffle_epi32(vnmask4567, _MM_SHUFFLE(3, 3, 1, 1));
889
890 const __m128i vprod02 = _mm_sub_epi64(_mm_xor_si128(vabsprod02, vnmask02), vnmask02);
891 const __m128i vprod13 = _mm_sub_epi64(_mm_xor_si128(vabsprod13, vnmask13), vnmask13);
892 const __m128i vprod46 = _mm_sub_epi64(_mm_xor_si128(vabsprod46, vnmask46), vnmask46);
893 const __m128i vprod57 = _mm_sub_epi64(_mm_xor_si128(vabsprod57, vnmask57), vnmask57);
894
895 const __m128i vq31prod02 = _mm_srli_epi64(_mm_add_epi64(vprod02, vrounding), 31);
896 const __m128i vq31prod13 = _mm_srli_epi64(_mm_add_epi64(vprod13, vrounding), 31);
897 const __m128i vq31prod46 = _mm_srli_epi64(_mm_add_epi64(vprod46, vrounding), 31);
898 const __m128i vq31prod57 = _mm_srli_epi64(_mm_add_epi64(vprod57, vrounding), 31);
899
900 const __m128i vq31prod0213 = _mm_castps_si128(_mm_shuffle_ps(
901 _mm_castsi128_ps(vq31prod02), _mm_castsi128_ps(vq31prod13), _MM_SHUFFLE(2, 0, 2, 0)));
902 const __m128i vq31prod4657 = _mm_castps_si128(_mm_shuffle_ps(
903 _mm_castsi128_ps(vq31prod46), _mm_castsi128_ps(vq31prod57), _MM_SHUFFLE(2, 0, 2, 0)));
904
905 const __m128i vq31prod0123 = _mm_shuffle_epi32(vq31prod0213, _MM_SHUFFLE(3, 1, 2, 0));
906 const __m128i vq31prod4567 = _mm_shuffle_epi32(vq31prod4657, _MM_SHUFFLE(3, 1, 2, 0));
907
Marat Dukhan9b474cf2021-05-25 16:37:48 -0700908 const __m128i vremainder_mask = _mm_load_si128((const __m128i*) params->gemmlowp_sse2.remainder_mask);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700909 const __m128i vrem0123 =
910 _mm_add_epi32(_mm_and_si128(vq31prod0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vq31prod0123));
911 const __m128i vrem4567 =
912 _mm_add_epi32(_mm_and_si128(vq31prod4567, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vq31prod4567));
913
Marat Dukhan9b474cf2021-05-25 16:37:48 -0700914 const __m128i vremainder_threshold = _mm_load_si128((const __m128i*) params->gemmlowp_sse2.remainder_threshold);
915 const __m128i vshift = _mm_loadl_epi64((const __m128i*) params->gemmlowp_sse2.shift);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700916 vacc0123 =
917 _mm_sub_epi32(_mm_sra_epi32(vq31prod0123, vshift), _mm_cmpgt_epi32(vrem0123, vremainder_threshold));
918 vacc4567 =
919 _mm_sub_epi32(_mm_sra_epi32(vq31prod4567, vshift), _mm_cmpgt_epi32(vrem4567, vremainder_threshold));
920
Marat Dukhan98042f22021-06-15 00:43:13 -0700921
Marat Dukhan9b474cf2021-05-25 16:37:48 -0700922 const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->gemmlowp_sse2.output_zero_point);
Marat Dukhan4ed14882021-05-12 17:50:40 -0700923 __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
924
Marat Dukhan9b474cf2021-05-25 16:37:48 -0700925 vout01234567 = _mm_max_epi16(vout01234567, _mm_load_si128((const __m128i*) params->gemmlowp_sse2.output_min));
926 vout01234567 = _mm_min_epi16(vout01234567, _mm_load_si128((const __m128i*) params->gemmlowp_sse2.output_max));
Marat Dukhan4ed14882021-05-12 17:50:40 -0700927
928 __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567);
929
Marat Dukhan748fd122021-05-22 20:46:56 -0700930
Marat Dukhan4ed14882021-05-12 17:50:40 -0700931 if (c & 4) {
932 *((uint32_t*) output) = (uint32_t) _mm_cvtsi128_si32(vout0123456701234567);
933 vout0123456701234567 = _mm_srli_epi64(vout0123456701234567, 32);
934 output += 4;
935 }
936 if (c & 2) {
937 *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(vout0123456701234567, 0);
938 vout0123456701234567 = _mm_srli_epi32(vout0123456701234567, 16);
939 output += 2;
940 }
941 if (c & 1) {
942 *output = (int32_t) _mm_cvtsi128_si32(vout0123456701234567);
943 output += 1;
944 }
945 }
946 }
947
948 output = (int8_t*) ((uintptr_t) output + output_increment);
949 } while (--output_width != 0);
950}