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