• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-gemm/neon-ld64.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_6x8__neonfma_lane_ld64(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_6x8__neonfma_lane_ld64(
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     for (; k >= 2 * sizeof(float); k -= 2 * sizeof(float)) {
88       const float32x2_t va0 = vld1_f32(a0); a0 += 2;
89       const float32x2_t va1 = vld1_f32(a1); a1 += 2;
90       const float32x2_t va2 = vld1_f32(a2); a2 += 2;
91       const float32x2_t va3 = vld1_f32(a3); a3 += 2;
92       const float32x2_t va4 = vld1_f32(a4); a4 += 2;
93       const float32x2_t va5 = vld1_f32(a5); a5 += 2;
94 
95       const float32x4_t vb0123c0 = vld1q_f32(w); w += 4;
96       const float32x4_t vb4567c0 = vld1q_f32(w); w += 4;
97 
98       vacc0x0123 = vfmaq_lane_f32(vacc0x0123, vb0123c0, va0, 0);
99       vacc1x0123 = vfmaq_lane_f32(vacc1x0123, vb0123c0, va1, 0);
100       vacc2x0123 = vfmaq_lane_f32(vacc2x0123, vb0123c0, va2, 0);
101       vacc3x0123 = vfmaq_lane_f32(vacc3x0123, vb0123c0, va3, 0);
102       vacc4x0123 = vfmaq_lane_f32(vacc4x0123, vb0123c0, va4, 0);
103       vacc5x0123 = vfmaq_lane_f32(vacc5x0123, vb0123c0, va5, 0);
104       vacc0x4567 = vfmaq_lane_f32(vacc0x4567, vb4567c0, va0, 0);
105       vacc1x4567 = vfmaq_lane_f32(vacc1x4567, vb4567c0, va1, 0);
106       vacc2x4567 = vfmaq_lane_f32(vacc2x4567, vb4567c0, va2, 0);
107       vacc3x4567 = vfmaq_lane_f32(vacc3x4567, vb4567c0, va3, 0);
108       vacc4x4567 = vfmaq_lane_f32(vacc4x4567, vb4567c0, va4, 0);
109       vacc5x4567 = vfmaq_lane_f32(vacc5x4567, vb4567c0, va5, 0);
110       const float32x4_t vb0123c1 = vld1q_f32(w); w += 4;
111       const float32x4_t vb4567c1 = vld1q_f32(w); w += 4;
112 
113       vacc0x0123 = vfmaq_lane_f32(vacc0x0123, vb0123c1, va0, 1);
114       vacc1x0123 = vfmaq_lane_f32(vacc1x0123, vb0123c1, va1, 1);
115       vacc2x0123 = vfmaq_lane_f32(vacc2x0123, vb0123c1, va2, 1);
116       vacc3x0123 = vfmaq_lane_f32(vacc3x0123, vb0123c1, va3, 1);
117       vacc4x0123 = vfmaq_lane_f32(vacc4x0123, vb0123c1, va4, 1);
118       vacc5x0123 = vfmaq_lane_f32(vacc5x0123, vb0123c1, va5, 1);
119       vacc0x4567 = vfmaq_lane_f32(vacc0x4567, vb4567c1, va0, 1);
120       vacc1x4567 = vfmaq_lane_f32(vacc1x4567, vb4567c1, va1, 1);
121       vacc2x4567 = vfmaq_lane_f32(vacc2x4567, vb4567c1, va2, 1);
122       vacc3x4567 = vfmaq_lane_f32(vacc3x4567, vb4567c1, va3, 1);
123       vacc4x4567 = vfmaq_lane_f32(vacc4x4567, vb4567c1, va4, 1);
124       vacc5x4567 = vfmaq_lane_f32(vacc5x4567, vb4567c1, va5, 1);
125     }
126     if XNN_UNLIKELY(k != 0) {
127       const float32x4_t va0 = vld1q_dup_f32(a0); a0 += 1;
128       const float32x4_t va1 = vld1q_dup_f32(a1); a1 += 1;
129       const float32x4_t va2 = vld1q_dup_f32(a2); a2 += 1;
130       const float32x4_t va3 = vld1q_dup_f32(a3); a3 += 1;
131       const float32x4_t va4 = vld1q_dup_f32(a4); a4 += 1;
132       const float32x4_t va5 = vld1q_dup_f32(a5); a5 += 1;
133 
134       const float32x4_t vb0123 = vld1q_f32(w); w += 4;
135       const float32x4_t vb4567 = vld1q_f32(w); w += 4;
136 
137       vacc0x0123 = vfmaq_f32(vacc0x0123, va0, vb0123);
138       vacc1x0123 = vfmaq_f32(vacc1x0123, va1, vb0123);
139       vacc2x0123 = vfmaq_f32(vacc2x0123, va2, vb0123);
140       vacc3x0123 = vfmaq_f32(vacc3x0123, va3, vb0123);
141       vacc4x0123 = vfmaq_f32(vacc4x0123, va4, vb0123);
142       vacc5x0123 = vfmaq_f32(vacc5x0123, va5, vb0123);
143       vacc0x4567 = vfmaq_f32(vacc0x4567, va0, vb4567);
144       vacc1x4567 = vfmaq_f32(vacc1x4567, va1, vb4567);
145       vacc2x4567 = vfmaq_f32(vacc2x4567, va2, vb4567);
146       vacc3x4567 = vfmaq_f32(vacc3x4567, va3, vb4567);
147       vacc4x4567 = vfmaq_f32(vacc4x4567, va4, vb4567);
148       vacc5x4567 = vfmaq_f32(vacc5x4567, va5, vb4567);
149     }
150     const float32x4_t vmax = vld1q_dup_f32(&params->scalar.max);
151     vacc0x0123 = vminq_f32(vacc0x0123, vmax);
152     vacc1x0123 = vminq_f32(vacc1x0123, vmax);
153     vacc2x0123 = vminq_f32(vacc2x0123, vmax);
154     vacc3x0123 = vminq_f32(vacc3x0123, vmax);
155     vacc4x0123 = vminq_f32(vacc4x0123, vmax);
156     vacc5x0123 = vminq_f32(vacc5x0123, vmax);
157     vacc0x4567 = vminq_f32(vacc0x4567, vmax);
158     vacc1x4567 = vminq_f32(vacc1x4567, vmax);
159     vacc2x4567 = vminq_f32(vacc2x4567, vmax);
160     vacc3x4567 = vminq_f32(vacc3x4567, vmax);
161     vacc4x4567 = vminq_f32(vacc4x4567, vmax);
162     vacc5x4567 = vminq_f32(vacc5x4567, vmax);
163 
164     const float32x4_t vmin = vld1q_dup_f32(&params->scalar.min);
165     vacc0x0123 = vmaxq_f32(vacc0x0123, vmin);
166     vacc1x0123 = vmaxq_f32(vacc1x0123, vmin);
167     vacc2x0123 = vmaxq_f32(vacc2x0123, vmin);
168     vacc3x0123 = vmaxq_f32(vacc3x0123, vmin);
169     vacc4x0123 = vmaxq_f32(vacc4x0123, vmin);
170     vacc5x0123 = vmaxq_f32(vacc5x0123, vmin);
171     vacc0x4567 = vmaxq_f32(vacc0x4567, vmin);
172     vacc1x4567 = vmaxq_f32(vacc1x4567, vmin);
173     vacc2x4567 = vmaxq_f32(vacc2x4567, vmin);
174     vacc3x4567 = vmaxq_f32(vacc3x4567, vmin);
175     vacc4x4567 = vmaxq_f32(vacc4x4567, vmin);
176     vacc5x4567 = vmaxq_f32(vacc5x4567, vmin);
177 
178     if XNN_LIKELY(nc >= 8) {
179       vst1q_f32(c5, vacc5x0123);
180       vst1q_f32(c5 + 4, vacc5x4567);
181       c5 = (float*) ((uintptr_t) c5 + cn_stride);
182       vst1q_f32(c4, vacc4x0123);
183       vst1q_f32(c4 + 4, vacc4x4567);
184       c4 = (float*) ((uintptr_t) c4 + cn_stride);
185       vst1q_f32(c3, vacc3x0123);
186       vst1q_f32(c3 + 4, vacc3x4567);
187       c3 = (float*) ((uintptr_t) c3 + cn_stride);
188       vst1q_f32(c2, vacc2x0123);
189       vst1q_f32(c2 + 4, vacc2x4567);
190       c2 = (float*) ((uintptr_t) c2 + cn_stride);
191       vst1q_f32(c1, vacc1x0123);
192       vst1q_f32(c1 + 4, vacc1x4567);
193       c1 = (float*) ((uintptr_t) c1 + cn_stride);
194       vst1q_f32(c0, vacc0x0123);
195       vst1q_f32(c0 + 4, vacc0x4567);
196       c0 = (float*) ((uintptr_t) c0 + cn_stride);
197 
198       a5 = (const float*) ((uintptr_t) a5 - kc);
199       a4 = (const float*) ((uintptr_t) a4 - kc);
200       a3 = (const float*) ((uintptr_t) a3 - kc);
201       a2 = (const float*) ((uintptr_t) a2 - kc);
202       a1 = (const float*) ((uintptr_t) a1 - kc);
203       a0 = (const float*) ((uintptr_t) a0 - kc);
204 
205       nc -= 8;
206 
207     } else {
208       if (nc & 4) {
209         vst1q_f32(c5, vacc5x0123); c5 += 4;
210         vst1q_f32(c4, vacc4x0123); c4 += 4;
211         vst1q_f32(c3, vacc3x0123); c3 += 4;
212         vst1q_f32(c2, vacc2x0123); c2 += 4;
213         vst1q_f32(c1, vacc1x0123); c1 += 4;
214         vst1q_f32(c0, vacc0x0123); c0 += 4;
215 
216         vacc5x0123 = vacc5x4567;
217         vacc4x0123 = vacc4x4567;
218         vacc3x0123 = vacc3x4567;
219         vacc2x0123 = vacc2x4567;
220         vacc1x0123 = vacc1x4567;
221         vacc0x0123 = vacc0x4567;
222       }
223       float32x2_t vacc5x01 = vget_low_f32(vacc5x0123);
224       float32x2_t vacc4x01 = vget_low_f32(vacc4x0123);
225       float32x2_t vacc3x01 = vget_low_f32(vacc3x0123);
226       float32x2_t vacc2x01 = vget_low_f32(vacc2x0123);
227       float32x2_t vacc1x01 = vget_low_f32(vacc1x0123);
228       float32x2_t vacc0x01 = vget_low_f32(vacc0x0123);
229       if (nc & 2) {
230         vst1_f32(c5, vacc5x01); c5 += 2;
231         vst1_f32(c4, vacc4x01); c4 += 2;
232         vst1_f32(c3, vacc3x01); c3 += 2;
233         vst1_f32(c2, vacc2x01); c2 += 2;
234         vst1_f32(c1, vacc1x01); c1 += 2;
235         vst1_f32(c0, vacc0x01); c0 += 2;
236 
237         vacc5x01 = vget_high_f32(vacc5x0123);
238         vacc4x01 = vget_high_f32(vacc4x0123);
239         vacc3x01 = vget_high_f32(vacc3x0123);
240         vacc2x01 = vget_high_f32(vacc2x0123);
241         vacc1x01 = vget_high_f32(vacc1x0123);
242         vacc0x01 = vget_high_f32(vacc0x0123);
243       }
244       if (nc & 1) {
245         vst1_lane_f32(c5, vacc5x01, 0);
246         vst1_lane_f32(c4, vacc4x01, 0);
247         vst1_lane_f32(c3, vacc3x01, 0);
248         vst1_lane_f32(c2, vacc2x01, 0);
249         vst1_lane_f32(c1, vacc1x01, 0);
250         vst1_lane_f32(c0, vacc0x01, 0);
251       }
252 
253       nc = 0;
254     }
255   } while (nc != 0);
256 }
257