1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/MRx4c2-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 <emmintrin.h>
13
14 #include <xnnpack/gemm.h>
15 #include <xnnpack/math.h>
16
17
xnn_qs8_gemm_minmax_ukernel_4x4c2__sse2_ld128(size_t mr,size_t nc,size_t kc,const int8_t * restrict a,size_t a_stride,const void * restrict w,int8_t * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_qs8_gemm_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qs8_gemm_minmax_ukernel_4x4c2__sse2_ld128(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 const int8_t* restrict a,
23 size_t a_stride,
24 const void* restrict w,
25 int8_t* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 const union xnn_qs8_gemm_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
29 {
30 assert(mr != 0);
31 assert(mr <= 4);
32 assert(nc != 0);
33 assert(kc != 0);
34 assert(kc % sizeof(int8_t) == 0);
35 assert(a != NULL);
36 assert(w != NULL);
37 assert(c != NULL);
38
39 kc = round_up_po2(kc, 2);
40 const int8_t* a0 = a;
41 int8_t* c0 = c;
42 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
43 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
44 if XNN_UNPREDICTABLE(mr < 2) {
45 a1 = a0;
46 c1 = c0;
47 }
48 const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride);
49 int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
50 if XNN_UNPREDICTABLE(mr <= 2) {
51 a2 = a1;
52 c2 = c1;
53 }
54 const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride);
55 int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride);
56 if XNN_UNPREDICTABLE(mr != 4) {
57 a3 = a2;
58 c3 = c2;
59 }
60
61 do {
62 __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w);
63 __m128i vacc1x0123 = vacc0x0123;
64 __m128i vacc2x0123 = vacc0x0123;
65 __m128i vacc3x0123 = vacc0x0123;
66 w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
67
68 size_t k = kc;
69 while (k >= 8 * sizeof(int8_t)) {
70 const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0);
71 const __m128i vxa0 = _mm_unpacklo_epi8(va0, _mm_cmpgt_epi8(_mm_setzero_si128(), va0));
72 a0 += 8;
73 const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1);
74 const __m128i vxa1 = _mm_unpacklo_epi8(va1, _mm_cmpgt_epi8(_mm_setzero_si128(), va1));
75 a1 += 8;
76 const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2);
77 const __m128i vxa2 = _mm_unpacklo_epi8(va2, _mm_cmpgt_epi8(_mm_setzero_si128(), va2));
78 a2 += 8;
79 const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3);
80 const __m128i vxa3 = _mm_unpacklo_epi8(va3, _mm_cmpgt_epi8(_mm_setzero_si128(), va3));
81 a3 += 8;
82
83 const __m128i vb01 = _mm_loadu_si128((const __m128i*) w);
84 const __m128i vsb01 = _mm_cmpgt_epi8(_mm_setzero_si128(), vb01);
85 const __m128i vxb0 = _mm_unpacklo_epi8(vb01, vsb01);
86 const __m128i vxb1 = _mm_unpackhi_epi8(vb01, vsb01);
87
88 vacc0x0123 = _mm_add_epi32(vacc0x0123,
89 _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0));
90 vacc1x0123 = _mm_add_epi32(vacc1x0123,
91 _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0));
92 vacc2x0123 = _mm_add_epi32(vacc2x0123,
93 _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0));
94 vacc3x0123 = _mm_add_epi32(vacc3x0123,
95 _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0));
96
97 vacc0x0123 = _mm_add_epi32(vacc0x0123,
98 _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1));
99 vacc1x0123 = _mm_add_epi32(vacc1x0123,
100 _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1));
101 vacc2x0123 = _mm_add_epi32(vacc2x0123,
102 _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1));
103 vacc3x0123 = _mm_add_epi32(vacc3x0123,
104 _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1));
105 const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((uintptr_t) w + 16 * sizeof(int8_t)));
106 const __m128i vsb23 = _mm_cmpgt_epi8(_mm_setzero_si128(), vb23);
107 const __m128i vxb2 = _mm_unpacklo_epi8(vb23, vsb23);
108 const __m128i vxb3 = _mm_unpackhi_epi8(vb23, vsb23);
109
110 vacc0x0123 = _mm_add_epi32(vacc0x0123,
111 _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2));
112 vacc1x0123 = _mm_add_epi32(vacc1x0123,
113 _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2));
114 vacc2x0123 = _mm_add_epi32(vacc2x0123,
115 _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2));
116 vacc3x0123 = _mm_add_epi32(vacc3x0123,
117 _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2));
118
119 vacc0x0123 = _mm_add_epi32(vacc0x0123,
120 _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3));
121 vacc1x0123 = _mm_add_epi32(vacc1x0123,
122 _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3));
123 vacc2x0123 = _mm_add_epi32(vacc2x0123,
124 _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3));
125 vacc3x0123 = _mm_add_epi32(vacc3x0123,
126 _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(3, 3, 3, 3)), vxb3));
127
128 w = (const void*) ((uintptr_t) w + 32 * sizeof(int8_t));
129 k -= 8 * sizeof(int8_t);
130 }
131 if (k != 0) {
132 const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0);
133 const __m128i vxa0 = _mm_unpacklo_epi8(va0, _mm_cmpgt_epi8(_mm_setzero_si128(), va0));
134 a0 = (const int8_t*) ((uintptr_t) a0 + k);
135 const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1);
136 const __m128i vxa1 = _mm_unpacklo_epi8(va1, _mm_cmpgt_epi8(_mm_setzero_si128(), va1));
137 a1 = (const int8_t*) ((uintptr_t) a1 + k);
138 const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2);
139 const __m128i vxa2 = _mm_unpacklo_epi8(va2, _mm_cmpgt_epi8(_mm_setzero_si128(), va2));
140 a2 = (const int8_t*) ((uintptr_t) a2 + k);
141 const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3);
142 const __m128i vxa3 = _mm_unpacklo_epi8(va3, _mm_cmpgt_epi8(_mm_setzero_si128(), va3));
143 a3 = (const int8_t*) ((uintptr_t) a3 + k);
144
145 const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w);
146 const __m128i vxb0 = _mm_unpacklo_epi8(vb0, _mm_cmpgt_epi8(_mm_setzero_si128(), vb0));
147 w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
148
149 vacc0x0123 = _mm_add_epi32(vacc0x0123,
150 _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0));
151 vacc1x0123 = _mm_add_epi32(vacc1x0123,
152 _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0));
153 vacc2x0123 = _mm_add_epi32(vacc2x0123,
154 _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0));
155 vacc3x0123 = _mm_add_epi32(vacc3x0123,
156 _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0));
157
158 if (k > 2 * sizeof(int8_t)) {
159 const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w);
160 const __m128i vxb1 = _mm_unpacklo_epi8(vb1, _mm_cmpgt_epi8(_mm_setzero_si128(), vb1));
161 w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
162
163 vacc0x0123 = _mm_add_epi32(vacc0x0123,
164 _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1));
165 vacc1x0123 = _mm_add_epi32(vacc1x0123,
166 _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1));
167 vacc2x0123 = _mm_add_epi32(vacc2x0123,
168 _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1));
169 vacc3x0123 = _mm_add_epi32(vacc3x0123,
170 _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1));
171
172 if (k > 4 * sizeof(int8_t)) {
173 const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w);
174 const __m128i vxb2 = _mm_unpacklo_epi8(vb2, _mm_cmpgt_epi8(_mm_setzero_si128(), vb2));
175 w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
176
177 vacc0x0123 = _mm_add_epi32(vacc0x0123,
178 _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2));
179 vacc1x0123 = _mm_add_epi32(vacc1x0123,
180 _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2));
181 vacc2x0123 = _mm_add_epi32(vacc2x0123,
182 _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2));
183 vacc3x0123 = _mm_add_epi32(vacc3x0123,
184 _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2));
185 }
186 }
187 }
188
189 const __m128i vmultiplier = _mm_load_si128((const __m128i*) params->sse2.multiplier);
190 const __m128i vrounding = _mm_load_si128((const __m128i*) params->sse2.rounding);
191
192 const __m128i vnmask0x0123 = _mm_cmpgt_epi32(_mm_setzero_si128(), vacc0x0123);
193 const __m128i vnmask1x0123 = _mm_cmpgt_epi32(_mm_setzero_si128(), vacc1x0123);
194 const __m128i vnmask2x0123 = _mm_cmpgt_epi32(_mm_setzero_si128(), vacc2x0123);
195 const __m128i vnmask3x0123 = _mm_cmpgt_epi32(_mm_setzero_si128(), vacc3x0123);
196
197 const __m128i vabsacc0x0123 = _mm_sub_epi32(_mm_xor_si128(vacc0x0123, vnmask0x0123), vnmask0x0123);
198 const __m128i vabsacc1x0123 = _mm_sub_epi32(_mm_xor_si128(vacc1x0123, vnmask1x0123), vnmask1x0123);
199 const __m128i vabsacc2x0123 = _mm_sub_epi32(_mm_xor_si128(vacc2x0123, vnmask2x0123), vnmask2x0123);
200 const __m128i vabsacc3x0123 = _mm_sub_epi32(_mm_xor_si128(vacc3x0123, vnmask3x0123), vnmask3x0123);
201
202 const __m128i vabsacc0x1133 = _mm_shuffle_epi32(vabsacc0x0123, _MM_SHUFFLE(3, 3, 1, 1));
203 const __m128i vabsacc1x1133 = _mm_shuffle_epi32(vabsacc1x0123, _MM_SHUFFLE(3, 3, 1, 1));
204 const __m128i vabsacc2x1133 = _mm_shuffle_epi32(vabsacc2x0123, _MM_SHUFFLE(3, 3, 1, 1));
205 const __m128i vabsacc3x1133 = _mm_shuffle_epi32(vabsacc3x0123, _MM_SHUFFLE(3, 3, 1, 1));
206
207 const __m128i vabsprod0x02 = _mm_mul_epu32(vabsacc0x0123, vmultiplier);
208 const __m128i vabsprod1x02 = _mm_mul_epu32(vabsacc1x0123, vmultiplier);
209 const __m128i vabsprod2x02 = _mm_mul_epu32(vabsacc2x0123, vmultiplier);
210 const __m128i vabsprod3x02 = _mm_mul_epu32(vabsacc3x0123, vmultiplier);
211
212 const __m128i vnmask0x02 = _mm_shuffle_epi32(vnmask0x0123, _MM_SHUFFLE(2, 2, 0, 0));
213 const __m128i vnmask1x02 = _mm_shuffle_epi32(vnmask1x0123, _MM_SHUFFLE(2, 2, 0, 0));
214 const __m128i vnmask2x02 = _mm_shuffle_epi32(vnmask2x0123, _MM_SHUFFLE(2, 2, 0, 0));
215 const __m128i vnmask3x02 = _mm_shuffle_epi32(vnmask3x0123, _MM_SHUFFLE(2, 2, 0, 0));
216
217 const __m128i vprod0x02 = _mm_sub_epi64(_mm_xor_si128(vabsprod0x02, vnmask0x02), vnmask0x02);
218 const __m128i vprod1x02 = _mm_sub_epi64(_mm_xor_si128(vabsprod1x02, vnmask1x02), vnmask1x02);
219 const __m128i vprod2x02 = _mm_sub_epi64(_mm_xor_si128(vabsprod2x02, vnmask2x02), vnmask2x02);
220 const __m128i vprod3x02 = _mm_sub_epi64(_mm_xor_si128(vabsprod3x02, vnmask3x02), vnmask3x02);
221
222 const __m128i vq31prod0x02 = _mm_srli_epi64(_mm_add_epi64(vprod0x02, vrounding), 31);
223 const __m128i vq31prod1x02 = _mm_srli_epi64(_mm_add_epi64(vprod1x02, vrounding), 31);
224 const __m128i vq31prod2x02 = _mm_srli_epi64(_mm_add_epi64(vprod2x02, vrounding), 31);
225 const __m128i vq31prod3x02 = _mm_srli_epi64(_mm_add_epi64(vprod3x02, vrounding), 31);
226
227 const __m128i vabsprod0x13 = _mm_mul_epu32(vabsacc0x1133, vmultiplier);
228 const __m128i vabsprod1x13 = _mm_mul_epu32(vabsacc1x1133, vmultiplier);
229 const __m128i vabsprod2x13 = _mm_mul_epu32(vabsacc2x1133, vmultiplier);
230 const __m128i vabsprod3x13 = _mm_mul_epu32(vabsacc3x1133, vmultiplier);
231
232 const __m128i vnmask0x13 = _mm_shuffle_epi32(vnmask0x0123, _MM_SHUFFLE(3, 3, 1, 1));
233 const __m128i vnmask1x13 = _mm_shuffle_epi32(vnmask1x0123, _MM_SHUFFLE(3, 3, 1, 1));
234 const __m128i vnmask2x13 = _mm_shuffle_epi32(vnmask2x0123, _MM_SHUFFLE(3, 3, 1, 1));
235 const __m128i vnmask3x13 = _mm_shuffle_epi32(vnmask3x0123, _MM_SHUFFLE(3, 3, 1, 1));
236
237 const __m128i vprod0x13 = _mm_sub_epi64(_mm_xor_si128(vabsprod0x13, vnmask0x13), vnmask0x13);
238 const __m128i vprod1x13 = _mm_sub_epi64(_mm_xor_si128(vabsprod1x13, vnmask1x13), vnmask1x13);
239 const __m128i vprod2x13 = _mm_sub_epi64(_mm_xor_si128(vabsprod2x13, vnmask2x13), vnmask2x13);
240 const __m128i vprod3x13 = _mm_sub_epi64(_mm_xor_si128(vabsprod3x13, vnmask3x13), vnmask3x13);
241
242 const __m128i vq31prod0x13 = _mm_srli_epi64(_mm_add_epi64(vprod0x13, vrounding), 31);
243 const __m128i vq31prod1x13 = _mm_srli_epi64(_mm_add_epi64(vprod1x13, vrounding), 31);
244 const __m128i vq31prod2x13 = _mm_srli_epi64(_mm_add_epi64(vprod2x13, vrounding), 31);
245 const __m128i vq31prod3x13 = _mm_srli_epi64(_mm_add_epi64(vprod3x13, vrounding), 31);
246
247 const __m128i vq31prod0x0213 = _mm_castps_si128(_mm_shuffle_ps(
248 _mm_castsi128_ps(vq31prod0x02), _mm_castsi128_ps(vq31prod0x13), _MM_SHUFFLE(2, 0, 2, 0)));
249 const __m128i vq31prod1x0213 = _mm_castps_si128(_mm_shuffle_ps(
250 _mm_castsi128_ps(vq31prod1x02), _mm_castsi128_ps(vq31prod1x13), _MM_SHUFFLE(2, 0, 2, 0)));
251 const __m128i vq31prod2x0213 = _mm_castps_si128(_mm_shuffle_ps(
252 _mm_castsi128_ps(vq31prod2x02), _mm_castsi128_ps(vq31prod2x13), _MM_SHUFFLE(2, 0, 2, 0)));
253 const __m128i vq31prod3x0213 = _mm_castps_si128(_mm_shuffle_ps(
254 _mm_castsi128_ps(vq31prod3x02), _mm_castsi128_ps(vq31prod3x13), _MM_SHUFFLE(2, 0, 2, 0)));
255
256 const __m128i vq31prod0x0123 = _mm_shuffle_epi32(vq31prod0x0213, _MM_SHUFFLE(3, 1, 2, 0));
257 const __m128i vq31prod1x0123 = _mm_shuffle_epi32(vq31prod1x0213, _MM_SHUFFLE(3, 1, 2, 0));
258 const __m128i vq31prod2x0123 = _mm_shuffle_epi32(vq31prod2x0213, _MM_SHUFFLE(3, 1, 2, 0));
259 const __m128i vq31prod3x0123 = _mm_shuffle_epi32(vq31prod3x0213, _MM_SHUFFLE(3, 1, 2, 0));
260
261 const __m128i vremainder_mask = _mm_load_si128((const __m128i*) params->sse2.remainder_mask);
262 const __m128i vrem0x0123 =
263 _mm_add_epi32(_mm_and_si128(vq31prod0x0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vq31prod0x0123));
264 const __m128i vrem1x0123 =
265 _mm_add_epi32(_mm_and_si128(vq31prod1x0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vq31prod1x0123));
266 const __m128i vrem2x0123 =
267 _mm_add_epi32(_mm_and_si128(vq31prod2x0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vq31prod2x0123));
268 const __m128i vrem3x0123 =
269 _mm_add_epi32(_mm_and_si128(vq31prod3x0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vq31prod3x0123));
270
271 const __m128i vremainder_threshold = _mm_load_si128((const __m128i*) params->sse2.remainder_threshold);
272 const __m128i vshift = _mm_load_si128((const __m128i*) params->sse2.shift);
273 vacc0x0123 =
274 _mm_sub_epi32(_mm_sra_epi32(vq31prod0x0123, vshift), _mm_cmpgt_epi32(vrem0x0123, vremainder_threshold));
275 vacc1x0123 =
276 _mm_sub_epi32(_mm_sra_epi32(vq31prod1x0123, vshift), _mm_cmpgt_epi32(vrem1x0123, vremainder_threshold));
277 vacc2x0123 =
278 _mm_sub_epi32(_mm_sra_epi32(vq31prod2x0123, vshift), _mm_cmpgt_epi32(vrem2x0123, vremainder_threshold));
279 vacc3x0123 =
280 _mm_sub_epi32(_mm_sra_epi32(vq31prod3x0123, vshift), _mm_cmpgt_epi32(vrem3x0123, vremainder_threshold));
281
282 const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse2.output_zero_point);
283 __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point);
284 __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point);
285
286 const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse2.output_min);
287 const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse2.output_max);
288 vacc01x0123 = _mm_min_epi16(_mm_max_epi16(vacc01x0123, voutput_min), voutput_max);
289 vacc23x0123 = _mm_min_epi16(_mm_max_epi16(vacc23x0123, voutput_min), voutput_max);
290
291 __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123);
292
293 if (nc >= 4) {
294 *((uint32_t*) c0) = (uint32_t) _mm_cvtsi128_si32(vout);
295 vout = _mm_srli_si128(vout, 4);
296 *((uint32_t*) c1) = (uint32_t) _mm_cvtsi128_si32(vout);
297 vout = _mm_srli_si128(vout, 4);
298 *((uint32_t*) c2) = (uint32_t) _mm_cvtsi128_si32(vout);
299 vout = _mm_srli_si128(vout, 4);
300 *((uint32_t*) c3) = (uint32_t) _mm_cvtsi128_si32(vout);
301
302 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
303 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
304 c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
305 c3 = (int8_t*) ((uintptr_t) c3 + cn_stride);
306
307 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
308 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
309 a2 = (const int8_t*) ((uintptr_t) a2 - kc);
310 a3 = (const int8_t*) ((uintptr_t) a3 - kc);
311
312 nc -= 4;
313 } else {
314 if (nc & 2) {
315 *((uint16_t*) c0) = (uint16_t) _mm_extract_epi16(vout, 0);
316 c0 += 2;
317 *((uint16_t*) c1) = (uint16_t) _mm_extract_epi16(vout, 2);
318 c1 += 2;
319 *((uint16_t*) c2) = (uint16_t) _mm_extract_epi16(vout, 4);
320 c2 += 2;
321 *((uint16_t*) c3) = (uint16_t) _mm_extract_epi16(vout, 6);
322 c3 += 2;
323 vout = _mm_srli_epi32(vout, 16);
324 }
325 if (nc & 1) {
326 *((int8_t*) c0) = (int8_t) _mm_cvtsi128_si32(vout);
327 *((int8_t*) c1) = (int8_t) _mm_extract_epi16(vout, 2);
328 *((int8_t*) c2) = (int8_t) _mm_extract_epi16(vout, 4);
329 *((int8_t*) c3) = (int8_t) _mm_extract_epi16(vout, 6);
330 }
331
332 nc = 0;
333 }
334 } while (nc != 0);
335 }
336