Debian Codegraph @

src/f32-spmm/gen/f32-spmm-128x1-minmax-hvx-x4.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-spmm/hvx.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2024 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 <hvx_hexagon_protos.h>
13 #include <hexagon_protos.h>
14 #include <hexagon_types.h>
15
16 #include "xnnpack/simd/f32-hvx.h"
17
18 #include "xnnpack/prefetch.h"
19 #include "xnnpack/spmm.h"
20
21 void xnn_f32_spmm_minmax_ukernel_128x1__hvx_x4(
22 size_t mc,
23 size_t nc,
24 const float* input,
25 const float* weights,
26 const int32_t* widx_dmap,
27 const uint32_t* nidx_nnzmap,
28 float* output,
29 size_t output_stride,
30 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
31 {
32 assert(mc != 0);
33 assert(mc % sizeof(float) == 0);
34 assert(nc != 0);
35
36 const HVX_Vector vmin = xnn_set1_f32(params->scalar.min);
37 const HVX_Vector vmax = xnn_set1_f32(params->scalar.max);
38
39 size_t output_decrement = output_stride * nc - 128 * sizeof(float);
40 while XNN_LIKELY(mc >= 128 * sizeof(float)) {
41 const float* w = weights;
42 const int32_t* dmap = widx_dmap;
43 const uint32_t* nnzmap = nidx_nnzmap;
44 size_t n = nc;
45 do {
46 uint32_t nnz = *nnzmap++;
47 HVX_Vector vacc0x0 = xnn_set1_f32(*w); w += 1;
48 HVX_Vector vacc0x1 = xnn_zero_f32();
49 HVX_Vector vacc0x2 = xnn_zero_f32();
50 HVX_Vector vacc0x3 = xnn_zero_f32();
51 HVX_Vector vacc1x0 = vacc0x0;
52 HVX_Vector vacc1x1 = xnn_zero_f32();
53 HVX_Vector vacc1x2 = xnn_zero_f32();
54 HVX_Vector vacc1x3 = xnn_zero_f32();
55 HVX_Vector vacc2x0 = vacc0x0;
56 HVX_Vector vacc2x1 = xnn_zero_f32();
57 HVX_Vector vacc2x2 = xnn_zero_f32();
58 HVX_Vector vacc2x3 = xnn_zero_f32();
59 HVX_Vector vacc3x0 = vacc0x0;
60 HVX_Vector vacc3x1 = xnn_zero_f32();
61 HVX_Vector vacc3x2 = xnn_zero_f32();
62 HVX_Vector vacc3x3 = xnn_zero_f32();
63 for (; nnz >= 4; nnz -= 4) {
64 const intptr_t diff0 = dmap[0];
65 const intptr_t diff1 = dmap[1];
66 const intptr_t diff2 = dmap[2];
67 const intptr_t diff3 = dmap[3];
68 dmap += 4;
69 const HVX_Vector vi0x0 = xnn_loadu_f32(input);
70 const HVX_Vector vi1x0 = xnn_loadu_f32(input + 32);
71 const HVX_Vector vi2x0 = xnn_loadu_f32(input + 64);
72 const HVX_Vector vi3x0 = xnn_loadu_f32(input + 96);
73 input = (const float*) ((uintptr_t) input + (uintptr_t) diff0);
74
75 const HVX_Vector vw0 = xnn_set1_f32(*w); w += 1;
76
77 vacc0x0 = xnn_fmadd_f32(vi0x0, vw0, vacc0x0);
78 vacc1x0 = xnn_fmadd_f32(vi1x0, vw0, vacc1x0);
79 vacc2x0 = xnn_fmadd_f32(vi2x0, vw0, vacc2x0);
80 vacc3x0 = xnn_fmadd_f32(vi3x0, vw0, vacc3x0);
81 const HVX_Vector vi0x1 = xnn_loadu_f32(input);
82 const HVX_Vector vi1x1 = xnn_loadu_f32(input + 32);
83 const HVX_Vector vi2x1 = xnn_loadu_f32(input + 64);
84 const HVX_Vector vi3x1 = xnn_loadu_f32(input + 96);
85 input = (const float*) ((uintptr_t) input + (uintptr_t) diff1);
86
87 const HVX_Vector vw1 = xnn_set1_f32(*w); w += 1;
88
89 vacc0x1 = xnn_fmadd_f32(vi0x1, vw1, vacc0x1);
90 vacc1x1 = xnn_fmadd_f32(vi1x1, vw1, vacc1x1);
91 vacc2x1 = xnn_fmadd_f32(vi2x1, vw1, vacc2x1);
92 vacc3x1 = xnn_fmadd_f32(vi3x1, vw1, vacc3x1);
93 const HVX_Vector vi0x2 = xnn_loadu_f32(input);
94 const HVX_Vector vi1x2 = xnn_loadu_f32(input + 32);
95 const HVX_Vector vi2x2 = xnn_loadu_f32(input + 64);
96 const HVX_Vector vi3x2 = xnn_loadu_f32(input + 96);
97 input = (const float*) ((uintptr_t) input + (uintptr_t) diff2);
98
99 const HVX_Vector vw2 = xnn_set1_f32(*w); w += 1;
100
101 vacc0x2 = xnn_fmadd_f32(vi0x2, vw2, vacc0x2);
102 vacc1x2 = xnn_fmadd_f32(vi1x2, vw2, vacc1x2);
103 vacc2x2 = xnn_fmadd_f32(vi2x2, vw2, vacc2x2);
104 vacc3x2 = xnn_fmadd_f32(vi3x2, vw2, vacc3x2);
105 const HVX_Vector vi0x3 = xnn_loadu_f32(input);
106 const HVX_Vector vi1x3 = xnn_loadu_f32(input + 32);
107 const HVX_Vector vi2x3 = xnn_loadu_f32(input + 64);
108 const HVX_Vector vi3x3 = xnn_loadu_f32(input + 96);
109 input = (const float*) ((uintptr_t) input + (uintptr_t) diff3);
110
111 const HVX_Vector vw3 = xnn_set1_f32(*w); w += 1;
112
113 vacc0x3 = xnn_fmadd_f32(vi0x3, vw3, vacc0x3);
114 vacc1x3 = xnn_fmadd_f32(vi1x3, vw3, vacc1x3);
115 vacc2x3 = xnn_fmadd_f32(vi2x3, vw3, vacc2x3);
116 vacc3x3 = xnn_fmadd_f32(vi3x3, vw3, vacc3x3);
117 }
118 HVX_Vector vacc0 = vacc0x0;
119 HVX_Vector vacc1 = vacc1x0;
120 HVX_Vector vacc2 = vacc2x0;
121 HVX_Vector vacc3 = vacc3x0;
122 vacc0 = xnn_add_f32(vacc0, vacc0x1);
123 vacc1 = xnn_add_f32(vacc1, vacc1x1);
124 vacc2 = xnn_add_f32(vacc2, vacc2x1);
125 vacc3 = xnn_add_f32(vacc3, vacc3x1);
126 vacc0 = xnn_add_f32(vacc0, vacc0x2);
127 vacc1 = xnn_add_f32(vacc1, vacc1x2);
128 vacc2 = xnn_add_f32(vacc2, vacc2x2);
129 vacc3 = xnn_add_f32(vacc3, vacc3x2);
130 vacc0 = xnn_add_f32(vacc0, vacc0x3);
131 vacc1 = xnn_add_f32(vacc1, vacc1x3);
132 vacc2 = xnn_add_f32(vacc2, vacc2x3);
133 vacc3 = xnn_add_f32(vacc3, vacc3x3);
134 if XNN_LIKELY(nnz != 0) {
135 do {
136 const intptr_t diff = *dmap++;
137 const HVX_Vector vi0 = xnn_loadu_f32(input);
138 const HVX_Vector vi1 = xnn_loadu_f32(input + 32);
139 const HVX_Vector vi2 = xnn_loadu_f32(input + 64);
140 const HVX_Vector vi3 = xnn_loadu_f32(input + 96);
141 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
142
143 const HVX_Vector vw = xnn_set1_f32(*w); w += 1;
144
145 vacc0 = xnn_fmadd_f32(vi0, vw, vacc0);
146 vacc1 = xnn_fmadd_f32(vi1, vw, vacc1);
147 vacc2 = xnn_fmadd_f32(vi2, vw, vacc2);
148 vacc3 = xnn_fmadd_f32(vi3, vw, vacc3);
149 } while (--nnz != 0);
150 }
151 HVX_Vector vout0 = xnn_min_f32(vacc0, vmax);
152 HVX_Vector vout1 = xnn_min_f32(vacc1, vmax);
153 HVX_Vector vout2 = xnn_min_f32(vacc2, vmax);
154 HVX_Vector vout3 = xnn_min_f32(vacc3, vmax);
155 vout0 = xnn_max_f32(vout0, vmin);
156 vout1 = xnn_max_f32(vout1, vmin);
157 vout2 = xnn_max_f32(vout2, vmin);
158 vout3 = xnn_max_f32(vout3, vmin);
159
160 xnn_storeu_f32(output, vout0);
161 xnn_storeu_f32(output + 32, vout1);
162 xnn_storeu_f32(output + 64, vout2);
163 xnn_storeu_f32(output + 96, vout3);
164 output = (float*) ((uintptr_t) output + output_stride);
165 } while (--n != 0);
166 output = (float*) ((uintptr_t) output - output_decrement);
167 input += 128;
168 mc -= 128 * sizeof(float);
169 }
170 if XNN_UNLIKELY(mc != 0) {
171 output_decrement += 64 * sizeof(float);
172 if (mc & (64 * sizeof(float))) {
173 const float* w = weights;
174 const int32_t* dmap = widx_dmap;
175 const uint32_t* nnzmap = nidx_nnzmap;
176 size_t n = nc;
177 do {
178 uint32_t nnz = *nnzmap++;
179 HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1;
180 HVX_Vector vacc1 = vacc0;
181 if XNN_LIKELY(nnz != 0) {
182 do {
183 const intptr_t diff = *dmap++;
184 const HVX_Vector vi0 = xnn_loadu_f32(input);
185 const HVX_Vector vi1 = xnn_loadu_f32(input + 32);
186 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
187 const HVX_Vector vw = xnn_set1_f32(*w); w += 1;
188 vacc0 = xnn_fmadd_f32(vi0, vw, vacc0);
189 vacc1 = xnn_fmadd_f32(vi1, vw, vacc1);
190 } while (--nnz != 0);
191 }
192 HVX_Vector vout0 = xnn_min_f32(vacc0, vmax);
193 HVX_Vector vout1 = xnn_min_f32(vacc1, vmax);
194 vout0 = xnn_max_f32(vout0, vmin);
195 vout1 = xnn_max_f32(vout1, vmin);
196
197 xnn_storeu_f32(output, vout0);
198 xnn_storeu_f32(output + 32, vout1);
199 output = (float*) ((uintptr_t) output + output_stride);
200 } while (--n != 0);
201 output = (float*) ((uintptr_t) output - output_decrement);
202 input += 64;
203 }
204 output_decrement += 32 * sizeof(float);
205 if (mc & (32 * sizeof(float))) {
206 const float* w = weights;
207 const int32_t* dmap = widx_dmap;
208 const uint32_t* nnzmap = nidx_nnzmap;
209 size_t n = nc;
210 do {
211 uint32_t nnz = *nnzmap++;
212 HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1;
213 if XNN_LIKELY(nnz != 0) {
214 do {
215 const intptr_t diff = *dmap++;
216 const HVX_Vector vi0 = xnn_loadu_f32(input);
217 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
218 const HVX_Vector vw = xnn_set1_f32(*w); w += 1;
219 vacc0 = xnn_fmadd_f32(vi0, vw, vacc0);
220 } while (--nnz != 0);
221 }
222 HVX_Vector vout0 = xnn_min_f32(vacc0, vmax);
223 vout0 = xnn_max_f32(vout0, vmin);
224
225 xnn_storeu_f32(output, vout0);
226 output = (float*) ((uintptr_t) output + output_stride);
227 } while (--n != 0);
228 output = (float*) ((uintptr_t) output - output_decrement);
229 input += 32;
230 }
231 output_decrement += 16 * sizeof(float);
232 if (mc & (16 * sizeof(float))) {
233 const float* w = weights;
234 const int32_t* dmap = widx_dmap;
235 const uint32_t* nnzmap = nidx_nnzmap;
236 size_t n = nc;
237 do {
238 uint32_t nnz = *nnzmap++;
239 HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1;
240 if XNN_LIKELY(nnz != 0) {
241 do {
242 const intptr_t diff = *dmap++;
243 const HVX_Vector vi0 = xnn_loadu_f32(input);
244 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
245 const HVX_Vector vw = xnn_set1_f32(*w); w += 1;
246 vacc0 = xnn_fmadd_f32(vi0, vw, vacc0);
247 } while (--nnz != 0);
248 }
249 HVX_Vector vout0 = xnn_min_f32(vacc0, vmax);
250 vout0 = xnn_max_f32(vout0, vmin);
251
252 xnn_store_tail_f32(output, vout0, 16);
253 output = (float*) ((uintptr_t) output + output_stride);
254 } while (--n != 0);
255 output = (float*) ((uintptr_t) output - output_decrement);
256 input += 16;
257 }
258 output_decrement += 8 * sizeof(float);
259 if (mc & (8 * sizeof(float))) {
260 const float* w = weights;
261 const int32_t* dmap = widx_dmap;
262 const uint32_t* nnzmap = nidx_nnzmap;
263 size_t n = nc;
264 do {
265 uint32_t nnz = *nnzmap++;
266 HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1;
267 if XNN_LIKELY(nnz != 0) {
268 do {
269 const intptr_t diff = *dmap++;
270 const HVX_Vector vi0 = xnn_loadu_f32(input);
271 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
272 const HVX_Vector vw = xnn_set1_f32(*w); w += 1;
273 vacc0 = xnn_fmadd_f32(vi0, vw, vacc0);
274 } while (--nnz != 0);
275 }
276 HVX_Vector vout0 = xnn_min_f32(vacc0, vmax);
277 vout0 = xnn_max_f32(vout0, vmin);
278
279 xnn_store_tail_f32(output, vout0, 8);
280 output = (float*) ((uintptr_t) output + output_stride);
281 } while (--n != 0);
282 output = (float*) ((uintptr_t) output - output_decrement);
283 input += 8;
284 }
285 output_decrement += 4 * sizeof(float);
286 if (mc & (4 * sizeof(float))) {
287 const float* w = weights;
288 const int32_t* dmap = widx_dmap;
289 const uint32_t* nnzmap = nidx_nnzmap;
290 size_t n = nc;
291 do {
292 uint32_t nnz = *nnzmap++;
293 HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1;
294 if XNN_LIKELY(nnz != 0) {
295 do {
296 const intptr_t diff = *dmap++;
297 const HVX_Vector vi0 = xnn_loadu_f32(input);
298 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
299 const HVX_Vector vw = xnn_set1_f32(*w); w += 1;
300 vacc0 = xnn_fmadd_f32(vi0, vw, vacc0);
301 } while (--nnz != 0);
302 }
303 HVX_Vector vout0 = xnn_min_f32(vacc0, vmax);
304 vout0 = xnn_max_f32(vout0, vmin);
305
306 xnn_store_tail_f32(output, vout0, 4);
307 output = (float*) ((uintptr_t) output + output_stride);
308 } while (--n != 0);
309 output = (float*) ((uintptr_t) output - output_decrement);
310 input += 4;
311 }
312 output_decrement += 2 * sizeof(float);
313 if (mc & (2 * sizeof(float))) {
314 const float* w = weights;
315 const int32_t* dmap = widx_dmap;
316 const uint32_t* nnzmap = nidx_nnzmap;
317 size_t n = nc;
318 do {
319 uint32_t nnz = *nnzmap++;
320 HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1;
321 if XNN_LIKELY(nnz != 0) {
322 do {
323 const intptr_t diff = *dmap++;
324 const HVX_Vector vi0 = xnn_loadu_f32(input);
325 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
326 const HVX_Vector vw = xnn_set1_f32(*w); w += 1;
327 vacc0 = xnn_fmadd_f32(vi0, vw, vacc0);
328 } while (--nnz != 0);
329 }
330 HVX_Vector vout0 = xnn_min_f32(vacc0, vmax);
331 vout0 = xnn_max_f32(vout0, vmin);
332
333 xnn_store_tail_f32(output, vout0, 2);
334 output = (float*) ((uintptr_t) output + output_stride);
335 } while (--n != 0);
336 output = (float*) ((uintptr_t) output - output_decrement);
337 input += 2;
338 }
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 do {
345 uint32_t nnz = *nnzmap++;
346 HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1;
347 if XNN_LIKELY(nnz != 0) {
348 do {
349 const intptr_t diff = *dmap++;
350 const HVX_Vector vi0 = xnn_loadu_f32(input);
351 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
352 const HVX_Vector vw = xnn_set1_f32(*w); w += 1;
353 vacc0 = xnn_fmadd_f32(vi0, vw, vacc0);
354 } while (--nnz != 0);
355 }
356 HVX_Vector vout0 = xnn_min_f32(vacc0, vmax);
357 vout0 = xnn_max_f32(vout0, vmin);
358
359 xnn_store_tail_f32(output, vout0, 1);
360 output = (float*) ((uintptr_t) output + output_stride);
361 } while (--n != 0);
362 }
363 }
364 }