• 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_4x8__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_4x8__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 <= 4);
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 
61   do {
62     psimd_f32 vacc0x0123 = psimd_load_f32(acc + 0);
63     psimd_f32 vacc0x4567 = psimd_load_f32(acc + 4);
64     psimd_f32 vacc1x0123 = psimd_load_f32(acc + 8);
65     psimd_f32 vacc1x4567 = psimd_load_f32(acc + 12);
66     psimd_f32 vacc2x0123 = psimd_load_f32(acc + 16);
67     psimd_f32 vacc2x4567 = psimd_load_f32(acc + 20);
68     psimd_f32 vacc3x0123 = psimd_load_f32(acc + 24);
69     psimd_f32 vacc3x4567 = psimd_load_f32(acc + 28);
70     acc += 32;
71 
72     size_t k = kc;
73     while (k >= 4 * sizeof(float)) {
74       const psimd_f32 va0 = psimd_load_f32(a0);
75       a0 += 4;
76       const psimd_f32 va1 = psimd_load_f32(a1);
77       a1 += 4;
78       const psimd_f32 va2 = psimd_load_f32(a2);
79       a2 += 4;
80       const psimd_f32 va3 = psimd_load_f32(a3);
81       a3 += 4;
82 
83       const psimd_f32 va0c0 = psimd_splat0_f32(va0);
84       const psimd_f32 va1c0 = psimd_splat0_f32(va1);
85       const psimd_f32 va2c0 = psimd_splat0_f32(va2);
86       const psimd_f32 va3c0 = psimd_splat0_f32(va3);
87 
88       const psimd_f32 vb0123c0 = psimd_load_f32(w + 0);
89       const psimd_f32 vb4567c0 = psimd_load_f32(w + 4);
90 
91       vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0c0, vb0123c0);
92       vacc1x0123 = psimd_qfma_f32(vacc1x0123, va1c0, vb0123c0);
93       vacc2x0123 = psimd_qfma_f32(vacc2x0123, va2c0, vb0123c0);
94       vacc3x0123 = psimd_qfma_f32(vacc3x0123, va3c0, vb0123c0);
95       vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0c0, vb4567c0);
96       vacc1x4567 = psimd_qfma_f32(vacc1x4567, va1c0, vb4567c0);
97       vacc2x4567 = psimd_qfma_f32(vacc2x4567, va2c0, vb4567c0);
98       vacc3x4567 = psimd_qfma_f32(vacc3x4567, va3c0, vb4567c0);
99       const psimd_f32 va0c1 = psimd_splat1_f32(va0);
100       const psimd_f32 va1c1 = psimd_splat1_f32(va1);
101       const psimd_f32 va2c1 = psimd_splat1_f32(va2);
102       const psimd_f32 va3c1 = psimd_splat1_f32(va3);
103 
104       const psimd_f32 vb0123c1 = psimd_load_f32(w + 8);
105       const psimd_f32 vb4567c1 = psimd_load_f32(w + 12);
106 
107       vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0c1, vb0123c1);
108       vacc1x0123 = psimd_qfma_f32(vacc1x0123, va1c1, vb0123c1);
109       vacc2x0123 = psimd_qfma_f32(vacc2x0123, va2c1, vb0123c1);
110       vacc3x0123 = psimd_qfma_f32(vacc3x0123, va3c1, vb0123c1);
111       vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0c1, vb4567c1);
112       vacc1x4567 = psimd_qfma_f32(vacc1x4567, va1c1, vb4567c1);
113       vacc2x4567 = psimd_qfma_f32(vacc2x4567, va2c1, vb4567c1);
114       vacc3x4567 = psimd_qfma_f32(vacc3x4567, va3c1, vb4567c1);
115       const psimd_f32 va0c2 = psimd_splat2_f32(va0);
116       const psimd_f32 va1c2 = psimd_splat2_f32(va1);
117       const psimd_f32 va2c2 = psimd_splat2_f32(va2);
118       const psimd_f32 va3c2 = psimd_splat2_f32(va3);
119 
120       const psimd_f32 vb0123c2 = psimd_load_f32(w + 16);
121       const psimd_f32 vb4567c2 = psimd_load_f32(w + 20);
122 
123       vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0c2, vb0123c2);
124       vacc1x0123 = psimd_qfma_f32(vacc1x0123, va1c2, vb0123c2);
125       vacc2x0123 = psimd_qfma_f32(vacc2x0123, va2c2, vb0123c2);
126       vacc3x0123 = psimd_qfma_f32(vacc3x0123, va3c2, vb0123c2);
127       vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0c2, vb4567c2);
128       vacc1x4567 = psimd_qfma_f32(vacc1x4567, va1c2, vb4567c2);
129       vacc2x4567 = psimd_qfma_f32(vacc2x4567, va2c2, vb4567c2);
130       vacc3x4567 = psimd_qfma_f32(vacc3x4567, va3c2, vb4567c2);
131       const psimd_f32 va0c3 = psimd_splat3_f32(va0);
132       const psimd_f32 va1c3 = psimd_splat3_f32(va1);
133       const psimd_f32 va2c3 = psimd_splat3_f32(va2);
134       const psimd_f32 va3c3 = psimd_splat3_f32(va3);
135 
136       const psimd_f32 vb0123c3 = psimd_load_f32(w + 24);
137       const psimd_f32 vb4567c3 = psimd_load_f32(w + 28);
138 
139       vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0c3, vb0123c3);
140       vacc1x0123 = psimd_qfma_f32(vacc1x0123, va1c3, vb0123c3);
141       vacc2x0123 = psimd_qfma_f32(vacc2x0123, va2c3, vb0123c3);
142       vacc3x0123 = psimd_qfma_f32(vacc3x0123, va3c3, vb0123c3);
143       vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0c3, vb4567c3);
144       vacc1x4567 = psimd_qfma_f32(vacc1x4567, va1c3, vb4567c3);
145       vacc2x4567 = psimd_qfma_f32(vacc2x4567, va2c3, vb4567c3);
146       vacc3x4567 = psimd_qfma_f32(vacc3x4567, va3c3, vb4567c3);
147 
148       w += 32;
149       k -= 4 * sizeof(float);
150     }
151     if XNN_UNLIKELY(k != 0) {
152       do {
153         const psimd_f32 va0 = psimd_load_splat_f32(a0);
154         a0 += 1;
155         const psimd_f32 va1 = psimd_load_splat_f32(a1);
156         a1 += 1;
157         const psimd_f32 va2 = psimd_load_splat_f32(a2);
158         a2 += 1;
159         const psimd_f32 va3 = psimd_load_splat_f32(a3);
160         a3 += 1;
161 
162         const psimd_f32 vb0123 = psimd_load_f32(w);
163         const psimd_f32 vb4567 = psimd_load_f32(w + 4);
164         w += 8;
165 
166         vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0, vb0123);
167         vacc1x0123 = psimd_qfma_f32(vacc1x0123, va1, vb0123);
168         vacc2x0123 = psimd_qfma_f32(vacc2x0123, va2, vb0123);
169         vacc3x0123 = psimd_qfma_f32(vacc3x0123, va3, vb0123);
170         vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0, vb4567);
171         vacc1x4567 = psimd_qfma_f32(vacc1x4567, va1, vb4567);
172         vacc2x4567 = psimd_qfma_f32(vacc2x4567, va2, vb4567);
173         vacc3x4567 = psimd_qfma_f32(vacc3x4567, va3, vb4567);
174 
175         k -= sizeof(float);
176       } while (k != 0);
177     }
178 
179     const psimd_f32 vmax = psimd_load_splat_f32(&params->scalar.max);
180     vacc0x0123 = psimd_min_f32(vacc0x0123, vmax);
181     vacc1x0123 = psimd_min_f32(vacc1x0123, vmax);
182     vacc2x0123 = psimd_min_f32(vacc2x0123, vmax);
183     vacc3x0123 = psimd_min_f32(vacc3x0123, vmax);
184     vacc0x4567 = psimd_min_f32(vacc0x4567, vmax);
185     vacc1x4567 = psimd_min_f32(vacc1x4567, vmax);
186     vacc2x4567 = psimd_min_f32(vacc2x4567, vmax);
187     vacc3x4567 = psimd_min_f32(vacc3x4567, vmax);
188 
189     const psimd_f32 vmin = psimd_load_splat_f32(&params->scalar.min);
190     vacc0x0123 = psimd_max_f32(vacc0x0123, vmin);
191     vacc1x0123 = psimd_max_f32(vacc1x0123, vmin);
192     vacc2x0123 = psimd_max_f32(vacc2x0123, vmin);
193     vacc3x0123 = psimd_max_f32(vacc3x0123, vmin);
194     vacc0x4567 = psimd_max_f32(vacc0x4567, vmin);
195     vacc1x4567 = psimd_max_f32(vacc1x4567, vmin);
196     vacc2x4567 = psimd_max_f32(vacc2x4567, vmin);
197     vacc3x4567 = psimd_max_f32(vacc3x4567, vmin);
198 
199     if XNN_LIKELY(nc >= 8) {
200       psimd_store_f32(c3, vacc3x0123);
201       psimd_store_f32(c3 + 4, vacc3x4567);
202       c3 = (float*) ((uintptr_t) c3 + cn_stride);
203       psimd_store_f32(c2, vacc2x0123);
204       psimd_store_f32(c2 + 4, vacc2x4567);
205       c2 = (float*) ((uintptr_t) c2 + cn_stride);
206       psimd_store_f32(c1, vacc1x0123);
207       psimd_store_f32(c1 + 4, vacc1x4567);
208       c1 = (float*) ((uintptr_t) c1 + cn_stride);
209       psimd_store_f32(c0, vacc0x0123);
210       psimd_store_f32(c0 + 4, vacc0x4567);
211       c0 = (float*) ((uintptr_t) c0 + cn_stride);
212 
213       a3 = (const float*) ((uintptr_t) a3 - kc);
214       a2 = (const float*) ((uintptr_t) a2 - kc);
215       a1 = (const float*) ((uintptr_t) a1 - kc);
216       a0 = (const float*) ((uintptr_t) a0 - kc);
217 
218       nc -= 8;
219     } else {
220       if (nc & 4) {
221         psimd_store_f32(c3, vacc3x0123);
222         psimd_store_f32(c2, vacc2x0123);
223         psimd_store_f32(c1, vacc1x0123);
224         psimd_store_f32(c0, vacc0x0123);
225 
226         vacc3x0123 = vacc3x4567;
227         vacc2x0123 = vacc2x4567;
228         vacc1x0123 = vacc1x4567;
229         vacc0x0123 = vacc0x4567;
230 
231         c3 += 4;
232         c2 += 4;
233         c1 += 4;
234         c0 += 4;
235       }
236       if (nc & 2) {
237         psimd_store2_f32(c3, vacc3x0123);
238         psimd_store2_f32(c2, vacc2x0123);
239         psimd_store2_f32(c1, vacc1x0123);
240         psimd_store2_f32(c0, vacc0x0123);
241 
242         vacc3x0123 = psimd_concat_hi_f32(vacc3x0123, vacc3x0123);
243         vacc2x0123 = psimd_concat_hi_f32(vacc2x0123, vacc2x0123);
244         vacc1x0123 = psimd_concat_hi_f32(vacc1x0123, vacc1x0123);
245         vacc0x0123 = psimd_concat_hi_f32(vacc0x0123, vacc0x0123);
246 
247         c3 += 2;
248         c2 += 2;
249         c1 += 2;
250         c0 += 2;
251       }
252       if (nc & 1) {
253         psimd_store1_f32(c3, vacc3x0123);
254         psimd_store1_f32(c2, vacc2x0123);
255         psimd_store1_f32(c1, vacc1x0123);
256         psimd_store1_f32(c0, vacc0x0123);
257       }
258 
259       nc = 0;
260     }
261   } while (nc != 0);
262 }
263