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