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_8x1__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_8x1__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 - 8 * sizeof(float);
36 while XNN_LIKELY(mc >= 8 * 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 for (; nnz >= 2; nnz -= 2) {
49 const intptr_t diff0 = dmap[0];
50 const intptr_t diff1 = dmap[1];
51 dmap += 2;
52 const v128_t vi0123x0 = wasm_v128_load(input);
53 const v128_t vi4567x0 = wasm_v128_load(input + 4);
54 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff0);
55 const v128_t vw0 = wasm_v32x4_load_splat(w);
56 w += 1;
57 vacc0123x0 = wasm_f32x4_add(vacc0123x0, wasm_f32x4_mul(vi0123x0, vw0));
58 vacc4567x0 = wasm_f32x4_add(vacc4567x0, wasm_f32x4_mul(vi4567x0, vw0));
59 const v128_t vi0123x1 = wasm_v128_load(input);
60 const v128_t vi4567x1 = wasm_v128_load(input + 4);
61 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff1);
62 const v128_t vw1 = wasm_v32x4_load_splat(w);
63 w += 1;
64 vacc0123x1 = wasm_f32x4_add(vacc0123x1, wasm_f32x4_mul(vi0123x1, vw1));
65 vacc4567x1 = wasm_f32x4_add(vacc4567x1, wasm_f32x4_mul(vi4567x1, vw1));
66 }
67 v128_t vacc0123 = vacc0123x0;
68 v128_t vacc4567 = vacc4567x0;
69 vacc0123 = wasm_f32x4_add(vacc0123, vacc0123x1);
70 vacc4567 = wasm_f32x4_add(vacc4567, vacc4567x1);
71 if XNN_LIKELY(nnz != 0) {
72 do {
73 const intptr_t diff = *dmap++;
74 const v128_t vi0123 = wasm_v128_load(input);
75 const v128_t vi4567 = wasm_v128_load(input + 4);
76 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
77 const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
78 vacc0123 = wasm_f32x4_add(vacc0123, wasm_f32x4_mul(vi0123, vw));
79 vacc4567 = wasm_f32x4_add(vacc4567, wasm_f32x4_mul(vi4567, vw));
80 } while (--nnz != 0);
81 }
82 v128_t vout0123 = wasm_v128_bitselect(vacc0123, vmax, wasm_f32x4_le(vacc0123, vmax));
83 v128_t vout4567 = wasm_v128_bitselect(vacc4567, vmax, wasm_f32x4_le(vacc4567, vmax));
84 vout0123 = wasm_v128_bitselect(vmin, vout0123, wasm_f32x4_lt(vout0123, vmin));
85 vout4567 = wasm_v128_bitselect(vmin, vout4567, wasm_f32x4_lt(vout4567, vmin));
86 wasm_v128_store(output, vout0123);
87 wasm_v128_store(output + 4, vout4567);
88 output = (float*restrict) ((uintptr_t) output + output_stride);
89 } while (--n != 0);
90 output = (float*restrict) ((uintptr_t) output - output_decrement);
91 input += 8;
92 mc -= 8 * sizeof(float);
93 }
94 if XNN_UNLIKELY(mc != 0) {
95 output_decrement += 4 * sizeof(float);
96 if (mc & (4 * sizeof(float))) {
97 const float*restrict w = weights;
98 const int32_t* dmap = widx_dmap;
99 const uint32_t* nnzmap = nidx_nnzmap;
100 size_t n = nc;
101 do {
102 uint32_t nnz = *nnzmap++;
103 v128_t vacc0123 = wasm_v32x4_load_splat(w); w += 1;
104 if XNN_LIKELY(nnz != 0) {
105 do {
106 const intptr_t diff = *dmap++;
107 const v128_t vi0123 = wasm_v128_load(input);
108 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
109 const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
110 vacc0123 = wasm_f32x4_add(vacc0123, wasm_f32x4_mul(vi0123, vw));
111 } while (--nnz != 0);
112 }
113 v128_t vout0123 = wasm_v128_bitselect(vacc0123, vmax, wasm_f32x4_le(vacc0123, vmax));
114 vout0123 = wasm_v128_bitselect(vmin, vout0123, wasm_f32x4_lt(vout0123, vmin));
115 wasm_v128_store(output, vout0123);
116
117 output = (float*restrict) ((uintptr_t) output + output_stride);
118 } while (--n != 0);
119 output = (float*restrict) ((uintptr_t) output - output_decrement);
120 input += 4;
121 }
122 output_decrement += 2 * sizeof(float);
123 if (mc & (2 * sizeof(float))) {
124 const float*restrict w = weights;
125 const int32_t* dmap = widx_dmap;
126 const uint32_t* nnzmap = nidx_nnzmap;
127 size_t n = nc;
128 do {
129 uint32_t nnz = *nnzmap++;
130 v128_t vacc01 = wasm_v32x4_load_splat(w); w += 1;
131 if XNN_LIKELY(nnz != 0) {
132 do {
133 const intptr_t diff = *dmap++;
134 const v128_t vi01 = wasm_v64x2_load_splat(input);
135 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
136 const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
137 vacc01 = wasm_f32x4_add(vacc01, wasm_f32x4_mul(vi01, vw));
138 } while (--nnz != 0);
139 }
140 v128_t vout01 = wasm_v128_bitselect(vacc01, vmax, wasm_f32x4_le(vacc01, vmax));
141 vout01 = wasm_v128_bitselect(vmin, vout01, wasm_f32x4_lt(vout01, vmin));
142 *((double*) output) = wasm_f64x2_extract_lane(vout01, 0);
143
144 output = (float*restrict) ((uintptr_t) output + output_stride);
145 } while (--n != 0);
146 output = (float*restrict) ((uintptr_t) output - output_decrement);
147 input += 2;
148 }
149 output_decrement += 1 * sizeof(float);
150 if (mc & (1 * sizeof(float))) {
151 const float*restrict w = weights;
152 const int32_t* dmap = widx_dmap;
153 const uint32_t* nnzmap = nidx_nnzmap;
154 size_t n = nc;
155 do {
156 uint32_t nnz = *nnzmap++;
157 v128_t vacc0 = wasm_v32x4_load_splat(w); w += 1;
158 if XNN_LIKELY(nnz != 0) {
159 do {
160 const intptr_t diff = *dmap++;
161 const v128_t vi0 = wasm_v32x4_load_splat(input);
162 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
163 const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
164 vacc0 = wasm_f32x4_add(vacc0, wasm_f32x4_mul(vi0, vw));
165 } while (--nnz != 0);
166 }
167 v128_t vout0 = wasm_v128_bitselect(vacc0, vmax, wasm_f32x4_le(vacc0, vmax));
168 vout0 = wasm_v128_bitselect(vmin, vout0, wasm_f32x4_lt(vout0, vmin));
169 *output = wasm_f32x4_extract_lane(vout0, 0);
170
171 output = (float*restrict) ((uintptr_t) output + output_stride);
172 } while (--n != 0);
173 output = (float*restrict) ((uintptr_t) output - output_decrement);
174 input += 1;
175 }
176 }
177 }
178