1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gavgpool/multipass-sse.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/gavgpool.h>
15 #include <xnnpack/math.h>
16
17
xnn_qs8_gavgpool_minmax_ukernel_7p7x__sse41_c16_acc2(size_t rows,size_t channels,const int8_t * input,size_t input_stride,const int8_t * zero,int32_t * buffer,int8_t * output,const union xnn_qs8_avgpool_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qs8_gavgpool_minmax_ukernel_7p7x__sse41_c16_acc2(
19 size_t rows,
20 size_t channels,
21 const int8_t* input,
22 size_t input_stride,
23 const int8_t* zero,
24 int32_t* buffer,
25 int8_t* output,
26 const union xnn_qs8_avgpool_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
27 {
28 assert(rows > 7);
29 assert(channels != 0);
30
31 const int8_t* i0 = input;
32 const int8_t* i1 = (const int8_t*) ((uintptr_t) i0 + input_stride);
33 const int8_t* i2 = (const int8_t*) ((uintptr_t) i1 + input_stride);
34 const int8_t* i3 = (const int8_t*) ((uintptr_t) i2 + input_stride);
35 const int8_t* i4 = (const int8_t*) ((uintptr_t) i3 + input_stride);
36 const int8_t* i5 = (const int8_t*) ((uintptr_t) i4 + input_stride);
37 const int8_t* i6 = (const int8_t*) ((uintptr_t) i5 + input_stride);
38 const size_t input_increment = 7 * input_stride - round_up_po2(channels, 16);
39
40 const __m128i vbias = _mm_load_si128((const __m128i*) params->sse2.bias);
41 int32_t* b = buffer;
42 size_t c = channels;
43 for (; c != 0; c = doz(c, 16)) {
44 const __m128i vxi0x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i0));
45 const __m128i vxi0x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i0 + 8)));
46 i0 += 16;
47 const __m128i vxi1x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i1));
48 const __m128i vxi1x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i1 + 8)));
49 i1 += 16;
50 const __m128i vxi2x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i2));
51 const __m128i vxi2x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i2 + 8)));
52 i2 += 16;
53 const __m128i vxi3x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i3));
54 const __m128i vxi3x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i3 + 8)));
55 i3 += 16;
56 const __m128i vxi4x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i4));
57 const __m128i vxi4x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i4 + 8)));
58 i4 += 16;
59 const __m128i vxi5x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i5));
60 const __m128i vxi5x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i5 + 8)));
61 i5 += 16;
62 const __m128i vxi6x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i6));
63 const __m128i vxi6x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i6 + 8)));
64 i6 += 16;
65
66
67 __m128i vacc0x01234567 = _mm_add_epi16(vxi0x01234567, vxi1x01234567);
68 __m128i vacc0x89ABCDEF = _mm_add_epi16(vxi0x89ABCDEF, vxi1x89ABCDEF);
69 __m128i vacc1x01234567 = _mm_add_epi16(vxi2x01234567, vxi3x01234567);
70 __m128i vacc1x89ABCDEF = _mm_add_epi16(vxi2x89ABCDEF, vxi3x89ABCDEF);
71
72 vacc0x01234567 = _mm_add_epi16(vacc0x01234567, vxi4x01234567);
73 vacc0x89ABCDEF = _mm_add_epi16(vacc0x89ABCDEF, vxi4x89ABCDEF);
74 vacc1x01234567 = _mm_add_epi16(vacc1x01234567, vxi5x01234567);
75 vacc1x89ABCDEF = _mm_add_epi16(vacc1x89ABCDEF, vxi5x89ABCDEF);
76 vacc0x01234567 = _mm_add_epi16(vacc0x01234567, vxi6x01234567);
77 vacc0x89ABCDEF = _mm_add_epi16(vacc0x89ABCDEF, vxi6x89ABCDEF);
78
79 // Add up all accumulators to vacc0x0123456789ABCDEF
80 vacc0x01234567 = _mm_add_epi16(vacc0x01234567, vacc1x01234567);
81 vacc0x89ABCDEF = _mm_add_epi16(vacc0x89ABCDEF, vacc1x89ABCDEF);
82
83 const __m128i vacc0123 = _mm_add_epi32(vbias, _mm_cvtepi16_epi32(vacc0x01234567));
84 const __m128i vacc4567 = _mm_add_epi32(vbias, _mm_unpackhi_epi16(vacc0x01234567, _mm_cmpgt_epi16(_mm_setzero_si128(), vacc0x01234567)));
85 const __m128i vacc89AB = _mm_add_epi32(vbias, _mm_cvtepi16_epi32(vacc0x89ABCDEF));
86 const __m128i vaccCDEF = _mm_add_epi32(vbias, _mm_unpackhi_epi16(vacc0x89ABCDEF, _mm_cmpgt_epi16(_mm_setzero_si128(), vacc0x89ABCDEF)));
87
88 _mm_store_si128((__m128i*) b, vacc0123);
89 _mm_store_si128((__m128i*) (b + 4), vacc4567);
90 _mm_store_si128((__m128i*) (b + 8), vacc89AB);
91 _mm_store_si128((__m128i*) (b + 12), vaccCDEF);
92 b += 16;
93 }
94
95 for (rows -= 7; rows > 7; rows -= 7) {
96 i0 = (const int8_t*) ((uintptr_t) i0 + input_increment);
97 i1 = (const int8_t*) ((uintptr_t) i1 + input_increment);
98 i2 = (const int8_t*) ((uintptr_t) i2 + input_increment);
99 i3 = (const int8_t*) ((uintptr_t) i3 + input_increment);
100 i4 = (const int8_t*) ((uintptr_t) i4 + input_increment);
101 i5 = (const int8_t*) ((uintptr_t) i5 + input_increment);
102 i6 = (const int8_t*) ((uintptr_t) i6 + input_increment);
103
104 int32_t* b = buffer;
105 size_t c = channels;
106 for (; c != 0; c = doz(c, 16)) {
107 const __m128i vxi0x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i0));
108 const __m128i vxi0x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i0 + 8)));
109 i0 += 16;
110 const __m128i vxi1x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i1));
111 const __m128i vxi1x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i1 + 8)));
112 i1 += 16;
113 const __m128i vxi2x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i2));
114 const __m128i vxi2x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i2 + 8)));
115 i2 += 16;
116 const __m128i vxi3x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i3));
117 const __m128i vxi3x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i3 + 8)));
118 i3 += 16;
119 const __m128i vxi4x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i4));
120 const __m128i vxi4x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i4 + 8)));
121 i4 += 16;
122 const __m128i vxi5x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i5));
123 const __m128i vxi5x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i5 + 8)));
124 i5 += 16;
125 const __m128i vxi6x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i6));
126 const __m128i vxi6x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i6 + 8)));
127 i6 += 16;
128
129
130 __m128i vacc0x01234567 = _mm_add_epi16(vxi0x01234567, vxi1x01234567);
131 __m128i vacc0x89ABCDEF = _mm_add_epi16(vxi0x89ABCDEF, vxi1x89ABCDEF);
132 __m128i vacc1x01234567 = _mm_add_epi16(vxi2x01234567, vxi3x01234567);
133 __m128i vacc1x89ABCDEF = _mm_add_epi16(vxi2x89ABCDEF, vxi3x89ABCDEF);
134
135 vacc0x01234567 = _mm_add_epi16(vacc0x01234567, vxi4x01234567);
136 vacc0x89ABCDEF = _mm_add_epi16(vacc0x89ABCDEF, vxi4x89ABCDEF);
137 vacc1x01234567 = _mm_add_epi16(vacc1x01234567, vxi5x01234567);
138 vacc1x89ABCDEF = _mm_add_epi16(vacc1x89ABCDEF, vxi5x89ABCDEF);
139 vacc0x01234567 = _mm_add_epi16(vacc0x01234567, vxi6x01234567);
140 vacc0x89ABCDEF = _mm_add_epi16(vacc0x89ABCDEF, vxi6x89ABCDEF);
141
142 // Add up all accumulators to vacc0x0123456789ABCDEF
143 vacc0x01234567 = _mm_add_epi16(vacc0x01234567, vacc1x01234567);
144 vacc0x89ABCDEF = _mm_add_epi16(vacc0x89ABCDEF, vacc1x89ABCDEF);
145
146 const __m128i vacc0123 = _mm_add_epi32(_mm_cvtepi16_epi32(vacc0x01234567), _mm_load_si128((const __m128i*) (b + 0)));
147 const __m128i vacc4567 = _mm_add_epi32(_mm_unpackhi_epi16(vacc0x01234567, _mm_cmpgt_epi16(_mm_setzero_si128(), vacc0x01234567)), _mm_load_si128((const __m128i*) (b + 4)));
148 const __m128i vacc89AB = _mm_add_epi32(_mm_cvtepi16_epi32(vacc0x89ABCDEF), _mm_load_si128((const __m128i*) (b + 8)));
149 const __m128i vaccCDEF = _mm_add_epi32(_mm_unpackhi_epi16(vacc0x89ABCDEF, _mm_cmpgt_epi16(_mm_setzero_si128(), vacc0x89ABCDEF)), _mm_load_si128((const __m128i*) (b + 12)));
150
151 _mm_store_si128((__m128i*) b, vacc0123);
152 _mm_store_si128((__m128i*) (b + 4), vacc4567);
153 _mm_store_si128((__m128i*) (b + 8), vacc89AB);
154 _mm_store_si128((__m128i*) (b + 12), vaccCDEF);
155 b += 16;
156 }
157 }
158
159 i0 = (const int8_t*) ((uintptr_t) i0 + input_increment);
160 i1 = (const int8_t*) ((uintptr_t) i1 + input_increment);
161 if XNN_UNPREDICTABLE(rows < 2) {
162 i1 = zero;
163 }
164 i2 = (const int8_t*) ((uintptr_t) i2 + input_increment);
165 if XNN_UNPREDICTABLE(rows <= 2) {
166 i2 = zero;
167 }
168 i3 = (const int8_t*) ((uintptr_t) i3 + input_increment);
169 if XNN_UNPREDICTABLE(rows < 4) {
170 i3 = zero;
171 }
172 i4 = (const int8_t*) ((uintptr_t) i4 + input_increment);
173 if XNN_UNPREDICTABLE(rows <= 4) {
174 i4 = zero;
175 }
176 i5 = (const int8_t*) ((uintptr_t) i5 + input_increment);
177 if XNN_UNPREDICTABLE(rows < 6) {
178 i5 = zero;
179 }
180 i6 = (const int8_t*) ((uintptr_t) i6 + input_increment);
181 if XNN_UNPREDICTABLE(rows <= 6) {
182 i6 = zero;
183 }
184
185 const __m128i vmultiplier = _mm_load_si128((const __m128i*) params->sse2.multiplier);
186 const __m128i vrounding = _mm_load_si128((const __m128i*) params->sse2.rounding);
187 const __m128i vshift = _mm_loadl_epi64((const __m128i*) params->sse2.shift);
188 while (channels >= 16) {
189 const __m128i vxi0x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i0));
190 const __m128i vxi0x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i0 + 8)));
191 i0 += 16;
192 const __m128i vxi1x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i1));
193 const __m128i vxi1x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i1 + 8)));
194 i1 += 16;
195 const __m128i vxi2x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i2));
196 const __m128i vxi2x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i2 + 8)));
197 i2 += 16;
198 const __m128i vxi3x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i3));
199 const __m128i vxi3x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i3 + 8)));
200 i3 += 16;
201 const __m128i vxi4x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i4));
202 const __m128i vxi4x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i4 + 8)));
203 i4 += 16;
204 const __m128i vxi5x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i5));
205 const __m128i vxi5x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i5 + 8)));
206 i5 += 16;
207 const __m128i vxi6x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i6));
208 const __m128i vxi6x89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (i6 + 8)));
209 i6 += 16;
210
211
212 __m128i vacc0x01234567 = _mm_add_epi16(vxi0x01234567, vxi1x01234567);
213 __m128i vacc0x89ABCDEF = _mm_add_epi16(vxi0x89ABCDEF, vxi1x89ABCDEF);
214 __m128i vacc1x01234567 = _mm_add_epi16(vxi2x01234567, vxi3x01234567);
215 __m128i vacc1x89ABCDEF = _mm_add_epi16(vxi2x89ABCDEF, vxi3x89ABCDEF);
216
217 vacc0x01234567 = _mm_add_epi16(vacc0x01234567, vxi4x01234567);
218 vacc0x89ABCDEF = _mm_add_epi16(vacc0x89ABCDEF, vxi4x89ABCDEF);
219 vacc1x01234567 = _mm_add_epi16(vacc1x01234567, vxi5x01234567);
220 vacc1x89ABCDEF = _mm_add_epi16(vacc1x89ABCDEF, vxi5x89ABCDEF);
221 vacc0x01234567 = _mm_add_epi16(vacc0x01234567, vxi6x01234567);
222 vacc0x89ABCDEF = _mm_add_epi16(vacc0x89ABCDEF, vxi6x89ABCDEF);
223
224 // Add up all accumulators to vacc0x0123456789ABCDEF
225 vacc0x01234567 = _mm_add_epi16(vacc0x01234567, vacc1x01234567);
226 vacc0x89ABCDEF = _mm_add_epi16(vacc0x89ABCDEF, vacc1x89ABCDEF);
227
228 const __m128i vacc0123 = _mm_add_epi32(_mm_cvtepi16_epi32(vacc0x01234567), _mm_load_si128((const __m128i*) (buffer + 0)));
229 const __m128i vacc4567 = _mm_add_epi32(_mm_unpackhi_epi16(vacc0x01234567, _mm_cmpgt_epi16(_mm_setzero_si128(), vacc0x01234567)), _mm_load_si128((const __m128i*) (buffer + 4)));
230 const __m128i vacc89AB = _mm_add_epi32(_mm_cvtepi16_epi32(vacc0x89ABCDEF), _mm_load_si128((const __m128i*) (buffer + 8)));
231 const __m128i vaccCDEF = _mm_add_epi32(_mm_unpackhi_epi16(vacc0x89ABCDEF, _mm_cmpgt_epi16(_mm_setzero_si128(), vacc0x89ABCDEF)), _mm_load_si128((const __m128i*) (buffer + 12)));
232 buffer += 16;
233
234 const __m128i vabsacc0123 = _mm_abs_epi32(vacc0123);
235 const __m128i vabsacc4567 = _mm_abs_epi32(vacc4567);
236 const __m128i vabsacc89AB = _mm_abs_epi32(vacc89AB);
237 const __m128i vabsaccCDEF = _mm_abs_epi32(vaccCDEF);
238
239 const __m128i vabsacc13 = _mm_shuffle_epi32(vabsacc0123, _MM_SHUFFLE(3, 3, 1, 1));
240 const __m128i vabsacc57 = _mm_shuffle_epi32(vabsacc4567, _MM_SHUFFLE(3, 3, 1, 1));
241 const __m128i vabsacc9B = _mm_shuffle_epi32(vabsacc89AB, _MM_SHUFFLE(3, 3, 1, 1));
242 const __m128i vabsaccDF = _mm_shuffle_epi32(vabsaccCDEF, _MM_SHUFFLE(3, 3, 1, 1));
243
244 const __m128i vabsprod02 = _mm_mul_epu32(vabsacc0123, vmultiplier);
245 const __m128i vabsprod13 = _mm_mul_epu32(vabsacc13, vmultiplier);
246 const __m128i vabsprod46 = _mm_mul_epu32(vabsacc4567, vmultiplier);
247 const __m128i vabsprod57 = _mm_mul_epu32(vabsacc57, vmultiplier);
248 const __m128i vabsprod8A = _mm_mul_epu32(vabsacc89AB, vmultiplier);
249 const __m128i vabsprod9B = _mm_mul_epu32(vabsacc9B, vmultiplier);
250 const __m128i vabsprodCE = _mm_mul_epu32(vabsaccCDEF, vmultiplier);
251 const __m128i vabsprodDF = _mm_mul_epu32(vabsaccDF, vmultiplier);
252
253 const __m128i vabsout02 = _mm_srl_epi64(_mm_add_epi64(vabsprod02, vrounding), vshift);
254 const __m128i vabsout13 = _mm_srl_epi64(_mm_add_epi64(vabsprod13, vrounding), vshift);
255 const __m128i vabsout46 = _mm_srl_epi64(_mm_add_epi64(vabsprod46, vrounding), vshift);
256 const __m128i vabsout57 = _mm_srl_epi64(_mm_add_epi64(vabsprod57, vrounding), vshift);
257 const __m128i vabsout8A = _mm_srl_epi64(_mm_add_epi64(vabsprod8A, vrounding), vshift);
258 const __m128i vabsout9B = _mm_srl_epi64(_mm_add_epi64(vabsprod9B, vrounding), vshift);
259 const __m128i vabsoutCE = _mm_srl_epi64(_mm_add_epi64(vabsprodCE, vrounding), vshift);
260 const __m128i vabsoutDF = _mm_srl_epi64(_mm_add_epi64(vabsprodDF, vrounding), vshift);
261
262 const __m128i vabsout0123 = _mm_blend_epi16(vabsout02, _mm_shuffle_epi32(vabsout13, _MM_SHUFFLE(2, 2, 0, 0)), 0xCC);
263 const __m128i vabsout4567 = _mm_blend_epi16(vabsout46, _mm_shuffle_epi32(vabsout57, _MM_SHUFFLE(2, 2, 0, 0)), 0xCC);
264 const __m128i vabsout89AB = _mm_blend_epi16(vabsout8A, _mm_shuffle_epi32(vabsout9B, _MM_SHUFFLE(2, 2, 0, 0)), 0xCC);
265 const __m128i vabsoutCDEF = _mm_blend_epi16(vabsoutCE, _mm_shuffle_epi32(vabsoutDF, _MM_SHUFFLE(2, 2, 0, 0)), 0xCC);
266
267 const __m128i vout0123 = _mm_sign_epi32(vabsout0123, vacc0123);
268 const __m128i vout4567 = _mm_sign_epi32(vabsout4567, vacc4567);
269 const __m128i vout89AB = _mm_sign_epi32(vabsout89AB, vacc89AB);
270 const __m128i voutCDEF = _mm_sign_epi32(vabsoutCDEF, vaccCDEF);
271
272 const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse2.output_zero_point);
273 __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vout0123, vout4567), voutput_zero_point);
274 __m128i vout89ABCDEF = _mm_adds_epi16(_mm_packs_epi32(vout89AB, voutCDEF), voutput_zero_point);
275
276 const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse2.output_min);
277 const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse2.output_max);
278 vout01234567 = _mm_min_epi16(_mm_max_epi16(vout01234567, voutput_min), voutput_max);
279 vout89ABCDEF = _mm_min_epi16(_mm_max_epi16(vout89ABCDEF, voutput_min), voutput_max);
280
281 __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF);
282
283 _mm_storeu_si128((__m128i*) output, vout0123456789ABCDEF);
284 output += 16;
285
286 channels -= 16;
287 }
288 if XNN_UNLIKELY(channels != 0) {
289 do {
290 const __m128i vxi0x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i0));
291 i0 += 8;
292 const __m128i vxi1x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i1));
293 i1 += 8;
294 const __m128i vxi2x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i2));
295 i2 += 8;
296 const __m128i vxi3x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i3));
297 i3 += 8;
298 const __m128i vxi4x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i4));
299 i4 += 8;
300 const __m128i vxi5x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i5));
301 i5 += 8;
302 const __m128i vxi6x01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i6));
303 i6 += 8;
304
305
306 __m128i vacc0x01234567 = _mm_add_epi16(vxi0x01234567, vxi1x01234567);
307 __m128i vacc1x01234567 = _mm_add_epi16(vxi2x01234567, vxi3x01234567);
308
309 vacc0x01234567 = _mm_add_epi16(vacc0x01234567, vxi4x01234567);
310 vacc1x01234567 = _mm_add_epi16(vacc1x01234567, vxi5x01234567);
311 vacc0x01234567 = _mm_add_epi16(vacc0x01234567, vxi6x01234567);
312
313 // Add up all accumulators to vacc0x01234567
314 vacc0x01234567 = _mm_add_epi16(vacc0x01234567, vacc1x01234567);
315
316 const __m128i vacc0123 = _mm_add_epi32(_mm_cvtepi16_epi32(vacc0x01234567), _mm_load_si128((const __m128i*) buffer));
317 const __m128i vacc4567 = _mm_add_epi32(_mm_unpackhi_epi16(vacc0x01234567, _mm_cmpgt_epi16(_mm_setzero_si128(), vacc0x01234567)), _mm_load_si128((const __m128i*) (buffer + 4)));
318 buffer += 8;
319
320 const __m128i vabsacc0123 = _mm_abs_epi32(vacc0123);
321 const __m128i vabsacc4567 = _mm_abs_epi32(vacc4567);
322
323 const __m128i vabsacc13 = _mm_shuffle_epi32(vabsacc0123, _MM_SHUFFLE(3, 3, 1, 1));
324 const __m128i vabsacc57 = _mm_shuffle_epi32(vabsacc4567, _MM_SHUFFLE(3, 3, 1, 1));
325
326 const __m128i vabsprod02 = _mm_mul_epu32(vabsacc0123, vmultiplier);
327 const __m128i vabsprod13 = _mm_mul_epu32(vabsacc13, vmultiplier);
328 const __m128i vabsprod46 = _mm_mul_epu32(vabsacc4567, vmultiplier);
329 const __m128i vabsprod57 = _mm_mul_epu32(vabsacc57, vmultiplier);
330
331 const __m128i vabsout02 = _mm_srl_epi64(_mm_add_epi64(vabsprod02, vrounding), vshift);
332 const __m128i vabsout13 = _mm_srl_epi64(_mm_add_epi64(vabsprod13, vrounding), vshift);
333 const __m128i vabsout46 = _mm_srl_epi64(_mm_add_epi64(vabsprod46, vrounding), vshift);
334 const __m128i vabsout57 = _mm_srl_epi64(_mm_add_epi64(vabsprod57, vrounding), vshift);
335
336 const __m128i vabsout0123 = _mm_blend_epi16(vabsout02, _mm_shuffle_epi32(vabsout13, _MM_SHUFFLE(2, 2, 0, 0)), 0xCC);
337 const __m128i vabsout4567 = _mm_blend_epi16(vabsout46, _mm_shuffle_epi32(vabsout57, _MM_SHUFFLE(2, 2, 0, 0)), 0xCC);
338
339 const __m128i vout0123 = _mm_sign_epi32(vabsout0123, vacc0123);
340 const __m128i vout4567 = _mm_sign_epi32(vabsout4567, vacc4567);
341
342 const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse2.output_zero_point);
343 __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vout0123, vout4567), voutput_zero_point);
344
345 const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse2.output_min);
346 const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse2.output_max);
347 vout01234567 = _mm_min_epi16(_mm_max_epi16(vout01234567, voutput_min), voutput_max);
348
349 __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567);
350
351 if XNN_LIKELY(channels >= 8) {
352 _mm_storel_epi64((__m128i*) output, vout0123456701234567);
353 output += 8;
354 channels -= 8;
355 } else {
356 if (channels & 4) {
357 *((uint32_t*) output) = (uint32_t) _mm_cvtsi128_si32(vout0123456701234567);
358 vout0123456701234567 = _mm_srli_epi64(vout0123456701234567, 32);
359 output += 4;
360 }
361 if (channels & 2) {
362 *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(vout0123456701234567, 0);
363 vout0123456701234567 = _mm_srli_epi32(vout0123456701234567, 16);
364 output += 2;
365 }
366 if (channels & 1) {
367 *output = (int8_t) _mm_extract_epi8(vout0123456701234567, 0);
368 output += 1;
369 }
370 channels = 0;
371 }
372 } while (channels != 0);
373 }
374 }
375