1 // Auto-generated file. Do not edit!
2 // Template: src/f32-gemm/sse-dup.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2019 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
16
xnn_f32_gemminc_minmax_ukernel_5x8__sse2_dup(size_t mr,size_t nc,size_t kc,const float * restrict a,size_t a_stride,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,const float * restrict acc,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_gemminc_minmax_ukernel_5x8__sse2_dup(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 const float*restrict a,
22 size_t a_stride,
23 const float*restrict w,
24 float*restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 const float*restrict acc,
28 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30 assert(mr != 0);
31 assert(mr <= 5);
32 assert(nc != 0);
33 assert(kc != 0);
34 assert(kc % sizeof(float) == 0);
35 assert(a != NULL);
36 assert(w != NULL);
37 assert(c != NULL);
38 assert(acc != NULL);
39
40 const float* a0 = a;
41 float* c0 = c;
42 const float* a1 = (const float*) ((uintptr_t) a0 + a_stride);
43 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
44 if XNN_UNPREDICTABLE(mr < 2) {
45 a1 = a0;
46 c1 = c0;
47 }
48 const float* a2 = (const float*) ((uintptr_t) a1 + a_stride);
49 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
50 if XNN_UNPREDICTABLE(mr <= 2) {
51 a2 = a1;
52 c2 = c1;
53 }
54 const float* a3 = (const float*) ((uintptr_t) a2 + a_stride);
55 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
56 if XNN_UNPREDICTABLE(mr < 4) {
57 a3 = a2;
58 c3 = c2;
59 }
60 const float* a4 = (const float*) ((uintptr_t) a3 + a_stride);
61 float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
62 if XNN_UNPREDICTABLE(mr <= 4) {
63 a4 = a3;
64 c4 = c3;
65 }
66
67 do {
68 __m128 vacc0x0123 = _mm_load_ps(acc + 0);
69 __m128 vacc0x4567 = _mm_load_ps(acc + 4);
70 __m128 vacc1x0123 = _mm_load_ps(acc + 8);
71 __m128 vacc1x4567 = _mm_load_ps(acc + 12);
72 __m128 vacc2x0123 = _mm_load_ps(acc + 16);
73 __m128 vacc2x4567 = _mm_load_ps(acc + 20);
74 __m128 vacc3x0123 = _mm_load_ps(acc + 24);
75 __m128 vacc3x4567 = _mm_load_ps(acc + 28);
76 __m128 vacc4x0123 = _mm_load_ps(acc + 32);
77 __m128 vacc4x4567 = _mm_load_ps(acc + 36);
78 acc += 40;
79
80 size_t k = kc;
81 while (k >= 4 * sizeof(float)) {
82 const __m128 va0 = _mm_loadu_ps(a0);
83 a0 += 4;
84 const __m128 va1 = _mm_loadu_ps(a1);
85 a1 += 4;
86 const __m128 va2 = _mm_loadu_ps(a2);
87 a2 += 4;
88 const __m128 va3 = _mm_loadu_ps(a3);
89 a3 += 4;
90 const __m128 va4 = _mm_loadu_ps(a4);
91 a4 += 4;
92
93
94 const __m128 va0c0000 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va0), _MM_SHUFFLE(0, 0, 0, 0)));
95 const __m128 va1c0000 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va1), _MM_SHUFFLE(0, 0, 0, 0)));
96 const __m128 va2c0000 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va2), _MM_SHUFFLE(0, 0, 0, 0)));
97 const __m128 va3c0000 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va3), _MM_SHUFFLE(0, 0, 0, 0)));
98 const __m128 va4c0000 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va4), _MM_SHUFFLE(0, 0, 0, 0)));
99
100 const __m128 vb0123c0 = _mm_load_ps(w + 0);
101 const __m128 vb4567c0 = _mm_load_ps(w + 4);
102
103 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c0000, vb0123c0));
104 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c0000, vb0123c0));
105 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c0000, vb0123c0));
106 vacc3x0123 = _mm_add_ps(vacc3x0123, _mm_mul_ps(va3c0000, vb0123c0));
107 vacc4x0123 = _mm_add_ps(vacc4x0123, _mm_mul_ps(va4c0000, vb0123c0));
108 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c0000, vb4567c0));
109 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c0000, vb4567c0));
110 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c0000, vb4567c0));
111 vacc3x4567 = _mm_add_ps(vacc3x4567, _mm_mul_ps(va3c0000, vb4567c0));
112 vacc4x4567 = _mm_add_ps(vacc4x4567, _mm_mul_ps(va4c0000, vb4567c0));
113
114 const __m128 va0c1111 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va0), _MM_SHUFFLE(1, 1, 1, 1)));
115 const __m128 va1c1111 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va1), _MM_SHUFFLE(1, 1, 1, 1)));
116 const __m128 va2c1111 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va2), _MM_SHUFFLE(1, 1, 1, 1)));
117 const __m128 va3c1111 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va3), _MM_SHUFFLE(1, 1, 1, 1)));
118 const __m128 va4c1111 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va4), _MM_SHUFFLE(1, 1, 1, 1)));
119
120 const __m128 vb0123c1 = _mm_load_ps(w + 8);
121 const __m128 vb4567c1 = _mm_load_ps(w + 12);
122
123 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c1111, vb0123c1));
124 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c1111, vb0123c1));
125 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c1111, vb0123c1));
126 vacc3x0123 = _mm_add_ps(vacc3x0123, _mm_mul_ps(va3c1111, vb0123c1));
127 vacc4x0123 = _mm_add_ps(vacc4x0123, _mm_mul_ps(va4c1111, vb0123c1));
128 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c1111, vb4567c1));
129 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c1111, vb4567c1));
130 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c1111, vb4567c1));
131 vacc3x4567 = _mm_add_ps(vacc3x4567, _mm_mul_ps(va3c1111, vb4567c1));
132 vacc4x4567 = _mm_add_ps(vacc4x4567, _mm_mul_ps(va4c1111, vb4567c1));
133
134 const __m128 va0c2222 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va0), _MM_SHUFFLE(2, 2, 2, 2)));
135 const __m128 va1c2222 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va1), _MM_SHUFFLE(2, 2, 2, 2)));
136 const __m128 va2c2222 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va2), _MM_SHUFFLE(2, 2, 2, 2)));
137 const __m128 va3c2222 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va3), _MM_SHUFFLE(2, 2, 2, 2)));
138 const __m128 va4c2222 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va4), _MM_SHUFFLE(2, 2, 2, 2)));
139
140 const __m128 vb0123c2 = _mm_load_ps(w + 16);
141 const __m128 vb4567c2 = _mm_load_ps(w + 20);
142
143 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c2222, vb0123c2));
144 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c2222, vb0123c2));
145 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c2222, vb0123c2));
146 vacc3x0123 = _mm_add_ps(vacc3x0123, _mm_mul_ps(va3c2222, vb0123c2));
147 vacc4x0123 = _mm_add_ps(vacc4x0123, _mm_mul_ps(va4c2222, vb0123c2));
148 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c2222, vb4567c2));
149 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c2222, vb4567c2));
150 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c2222, vb4567c2));
151 vacc3x4567 = _mm_add_ps(vacc3x4567, _mm_mul_ps(va3c2222, vb4567c2));
152 vacc4x4567 = _mm_add_ps(vacc4x4567, _mm_mul_ps(va4c2222, vb4567c2));
153
154 const __m128 va0c3333 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(3, 3, 3, 3));
155 const __m128 va1c3333 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(3, 3, 3, 3));
156 const __m128 va2c3333 = _mm_shuffle_ps(va2, va2, _MM_SHUFFLE(3, 3, 3, 3));
157 const __m128 va3c3333 = _mm_shuffle_ps(va3, va3, _MM_SHUFFLE(3, 3, 3, 3));
158 const __m128 va4c3333 = _mm_shuffle_ps(va4, va4, _MM_SHUFFLE(3, 3, 3, 3));
159
160 const __m128 vb0123c3 = _mm_load_ps(w + 24);
161 const __m128 vb4567c3 = _mm_load_ps(w + 28);
162
163 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c3333, vb0123c3));
164 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c3333, vb0123c3));
165 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c3333, vb0123c3));
166 vacc3x0123 = _mm_add_ps(vacc3x0123, _mm_mul_ps(va3c3333, vb0123c3));
167 vacc4x0123 = _mm_add_ps(vacc4x0123, _mm_mul_ps(va4c3333, vb0123c3));
168 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c3333, vb4567c3));
169 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c3333, vb4567c3));
170 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c3333, vb4567c3));
171 vacc3x4567 = _mm_add_ps(vacc3x4567, _mm_mul_ps(va3c3333, vb4567c3));
172 vacc4x4567 = _mm_add_ps(vacc4x4567, _mm_mul_ps(va4c3333, vb4567c3));
173
174 w += 32;
175 k -= 4 * sizeof(float);
176 }
177 if XNN_UNLIKELY(k != 0) {
178 do {
179 const __m128 va0 = _mm_load1_ps(a0);
180 a0 += 1;
181 const __m128 va1 = _mm_load1_ps(a1);
182 a1 += 1;
183 const __m128 va2 = _mm_load1_ps(a2);
184 a2 += 1;
185 const __m128 va3 = _mm_load1_ps(a3);
186 a3 += 1;
187 const __m128 va4 = _mm_load1_ps(a4);
188 a4 += 1;
189
190 const __m128 vb0123 = _mm_load_ps(w);
191 const __m128 vb4567 = _mm_load_ps(w + 4);
192 w += 8;
193
194 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0, vb0123));
195 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1, vb0123));
196 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2, vb0123));
197 vacc3x0123 = _mm_add_ps(vacc3x0123, _mm_mul_ps(va3, vb0123));
198 vacc4x0123 = _mm_add_ps(vacc4x0123, _mm_mul_ps(va4, vb0123));
199 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0, vb4567));
200 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1, vb4567));
201 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2, vb4567));
202 vacc3x4567 = _mm_add_ps(vacc3x4567, _mm_mul_ps(va3, vb4567));
203 vacc4x4567 = _mm_add_ps(vacc4x4567, _mm_mul_ps(va4, vb4567));
204
205 k -= sizeof(float);
206 } while (k != 0);
207 }
208
209 const __m128 vmax = _mm_load_ps(params->sse.max);
210 vacc0x0123 = _mm_min_ps(vacc0x0123, vmax);
211 vacc1x0123 = _mm_min_ps(vacc1x0123, vmax);
212 vacc2x0123 = _mm_min_ps(vacc2x0123, vmax);
213 vacc3x0123 = _mm_min_ps(vacc3x0123, vmax);
214 vacc4x0123 = _mm_min_ps(vacc4x0123, vmax);
215 vacc0x4567 = _mm_min_ps(vacc0x4567, vmax);
216 vacc1x4567 = _mm_min_ps(vacc1x4567, vmax);
217 vacc2x4567 = _mm_min_ps(vacc2x4567, vmax);
218 vacc3x4567 = _mm_min_ps(vacc3x4567, vmax);
219 vacc4x4567 = _mm_min_ps(vacc4x4567, vmax);
220
221 const __m128 vmin = _mm_load_ps(params->sse.min);
222 vacc0x0123 = _mm_max_ps(vacc0x0123, vmin);
223 vacc1x0123 = _mm_max_ps(vacc1x0123, vmin);
224 vacc2x0123 = _mm_max_ps(vacc2x0123, vmin);
225 vacc3x0123 = _mm_max_ps(vacc3x0123, vmin);
226 vacc4x0123 = _mm_max_ps(vacc4x0123, vmin);
227 vacc0x4567 = _mm_max_ps(vacc0x4567, vmin);
228 vacc1x4567 = _mm_max_ps(vacc1x4567, vmin);
229 vacc2x4567 = _mm_max_ps(vacc2x4567, vmin);
230 vacc3x4567 = _mm_max_ps(vacc3x4567, vmin);
231 vacc4x4567 = _mm_max_ps(vacc4x4567, vmin);
232
233 if XNN_LIKELY(nc >= 8) {
234 _mm_storeu_ps(c4, vacc4x0123);
235 _mm_storeu_ps(c4 + 4, vacc4x4567);
236 c4 = (float*) ((uintptr_t) c4 + cn_stride);
237 _mm_storeu_ps(c3, vacc3x0123);
238 _mm_storeu_ps(c3 + 4, vacc3x4567);
239 c3 = (float*) ((uintptr_t) c3 + cn_stride);
240 _mm_storeu_ps(c2, vacc2x0123);
241 _mm_storeu_ps(c2 + 4, vacc2x4567);
242 c2 = (float*) ((uintptr_t) c2 + cn_stride);
243 _mm_storeu_ps(c1, vacc1x0123);
244 _mm_storeu_ps(c1 + 4, vacc1x4567);
245 c1 = (float*) ((uintptr_t) c1 + cn_stride);
246 _mm_storeu_ps(c0, vacc0x0123);
247 _mm_storeu_ps(c0 + 4, vacc0x4567);
248 c0 = (float*) ((uintptr_t) c0 + cn_stride);
249
250 a4 = (const float*) ((uintptr_t) a4 - kc);
251 a3 = (const float*) ((uintptr_t) a3 - kc);
252 a2 = (const float*) ((uintptr_t) a2 - kc);
253 a1 = (const float*) ((uintptr_t) a1 - kc);
254 a0 = (const float*) ((uintptr_t) a0 - kc);
255
256 nc -= 8;
257 } else {
258 if (nc & 4) {
259 _mm_storeu_ps(c4, vacc4x0123);
260 _mm_storeu_ps(c3, vacc3x0123);
261 _mm_storeu_ps(c2, vacc2x0123);
262 _mm_storeu_ps(c1, vacc1x0123);
263 _mm_storeu_ps(c0, vacc0x0123);
264
265 vacc4x0123 = vacc4x4567;
266 vacc3x0123 = vacc3x4567;
267 vacc2x0123 = vacc2x4567;
268 vacc1x0123 = vacc1x4567;
269 vacc0x0123 = vacc0x4567;
270
271 c4 += 4;
272 c3 += 4;
273 c2 += 4;
274 c1 += 4;
275 c0 += 4;
276 }
277 if (nc & 2) {
278 _mm_storel_pi((__m64*) c4, vacc4x0123);
279 _mm_storel_pi((__m64*) c3, vacc3x0123);
280 _mm_storel_pi((__m64*) c2, vacc2x0123);
281 _mm_storel_pi((__m64*) c1, vacc1x0123);
282 _mm_storel_pi((__m64*) c0, vacc0x0123);
283
284 vacc4x0123 = _mm_movehl_ps(vacc4x0123, vacc4x0123);
285 vacc3x0123 = _mm_movehl_ps(vacc3x0123, vacc3x0123);
286 vacc2x0123 = _mm_movehl_ps(vacc2x0123, vacc2x0123);
287 vacc1x0123 = _mm_movehl_ps(vacc1x0123, vacc1x0123);
288 vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
289
290 c4 += 2;
291 c3 += 2;
292 c2 += 2;
293 c1 += 2;
294 c0 += 2;
295 }
296 if (nc & 1) {
297 _mm_store_ss(c4, vacc4x0123);
298 _mm_store_ss(c3, vacc3x0123);
299 _mm_store_ss(c2, vacc2x0123);
300 _mm_store_ss(c1, vacc1x0123);
301 _mm_store_ss(c0, vacc0x0123);
302 }
303
304 nc = 0;
305 }
306 } while (nc != 0);
307 }
308