• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-spmm/wasmsimd-pipelined.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_pipelined(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_pipelined(
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(&params->scalar.min);
33   const v128_t vmax = wasm_v32x4_load_splat(&params->scalar.max);
34   size_t output_decrement = output_stride * nc - 4 * sizeof(float);
35   while XNN_LIKELY(mc >= 4 * sizeof(float)) {
36     const float*restrict w = weights;
37     const int32_t* dmap = widx_dmap;
38     const uint32_t* nnzmap = nidx_nnzmap;
39     v128_t vw = wasm_v32x4_load_splat(w); w += 1;
40     intptr_t diff = *dmap++;
41     v128_t vi0123 = wasm_v128_load(input + 0);
42     size_t n = nc;
43     do {
44       uint32_t nnz = *nnzmap++;
45        v128_t vacc0123 = vw;
46       vw = wasm_v32x4_load_splat(w); w += 1;
47 
48 
49       if XNN_LIKELY(nnz != 0) {
50         do {
51           vacc0123 = wasm_f32x4_add(vacc0123, wasm_f32x4_mul(vi0123, vw));
52           input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
53 
54           diff = *dmap++;
55           vw = wasm_v32x4_load_splat(w); w += 1;
56           vi0123 = wasm_v128_load(input + 0);
57         } while (--nnz != 0);
58       }
59       v128_t vout0123 = wasm_v128_bitselect(vacc0123, vmax, wasm_f32x4_le(vacc0123, vmax));
60       vout0123 = wasm_v128_bitselect(vmin, vout0123, wasm_f32x4_lt(vout0123, vmin));
61       wasm_v128_store(output, vout0123);
62       output = (float*restrict) ((uintptr_t) output + output_stride);
63     } while (--n != 0);
64     output = (float*restrict) ((uintptr_t) output - output_decrement);
65     input += 4;
66     mc -= 4 * sizeof(float);
67   }
68   if XNN_UNLIKELY(mc != 0) {
69     output_decrement += 2 * sizeof(float);
70     if (mc & (2 * sizeof(float))) {
71       const float*restrict w = weights;
72       const int32_t* dmap = widx_dmap;
73       const uint32_t* nnzmap = nidx_nnzmap;
74       size_t n = nc;
75       do {
76         uint32_t nnz = *nnzmap++;
77         v128_t vacc01 = wasm_v32x4_load_splat(w); w += 1;
78         if XNN_LIKELY(nnz != 0) {
79           do {
80             const intptr_t diff = *dmap++;
81             const v128_t vi01 = wasm_v64x2_load_splat(input);
82             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
83             const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
84             vacc01 = wasm_f32x4_add(vacc01, wasm_f32x4_mul(vi01, vw));
85           } while (--nnz != 0);
86         }
87         v128_t vout01 = wasm_v128_bitselect(vacc01, vmax, wasm_f32x4_le(vacc01, vmax));
88         vout01 = wasm_v128_bitselect(vmin, vout01, wasm_f32x4_lt(vout01, vmin));
89         *((double*) output) = wasm_f64x2_extract_lane(vout01, 0);
90 
91         output = (float*restrict) ((uintptr_t) output + output_stride);
92       } while (--n != 0);
93       output = (float*restrict) ((uintptr_t) output - output_decrement);
94       input += 2;
95     }
96     output_decrement += 1 * sizeof(float);
97     if (mc & (1 * sizeof(float))) {
98       const float*restrict w = weights;
99       const int32_t* dmap = widx_dmap;
100       const uint32_t* nnzmap = nidx_nnzmap;
101       size_t n = nc;
102       do {
103         uint32_t nnz = *nnzmap++;
104         v128_t vacc0 = wasm_v32x4_load_splat(w); w += 1;
105         if XNN_LIKELY(nnz != 0) {
106           do {
107             const intptr_t diff = *dmap++;
108             const v128_t vi0 = wasm_v32x4_load_splat(input);
109             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
110             const v128_t vw = wasm_v32x4_load_splat(w); w += 1;
111             vacc0 = wasm_f32x4_add(vacc0, wasm_f32x4_mul(vi0, vw));
112           } while (--nnz != 0);
113         }
114         v128_t vout0 = wasm_v128_bitselect(vacc0, vmax, wasm_f32x4_le(vacc0, vmax));
115         vout0 = wasm_v128_bitselect(vmin, vout0, wasm_f32x4_lt(vout0, vmin));
116         *output = wasm_f32x4_extract_lane(vout0, 0);
117 
118         output = (float*restrict) ((uintptr_t) output + output_stride);
119       } while (--n != 0);
120       output = (float*restrict) ((uintptr_t) output - output_decrement);
121       input += 1;
122     }
123   }
124 }
125