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