1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-spmm/scalar.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2019 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 <xnnpack/math.h>
13 #include <xnnpack/spmm.h>
14 
15 
xnn_f32_spmm_minmax_ukernel_2x1__scalar(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)])16 void xnn_f32_spmm_minmax_ukernel_2x1__scalar(
17     size_t mc,
18     size_t nc,
19     const float*restrict input,
20     const float*restrict weights,
21     const int32_t*restrict widx_dmap,
22     const uint32_t*restrict nidx_nnzmap,
23     float*restrict output,
24     size_t output_stride,
25     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
26 {
27   assert(mc != 0);
28   assert(mc % sizeof(float) == 0);
29   assert(nc != 0);
30 
31   const float vmin = params->scalar.min;
32   const float vmax = params->scalar.max;
33   size_t output_decrement = output_stride * nc - 2 * sizeof(float);
34   while (mc >= 2 * sizeof(float)) {
35     const float*restrict w = weights;
36     const int32_t* dmap = widx_dmap;
37     const uint32_t* nnzmap = nidx_nnzmap;
38     size_t n = nc;
39     while (n >= 1) {
40       uint32_t nnz = *nnzmap++;
41       float vacc0x0 = *w++;
42       float vacc1x0 = vacc0x0;
43       if XNN_LIKELY(nnz != 0) {
44         do {
45           const intptr_t diff = *dmap++;
46           const float vi0 = input[0];
47           const float vi1 = input[1];
48           input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
49           const float vw0 = *w++;
50           vacc0x0 += vi0 * vw0;
51           vacc1x0 += vi1 * vw0;
52         } while (--nnz != 0);
53       }
54       float vout0x0 = math_min_f32(vacc0x0, vmax);
55       float vout1x0 = math_min_f32(vacc1x0, vmax);
56       vout0x0 = math_max_f32(vout0x0, vmin);
57       vout1x0 = math_max_f32(vout1x0, vmin);
58       output[0] = vout0x0;
59       output[1] = vout1x0;
60       output[0] = vout0x0;
61       output[1] = vout1x0;
62       output = (float*restrict) ((uintptr_t) output + output_stride);
63       n -= 1;
64     }
65     if XNN_UNLIKELY(n != 0) {
66       do {
67         uint32_t nnz = *nnzmap++;
68         float vacc0 = *w++;
69         float vacc1 = vacc0;
70         if XNN_LIKELY(nnz != 0) {
71           do {
72             const intptr_t diff = *dmap++;
73             const float vi0 = input[0];
74             const float vi1 = input[1];
75             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
76             const float vw = *w++;
77             vacc0 += vi0 * vw;
78             vacc1 += vi1 * vw;
79           } while (--nnz != 0);
80         }
81         float vout0 = math_min_f32(vacc0, vmax);
82         float vout1 = math_min_f32(vacc1, vmax);
83         vout0 = math_max_f32(vout0, vmin);
84         vout1 = math_max_f32(vout1, vmin);
85         output[0] = vout0;
86         output[1] = vout1;
87         output = (float*restrict) ((uintptr_t) output + output_stride);
88         n -= 1;
89       } while (n != 0);
90     }
91     output = (float*restrict) ((uintptr_t) output - output_decrement);
92     input += 2;
93     mc -= 2 * sizeof(float);
94   }
95   if XNN_UNLIKELY(mc != 0) {
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       while (n >= 1) {
103         uint32_t nnz = *nnzmap++;
104         float vacc0x0 = *w++;
105         if XNN_LIKELY(nnz != 0) {
106           do {
107             const intptr_t diff = *dmap++;
108             const float vi0 = input[0];
109             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
110             const float vw0 = *w++;
111             vacc0x0 += vi0 * vw0;
112           } while (--nnz != 0);
113         }
114         float vout0x0 = math_min_f32(vacc0x0, vmax);
115         vout0x0 = math_max_f32(vout0x0, vmin);
116         output[0] = vout0x0;
117         output = (float*restrict) ((uintptr_t) output + output_stride);
118         n -= 1;
119       }
120       if XNN_UNLIKELY(n != 0) {
121         do {
122           uint32_t nnz = *nnzmap++;
123           float vacc0 = *w++;
124           if XNN_LIKELY(nnz != 0) {
125             do {
126               const intptr_t diff = *dmap++;
127               const float vi0 = input[0];
128               input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
129               const float vw = *w++;
130               vacc0 += vi0 * vw;
131             } while (--nnz != 0);
132           }
133           float vout0 = math_min_f32(vacc0, vmax);
134           vout0 = math_max_f32(vout0, vmin);
135           output[0] = vout0;
136           output = (float*restrict) ((uintptr_t) output + output_stride);
137           n -= 1;
138         } while (n != 0);
139       }
140       output = (float*restrict) ((uintptr_t) output - output_decrement);
141       input += 1;
142     }
143   }
144 }
145