1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-spmm/neon.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 <arm_neon.h>
13 
14 #include <xnnpack/spmm.h>
15 
16 
xnn_f32_spmm_minmax_ukernel_4x1__neon(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__neon(
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 float32x4_t vmin = vld1q_dup_f32(&params->scalar.min);
33   const float32x4_t vmax = vld1q_dup_f32(&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     size_t n = nc;
40     do {
41       uint32_t nnz = *nnzmap++;
42       float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1;
43       if XNN_LIKELY(nnz != 0) {
44         do {
45           const intptr_t diff = *dmap++;
46           const float32x4_t vi0123 = vld1q_f32(input);
47           input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
48           __builtin_prefetch(input + 16);
49           const float32x4_t vw = vld1q_dup_f32(w); w += 1;
50           __builtin_prefetch(w + 32);
51           vacc0123 = vmlaq_f32(vacc0123, vi0123, vw);
52         } while (--nnz != 0);
53       }
54       float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
55       vout0123 = vmaxq_f32(vout0123, vmin);
56       vst1q_f32(output, vout0123);
57       output = (float*restrict) ((uintptr_t) output + output_stride);
58     } while (--n != 0);
59     output = (float*restrict) ((uintptr_t) output - output_decrement);
60     input += 4;
61     mc -= 4 * sizeof(float);
62   }
63   if XNN_UNLIKELY(mc != 0) {
64     output_decrement += 2 * sizeof(float);
65     if (mc & (2 * sizeof(float))) {
66       const float*restrict w = weights;
67       const int32_t* dmap = widx_dmap;
68       const uint32_t* nnzmap = nidx_nnzmap;
69       size_t n = nc;
70       do {
71         uint32_t nnz = *nnzmap++;
72         float32x2_t vacc01 = vld1_dup_f32(w); w += 1;
73         if XNN_LIKELY(nnz != 0) {
74           do {
75             const intptr_t diff = *dmap++;
76             const float32x2_t vi01 = vld1_f32(input);
77             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
78             const float32x2_t vw = vld1_dup_f32(w); w += 1;
79             vacc01 = vmla_f32(vacc01, vi01, vw);
80           } while (--nnz != 0);
81         }
82         float32x2_t vout01 = vmin_f32(vacc01, vget_low_f32(vmax));
83         vout01 = vmax_f32(vout01, vget_low_f32(vmin));
84         vst1_f32(output, vout01);
85         output = (float*restrict) ((uintptr_t) output + output_stride);
86       } while (--n != 0);
87       output = (float*restrict) ((uintptr_t) output - output_decrement);
88       input += 2;
89     }
90     output_decrement += 1 * sizeof(float);
91     if (mc & (1 * sizeof(float))) {
92       const float*restrict w = weights;
93       const int32_t* dmap = widx_dmap;
94       const uint32_t* nnzmap = nidx_nnzmap;
95       size_t n = nc;
96       do {
97         uint32_t nnz = *nnzmap++;
98         float32x2_t vacc0 = vld1_dup_f32(w); w += 1;
99         if XNN_LIKELY(nnz != 0) {
100           do {
101             const intptr_t diff = *dmap++;
102             const float32x2_t vi0 = vld1_dup_f32(input);
103             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
104             const float32x2_t vw = vld1_dup_f32(w); w += 1;
105             vacc0 = vmla_f32(vacc0, vi0, vw);
106           } while (--nnz != 0);
107         }
108         float32x2_t vout0 = vmin_f32(vacc0, vget_low_f32(vmax));
109         vout0 = vmax_f32(vout0, vget_low_f32(vmin));
110         vst1_lane_f32(output, vout0, 0);
111         output = (float*restrict) ((uintptr_t) output + output_stride);
112       } while (--n != 0);
113       output = (float*restrict) ((uintptr_t) output - output_decrement);
114       input += 1;
115     }
116   }
117 }
118