blob: 03fef19146f50ef78f4e9e1a920a2894adac6aab [file] [log] [blame]
XNNPACK Teamb455b122019-09-27 18:10:33 -07001// Auto-generated file. Do not edit!
2// Template: src/f32-gemm/psimd-splat.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 <psimd.h>
13
14#include <xnnpack/gemm.h>
15
16
17void xnn_f32_gemm_ukernel_6x8__psimd_splat(
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,
Marat Dukhaneb09a6b2020-04-08 17:34:32 -070027 const union xnn_f32_minmax_params params[restrict static 1])
XNNPACK Teamb455b122019-09-27 18:10:33 -070028{
29 assert(mr != 0);
30 assert(mr <= 6);
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 const float* a5 = (const float*) ((uintptr_t) a4 + a_stride);
65 float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
66 if XNN_UNPREDICTABLE(mr != 6) {
67 a5 = a4;
68 c5 = c4;
69 }
70
71 do {
72 psimd_f32 vacc0x0123 = psimd_load_f32(w + 0);
73 psimd_f32 vacc0x4567 = psimd_load_f32(w + 4);
74 psimd_f32 vacc1x0123 = vacc0x0123;
75 psimd_f32 vacc1x4567 = vacc0x4567;
76 psimd_f32 vacc2x0123 = vacc0x0123;
77 psimd_f32 vacc2x4567 = vacc0x4567;
78 psimd_f32 vacc3x0123 = vacc0x0123;
79 psimd_f32 vacc3x4567 = vacc0x4567;
80 psimd_f32 vacc4x0123 = vacc0x0123;
81 psimd_f32 vacc4x4567 = vacc0x4567;
82 psimd_f32 vacc5x0123 = vacc0x0123;
83 psimd_f32 vacc5x4567 = vacc0x4567;
84 w += 8;
85
86 size_t k = kc;
87 while (k >= 4 * sizeof(float)) {
88 const psimd_f32 va0 = psimd_load_f32(a0);
89 a0 += 4;
90 const psimd_f32 va1 = psimd_load_f32(a1);
91 a1 += 4;
92 const psimd_f32 va2 = psimd_load_f32(a2);
93 a2 += 4;
94 const psimd_f32 va3 = psimd_load_f32(a3);
95 a3 += 4;
96 const psimd_f32 va4 = psimd_load_f32(a4);
97 a4 += 4;
98 const psimd_f32 va5 = psimd_load_f32(a5);
99 a5 += 4;
100
101 const psimd_f32 va0c0 = psimd_splat0_f32(va0);
102 const psimd_f32 va1c0 = psimd_splat0_f32(va1);
103 const psimd_f32 va2c0 = psimd_splat0_f32(va2);
104 const psimd_f32 va3c0 = psimd_splat0_f32(va3);
105 const psimd_f32 va4c0 = psimd_splat0_f32(va4);
106 const psimd_f32 va5c0 = psimd_splat0_f32(va5);
107
108 const psimd_f32 vb0123c0 = psimd_load_f32(w + 0);
109 const psimd_f32 vb4567c0 = psimd_load_f32(w + 4);
110
111 vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0c0, vb0123c0);
112 vacc1x0123 = psimd_qfma_f32(vacc1x0123, va1c0, vb0123c0);
113 vacc2x0123 = psimd_qfma_f32(vacc2x0123, va2c0, vb0123c0);
114 vacc3x0123 = psimd_qfma_f32(vacc3x0123, va3c0, vb0123c0);
115 vacc4x0123 = psimd_qfma_f32(vacc4x0123, va4c0, vb0123c0);
116 vacc5x0123 = psimd_qfma_f32(vacc5x0123, va5c0, vb0123c0);
117 vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0c0, vb4567c0);
118 vacc1x4567 = psimd_qfma_f32(vacc1x4567, va1c0, vb4567c0);
119 vacc2x4567 = psimd_qfma_f32(vacc2x4567, va2c0, vb4567c0);
120 vacc3x4567 = psimd_qfma_f32(vacc3x4567, va3c0, vb4567c0);
121 vacc4x4567 = psimd_qfma_f32(vacc4x4567, va4c0, vb4567c0);
122 vacc5x4567 = psimd_qfma_f32(vacc5x4567, va5c0, vb4567c0);
123 const psimd_f32 va0c1 = psimd_splat1_f32(va0);
124 const psimd_f32 va1c1 = psimd_splat1_f32(va1);
125 const psimd_f32 va2c1 = psimd_splat1_f32(va2);
126 const psimd_f32 va3c1 = psimd_splat1_f32(va3);
127 const psimd_f32 va4c1 = psimd_splat1_f32(va4);
128 const psimd_f32 va5c1 = psimd_splat1_f32(va5);
129
130 const psimd_f32 vb0123c1 = psimd_load_f32(w + 8);
131 const psimd_f32 vb4567c1 = psimd_load_f32(w + 12);
132
133 vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0c1, vb0123c1);
134 vacc1x0123 = psimd_qfma_f32(vacc1x0123, va1c1, vb0123c1);
135 vacc2x0123 = psimd_qfma_f32(vacc2x0123, va2c1, vb0123c1);
136 vacc3x0123 = psimd_qfma_f32(vacc3x0123, va3c1, vb0123c1);
137 vacc4x0123 = psimd_qfma_f32(vacc4x0123, va4c1, vb0123c1);
138 vacc5x0123 = psimd_qfma_f32(vacc5x0123, va5c1, vb0123c1);
139 vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0c1, vb4567c1);
140 vacc1x4567 = psimd_qfma_f32(vacc1x4567, va1c1, vb4567c1);
141 vacc2x4567 = psimd_qfma_f32(vacc2x4567, va2c1, vb4567c1);
142 vacc3x4567 = psimd_qfma_f32(vacc3x4567, va3c1, vb4567c1);
143 vacc4x4567 = psimd_qfma_f32(vacc4x4567, va4c1, vb4567c1);
144 vacc5x4567 = psimd_qfma_f32(vacc5x4567, va5c1, vb4567c1);
145 const psimd_f32 va0c2 = psimd_splat2_f32(va0);
146 const psimd_f32 va1c2 = psimd_splat2_f32(va1);
147 const psimd_f32 va2c2 = psimd_splat2_f32(va2);
148 const psimd_f32 va3c2 = psimd_splat2_f32(va3);
149 const psimd_f32 va4c2 = psimd_splat2_f32(va4);
150 const psimd_f32 va5c2 = psimd_splat2_f32(va5);
151
152 const psimd_f32 vb0123c2 = psimd_load_f32(w + 16);
153 const psimd_f32 vb4567c2 = psimd_load_f32(w + 20);
154
155 vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0c2, vb0123c2);
156 vacc1x0123 = psimd_qfma_f32(vacc1x0123, va1c2, vb0123c2);
157 vacc2x0123 = psimd_qfma_f32(vacc2x0123, va2c2, vb0123c2);
158 vacc3x0123 = psimd_qfma_f32(vacc3x0123, va3c2, vb0123c2);
159 vacc4x0123 = psimd_qfma_f32(vacc4x0123, va4c2, vb0123c2);
160 vacc5x0123 = psimd_qfma_f32(vacc5x0123, va5c2, vb0123c2);
161 vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0c2, vb4567c2);
162 vacc1x4567 = psimd_qfma_f32(vacc1x4567, va1c2, vb4567c2);
163 vacc2x4567 = psimd_qfma_f32(vacc2x4567, va2c2, vb4567c2);
164 vacc3x4567 = psimd_qfma_f32(vacc3x4567, va3c2, vb4567c2);
165 vacc4x4567 = psimd_qfma_f32(vacc4x4567, va4c2, vb4567c2);
166 vacc5x4567 = psimd_qfma_f32(vacc5x4567, va5c2, vb4567c2);
167 const psimd_f32 va0c3 = psimd_splat3_f32(va0);
168 const psimd_f32 va1c3 = psimd_splat3_f32(va1);
169 const psimd_f32 va2c3 = psimd_splat3_f32(va2);
170 const psimd_f32 va3c3 = psimd_splat3_f32(va3);
171 const psimd_f32 va4c3 = psimd_splat3_f32(va4);
172 const psimd_f32 va5c3 = psimd_splat3_f32(va5);
173
174 const psimd_f32 vb0123c3 = psimd_load_f32(w + 24);
175 const psimd_f32 vb4567c3 = psimd_load_f32(w + 28);
176
177 vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0c3, vb0123c3);
178 vacc1x0123 = psimd_qfma_f32(vacc1x0123, va1c3, vb0123c3);
179 vacc2x0123 = psimd_qfma_f32(vacc2x0123, va2c3, vb0123c3);
180 vacc3x0123 = psimd_qfma_f32(vacc3x0123, va3c3, vb0123c3);
181 vacc4x0123 = psimd_qfma_f32(vacc4x0123, va4c3, vb0123c3);
182 vacc5x0123 = psimd_qfma_f32(vacc5x0123, va5c3, vb0123c3);
183 vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0c3, vb4567c3);
184 vacc1x4567 = psimd_qfma_f32(vacc1x4567, va1c3, vb4567c3);
185 vacc2x4567 = psimd_qfma_f32(vacc2x4567, va2c3, vb4567c3);
186 vacc3x4567 = psimd_qfma_f32(vacc3x4567, va3c3, vb4567c3);
187 vacc4x4567 = psimd_qfma_f32(vacc4x4567, va4c3, vb4567c3);
188 vacc5x4567 = psimd_qfma_f32(vacc5x4567, va5c3, vb4567c3);
189
190 w += 32;
191 k -= 4 * sizeof(float);
192 }
193 if XNN_UNLIKELY(k != 0) {
194 do {
195 const psimd_f32 va0 = psimd_load_splat_f32(a0);
196 a0 += 1;
197 const psimd_f32 va1 = psimd_load_splat_f32(a1);
198 a1 += 1;
199 const psimd_f32 va2 = psimd_load_splat_f32(a2);
200 a2 += 1;
201 const psimd_f32 va3 = psimd_load_splat_f32(a3);
202 a3 += 1;
203 const psimd_f32 va4 = psimd_load_splat_f32(a4);
204 a4 += 1;
205 const psimd_f32 va5 = psimd_load_splat_f32(a5);
206 a5 += 1;
207
208 const psimd_f32 vb0123 = psimd_load_f32(w);
209 const psimd_f32 vb4567 = psimd_load_f32(w + 4);
210 w += 8;
211
212 vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0, vb0123);
213 vacc1x0123 = psimd_qfma_f32(vacc1x0123, va1, vb0123);
214 vacc2x0123 = psimd_qfma_f32(vacc2x0123, va2, vb0123);
215 vacc3x0123 = psimd_qfma_f32(vacc3x0123, va3, vb0123);
216 vacc4x0123 = psimd_qfma_f32(vacc4x0123, va4, vb0123);
217 vacc5x0123 = psimd_qfma_f32(vacc5x0123, va5, vb0123);
218 vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0, vb4567);
219 vacc1x4567 = psimd_qfma_f32(vacc1x4567, va1, vb4567);
220 vacc2x4567 = psimd_qfma_f32(vacc2x4567, va2, vb4567);
221 vacc3x4567 = psimd_qfma_f32(vacc3x4567, va3, vb4567);
222 vacc4x4567 = psimd_qfma_f32(vacc4x4567, va4, vb4567);
223 vacc5x4567 = psimd_qfma_f32(vacc5x4567, va5, vb4567);
224
225 k -= sizeof(float);
226 } while (k != 0);
227 }
228
229 const psimd_f32 vmax = psimd_load_splat_f32(&params->scalar.max);
230 vacc0x0123 = psimd_min_f32(vacc0x0123, vmax);
231 vacc1x0123 = psimd_min_f32(vacc1x0123, vmax);
232 vacc2x0123 = psimd_min_f32(vacc2x0123, vmax);
233 vacc3x0123 = psimd_min_f32(vacc3x0123, vmax);
234 vacc4x0123 = psimd_min_f32(vacc4x0123, vmax);
235 vacc5x0123 = psimd_min_f32(vacc5x0123, vmax);
236 vacc0x4567 = psimd_min_f32(vacc0x4567, vmax);
237 vacc1x4567 = psimd_min_f32(vacc1x4567, vmax);
238 vacc2x4567 = psimd_min_f32(vacc2x4567, vmax);
239 vacc3x4567 = psimd_min_f32(vacc3x4567, vmax);
240 vacc4x4567 = psimd_min_f32(vacc4x4567, vmax);
241 vacc5x4567 = psimd_min_f32(vacc5x4567, vmax);
242
243 const psimd_f32 vmin = psimd_load_splat_f32(&params->scalar.min);
244 vacc0x0123 = psimd_max_f32(vacc0x0123, vmin);
245 vacc1x0123 = psimd_max_f32(vacc1x0123, vmin);
246 vacc2x0123 = psimd_max_f32(vacc2x0123, vmin);
247 vacc3x0123 = psimd_max_f32(vacc3x0123, vmin);
248 vacc4x0123 = psimd_max_f32(vacc4x0123, vmin);
249 vacc5x0123 = psimd_max_f32(vacc5x0123, vmin);
250 vacc0x4567 = psimd_max_f32(vacc0x4567, vmin);
251 vacc1x4567 = psimd_max_f32(vacc1x4567, vmin);
252 vacc2x4567 = psimd_max_f32(vacc2x4567, vmin);
253 vacc3x4567 = psimd_max_f32(vacc3x4567, vmin);
254 vacc4x4567 = psimd_max_f32(vacc4x4567, vmin);
255 vacc5x4567 = psimd_max_f32(vacc5x4567, vmin);
256
257 if XNN_LIKELY(nc >= 8) {
258 psimd_store_f32(c5, vacc5x0123);
259 psimd_store_f32(c5 + 4, vacc5x4567);
260 c5 = (float*) ((uintptr_t) c5 + cn_stride);
261 psimd_store_f32(c4, vacc4x0123);
262 psimd_store_f32(c4 + 4, vacc4x4567);
263 c4 = (float*) ((uintptr_t) c4 + cn_stride);
264 psimd_store_f32(c3, vacc3x0123);
265 psimd_store_f32(c3 + 4, vacc3x4567);
266 c3 = (float*) ((uintptr_t) c3 + cn_stride);
267 psimd_store_f32(c2, vacc2x0123);
268 psimd_store_f32(c2 + 4, vacc2x4567);
269 c2 = (float*) ((uintptr_t) c2 + cn_stride);
270 psimd_store_f32(c1, vacc1x0123);
271 psimd_store_f32(c1 + 4, vacc1x4567);
272 c1 = (float*) ((uintptr_t) c1 + cn_stride);
273 psimd_store_f32(c0, vacc0x0123);
274 psimd_store_f32(c0 + 4, vacc0x4567);
275 c0 = (float*) ((uintptr_t) c0 + cn_stride);
276
277 a5 = (const float*) ((uintptr_t) a5 - kc);
278 a4 = (const float*) ((uintptr_t) a4 - kc);
279 a3 = (const float*) ((uintptr_t) a3 - kc);
280 a2 = (const float*) ((uintptr_t) a2 - kc);
281 a1 = (const float*) ((uintptr_t) a1 - kc);
282 a0 = (const float*) ((uintptr_t) a0 - kc);
283
284 nc -= 8;
285 } else {
286 if (nc & 4) {
287 psimd_store_f32(c5, vacc5x0123);
288 psimd_store_f32(c4, vacc4x0123);
289 psimd_store_f32(c3, vacc3x0123);
290 psimd_store_f32(c2, vacc2x0123);
291 psimd_store_f32(c1, vacc1x0123);
292 psimd_store_f32(c0, vacc0x0123);
293
294 vacc5x0123 = vacc5x4567;
295 vacc4x0123 = vacc4x4567;
296 vacc3x0123 = vacc3x4567;
297 vacc2x0123 = vacc2x4567;
298 vacc1x0123 = vacc1x4567;
299 vacc0x0123 = vacc0x4567;
300
301 c5 += 4;
302 c4 += 4;
303 c3 += 4;
304 c2 += 4;
305 c1 += 4;
306 c0 += 4;
307 }
308 if (nc & 2) {
309 psimd_store2_f32(c5, vacc5x0123);
310 psimd_store2_f32(c4, vacc4x0123);
311 psimd_store2_f32(c3, vacc3x0123);
312 psimd_store2_f32(c2, vacc2x0123);
313 psimd_store2_f32(c1, vacc1x0123);
314 psimd_store2_f32(c0, vacc0x0123);
315
316 vacc5x0123 = psimd_concat_hi_f32(vacc5x0123, vacc5x0123);
317 vacc4x0123 = psimd_concat_hi_f32(vacc4x0123, vacc4x0123);
318 vacc3x0123 = psimd_concat_hi_f32(vacc3x0123, vacc3x0123);
319 vacc2x0123 = psimd_concat_hi_f32(vacc2x0123, vacc2x0123);
320 vacc1x0123 = psimd_concat_hi_f32(vacc1x0123, vacc1x0123);
321 vacc0x0123 = psimd_concat_hi_f32(vacc0x0123, vacc0x0123);
322
323 c5 += 2;
324 c4 += 2;
325 c3 += 2;
326 c2 += 2;
327 c1 += 2;
328 c0 += 2;
329 }
330 if (nc & 1) {
331 psimd_store1_f32(c5, vacc5x0123);
332 psimd_store1_f32(c4, vacc4x0123);
333 psimd_store1_f32(c3, vacc3x0123);
334 psimd_store1_f32(c2, vacc2x0123);
335 psimd_store1_f32(c1, vacc1x0123);
336 psimd_store1_f32(c0, vacc0x0123);
337 }
338
339 nc = 0;
340 }
341 } while (nc != 0);
342}