• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-gemm/neon-shuffle.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 
11 #include <assert.h>
12 
13 #include <arm_neon.h>
14 
15 #include <xnnpack/gemm.h>
16 
17 
xnn_f32_gemm_minmax_ukernel_6x8s4__neonfma(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)])18 void xnn_f32_gemm_minmax_ukernel_6x8s4__neonfma(
19     size_t mr,
20     size_t nc,
21     size_t kc,
22     const float* restrict a,
23     size_t a_stride,
24     const float* restrict w,
25     float* restrict c,
26     size_t cm_stride,
27     size_t cn_stride,
28     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(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 
39   const float* a0 = a;
40   float* c0 = c;
41   const float* a1 = (const float*) ((uintptr_t) a0 + a_stride);
42   float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
43   if XNN_UNPREDICTABLE(mr < 2) {
44     a1 = a0;
45     c1 = c0;
46   }
47   const float* a2 = (const float*) ((uintptr_t) a1 + a_stride);
48   float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
49   if XNN_UNPREDICTABLE(mr <= 2) {
50     a2 = a1;
51     c2 = c1;
52   }
53   const float* a3 = (const float*) ((uintptr_t) a2 + a_stride);
54   float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
55   if XNN_UNPREDICTABLE(mr < 4) {
56     a3 = a2;
57     c3 = c2;
58   }
59   const float* a4 = (const float*) ((uintptr_t) a3 + a_stride);
60   float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
61   if XNN_UNPREDICTABLE(mr <= 4) {
62     a4 = a3;
63     c4 = c3;
64   }
65   const float* a5 = (const float*) ((uintptr_t) a4 + a_stride);
66   float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
67   if XNN_UNPREDICTABLE(mr != 6) {
68     a5 = a4;
69     c5 = c4;
70   }
71 
72   do {
73     float32x4_t vacc0x0123 = vld1q_f32(w); w += 4;
74     float32x4_t vacc0x4567 = vld1q_f32(w); w += 4;
75     float32x4_t vacc1x0123 = vacc0x0123;
76     float32x4_t vacc1x4567 = vacc0x4567;
77     float32x4_t vacc2x0123 = vacc0x0123;
78     float32x4_t vacc2x4567 = vacc0x4567;
79     float32x4_t vacc3x0123 = vacc0x0123;
80     float32x4_t vacc3x4567 = vacc0x4567;
81     float32x4_t vacc4x0123 = vacc0x0123;
82     float32x4_t vacc4x4567 = vacc0x4567;
83     float32x4_t vacc5x0123 = vacc0x0123;
84     float32x4_t vacc5x4567 = vacc0x4567;
85 
86     size_t k = kc;
87     while (k >= 4 * sizeof(float)) {
88       float32x4_t va0 = vld1q_f32(a0); a0 += 4;
89       float32x4_t va1 = vld1q_f32(a1); a1 += 4;
90       float32x4_t va2 = vld1q_f32(a2); a2 += 4;
91       float32x4_t va3 = vld1q_f32(a3); a3 += 4;
92       float32x4_t va4 = vld1q_f32(a4); a4 += 4;
93       float32x4_t va5 = vld1q_f32(a5); a5 += 4;
94 
95 
96       const float32x4_t vb0123c0 = vld1q_f32(w + 0);
97       const float32x4_t vb4567c0 = vld1q_f32(w + 4);
98 
99       vacc0x0123 = vfmaq_f32(vacc0x0123, va0, vb0123c0);
100       vacc1x0123 = vfmaq_f32(vacc1x0123, va1, vb0123c0);
101       vacc2x0123 = vfmaq_f32(vacc2x0123, va2, vb0123c0);
102       vacc3x0123 = vfmaq_f32(vacc3x0123, va3, vb0123c0);
103       vacc4x0123 = vfmaq_f32(vacc4x0123, va4, vb0123c0);
104       vacc5x0123 = vfmaq_f32(vacc5x0123, va5, vb0123c0);
105       vacc0x4567 = vfmaq_f32(vacc0x4567, va0, vb4567c0);
106       vacc1x4567 = vfmaq_f32(vacc1x4567, va1, vb4567c0);
107       vacc2x4567 = vfmaq_f32(vacc2x4567, va2, vb4567c0);
108       vacc3x4567 = vfmaq_f32(vacc3x4567, va3, vb4567c0);
109       vacc4x4567 = vfmaq_f32(vacc4x4567, va4, vb4567c0);
110       vacc5x4567 = vfmaq_f32(vacc5x4567, va5, vb4567c0);
111 
112       va0 = vextq_f32(va0, va0, 1);
113       va1 = vextq_f32(va1, va1, 1);
114       va2 = vextq_f32(va2, va2, 1);
115       va3 = vextq_f32(va3, va3, 1);
116       va4 = vextq_f32(va4, va4, 1);
117       va5 = vextq_f32(va5, va5, 1);
118 
119       const float32x4_t vb0123c1 = vld1q_f32(w + 8);
120       const float32x4_t vb4567c1 = vld1q_f32(w + 12);
121 
122       vacc0x0123 = vfmaq_f32(vacc0x0123, va0, vb0123c1);
123       vacc1x0123 = vfmaq_f32(vacc1x0123, va1, vb0123c1);
124       vacc2x0123 = vfmaq_f32(vacc2x0123, va2, vb0123c1);
125       vacc3x0123 = vfmaq_f32(vacc3x0123, va3, vb0123c1);
126       vacc4x0123 = vfmaq_f32(vacc4x0123, va4, vb0123c1);
127       vacc5x0123 = vfmaq_f32(vacc5x0123, va5, vb0123c1);
128       vacc0x4567 = vfmaq_f32(vacc0x4567, va0, vb4567c1);
129       vacc1x4567 = vfmaq_f32(vacc1x4567, va1, vb4567c1);
130       vacc2x4567 = vfmaq_f32(vacc2x4567, va2, vb4567c1);
131       vacc3x4567 = vfmaq_f32(vacc3x4567, va3, vb4567c1);
132       vacc4x4567 = vfmaq_f32(vacc4x4567, va4, vb4567c1);
133       vacc5x4567 = vfmaq_f32(vacc5x4567, va5, vb4567c1);
134 
135       va0 = vextq_f32(va0, va0, 1);
136       va1 = vextq_f32(va1, va1, 1);
137       va2 = vextq_f32(va2, va2, 1);
138       va3 = vextq_f32(va3, va3, 1);
139       va4 = vextq_f32(va4, va4, 1);
140       va5 = vextq_f32(va5, va5, 1);
141 
142       const float32x4_t vb0123c2 = vld1q_f32(w + 16);
143       const float32x4_t vb4567c2 = vld1q_f32(w + 20);
144 
145       vacc0x0123 = vfmaq_f32(vacc0x0123, va0, vb0123c2);
146       vacc1x0123 = vfmaq_f32(vacc1x0123, va1, vb0123c2);
147       vacc2x0123 = vfmaq_f32(vacc2x0123, va2, vb0123c2);
148       vacc3x0123 = vfmaq_f32(vacc3x0123, va3, vb0123c2);
149       vacc4x0123 = vfmaq_f32(vacc4x0123, va4, vb0123c2);
150       vacc5x0123 = vfmaq_f32(vacc5x0123, va5, vb0123c2);
151       vacc0x4567 = vfmaq_f32(vacc0x4567, va0, vb4567c2);
152       vacc1x4567 = vfmaq_f32(vacc1x4567, va1, vb4567c2);
153       vacc2x4567 = vfmaq_f32(vacc2x4567, va2, vb4567c2);
154       vacc3x4567 = vfmaq_f32(vacc3x4567, va3, vb4567c2);
155       vacc4x4567 = vfmaq_f32(vacc4x4567, va4, vb4567c2);
156       vacc5x4567 = vfmaq_f32(vacc5x4567, va5, vb4567c2);
157 
158       va0 = vextq_f32(va0, va0, 1);
159       va1 = vextq_f32(va1, va1, 1);
160       va2 = vextq_f32(va2, va2, 1);
161       va3 = vextq_f32(va3, va3, 1);
162       va4 = vextq_f32(va4, va4, 1);
163       va5 = vextq_f32(va5, va5, 1);
164 
165       const float32x4_t vb0123c3 = vld1q_f32(w + 24);
166       const float32x4_t vb4567c3 = vld1q_f32(w + 28);
167 
168       vacc0x0123 = vfmaq_f32(vacc0x0123, va0, vb0123c3);
169       vacc1x0123 = vfmaq_f32(vacc1x0123, va1, vb0123c3);
170       vacc2x0123 = vfmaq_f32(vacc2x0123, va2, vb0123c3);
171       vacc3x0123 = vfmaq_f32(vacc3x0123, va3, vb0123c3);
172       vacc4x0123 = vfmaq_f32(vacc4x0123, va4, vb0123c3);
173       vacc5x0123 = vfmaq_f32(vacc5x0123, va5, vb0123c3);
174       vacc0x4567 = vfmaq_f32(vacc0x4567, va0, vb4567c3);
175       vacc1x4567 = vfmaq_f32(vacc1x4567, va1, vb4567c3);
176       vacc2x4567 = vfmaq_f32(vacc2x4567, va2, vb4567c3);
177       vacc3x4567 = vfmaq_f32(vacc3x4567, va3, vb4567c3);
178       vacc4x4567 = vfmaq_f32(vacc4x4567, va4, vb4567c3);
179       vacc5x4567 = vfmaq_f32(vacc5x4567, va5, vb4567c3);
180 
181 
182       w += 32;
183       k -= 4 * sizeof(float);
184     }
185     if XNN_UNLIKELY(k != 0) {
186       do {
187         const float32x4_t va0 = vld1q_dup_f32(a0); a0 += 1;
188         const float32x4_t va1 = vld1q_dup_f32(a1); a1 += 1;
189         const float32x4_t va2 = vld1q_dup_f32(a2); a2 += 1;
190         const float32x4_t va3 = vld1q_dup_f32(a3); a3 += 1;
191         const float32x4_t va4 = vld1q_dup_f32(a4); a4 += 1;
192         const float32x4_t va5 = vld1q_dup_f32(a5); a5 += 1;
193 
194         const float32x4_t vb0123 = vld1q_f32(w); w += 4;
195         const float32x4_t vb4567 = vld1q_f32(w); w += 4;
196 
197         vacc0x0123 = vfmaq_f32(vacc0x0123, va0, vb0123);
198         vacc1x0123 = vfmaq_f32(vacc1x0123, va1, vb0123);
199         vacc2x0123 = vfmaq_f32(vacc2x0123, va2, vb0123);
200         vacc3x0123 = vfmaq_f32(vacc3x0123, va3, vb0123);
201         vacc4x0123 = vfmaq_f32(vacc4x0123, va4, vb0123);
202         vacc5x0123 = vfmaq_f32(vacc5x0123, va5, vb0123);
203         vacc0x4567 = vfmaq_f32(vacc0x4567, va0, vb4567);
204         vacc1x4567 = vfmaq_f32(vacc1x4567, va1, vb4567);
205         vacc2x4567 = vfmaq_f32(vacc2x4567, va2, vb4567);
206         vacc3x4567 = vfmaq_f32(vacc3x4567, va3, vb4567);
207         vacc4x4567 = vfmaq_f32(vacc4x4567, va4, vb4567);
208         vacc5x4567 = vfmaq_f32(vacc5x4567, va5, vb4567);
209 
210         k -= sizeof(float);
211       } while (k != 0);
212     }
213     const float32x4_t vmax = vld1q_dup_f32(&params->scalar.max);
214     vacc0x0123 = vminq_f32(vacc0x0123, vmax);
215     vacc1x0123 = vminq_f32(vacc1x0123, vmax);
216     vacc2x0123 = vminq_f32(vacc2x0123, vmax);
217     vacc3x0123 = vminq_f32(vacc3x0123, vmax);
218     vacc4x0123 = vminq_f32(vacc4x0123, vmax);
219     vacc5x0123 = vminq_f32(vacc5x0123, vmax);
220     vacc0x4567 = vminq_f32(vacc0x4567, vmax);
221     vacc1x4567 = vminq_f32(vacc1x4567, vmax);
222     vacc2x4567 = vminq_f32(vacc2x4567, vmax);
223     vacc3x4567 = vminq_f32(vacc3x4567, vmax);
224     vacc4x4567 = vminq_f32(vacc4x4567, vmax);
225     vacc5x4567 = vminq_f32(vacc5x4567, vmax);
226 
227     const float32x4_t vmin = vld1q_dup_f32(&params->scalar.min);
228     vacc0x0123 = vmaxq_f32(vacc0x0123, vmin);
229     vacc1x0123 = vmaxq_f32(vacc1x0123, vmin);
230     vacc2x0123 = vmaxq_f32(vacc2x0123, vmin);
231     vacc3x0123 = vmaxq_f32(vacc3x0123, vmin);
232     vacc4x0123 = vmaxq_f32(vacc4x0123, vmin);
233     vacc5x0123 = vmaxq_f32(vacc5x0123, vmin);
234     vacc0x4567 = vmaxq_f32(vacc0x4567, vmin);
235     vacc1x4567 = vmaxq_f32(vacc1x4567, vmin);
236     vacc2x4567 = vmaxq_f32(vacc2x4567, vmin);
237     vacc3x4567 = vmaxq_f32(vacc3x4567, vmin);
238     vacc4x4567 = vmaxq_f32(vacc4x4567, vmin);
239     vacc5x4567 = vmaxq_f32(vacc5x4567, vmin);
240 
241     if XNN_LIKELY(nc >= 8) {
242       vst1q_f32(c5, vacc5x0123);
243       vst1q_f32(c5 + 4, vacc5x4567);
244       c5 = (float*) ((uintptr_t) c5 + cn_stride);
245       vst1q_f32(c4, vacc4x0123);
246       vst1q_f32(c4 + 4, vacc4x4567);
247       c4 = (float*) ((uintptr_t) c4 + cn_stride);
248       vst1q_f32(c3, vacc3x0123);
249       vst1q_f32(c3 + 4, vacc3x4567);
250       c3 = (float*) ((uintptr_t) c3 + cn_stride);
251       vst1q_f32(c2, vacc2x0123);
252       vst1q_f32(c2 + 4, vacc2x4567);
253       c2 = (float*) ((uintptr_t) c2 + cn_stride);
254       vst1q_f32(c1, vacc1x0123);
255       vst1q_f32(c1 + 4, vacc1x4567);
256       c1 = (float*) ((uintptr_t) c1 + cn_stride);
257       vst1q_f32(c0, vacc0x0123);
258       vst1q_f32(c0 + 4, vacc0x4567);
259       c0 = (float*) ((uintptr_t) c0 + cn_stride);
260 
261       a5 = (const float*) ((uintptr_t) a5 - kc);
262       a4 = (const float*) ((uintptr_t) a4 - kc);
263       a3 = (const float*) ((uintptr_t) a3 - kc);
264       a2 = (const float*) ((uintptr_t) a2 - kc);
265       a1 = (const float*) ((uintptr_t) a1 - kc);
266       a0 = (const float*) ((uintptr_t) a0 - kc);
267 
268       nc -= 8;
269 
270     } else {
271       if (nc & 4) {
272         vst1q_f32(c5, vacc5x0123); c5 += 4;
273         vst1q_f32(c4, vacc4x0123); c4 += 4;
274         vst1q_f32(c3, vacc3x0123); c3 += 4;
275         vst1q_f32(c2, vacc2x0123); c2 += 4;
276         vst1q_f32(c1, vacc1x0123); c1 += 4;
277         vst1q_f32(c0, vacc0x0123); c0 += 4;
278 
279         vacc5x0123 = vacc5x4567;
280         vacc4x0123 = vacc4x4567;
281         vacc3x0123 = vacc3x4567;
282         vacc2x0123 = vacc2x4567;
283         vacc1x0123 = vacc1x4567;
284         vacc0x0123 = vacc0x4567;
285       }
286       float32x2_t vacc5x01 = vget_low_f32(vacc5x0123);
287       float32x2_t vacc4x01 = vget_low_f32(vacc4x0123);
288       float32x2_t vacc3x01 = vget_low_f32(vacc3x0123);
289       float32x2_t vacc2x01 = vget_low_f32(vacc2x0123);
290       float32x2_t vacc1x01 = vget_low_f32(vacc1x0123);
291       float32x2_t vacc0x01 = vget_low_f32(vacc0x0123);
292       if (nc & 2) {
293         vst1_f32(c5, vacc5x01); c5 += 2;
294         vst1_f32(c4, vacc4x01); c4 += 2;
295         vst1_f32(c3, vacc3x01); c3 += 2;
296         vst1_f32(c2, vacc2x01); c2 += 2;
297         vst1_f32(c1, vacc1x01); c1 += 2;
298         vst1_f32(c0, vacc0x01); c0 += 2;
299 
300         vacc5x01 = vget_high_f32(vacc5x0123);
301         vacc4x01 = vget_high_f32(vacc4x0123);
302         vacc3x01 = vget_high_f32(vacc3x0123);
303         vacc2x01 = vget_high_f32(vacc2x0123);
304         vacc1x01 = vget_high_f32(vacc1x0123);
305         vacc0x01 = vget_high_f32(vacc0x0123);
306       }
307       if (nc & 1) {
308         vst1_lane_f32(c5, vacc5x01, 0);
309         vst1_lane_f32(c4, vacc4x01, 0);
310         vst1_lane_f32(c3, vacc3x01, 0);
311         vst1_lane_f32(c2, vacc2x01, 0);
312         vst1_lane_f32(c1, vacc1x01, 0);
313         vst1_lane_f32(c0, vacc0x01, 0);
314       }
315 
316       nc = 0;
317     }
318   } while (nc != 0);
319 }
320