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