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
xnn_f32_spmm_minmax_ukernel_16x1__wasmsimd_x86_x2(size_t mc,size_t nc,const float * restrict input,const float * restrict weights,const int32_t * restrict widx_dmap,const uint32_t * restrict nidx_nnzmap,float * restrict output,size_t output_stride,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_spmm_minmax_ukernel_16x1__wasmsimd_x86_x2(
18 size_t mc,
19 size_t nc,
20 const float*restrict input,
21 const float*restrict weights,
22 const int32_t*restrict widx_dmap,
23 const uint32_t*restrict nidx_nnzmap,
24 float*restrict 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_v32x4_load_splat(¶ms->scalar.min);
33 const v128_t vmax = wasm_v32x4_load_splat(¶ms->scalar.max);
34 const v128_t vzero = wasm_f64x2_splat(0.0);
35 size_t output_decrement = output_stride * nc - 16 * sizeof(float);
36 while XNN_LIKELY(mc >= 16 * sizeof(float)) {
37 const float*restrict w = weights;
38 const int32_t* dmap = widx_dmap;
39 const uint32_t* nnzmap = nidx_nnzmap;
40 size_t n = nc;
41 do {
42 uint32_t nnz = *nnzmap++;
43 v128_t vacc0123x0 = wasm_v32x4_load_splat(w);
44 w += 1;
45 v128_t vacc0123x1 = vzero;
46 v128_t vacc4567x0 = vacc0123x0;
47 v128_t vacc4567x1 = vzero;
48 v128_t vacc89ABx0 = vacc0123x0;
49 v128_t vacc89ABx1 = vzero;
50 v128_t vaccCDEFx0 = vacc0123x0;
51 v128_t vaccCDEFx1 = vzero;
52 for (; nnz >= 2; nnz -= 2) {
53 const intptr_t diff0 = dmap[0];
54 const intptr_t diff1 = dmap[1];
55 dmap += 2;
56 const v128_t vi0123x0 = wasm_v128_load(input);
57 const v128_t vi4567x0 = wasm_v128_load(input + 4);
58 const v128_t vi89ABx0 = wasm_v128_load(input + 8);
59 const v128_t viCDEFx0 = wasm_v128_load(input + 12);
60 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff0);
61 const v128_t vw0 = wasm_v32x4_load_splat(w);
62 w += 1;
63 vacc0123x0 = wasm_f32x4_add(vacc0123x0, wasm_f32x4_mul(vi0123x0, vw0));
64 vacc4567x0 = wasm_f32x4_add(vacc4567x0, wasm_f32x4_mul(vi4567x0, vw0));
65 vacc89ABx0 = wasm_f32x4_add(vacc89ABx0, wasm_f32x4_mul(vi89ABx0, vw0));
66 vaccCDEFx0 = wasm_f32x4_add(vaccCDEFx0, wasm_f32x4_mul(viCDEFx0, vw0));
67 const v128_t vi0123x1 = wasm_v128_load(input);
68 const v128_t vi4567x1 = wasm_v128_load(input + 4);
69 const v128_t vi89ABx1 = wasm_v128_load(input + 8);
70 const v128_t viCDEFx1 = wasm_v128_load(input + 12);
71 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff1);
72 const v128_t vw1 = wasm_v32x4_load_splat(w);
73 w += 1;
74 vacc0123x1 = wasm_f32x4_add(vacc0123x1, wasm_f32x4_mul(vi0123x1, vw1));
75 vacc4567x1 = wasm_f32x4_add(vacc4567x1, wasm_f32x4_mul(vi4567x1, vw1));
76 vacc89ABx1 = wasm_f32x4_add(vacc89ABx1, wasm_f32x4_mul(vi89ABx1, vw1));
77 vaccCDEFx1 = wasm_f32x4_add(vaccCDEFx1, wasm_f32x4_mul(viCDEFx1, vw1));
78 }
79 v128_t vacc0123 = vacc0123x0;
80 v128_t vacc4567 = vacc4567x0;
81 v128_t vacc89AB = vacc89ABx0;
82 v128_t vaccCDEF = vaccCDEFx0;
83 vacc0123 = wasm_f32x4_add(vacc0123, vacc0123x1);
84 vacc4567 = wasm_f32x4_add(vacc4567, vacc4567x1);
85 vacc89AB = wasm_f32x4_add(vacc89AB, vacc89ABx1);
86 vaccCDEF = wasm_f32x4_add(vaccCDEF, vaccCDEFx1);
87 if XNN_LIKELY(nnz != 0) {
88 do {
89 const intptr_t diff = *dmap++;
90 const v128_t vi0123 = wasm_v128_load(input);
91 const v128_t vi4567 = wasm_v128_load(input + 4);
92 const v128_t vi89AB = wasm_v128_load(input + 8);
93 const v128_t viCDEF = wasm_v128_load(input + 12);
94 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
95 const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
96 vacc0123 = wasm_f32x4_add(vacc0123, wasm_f32x4_mul(vi0123, vw));
97 vacc4567 = wasm_f32x4_add(vacc4567, wasm_f32x4_mul(vi4567, vw));
98 vacc89AB = wasm_f32x4_add(vacc89AB, wasm_f32x4_mul(vi89AB, vw));
99 vaccCDEF = wasm_f32x4_add(vaccCDEF, wasm_f32x4_mul(viCDEF, vw));
100 } while (--nnz != 0);
101 }
102 v128_t vout0123 = wasm_v128_bitselect(vacc0123, vmax, wasm_f32x4_le(vacc0123, vmax));
103 v128_t vout4567 = wasm_v128_bitselect(vacc4567, vmax, wasm_f32x4_le(vacc4567, vmax));
104 v128_t vout89AB = wasm_v128_bitselect(vacc89AB, vmax, wasm_f32x4_le(vacc89AB, vmax));
105 v128_t voutCDEF = wasm_v128_bitselect(vaccCDEF, vmax, wasm_f32x4_le(vaccCDEF, vmax));
106 vout0123 = wasm_v128_bitselect(vmin, vout0123, wasm_f32x4_lt(vout0123, vmin));
107 vout4567 = wasm_v128_bitselect(vmin, vout4567, wasm_f32x4_lt(vout4567, vmin));
108 vout89AB = wasm_v128_bitselect(vmin, vout89AB, wasm_f32x4_lt(vout89AB, vmin));
109 voutCDEF = wasm_v128_bitselect(vmin, voutCDEF, wasm_f32x4_lt(voutCDEF, vmin));
110 wasm_v128_store(output, vout0123);
111 wasm_v128_store(output + 4, vout4567);
112 wasm_v128_store(output + 8, vout89AB);
113 wasm_v128_store(output + 12, voutCDEF);
114 output = (float*restrict) ((uintptr_t) output + output_stride);
115 } while (--n != 0);
116 output = (float*restrict) ((uintptr_t) output - output_decrement);
117 input += 16;
118 mc -= 16 * sizeof(float);
119 }
120 if XNN_UNLIKELY(mc != 0) {
121 output_decrement += 8 * sizeof(float);
122 if (mc & (8 * sizeof(float))) {
123 const float*restrict w = weights;
124 const int32_t* dmap = widx_dmap;
125 const uint32_t* nnzmap = nidx_nnzmap;
126 size_t n = nc;
127 do {
128 uint32_t nnz = *nnzmap++;
129 v128_t vacc0123 = wasm_v32x4_load_splat(w); w += 1;
130 v128_t vacc4567 = vacc0123;
131 if XNN_LIKELY(nnz != 0) {
132 do {
133 const intptr_t diff = *dmap++;
134 const v128_t vi0123 = wasm_v128_load(input);
135 const v128_t vi4567 = wasm_v128_load(input + 4);
136 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
137 const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
138 vacc0123 = wasm_f32x4_add(vacc0123, wasm_f32x4_mul(vi0123, vw));
139 vacc4567 = wasm_f32x4_add(vacc4567, wasm_f32x4_mul(vi4567, vw));
140 } while (--nnz != 0);
141 }
142 v128_t vout0123 = wasm_v128_bitselect(vacc0123, vmax, wasm_f32x4_le(vacc0123, vmax));
143 v128_t vout4567 = wasm_v128_bitselect(vacc4567, vmax, wasm_f32x4_le(vacc4567, vmax));
144 vout0123 = wasm_v128_bitselect(vmin, vout0123, wasm_f32x4_lt(vout0123, vmin));
145 vout4567 = wasm_v128_bitselect(vmin, vout4567, wasm_f32x4_lt(vout4567, vmin));
146 wasm_v128_store(output, vout0123);
147
148 wasm_v128_store(output + 4, vout4567);
149 output = (float*restrict) ((uintptr_t) output + output_stride);
150 } while (--n != 0);
151 output = (float*restrict) ((uintptr_t) output - output_decrement);
152 input += 8;
153 }
154 output_decrement += 4 * sizeof(float);
155 if (mc & (4 * sizeof(float))) {
156 const float*restrict w = weights;
157 const int32_t* dmap = widx_dmap;
158 const uint32_t* nnzmap = nidx_nnzmap;
159 size_t n = nc;
160 do {
161 uint32_t nnz = *nnzmap++;
162 v128_t vacc0123 = wasm_v32x4_load_splat(w); w += 1;
163 if XNN_LIKELY(nnz != 0) {
164 do {
165 const intptr_t diff = *dmap++;
166 const v128_t vi0123 = wasm_v128_load(input);
167 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
168 const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
169 vacc0123 = wasm_f32x4_add(vacc0123, wasm_f32x4_mul(vi0123, vw));
170 } while (--nnz != 0);
171 }
172 v128_t vout0123 = wasm_v128_bitselect(vacc0123, vmax, wasm_f32x4_le(vacc0123, vmax));
173 vout0123 = wasm_v128_bitselect(vmin, vout0123, wasm_f32x4_lt(vout0123, vmin));
174 wasm_v128_store(output, vout0123);
175
176 output = (float*restrict) ((uintptr_t) output + output_stride);
177 } while (--n != 0);
178 output = (float*restrict) ((uintptr_t) output - output_decrement);
179 input += 4;
180 }
181 output_decrement += 2 * sizeof(float);
182 if (mc & (2 * sizeof(float))) {
183 const float*restrict w = weights;
184 const int32_t* dmap = widx_dmap;
185 const uint32_t* nnzmap = nidx_nnzmap;
186 size_t n = nc;
187 do {
188 uint32_t nnz = *nnzmap++;
189 v128_t vacc01 = wasm_v32x4_load_splat(w); w += 1;
190 if XNN_LIKELY(nnz != 0) {
191 do {
192 const intptr_t diff = *dmap++;
193 const v128_t vi01 = wasm_v64x2_load_splat(input);
194 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
195 const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
196 vacc01 = wasm_f32x4_add(vacc01, wasm_f32x4_mul(vi01, vw));
197 } while (--nnz != 0);
198 }
199 v128_t vout01 = wasm_v128_bitselect(vacc01, vmax, wasm_f32x4_le(vacc01, vmax));
200 vout01 = wasm_v128_bitselect(vmin, vout01, wasm_f32x4_lt(vout01, vmin));
201 *((double*) output) = wasm_f64x2_extract_lane(vout01, 0);
202
203 output = (float*restrict) ((uintptr_t) output + output_stride);
204 } while (--n != 0);
205 output = (float*restrict) ((uintptr_t) output - output_decrement);
206 input += 2;
207 }
208 output_decrement += 1 * sizeof(float);
209 if (mc & (1 * sizeof(float))) {
210 const float*restrict w = weights;
211 const int32_t* dmap = widx_dmap;
212 const uint32_t* nnzmap = nidx_nnzmap;
213 size_t n = nc;
214 do {
215 uint32_t nnz = *nnzmap++;
216 v128_t vacc0 = wasm_v32x4_load_splat(w); w += 1;
217 if XNN_LIKELY(nnz != 0) {
218 do {
219 const intptr_t diff = *dmap++;
220 const v128_t vi0 = wasm_v32x4_load_splat(input);
221 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
222 const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
223 vacc0 = wasm_f32x4_add(vacc0, wasm_f32x4_mul(vi0, vw));
224 } while (--nnz != 0);
225 }
226 v128_t vout0 = wasm_v128_bitselect(vacc0, vmax, wasm_f32x4_le(vacc0, vmax));
227 vout0 = wasm_v128_bitselect(vmin, vout0, wasm_f32x4_lt(vout0, vmin));
228 *output = wasm_f32x4_extract_lane(vout0, 0);
229
230 output = (float*restrict) ((uintptr_t) output + output_stride);
231 } while (--n != 0);
232 output = (float*restrict) ((uintptr_t) output - output_decrement);
233 input += 1;
234 }
235 }
236 }
237