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_minmax_ukernel_4x8s4__neonfma(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_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_igemm_minmax_ukernel_4x8s4__neonfma(
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_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
30 {
31   assert(mr != 0);
32   assert(mr <= 4);
33   assert(nc != 0);
34   assert(kc != 0);
35   assert(kc % sizeof(float) == 0);
36   assert(ks != 0);
37   assert(ks % (4 * 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 
57   do {
58     float32x4_t vacc0x0123 = vld1q_f32(w); w += 4;
59     float32x4_t vacc0x4567 = vld1q_f32(w); w += 4;
60     float32x4_t vacc1x0123 = vacc0x0123;
61     float32x4_t vacc1x4567 = vacc0x4567;
62     float32x4_t vacc2x0123 = vacc0x0123;
63     float32x4_t vacc2x4567 = vacc0x4567;
64     float32x4_t vacc3x0123 = vacc0x0123;
65     float32x4_t vacc3x4567 = vacc0x4567;
66 
67     size_t p = ks;
68     do {
69       const float* restrict a0 = a[0];
70       assert(a0 != NULL);
71       if XNN_UNPREDICTABLE(a0 != zero) {
72         a0 = (const float*) ((uintptr_t) a0 + a_offset);
73       }
74       const float* restrict a1 = a[1];
75       assert(a1 != NULL);
76       if XNN_UNPREDICTABLE(a1 != zero) {
77         a1 = (const float*) ((uintptr_t) a1 + a_offset);
78       }
79       const float* restrict a2 = a[2];
80       assert(a2 != NULL);
81       if XNN_UNPREDICTABLE(a2 != zero) {
82         a2 = (const float*) ((uintptr_t) a2 + a_offset);
83       }
84       const float* restrict a3 = a[3];
85       assert(a3 != NULL);
86       if XNN_UNPREDICTABLE(a3 != zero) {
87         a3 = (const float*) ((uintptr_t) a3 + a_offset);
88       }
89       a += 4;
90 
91       size_t k = kc;
92       while (k >= 4 * sizeof(float)) {
93         float32x4_t va0 = vld1q_f32(a0); a0 += 4;
94         float32x4_t va1 = vld1q_f32(a1); a1 += 4;
95         float32x4_t va2 = vld1q_f32(a2); a2 += 4;
96         float32x4_t va3 = vld1q_f32(a3); a3 += 4;
97 
98 
99         const float32x4_t vb0123c0 = vld1q_f32(w + 0);
100         const float32x4_t vb4567c0 = vld1q_f32(w + 4);
101 
102         vacc0x0123 = vfmaq_f32(vacc0x0123, va0, vb0123c0);
103         vacc1x0123 = vfmaq_f32(vacc1x0123, va1, vb0123c0);
104         vacc2x0123 = vfmaq_f32(vacc2x0123, va2, vb0123c0);
105         vacc3x0123 = vfmaq_f32(vacc3x0123, va3, vb0123c0);
106         vacc0x4567 = vfmaq_f32(vacc0x4567, va0, vb4567c0);
107         vacc1x4567 = vfmaq_f32(vacc1x4567, va1, vb4567c0);
108         vacc2x4567 = vfmaq_f32(vacc2x4567, va2, vb4567c0);
109         vacc3x4567 = vfmaq_f32(vacc3x4567, va3, vb4567c0);
110 
111         va0 = vextq_f32(va0, va0, 1);
112         va1 = vextq_f32(va1, va1, 1);
113         va2 = vextq_f32(va2, va2, 1);
114         va3 = vextq_f32(va3, va3, 1);
115 
116         const float32x4_t vb0123c1 = vld1q_f32(w + 8);
117         const float32x4_t vb4567c1 = vld1q_f32(w + 12);
118 
119         vacc0x0123 = vfmaq_f32(vacc0x0123, va0, vb0123c1);
120         vacc1x0123 = vfmaq_f32(vacc1x0123, va1, vb0123c1);
121         vacc2x0123 = vfmaq_f32(vacc2x0123, va2, vb0123c1);
122         vacc3x0123 = vfmaq_f32(vacc3x0123, va3, vb0123c1);
123         vacc0x4567 = vfmaq_f32(vacc0x4567, va0, vb4567c1);
124         vacc1x4567 = vfmaq_f32(vacc1x4567, va1, vb4567c1);
125         vacc2x4567 = vfmaq_f32(vacc2x4567, va2, vb4567c1);
126         vacc3x4567 = vfmaq_f32(vacc3x4567, va3, vb4567c1);
127 
128         va0 = vextq_f32(va0, va0, 1);
129         va1 = vextq_f32(va1, va1, 1);
130         va2 = vextq_f32(va2, va2, 1);
131         va3 = vextq_f32(va3, va3, 1);
132 
133         const float32x4_t vb0123c2 = vld1q_f32(w + 16);
134         const float32x4_t vb4567c2 = vld1q_f32(w + 20);
135 
136         vacc0x0123 = vfmaq_f32(vacc0x0123, va0, vb0123c2);
137         vacc1x0123 = vfmaq_f32(vacc1x0123, va1, vb0123c2);
138         vacc2x0123 = vfmaq_f32(vacc2x0123, va2, vb0123c2);
139         vacc3x0123 = vfmaq_f32(vacc3x0123, va3, vb0123c2);
140         vacc0x4567 = vfmaq_f32(vacc0x4567, va0, vb4567c2);
141         vacc1x4567 = vfmaq_f32(vacc1x4567, va1, vb4567c2);
142         vacc2x4567 = vfmaq_f32(vacc2x4567, va2, vb4567c2);
143         vacc3x4567 = vfmaq_f32(vacc3x4567, va3, vb4567c2);
144 
145         va0 = vextq_f32(va0, va0, 1);
146         va1 = vextq_f32(va1, va1, 1);
147         va2 = vextq_f32(va2, va2, 1);
148         va3 = vextq_f32(va3, va3, 1);
149 
150         const float32x4_t vb0123c3 = vld1q_f32(w + 24);
151         const float32x4_t vb4567c3 = vld1q_f32(w + 28);
152 
153         vacc0x0123 = vfmaq_f32(vacc0x0123, va0, vb0123c3);
154         vacc1x0123 = vfmaq_f32(vacc1x0123, va1, vb0123c3);
155         vacc2x0123 = vfmaq_f32(vacc2x0123, va2, vb0123c3);
156         vacc3x0123 = vfmaq_f32(vacc3x0123, va3, vb0123c3);
157         vacc0x4567 = vfmaq_f32(vacc0x4567, va0, vb4567c3);
158         vacc1x4567 = vfmaq_f32(vacc1x4567, va1, vb4567c3);
159         vacc2x4567 = vfmaq_f32(vacc2x4567, va2, vb4567c3);
160         vacc3x4567 = vfmaq_f32(vacc3x4567, va3, vb4567c3);
161 
162 
163         w += 32;
164         k -= 4 * sizeof(float);
165       }
166       if XNN_UNLIKELY(k != 0) {
167         do {
168           const float32x4_t va0 = vld1q_dup_f32(a0); a0 += 1;
169           const float32x4_t va1 = vld1q_dup_f32(a1); a1 += 1;
170           const float32x4_t va2 = vld1q_dup_f32(a2); a2 += 1;
171           const float32x4_t va3 = vld1q_dup_f32(a3); a3 += 1;
172 
173           const float32x4_t vb0123 = vld1q_f32(w); w += 4;
174           const float32x4_t vb4567 = vld1q_f32(w); w += 4;
175 
176           vacc0x0123 = vfmaq_f32(vacc0x0123, va0, vb0123);
177           vacc1x0123 = vfmaq_f32(vacc1x0123, va1, vb0123);
178           vacc2x0123 = vfmaq_f32(vacc2x0123, va2, vb0123);
179           vacc3x0123 = vfmaq_f32(vacc3x0123, va3, vb0123);
180           vacc0x4567 = vfmaq_f32(vacc0x4567, va0, vb4567);
181           vacc1x4567 = vfmaq_f32(vacc1x4567, va1, vb4567);
182           vacc2x4567 = vfmaq_f32(vacc2x4567, va2, vb4567);
183           vacc3x4567 = vfmaq_f32(vacc3x4567, va3, vb4567);
184 
185           k -= sizeof(float);
186         } while (k != 0);
187       }
188 
189       p -= 4 * sizeof(void*);
190     } while (p != 0);
191 
192     const float32x4_t vmax = vld1q_dup_f32(&params->scalar.max);
193     vacc0x0123 = vminq_f32(vacc0x0123, vmax);
194     vacc1x0123 = vminq_f32(vacc1x0123, vmax);
195     vacc2x0123 = vminq_f32(vacc2x0123, vmax);
196     vacc3x0123 = vminq_f32(vacc3x0123, vmax);
197     vacc0x4567 = vminq_f32(vacc0x4567, vmax);
198     vacc1x4567 = vminq_f32(vacc1x4567, vmax);
199     vacc2x4567 = vminq_f32(vacc2x4567, vmax);
200     vacc3x4567 = vminq_f32(vacc3x4567, vmax);
201 
202     const float32x4_t vmin = vld1q_dup_f32(&params->scalar.min);
203     vacc0x0123 = vmaxq_f32(vacc0x0123, vmin);
204     vacc1x0123 = vmaxq_f32(vacc1x0123, vmin);
205     vacc2x0123 = vmaxq_f32(vacc2x0123, vmin);
206     vacc3x0123 = vmaxq_f32(vacc3x0123, vmin);
207     vacc0x4567 = vmaxq_f32(vacc0x4567, vmin);
208     vacc1x4567 = vmaxq_f32(vacc1x4567, vmin);
209     vacc2x4567 = vmaxq_f32(vacc2x4567, vmin);
210     vacc3x4567 = vmaxq_f32(vacc3x4567, vmin);
211 
212     if XNN_LIKELY(nc >= 8) {
213       vst1q_f32(c3, vacc3x0123);
214       vst1q_f32(c3 + 4, vacc3x4567);
215       c3 = (float*) ((uintptr_t) c3 + cn_stride);
216       vst1q_f32(c2, vacc2x0123);
217       vst1q_f32(c2 + 4, vacc2x4567);
218       c2 = (float*) ((uintptr_t) c2 + cn_stride);
219       vst1q_f32(c1, vacc1x0123);
220       vst1q_f32(c1 + 4, vacc1x4567);
221       c1 = (float*) ((uintptr_t) c1 + cn_stride);
222       vst1q_f32(c0, vacc0x0123);
223       vst1q_f32(c0 + 4, vacc0x4567);
224       c0 = (float*) ((uintptr_t) c0 + cn_stride);
225 
226       a = (const float**restrict) ((uintptr_t) a - ks);
227       nc -= 8;
228     } else {
229       if (nc & 4) {
230         vst1q_f32(c3, vacc3x0123); c3 += 4;
231         vst1q_f32(c2, vacc2x0123); c2 += 4;
232         vst1q_f32(c1, vacc1x0123); c1 += 4;
233         vst1q_f32(c0, vacc0x0123); c0 += 4;
234 
235         vacc3x0123 = vacc3x4567;
236         vacc2x0123 = vacc2x4567;
237         vacc1x0123 = vacc1x4567;
238         vacc0x0123 = vacc0x4567;
239       }
240       float32x2_t vacc3x01 = vget_low_f32(vacc3x0123);
241       float32x2_t vacc2x01 = vget_low_f32(vacc2x0123);
242       float32x2_t vacc1x01 = vget_low_f32(vacc1x0123);
243       float32x2_t vacc0x01 = vget_low_f32(vacc0x0123);
244       if (nc & 2) {
245         vst1_f32(c3, vacc3x01); c3 += 2;
246         vst1_f32(c2, vacc2x01); c2 += 2;
247         vst1_f32(c1, vacc1x01); c1 += 2;
248         vst1_f32(c0, vacc0x01); c0 += 2;
249 
250         vacc3x01 = vget_high_f32(vacc3x0123);
251         vacc2x01 = vget_high_f32(vacc2x0123);
252         vacc1x01 = vget_high_f32(vacc1x0123);
253         vacc0x01 = vget_high_f32(vacc0x0123);
254       }
255       if (nc & 1) {
256         vst1_lane_f32(c3, vacc3x01, 0);
257         vst1_lane_f32(c2, vacc2x01, 0);
258         vst1_lane_f32(c1, vacc1x01, 0);
259         vst1_lane_f32(c0, vacc0x01, 0);
260       }
261 
262       nc = 0;
263     }
264   } while (nc != 0);
265 }
266