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