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