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_arm(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_arm(
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 size_t output_decrement = output_stride * nc - 8 * sizeof(float);
35 while XNN_LIKELY(mc >= 8 * sizeof(float)) {
36 const float*restrict w = weights;
37 const int32_t* dmap = widx_dmap;
38 const uint32_t* nnzmap = nidx_nnzmap;
39 size_t n = nc;
40 do {
41 uint32_t nnz = *nnzmap++;
42 v128_t vacc0123 = wasm_v32x4_load_splat(w); w += 1;
43 v128_t vacc4567 = vacc0123;
44 if XNN_LIKELY(nnz != 0) {
45 do {
46 const intptr_t diff = *dmap++;
47 const v128_t vi0123 = wasm_v128_load(input);
48 const v128_t vi4567 = wasm_v128_load(input + 4);
49 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
50 const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
51 vacc0123 = wasm_f32x4_add(vacc0123, wasm_f32x4_mul(vi0123, vw));
52 vacc4567 = wasm_f32x4_add(vacc4567, wasm_f32x4_mul(vi4567, vw));
53 } while (--nnz != 0);
54 }
55 v128_t vout0123 = wasm_f32x4_min(vacc0123, vmax);
56 v128_t vout4567 = wasm_f32x4_min(vacc4567, vmax);
57 vout0123 = wasm_f32x4_max(vout0123, vmin);
58 vout4567 = wasm_f32x4_max(vout4567, vmin);
59 wasm_v128_store(output, vout0123);
60 wasm_v128_store(output + 4, vout4567);
61 output = (float*restrict) ((uintptr_t) output + output_stride);
62 } while (--n != 0);
63 output = (float*restrict) ((uintptr_t) output - output_decrement);
64 input += 8;
65 mc -= 8 * sizeof(float);
66 }
67 if XNN_UNLIKELY(mc != 0) {
68 output_decrement += 4 * sizeof(float);
69 if (mc & (4 * sizeof(float))) {
70 const float*restrict w = weights;
71 const int32_t* dmap = widx_dmap;
72 const uint32_t* nnzmap = nidx_nnzmap;
73 size_t n = nc;
74 do {
75 uint32_t nnz = *nnzmap++;
76 v128_t vacc0123 = wasm_v32x4_load_splat(w); w += 1;
77 if XNN_LIKELY(nnz != 0) {
78 do {
79 const intptr_t diff = *dmap++;
80 const v128_t vi0123 = wasm_v128_load(input);
81 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
82 const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
83 vacc0123 = wasm_f32x4_add(vacc0123, wasm_f32x4_mul(vi0123, vw));
84 } while (--nnz != 0);
85 }
86 v128_t vout0123 = wasm_f32x4_min(vacc0123, vmax);
87 vout0123 = wasm_f32x4_max(vout0123, vmin);
88 wasm_v128_store(output, vout0123);
89
90 output = (float*restrict) ((uintptr_t) output + output_stride);
91 } while (--n != 0);
92 output = (float*restrict) ((uintptr_t) output - output_decrement);
93 input += 4;
94 }
95 output_decrement += 2 * sizeof(float);
96 if (mc & (2 * 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 vacc01 = 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 vi01 = wasm_v64x2_load_splat(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 vacc01 = wasm_f32x4_add(vacc01, wasm_f32x4_mul(vi01, vw));
111 } while (--nnz != 0);
112 }
113 v128_t vout01 = wasm_f32x4_min(vacc01, vmax);
114 vout01 = wasm_f32x4_max(vout01, vmin);
115 *((double*) output) = wasm_f64x2_extract_lane(vout01, 0);
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 += 2;
121 }
122 output_decrement += 1 * sizeof(float);
123 if (mc & (1 * 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 vacc0 = 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 vi0 = wasm_v32x4_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 vacc0 = wasm_f32x4_add(vacc0, wasm_f32x4_mul(vi0, vw));
138 } while (--nnz != 0);
139 }
140 v128_t vout0 = wasm_f32x4_min(vacc0, vmax);
141 vout0 = wasm_f32x4_max(vout0, vmin);
142 *output = wasm_f32x4_extract_lane(vout0, 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 += 1;
148 }
149 }
150 }
151