Debian Codegraph @

src/f32-spmm/gen/f32-spmm-32x1-minmax-neon.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-spmm/neon.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_32x1__neon(
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 - 32 * sizeof(float);
44 while XNN_LIKELY(mc >= 32 * 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 do {
50 uint32_t nnz = *nnzmap++;
51 float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1;
52 float32x4_t vacc4567 = vacc0123;
53 float32x4_t vacc89AB = vacc0123;
54 float32x4_t vaccCDEF = vacc0123;
55 float32x4_t vaccGHIJ = vacc0123;
56 float32x4_t vaccKLMN = vacc0123;
57 float32x4_t vaccOPQR = vacc0123;
58 float32x4_t vaccSTUV = vacc0123;
59 if XNN_LIKELY(nnz != 0) {
60 do {
61 const intptr_t diff = *dmap++;
62 const float32x4_t vi0123 = vld1q_f32(input);
63 const float32x4_t vi4567 = vld1q_f32(input + 4);
64 const float32x4_t vi89AB = vld1q_f32(input + 8);
65 const float32x4_t viCDEF = vld1q_f32(input + 12);
66 const float32x4_t viGHIJ = vld1q_f32(input + 16);
67 const float32x4_t viKLMN = vld1q_f32(input + 20);
68 const float32x4_t viOPQR = vld1q_f32(input + 24);
69 const float32x4_t viSTUV = vld1q_f32(input + 28);
70 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
71 xnn_prefetch_to_l1(input + 16);
72 xnn_prefetch_to_l1(input + 32);
73 const float32x4_t vw = vld1q_dup_f32(w); w += 1;
74 xnn_prefetch_to_l1(w + 32);
75 vacc0123 = vmlaq_f32(vacc0123, vi0123, vw);
76 vacc4567 = vmlaq_f32(vacc4567, vi4567, vw);
77 vacc89AB = vmlaq_f32(vacc89AB, vi89AB, vw);
78 vaccCDEF = vmlaq_f32(vaccCDEF, viCDEF, vw);
79 vaccGHIJ = vmlaq_f32(vaccGHIJ, viGHIJ, vw);
80 vaccKLMN = vmlaq_f32(vaccKLMN, viKLMN, vw);
81 vaccOPQR = vmlaq_f32(vaccOPQR, viOPQR, vw);
82 vaccSTUV = vmlaq_f32(vaccSTUV, viSTUV, vw);
83 } while (--nnz != 0);
84 }
85 float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
86 float32x4_t vout4567 = vminq_f32(vacc4567, vmax);
87 float32x4_t vout89AB = vminq_f32(vacc89AB, vmax);
88 float32x4_t voutCDEF = vminq_f32(vaccCDEF, vmax);
89 float32x4_t voutGHIJ = vminq_f32(vaccGHIJ, vmax);
90 float32x4_t voutKLMN = vminq_f32(vaccKLMN, vmax);
91 float32x4_t voutOPQR = vminq_f32(vaccOPQR, vmax);
92 float32x4_t voutSTUV = vminq_f32(vaccSTUV, vmax);
93 vout0123 = vmaxq_f32(vout0123, vmin);
94 vout4567 = vmaxq_f32(vout4567, vmin);
95 vout89AB = vmaxq_f32(vout89AB, vmin);
96 voutCDEF = vmaxq_f32(voutCDEF, vmin);
97 voutGHIJ = vmaxq_f32(voutGHIJ, vmin);
98 voutKLMN = vmaxq_f32(voutKLMN, vmin);
99 voutOPQR = vmaxq_f32(voutOPQR, vmin);
100 voutSTUV = vmaxq_f32(voutSTUV, vmin);
101 vst1q_f32(output, vout0123);
102 vst1q_f32(output + 4, vout4567);
103 vst1q_f32(output + 8, vout89AB);
104 vst1q_f32(output + 12, voutCDEF);
105 vst1q_f32(output + 16, voutGHIJ);
106 vst1q_f32(output + 20, voutKLMN);
107 vst1q_f32(output + 24, voutOPQR);
108 vst1q_f32(output + 28, voutSTUV);
109 output = (float*) ((uintptr_t) output + output_stride);
110 } while (--n != 0);
111 output = (float*) ((uintptr_t) output - output_decrement);
112 input += 32;
113 mc -= 32 * sizeof(float);
114 }
115 if XNN_UNLIKELY(mc != 0) {
116 output_decrement += 16 * sizeof(float);
117 if (mc & (16 * sizeof(float))) {
118 const float* w = weights;
119 const int32_t* dmap = widx_dmap;
120 const uint32_t* nnzmap = nidx_nnzmap;
121 size_t n = nc;
122 do {
123 uint32_t nnz = *nnzmap++;
124 float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1;
125 float32x4_t vacc4567 = vacc0123;
126 float32x4_t vacc89AB = vacc0123;
127 float32x4_t vaccCDEF = vacc0123;
128 if XNN_LIKELY(nnz != 0) {
129 do {
130 const intptr_t diff = *dmap++;
131 const float32x4_t vi0123 = vld1q_f32(input);
132 const float32x4_t vi4567 = vld1q_f32(input + 4);
133 const float32x4_t vi89AB = vld1q_f32(input + 8);
134 const float32x4_t viCDEF = vld1q_f32(input + 12);
135 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
136 const float32x4_t vw = vld1q_dup_f32(w); w += 1;
137 vacc0123 = vmlaq_f32(vacc0123, vi0123, vw);
138 vacc4567 = vmlaq_f32(vacc4567, vi4567, vw);
139 vacc89AB = vmlaq_f32(vacc89AB, vi89AB, vw);
140 vaccCDEF = vmlaq_f32(vaccCDEF, viCDEF, vw);
141 } while (--nnz != 0);
142 }
143 float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
144 float32x4_t vout4567 = vminq_f32(vacc4567, vmax);
145 float32x4_t vout89AB = vminq_f32(vacc89AB, vmax);
146 float32x4_t voutCDEF = vminq_f32(vaccCDEF, vmax);
147 vout0123 = vmaxq_f32(vout0123, vmin);
148 vout4567 = vmaxq_f32(vout4567, vmin);
149 vout89AB = vmaxq_f32(vout89AB, vmin);
150 voutCDEF = vmaxq_f32(voutCDEF, vmin);
151 vst1q_f32(output, vout0123);
152 vst1q_f32(output + 4, vout4567);
153 vst1q_f32(output + 8, vout89AB);
154 vst1q_f32(output + 12, voutCDEF);
155 output = (float*) ((uintptr_t) output + output_stride);
156 } while (--n != 0);
157 output = (float*) ((uintptr_t) output - output_decrement);
158 input += 16;
159 }
160 output_decrement += 8 * sizeof(float);
161 if (mc & (8 * sizeof(float))) {
162 const float* w = weights;
163 const int32_t* dmap = widx_dmap;
164 const uint32_t* nnzmap = nidx_nnzmap;
165 size_t n = nc;
166 do {
167 uint32_t nnz = *nnzmap++;
168 float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1;
169 float32x4_t vacc4567 = vacc0123;
170 if XNN_LIKELY(nnz != 0) {
171 do {
172 const intptr_t diff = *dmap++;
173 const float32x4_t vi0123 = vld1q_f32(input);
174 const float32x4_t vi4567 = vld1q_f32(input + 4);
175 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
176 const float32x4_t vw = vld1q_dup_f32(w); w += 1;
177 vacc0123 = vmlaq_f32(vacc0123, vi0123, vw);
178 vacc4567 = vmlaq_f32(vacc4567, vi4567, vw);
179 } while (--nnz != 0);
180 }
181 float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
182 float32x4_t vout4567 = vminq_f32(vacc4567, vmax);
183 vout0123 = vmaxq_f32(vout0123, vmin);
184 vout4567 = vmaxq_f32(vout4567, vmin);
185 vst1q_f32(output, vout0123);
186 vst1q_f32(output + 4, vout4567);
187 output = (float*) ((uintptr_t) output + output_stride);
188 } while (--n != 0);
189 output = (float*) ((uintptr_t) output - output_decrement);
190 input += 8;
191 }
192 output_decrement += 4 * sizeof(float);
193 if (mc & (4 * sizeof(float))) {
194 const float* w = weights;
195 const int32_t* dmap = widx_dmap;
196 const uint32_t* nnzmap = nidx_nnzmap;
197 size_t n = nc;
198 do {
199 uint32_t nnz = *nnzmap++;
200 float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1;
201 if XNN_LIKELY(nnz != 0) {
202 do {
203 const intptr_t diff = *dmap++;
204 const float32x4_t vi0123 = vld1q_f32(input);
205 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
206 const float32x4_t vw = vld1q_dup_f32(w); w += 1;
207 vacc0123 = vmlaq_f32(vacc0123, vi0123, vw);
208 } while (--nnz != 0);
209 }
210 float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
211 vout0123 = vmaxq_f32(vout0123, vmin);
212 vst1q_f32(output, vout0123);
213 output = (float*) ((uintptr_t) output + output_stride);
214 } while (--n != 0);
215 output = (float*) ((uintptr_t) output - output_decrement);
216 input += 4;
217 }
218 output_decrement += 2 * sizeof(float);
219 if (mc & (2 * sizeof(float))) {
220 const float* w = weights;
221 const int32_t* dmap = widx_dmap;
222 const uint32_t* nnzmap = nidx_nnzmap;
223 size_t n = nc;
224 do {
225 uint32_t nnz = *nnzmap++;
226 float32x2_t vacc01 = vld1_dup_f32(w); w += 1;
227 if XNN_LIKELY(nnz != 0) {
228 do {
229 const intptr_t diff = *dmap++;
230 const float32x2_t vi01 = vld1_f32(input);
231 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
232 const float32x2_t vw = vld1_dup_f32(w); w += 1;
233 vacc01 = vmla_f32(vacc01, vi01, vw);
234 } while (--nnz != 0);
235 }
236 float32x2_t vout01 = vmin_f32(vacc01, vget_low_f32(vmax));
237 vout01 = vmax_f32(vout01, vget_low_f32(vmin));
238 vst1_f32(output, vout01);
239 output = (float*) ((uintptr_t) output + output_stride);
240 } while (--n != 0);
241 output = (float*) ((uintptr_t) output - output_decrement);
242 input += 2;
243 }
244 output_decrement += 1 * sizeof(float);
245 if (mc & (1 * sizeof(float))) {
246 const float* w = weights;
247 const int32_t* dmap = widx_dmap;
248 const uint32_t* nnzmap = nidx_nnzmap;
249 size_t n = nc;
250 do {
251 uint32_t nnz = *nnzmap++;
252 float32x2_t vacc0 = vld1_dup_f32(w); w += 1;
253 if XNN_LIKELY(nnz != 0) {
254 do {
255 const intptr_t diff = *dmap++;
256 const float32x2_t vi0 = vld1_dup_f32(input);
257 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
258 const float32x2_t vw = vld1_dup_f32(w); w += 1;
259 vacc0 = vmla_f32(vacc0, vi0, vw);
260 } while (--nnz != 0);
261 }
262 float32x2_t vout0 = vmin_f32(vacc0, vget_low_f32(vmax));
263 vout0 = vmax_f32(vout0, vget_low_f32(vmin));
264 vst1_lane_f32(output, vout0, 0);
265 output = (float*) ((uintptr_t) output + output_stride);
266 } while (--n != 0);
267 output = (float*) ((uintptr_t) output - output_decrement);
268 input += 1;
269 }
270 }
271 }