Debian Codegraph @

src/f32-spmm/gen/f32-spmm-16x1-minmax-wasmsimd-arm-x4.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-spmm/wasmsimd.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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 <wasm_simd128.h>
13
14 #include "xnnpack/spmm.h"
15
16
17 void xnn_f32_spmm_minmax_ukernel_16x1__wasmsimd_arm_x4(
18 size_t mc,
19 size_t nc,
20 const float* input,
21 const float* weights,
22 const int32_t* widx_dmap,
23 const uint32_t* nidx_nnzmap,
24 float* output,
25 size_t output_stride,
26 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
27 {
28 assert(mc != 0);
29 assert(mc % sizeof(float) == 0);
30 assert(nc != 0);
31
32 const v128_t vmin = wasm_v128_load32_splat(&params->scalar.min);
33 const v128_t vmax = wasm_v128_load32_splat(&params->scalar.max);
34 XNN_FORCE_REALIZATION(vmin);
35 XNN_FORCE_REALIZATION(vmax);
36 size_t output_decrement = output_stride * nc - 16 * sizeof(float);
37 while XNN_LIKELY(mc >= 16 * sizeof(float)) {
38 const float* w = weights;
39 const int32_t* dmap = widx_dmap;
40 const uint32_t* nnzmap = nidx_nnzmap;
41 size_t n = nc;
42 do {
43 uint32_t nnz = *nnzmap++;
44 v128_t vacc0123x0 = wasm_v128_load32_splat(w);
45 w += 1;
46 v128_t vacc0123x1 = wasm_f32x4_const_splat(0.0f);
47 v128_t vacc0123x2 = wasm_f32x4_const_splat(0.0f);
48 v128_t vacc0123x3 = wasm_f32x4_const_splat(0.0f);
49 v128_t vacc4567x0 = vacc0123x0;
50 v128_t vacc4567x1 = wasm_f32x4_const_splat(0.0f);
51 v128_t vacc4567x2 = wasm_f32x4_const_splat(0.0f);
52 v128_t vacc4567x3 = wasm_f32x4_const_splat(0.0f);
53 v128_t vacc89ABx0 = vacc0123x0;
54 v128_t vacc89ABx1 = wasm_f32x4_const_splat(0.0f);
55 v128_t vacc89ABx2 = wasm_f32x4_const_splat(0.0f);
56 v128_t vacc89ABx3 = wasm_f32x4_const_splat(0.0f);
57 v128_t vaccCDEFx0 = vacc0123x0;
58 v128_t vaccCDEFx1 = wasm_f32x4_const_splat(0.0f);
59 v128_t vaccCDEFx2 = wasm_f32x4_const_splat(0.0f);
60 v128_t vaccCDEFx3 = wasm_f32x4_const_splat(0.0f);
61 for (; nnz >= 4; nnz -= 4) {
62 const intptr_t diff0 = dmap[0];
63 const intptr_t diff1 = dmap[1];
64 const intptr_t diff2 = dmap[2];
65 const intptr_t diff3 = dmap[3];
66 dmap += 4;
67 const v128_t vi0123x0 = wasm_v128_load(input);
68 const v128_t vi4567x0 = wasm_v128_load(input + 4);
69 const v128_t vi89ABx0 = wasm_v128_load(input + 8);
70 const v128_t viCDEFx0 = wasm_v128_load(input + 12);
71 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff0);
72 const v128_t vw0 = wasm_v128_load32_splat(w);
73 w += 1;
74 vacc0123x0 = wasm_f32x4_add(vacc0123x0, wasm_f32x4_mul(vi0123x0, vw0));
75 vacc4567x0 = wasm_f32x4_add(vacc4567x0, wasm_f32x4_mul(vi4567x0, vw0));
76 vacc89ABx0 = wasm_f32x4_add(vacc89ABx0, wasm_f32x4_mul(vi89ABx0, vw0));
77 vaccCDEFx0 = wasm_f32x4_add(vaccCDEFx0, wasm_f32x4_mul(viCDEFx0, vw0));
78 const v128_t vi0123x1 = wasm_v128_load(input);
79 const v128_t vi4567x1 = wasm_v128_load(input + 4);
80 const v128_t vi89ABx1 = wasm_v128_load(input + 8);
81 const v128_t viCDEFx1 = wasm_v128_load(input + 12);
82 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff1);
83 const v128_t vw1 = wasm_v128_load32_splat(w);
84 w += 1;
85 vacc0123x1 = wasm_f32x4_add(vacc0123x1, wasm_f32x4_mul(vi0123x1, vw1));
86 vacc4567x1 = wasm_f32x4_add(vacc4567x1, wasm_f32x4_mul(vi4567x1, vw1));
87 vacc89ABx1 = wasm_f32x4_add(vacc89ABx1, wasm_f32x4_mul(vi89ABx1, vw1));
88 vaccCDEFx1 = wasm_f32x4_add(vaccCDEFx1, wasm_f32x4_mul(viCDEFx1, vw1));
89 const v128_t vi0123x2 = wasm_v128_load(input);
90 const v128_t vi4567x2 = wasm_v128_load(input + 4);
91 const v128_t vi89ABx2 = wasm_v128_load(input + 8);
92 const v128_t viCDEFx2 = wasm_v128_load(input + 12);
93 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff2);
94 const v128_t vw2 = wasm_v128_load32_splat(w);
95 w += 1;
96 vacc0123x2 = wasm_f32x4_add(vacc0123x2, wasm_f32x4_mul(vi0123x2, vw2));
97 vacc4567x2 = wasm_f32x4_add(vacc4567x2, wasm_f32x4_mul(vi4567x2, vw2));
98 vacc89ABx2 = wasm_f32x4_add(vacc89ABx2, wasm_f32x4_mul(vi89ABx2, vw2));
99 vaccCDEFx2 = wasm_f32x4_add(vaccCDEFx2, wasm_f32x4_mul(viCDEFx2, vw2));
100 const v128_t vi0123x3 = wasm_v128_load(input);
101 const v128_t vi4567x3 = wasm_v128_load(input + 4);
102 const v128_t vi89ABx3 = wasm_v128_load(input + 8);
103 const v128_t viCDEFx3 = wasm_v128_load(input + 12);
104 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff3);
105 const v128_t vw3 = wasm_v128_load32_splat(w);
106 w += 1;
107 vacc0123x3 = wasm_f32x4_add(vacc0123x3, wasm_f32x4_mul(vi0123x3, vw3));
108 vacc4567x3 = wasm_f32x4_add(vacc4567x3, wasm_f32x4_mul(vi4567x3, vw3));
109 vacc89ABx3 = wasm_f32x4_add(vacc89ABx3, wasm_f32x4_mul(vi89ABx3, vw3));
110 vaccCDEFx3 = wasm_f32x4_add(vaccCDEFx3, wasm_f32x4_mul(viCDEFx3, vw3));
111 }
112 v128_t vacc0123 = vacc0123x0;
113 v128_t vacc4567 = vacc4567x0;
114 v128_t vacc89AB = vacc89ABx0;
115 v128_t vaccCDEF = vaccCDEFx0;
116 vacc0123 = wasm_f32x4_add(vacc0123, vacc0123x1);
117 vacc4567 = wasm_f32x4_add(vacc4567, vacc4567x1);
118 vacc89AB = wasm_f32x4_add(vacc89AB, vacc89ABx1);
119 vaccCDEF = wasm_f32x4_add(vaccCDEF, vaccCDEFx1);
120 vacc0123 = wasm_f32x4_add(vacc0123, vacc0123x2);
121 vacc4567 = wasm_f32x4_add(vacc4567, vacc4567x2);
122 vacc89AB = wasm_f32x4_add(vacc89AB, vacc89ABx2);
123 vaccCDEF = wasm_f32x4_add(vaccCDEF, vaccCDEFx2);
124 vacc0123 = wasm_f32x4_add(vacc0123, vacc0123x3);
125 vacc4567 = wasm_f32x4_add(vacc4567, vacc4567x3);
126 vacc89AB = wasm_f32x4_add(vacc89AB, vacc89ABx3);
127 vaccCDEF = wasm_f32x4_add(vaccCDEF, vaccCDEFx3);
128 if XNN_LIKELY(nnz != 0) {
129 do {
130 const intptr_t diff = *dmap++;
131 const v128_t vi0123 = wasm_v128_load(input);
132 const v128_t vi4567 = wasm_v128_load(input + 4);
133 const v128_t vi89AB = wasm_v128_load(input + 8);
134 const v128_t viCDEF = wasm_v128_load(input + 12);
135 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
136 const v128_t vw = wasm_v128_load32_splat(w); w += 1;
137 vacc0123 = wasm_f32x4_add(vacc0123, wasm_f32x4_mul(vi0123, vw));
138 vacc4567 = wasm_f32x4_add(vacc4567, wasm_f32x4_mul(vi4567, vw));
139 vacc89AB = wasm_f32x4_add(vacc89AB, wasm_f32x4_mul(vi89AB, vw));
140 vaccCDEF = wasm_f32x4_add(vaccCDEF, wasm_f32x4_mul(viCDEF, vw));
141 } while (--nnz != 0);
142 }
143 v128_t vout0123 = wasm_f32x4_min(vmax, vacc0123);
144 v128_t vout4567 = wasm_f32x4_min(vmax, vacc4567);
145 v128_t vout89AB = wasm_f32x4_min(vmax, vacc89AB);
146 v128_t voutCDEF = wasm_f32x4_min(vmax, vaccCDEF);
147 vout0123 = wasm_f32x4_max(vmin, vout0123);
148 vout4567 = wasm_f32x4_max(vmin, vout4567);
149 vout89AB = wasm_f32x4_max(vmin, vout89AB);
150 voutCDEF = wasm_f32x4_max(vmin, voutCDEF);
151 wasm_v128_store(output, vout0123);
152 wasm_v128_store(output + 4, vout4567);
153 wasm_v128_store(output + 8, vout89AB);
154 wasm_v128_store(output + 12, voutCDEF);
155 output = (float*restrict) ((uintptr_t) output + output_stride);
156 } while (--n != 0);
157 output = (float*restrict) ((uintptr_t) output - output_decrement);
158 input += 16;
159 mc -= 16 * sizeof(float);
160 }
161 if XNN_UNLIKELY(mc != 0) {
162 output_decrement += 8 * sizeof(float);
163 if (mc & (8 * sizeof(float))) {
164 const float* w = weights;
165 const int32_t* dmap = widx_dmap;
166 const uint32_t* nnzmap = nidx_nnzmap;
167 size_t n = nc;
168 do {
169 uint32_t nnz = *nnzmap++;
170 v128_t vacc0123 = wasm_v128_load32_splat(w); w += 1;
171 v128_t vacc4567 = vacc0123;
172 if XNN_LIKELY(nnz != 0) {
173 do {
174 const intptr_t diff = *dmap++;
175 const v128_t vi0123 = wasm_v128_load(input);
176 const v128_t vi4567 = wasm_v128_load(input + 4);
177 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
178 const v128_t vw = wasm_v128_load32_splat(w); w += 1;
179 vacc0123 = wasm_f32x4_add(vacc0123, wasm_f32x4_mul(vi0123, vw));
180 vacc4567 = wasm_f32x4_add(vacc4567, wasm_f32x4_mul(vi4567, vw));
181 } while (--nnz != 0);
182 }
183 v128_t vout0123 = wasm_f32x4_min(vmax, vacc0123);
184 v128_t vout4567 = wasm_f32x4_min(vmax, vacc4567);
185 vout0123 = wasm_f32x4_max(vmin, vout0123);
186 vout4567 = wasm_f32x4_max(vmin, vout4567);
187 wasm_v128_store(output, vout0123);
188
189 wasm_v128_store(output + 4, vout4567);
190 output = (float*restrict) ((uintptr_t) output + output_stride);
191 } while (--n != 0);
192 output = (float*restrict) ((uintptr_t) output - output_decrement);
193 input += 8;
194 }
195 output_decrement += 4 * sizeof(float);
196 if (mc & (4 * sizeof(float))) {
197 const float* w = weights;
198 const int32_t* dmap = widx_dmap;
199 const uint32_t* nnzmap = nidx_nnzmap;
200 size_t n = nc;
201 do {
202 uint32_t nnz = *nnzmap++;
203 v128_t vacc0123 = wasm_v128_load32_splat(w); w += 1;
204 if XNN_LIKELY(nnz != 0) {
205 do {
206 const intptr_t diff = *dmap++;
207 const v128_t vi0123 = wasm_v128_load(input);
208 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
209 const v128_t vw = wasm_v128_load32_splat(w); w += 1;
210 vacc0123 = wasm_f32x4_add(vacc0123, wasm_f32x4_mul(vi0123, vw));
211 } while (--nnz != 0);
212 }
213 v128_t vout0123 = wasm_f32x4_min(vmax, vacc0123);
214 vout0123 = wasm_f32x4_max(vmin, vout0123);
215 wasm_v128_store(output, vout0123);
216
217 output = (float*restrict) ((uintptr_t) output + output_stride);
218 } while (--n != 0);
219 output = (float*restrict) ((uintptr_t) output - output_decrement);
220 input += 4;
221 }
222 output_decrement += 2 * sizeof(float);
223 if (mc & (2 * sizeof(float))) {
224 const float* w = weights;
225 const int32_t* dmap = widx_dmap;
226 const uint32_t* nnzmap = nidx_nnzmap;
227 size_t n = nc;
228 do {
229 uint32_t nnz = *nnzmap++;
230 v128_t vacc01 = wasm_v128_load32_splat(w); w += 1;
231 if XNN_LIKELY(nnz != 0) {
232 do {
233 const intptr_t diff = *dmap++;
234 const v128_t vi01 = wasm_v128_load64_splat(input);
235 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
236 const v128_t vw = wasm_v128_load32_splat(w); w += 1;
237 vacc01 = wasm_f32x4_add(vacc01, wasm_f32x4_mul(vi01, vw));
238 } while (--nnz != 0);
239 }
240 v128_t vout01 = wasm_f32x4_min(vmax, vacc01);
241 vout01 = wasm_f32x4_max(vmin, vout01);
242 wasm_v128_store64_lane(output, vout01, 0);
243
244 output = (float*restrict) ((uintptr_t) output + output_stride);
245 } while (--n != 0);
246 output = (float*restrict) ((uintptr_t) output - output_decrement);
247 input += 2;
248 }
249 output_decrement += 1 * sizeof(float);
250 if (mc & (1 * sizeof(float))) {
251 const float* w = weights;
252 const int32_t* dmap = widx_dmap;
253 const uint32_t* nnzmap = nidx_nnzmap;
254 size_t n = nc;
255 do {
256 uint32_t nnz = *nnzmap++;
257 v128_t vacc0 = wasm_v128_load32_splat(w); w += 1;
258 if XNN_LIKELY(nnz != 0) {
259 do {
260 const intptr_t diff = *dmap++;
261 const v128_t vi0 = wasm_v128_load32_splat(input);
262 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
263 const v128_t vw = wasm_v128_load32_splat(w); w += 1;
264 vacc0 = wasm_f32x4_add(vacc0, wasm_f32x4_mul(vi0, vw));
265 } while (--nnz != 0);
266 }
267 v128_t vout0 = wasm_f32x4_min(vmax, vacc0);
268 vout0 = wasm_f32x4_max(vmin, vout0);
269 wasm_v128_store32_lane(output, vout0, 0);
270
271 output = (float*restrict) ((uintptr_t) output + output_stride);
272 } while (--n != 0);
273 output = (float*restrict) ((uintptr_t) output - output_decrement);
274 input += 1;
275 }
276 }
277 }