Debian Codegraph @

src/f32-spmm/gen/f32-spmm-12x2-minmax-aarch64-neonfma.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-spmm/neon-blocked.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/prefetch.h"
15 #include "xnnpack/spmm.h"
16
17
18 void xnn_f32_spmm_minmax_ukernel_12x2__aarch64_neonfma(
19 size_t mc,
20 size_t nc,
21 const float* input,
22 const float* weights,
23 const int32_t* widx_dmap,
24 const uint32_t* nidx_nnzmap,
25 float* output,
26 size_t output_stride,
27 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
28 {
29 assert(mc != 0);
30 assert(mc % sizeof(float) == 0);
31 assert(nc != 0);
32
33 #if XNN_ARCH_ARM64
34 const float32x4x2_t vminmax = vld2q_dup_f32(&params->scalar.min);
35 const float32x4_t vmin = vminmax.val[0];
36 const float32x4_t vmax = vminmax.val[1];
37 #else
38 const float32x2x2_t vminmax = vld2_dup_f32(&params->scalar.min);
39 const float32x4_t vmin = vcombine_f32(vminmax.val[0], vminmax.val[0]);
40 const float32x4_t vmax = vcombine_f32(vminmax.val[1], vminmax.val[1]);
41 #endif
42
43 size_t output_decrement = output_stride * nc - 12 * sizeof(float);
44 while XNN_LIKELY(mc >= 12 * sizeof(float)) {
45 const float* w = weights;
46 const int32_t* dmap = widx_dmap;
47 const uint32_t* nnzmap = nidx_nnzmap;
48 size_t n = nc;
49 while (n >= 2) {
50 uint32_t nnz = *nnzmap++;
51 float32x4_t vacc0123n0 = vld1q_dup_f32(w); w += 1;
52 float32x4_t vacc4567n0 = vacc0123n0;
53 float32x4_t vacc89ABn0 = vacc0123n0;
54 float32x4_t vacc0123n1 = vld1q_dup_f32(w); w += 1;
55 float32x4_t vacc4567n1 = vacc0123n1;
56 float32x4_t vacc89ABn1 = vacc0123n1;
57 if XNN_LIKELY(nnz != 0) {
58 do {
59 const intptr_t diff = *dmap++;
60 const float32x4_t vi0123 = vld1q_f32(input);
61 const float32x4_t vi4567 = vld1q_f32(input + 4);
62 const float32x4_t vi89AB = vld1q_f32(input + 8);
63 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
64 xnn_prefetch_to_l1(input + 16);
65 const float32x2_t vw = vld1_f32(w); w += 2;
66 xnn_prefetch_to_l1(w + 32);
67 vacc0123n0 = vfmaq_lane_f32(vacc0123n0, vi0123, vw, 0);
68 vacc4567n0 = vfmaq_lane_f32(vacc4567n0, vi4567, vw, 0);
69 vacc89ABn0 = vfmaq_lane_f32(vacc89ABn0, vi89AB, vw, 0);
70 vacc0123n1 = vfmaq_lane_f32(vacc0123n1, vi0123, vw, 1);
71 vacc4567n1 = vfmaq_lane_f32(vacc4567n1, vi4567, vw, 1);
72 vacc89ABn1 = vfmaq_lane_f32(vacc89ABn1, vi89AB, vw, 1);
73 } while (--nnz != 0);
74 }
75 float32x4_t vout0123n0 = vminq_f32(vacc0123n0, vmax);
76 float32x4_t vout4567n0 = vminq_f32(vacc4567n0, vmax);
77 float32x4_t vout89ABn0 = vminq_f32(vacc89ABn0, vmax);
78 float32x4_t vout0123n1 = vminq_f32(vacc0123n1, vmax);
79 float32x4_t vout4567n1 = vminq_f32(vacc4567n1, vmax);
80 float32x4_t vout89ABn1 = vminq_f32(vacc89ABn1, vmax);
81
82 vout0123n0 = vmaxq_f32(vout0123n0, vmin);
83 vout4567n0 = vmaxq_f32(vout4567n0, vmin);
84 vout89ABn0 = vmaxq_f32(vout89ABn0, vmin);
85 vout0123n1 = vmaxq_f32(vout0123n1, vmin);
86 vout4567n1 = vmaxq_f32(vout4567n1, vmin);
87 vout89ABn1 = vmaxq_f32(vout89ABn1, vmin);
88
89 vst1q_f32(output + 0, vout0123n0);
90 vst1q_f32(output + 4, vout4567n0);
91 vst1q_f32(output + 8, vout89ABn0);
92 output = (float*) ((uintptr_t) output + output_stride);
93 vst1q_f32(output + 0, vout0123n1);
94 vst1q_f32(output + 4, vout4567n1);
95 vst1q_f32(output + 8, vout89ABn1);
96 output = (float*) ((uintptr_t) output + output_stride);
97 n -= 2;
98 }
99
100 // clean up loop, fall back to nr=1
101 if XNN_UNLIKELY(n != 0) {
102 do {
103 uint32_t nnz = *nnzmap++;
104 float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1;
105 float32x4_t vacc4567 = vacc0123;
106 float32x4_t vacc89AB = vacc0123;
107 if XNN_LIKELY(nnz != 0) {
108 do {
109 const intptr_t diff = *dmap++;
110 const float32x4_t vi0123 = vld1q_f32(input);
111 const float32x4_t vi4567 = vld1q_f32(input + 4);
112 const float32x4_t vi89AB = vld1q_f32(input + 8);
113 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
114 xnn_prefetch_to_l1(input + 16);
115 const float32x4_t vw = vld1q_dup_f32(w); w += 1;
116 xnn_prefetch_to_l1(w + 32);
117 vacc0123 = vfmaq_f32(vacc0123, vi0123, vw);
118 vacc4567 = vfmaq_f32(vacc4567, vi4567, vw);
119 vacc89AB = vfmaq_f32(vacc89AB, vi89AB, vw);
120 } while (--nnz != 0);
121 }
122 float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
123 float32x4_t vout4567 = vminq_f32(vacc4567, vmax);
124 float32x4_t vout89AB = vminq_f32(vacc89AB, vmax);
125
126 vout0123 = vmaxq_f32(vout0123, vmin);
127 vout4567 = vmaxq_f32(vout4567, vmin);
128 vout89AB = vmaxq_f32(vout89AB, vmin);
129
130 vst1q_f32(output + 0, vout0123);
131 vst1q_f32(output + 4, vout4567);
132 vst1q_f32(output + 8, vout89AB);
133 output = (float*) ((uintptr_t) output + output_stride);
134 n -= 1;
135 } while (n != 0);
136 }
137 output = (float*) ((uintptr_t) output - output_decrement);
138 input += 12;
139 mc -= 12 * sizeof(float);
140 }
141 if XNN_UNLIKELY(mc != 0) {
142 output_decrement += 4 * sizeof(float);
143 if (mc & (8 * sizeof(float))) {
144 const float* w = weights;
145 const int32_t* dmap = widx_dmap;
146 const uint32_t* nnzmap = nidx_nnzmap;
147 size_t n = nc;
148 while (n >= 2) {
149 uint32_t nnz = *nnzmap++;
150 float32x4_t vacc0123n0 = vld1q_dup_f32(w); w += 1;
151 float32x4_t vacc4567n0 = vacc0123n0;
152 float32x4_t vacc0123n1 = vld1q_dup_f32(w); w += 1;
153 float32x4_t vacc4567n1 = vacc0123n1;
154 if XNN_LIKELY(nnz != 0) {
155 do {
156 const intptr_t diff = *dmap++;
157 const float32x4_t vi0123 = vld1q_f32(input);
158 const float32x4_t vi4567 = vld1q_f32(input + 4);
159 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
160 const float32x2_t vw = vld1_f32(w); w += 2;
161
162 vacc0123n0 = vfmaq_lane_f32(vacc0123n0, vi0123, vw, 0);
163 vacc4567n0 = vfmaq_lane_f32(vacc4567n0, vi4567, vw, 0);
164 vacc0123n1 = vfmaq_lane_f32(vacc0123n1, vi0123, vw, 1);
165 vacc4567n1 = vfmaq_lane_f32(vacc4567n1, vi4567, vw, 1);
166 } while (--nnz != 0);
167 }
168 float32x4_t vout0123n0 = vminq_f32(vacc0123n0, vmax);
169 float32x4_t vout4567n0 = vminq_f32(vacc4567n0, vmax);
170 float32x4_t vout0123n1 = vminq_f32(vacc0123n1, vmax);
171 float32x4_t vout4567n1 = vminq_f32(vacc4567n1, vmax);
172
173 vout0123n0 = vmaxq_f32(vout0123n0, vmin);
174 vout4567n0 = vmaxq_f32(vout4567n0, vmin);
175 vout0123n1 = vmaxq_f32(vout0123n1, vmin);
176 vout4567n1 = vmaxq_f32(vout4567n1, vmin);
177
178 vst1q_f32(output + 0, vout0123n0);
179 vst1q_f32(output + 4, vout4567n0);
180 output = (float*) ((uintptr_t) output + output_stride);
181 vst1q_f32(output + 0, vout0123n1);
182 vst1q_f32(output + 4, vout4567n1);
183 output = (float*) ((uintptr_t) output + output_stride);
184 n -= 2;
185 }
186
187 // clean up loop, fall back to nr=1
188 if XNN_UNLIKELY(n != 0) {
189 do {
190 uint32_t nnz = *nnzmap++;
191 float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1;
192 float32x4_t vacc4567 = vacc0123;
193 if XNN_LIKELY(nnz != 0) {
194 do {
195 const intptr_t diff = *dmap++;
196 const float32x4_t vi0123 = vld1q_f32(input);
197 const float32x4_t vi4567 = vld1q_f32(input + 4);
198 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
199 const float32x4_t vw = vld1q_dup_f32(w); w += 1;
200 vacc0123 = vfmaq_f32(vacc0123, vi0123, vw);
201 vacc4567 = vfmaq_f32(vacc4567, vi4567, vw);
202 } while (--nnz != 0);
203 }
204 float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
205 float32x4_t vout4567 = vminq_f32(vacc4567, vmax);
206
207 vout0123 = vmaxq_f32(vout0123, vmin);
208 vout4567 = vmaxq_f32(vout4567, vmin);
209
210 vst1q_f32(output + 0, vout0123);
211 vst1q_f32(output + 4, vout4567);
212 output = (float*) ((uintptr_t) output + output_stride);
213 n -= 1;
214 } while (n != 0);
215 }
216 output = (float*) ((uintptr_t) output - output_decrement);
217 input += 8;
218 }
219 output_decrement += 4 * sizeof(float);
220 if (mc & (4 * sizeof(float))) {
221 const float* w = weights;
222 const int32_t* dmap = widx_dmap;
223 const uint32_t* nnzmap = nidx_nnzmap;
224 size_t n = nc;
225 while (n >= 2) {
226 uint32_t nnz = *nnzmap++;
227 float32x4_t vacc0123n0 = vld1q_dup_f32(w); w += 1;
228 float32x4_t vacc0123n1 = vld1q_dup_f32(w); w += 1;
229 if XNN_LIKELY(nnz != 0) {
230 do {
231 const intptr_t diff = *dmap++;
232 const float32x4_t vi0123 = vld1q_f32(input);
233 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
234 const float32x2_t vw = vld1_f32(w); w += 2;
235
236 vacc0123n0 = vfmaq_lane_f32(vacc0123n0, vi0123, vw, 0);
237 vacc0123n1 = vfmaq_lane_f32(vacc0123n1, vi0123, vw, 1);
238 } while (--nnz != 0);
239 }
240 float32x4_t vout0123n0 = vminq_f32(vacc0123n0, vmax);
241 float32x4_t vout0123n1 = vminq_f32(vacc0123n1, vmax);
242
243 vout0123n0 = vmaxq_f32(vout0123n0, vmin);
244 vout0123n1 = vmaxq_f32(vout0123n1, vmin);
245
246 vst1q_f32(output + 0, vout0123n0);
247 output = (float*) ((uintptr_t) output + output_stride);
248 vst1q_f32(output + 0, vout0123n1);
249 output = (float*) ((uintptr_t) output + output_stride);
250 n -= 2;
251 }
252
253 // clean up loop, fall back to nr=1
254 if XNN_UNLIKELY(n != 0) {
255 do {
256 uint32_t nnz = *nnzmap++;
257 float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1;
258 if XNN_LIKELY(nnz != 0) {
259 do {
260 const intptr_t diff = *dmap++;
261 const float32x4_t vi0123 = vld1q_f32(input);
262 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
263 const float32x4_t vw = vld1q_dup_f32(w); w += 1;
264 vacc0123 = vfmaq_f32(vacc0123, vi0123, vw);
265 } while (--nnz != 0);
266 }
267 float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
268
269 vout0123 = vmaxq_f32(vout0123, vmin);
270
271 vst1q_f32(output + 0, vout0123);
272 output = (float*) ((uintptr_t) output + output_stride);
273 n -= 1;
274 } while (n != 0);
275 }
276 output = (float*) ((uintptr_t) output - output_decrement);
277 input += 4;
278 }
279 output_decrement += 2 * sizeof(float);
280 if (mc & (2 * sizeof(float))) {
281 const float* w = weights;
282 const int32_t* dmap = widx_dmap;
283 const uint32_t* nnzmap = nidx_nnzmap;
284 size_t n = nc;
285 while (n >= 2) {
286 uint32_t nnz = *nnzmap++;
287 float32x2_t vacc01n0 = vld1_dup_f32(w); w += 1;
288 float32x2_t vacc01n1 = vld1_dup_f32(w); w += 1;
289 if XNN_LIKELY(nnz != 0) {
290 do {
291 const intptr_t diff = *dmap++;
292 const float32x2_t vi01 = vld1_f32(input);
293 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
294 const float32x2_t vw = vld1_f32(w); w += 2;
295
296 vacc01n0 = vfma_lane_f32(vacc01n0, vi01, vw, 0);
297 vacc01n1 = vfma_lane_f32(vacc01n1, vi01, vw, 1);
298 } while (--nnz != 0);
299 }
300 float32x2_t vout01n0 = vmin_f32(vacc01n0, vget_low_f32(vmax));
301 float32x2_t vout01n1 = vmin_f32(vacc01n1, vget_low_f32(vmax));
302
303 vout01n0 = vmax_f32(vout01n0, vget_low_f32(vmin));
304 vout01n1 = vmax_f32(vout01n1, vget_low_f32(vmin));
305
306 vst1_f32(output + 0, vout01n0);
307 output = (float*) ((uintptr_t) output + output_stride);
308 vst1_f32(output + 0, vout01n1);
309 output = (float*) ((uintptr_t) output + output_stride);
310 n -= 2;
311 }
312
313 // clean up loop, fall back to nr=1
314 if XNN_UNLIKELY(n != 0) {
315 do {
316 uint32_t nnz = *nnzmap++;
317 float32x2_t vacc01 = vld1_dup_f32(w); w += 1;
318 if XNN_LIKELY(nnz != 0) {
319 do {
320 const intptr_t diff = *dmap++;
321 const float32x2_t vi01 = vld1_f32(input);
322 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
323 const float32x2_t vw = vld1_dup_f32(w); w += 1;
324 vacc01 = vfma_f32(vacc01, vi01, vw);
325 } while (--nnz != 0);
326 }
327 float32x2_t vout01 = vmin_f32(vacc01, vget_low_f32(vmax));
328 vout01 = vmax_f32(vout01, vget_low_f32(vmin));
329
330 vst1_f32(output, vout01);
331 output = (float*) ((uintptr_t) output + output_stride);
332 n -= 1;
333 } while (n != 0);
334 }
335 output = (float*) ((uintptr_t) output - output_decrement);
336 input += 2;
337 }
338 output_decrement += 1 * sizeof(float);
339 if (mc & (1 * sizeof(float))) {
340 const float* w = weights;
341 const int32_t* dmap = widx_dmap;
342 const uint32_t* nnzmap = nidx_nnzmap;
343 size_t n = nc;
344 while (n >= 2) {
345 uint32_t nnz = *nnzmap++;
346 float32x2_t vacc0n0 = vld1_dup_f32(w); w += 1;
347 float32x2_t vacc0n1 = vld1_dup_f32(w); w += 1;
348 if XNN_LIKELY(nnz != 0) {
349 do {
350 const intptr_t diff = *dmap++;
351 const float32x2_t vi0 = vld1_dup_f32(input);
352 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
353 const float32x2_t vw = vld1_f32(w); w += 2;
354
355 vacc0n0 = vfma_lane_f32(vacc0n0, vi0, vw, 0);
356 vacc0n1 = vfma_lane_f32(vacc0n1, vi0, vw, 1);
357 } while (--nnz != 0);
358 }
359 float32x2_t vout0n0 = vmin_f32(vacc0n0, vget_low_f32(vmax));
360 float32x2_t vout0n1 = vmin_f32(vacc0n1, vget_low_f32(vmax));
361
362 vout0n0 = vmax_f32(vout0n0, vget_low_f32(vmin));
363 vout0n1 = vmax_f32(vout0n1, vget_low_f32(vmin));
364
365 vst1_lane_f32(output + 0, vout0n0, 0);
366 output = (float*) ((uintptr_t) output + output_stride);
367 vst1_lane_f32(output + 0, vout0n1, 0);
368 output = (float*) ((uintptr_t) output + output_stride);
369 n -= 2;
370 }
371
372 // clean up loop, fall back to nr=1
373 if XNN_UNLIKELY(n != 0) {
374 do {
375 uint32_t nnz = *nnzmap++;
376 float32x2_t vacc0 = vld1_dup_f32(w); w += 1;
377 if XNN_LIKELY(nnz != 0) {
378 do {
379 const intptr_t diff = *dmap++;
380 const float32x2_t vi0 = vld1_dup_f32(input);
381 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
382 const float32x2_t vw = vld1_dup_f32(w); w += 1;
383 vacc0 = vfma_f32(vacc0, vi0, vw);
384 } while (--nnz != 0);
385 }
386 float32x2_t vout0 = vmin_f32(vacc0, vget_low_f32(vmax));
387 vout0 = vmax_f32(vout0, vget_low_f32(vmin));
388
389 vst1_lane_f32(output, vout0, 1);
390 output = (float*) ((uintptr_t) output + output_stride);
391 n -= 1;
392 } while (n != 0);
393 }
394 output = (float*) ((uintptr_t) output - output_decrement);
395 input += 1;
396 }
397 }
398 }