• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ukernel_4x1__neonfma_unroll2(uint32_t m,uint32_t n,const float * restrict a,const float * restrict weights,const int32_t * restrict widx_dmap,const uint32_t * restrict nidx_nnzmap,float * restrict c,const union xnn_f32_output_params params[restrict static1])17 void xnn_f32_spmm_ukernel_4x1__neonfma_unroll2(
18     uint32_t m,
19     uint32_t n,
20     const float*restrict a,
21     const float*restrict weights,
22     const int32_t*restrict widx_dmap,
23     const uint32_t*restrict nidx_nnzmap,
24     float*restrict c,
25     const union xnn_f32_output_params params[restrict static 1])
26 {
27   assert(m != 0);
28 
29   const float32x4_t vmin = vld1q_dup_f32(&params->scalar.min);
30   const float32x4_t vmax = vld1q_dup_f32(&params->scalar.max);
31   size_t i = m;
32   while XNN_LIKELY(i >= 4) {
33     const float*restrict w = weights;
34     const int32_t* dmap = widx_dmap;
35     const uint32_t* nnzmap = nidx_nnzmap;
36     size_t j = n;
37     do {
38       uint32_t nnz = *nnzmap++;
39       float32x4_t vacc0123x0 = vld1q_dup_f32(w); w += 1;
40       float32x4_t vacc0123x1 = vmovq_n_f32(0.0f);
41       for (; nnz >= 2; nnz -= 2) {
42         const intptr_t diff0 = dmap[0];
43         const intptr_t diff1 = dmap[1];
44         dmap += 2;
45         const float32x4_t va0123x0 = vld1q_f32(a);
46         a = (const float*restrict) ((uintptr_t) a + (uintptr_t) diff0);
47         const float32x4_t vb0 = vld1q_dup_f32(w); w += 1;
48         vacc0123x0 = vfmaq_f32(vacc0123x0, va0123x0, vb0);
49         const float32x4_t va0123x1 = vld1q_f32(a);
50         a = (const float*restrict) ((uintptr_t) a + (uintptr_t) diff1);
51         const float32x4_t vb1 = vld1q_dup_f32(w); w += 1;
52         vacc0123x1 = vfmaq_f32(vacc0123x1, va0123x1, vb1);
53       }
54       float32x4_t vacc0123 = vacc0123x0;
55       vacc0123 = vaddq_f32(vacc0123, vacc0123x1);
56       if XNN_LIKELY(nnz != 0) {
57         do {
58           const intptr_t diff = *dmap++;
59           const float32x4_t va0123 = vld1q_f32(a);
60           a = (const float*restrict) ((uintptr_t) a + (uintptr_t) diff);
61           const float32x4_t vb = vld1q_dup_f32(w); w += 1;
62           vacc0123 = vfmaq_f32(vacc0123, va0123, vb);
63         } while (--nnz != 0);
64       }
65       float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
66       vout0123 = vmaxq_f32(vout0123, vmin);
67       vst1q_f32(c, vout0123);
68       c += m;
69     } while (--j != 0);
70     c -= m * n;
71     c += 4;
72     a += 4;
73     i -= 4;
74   }
75   if XNN_UNLIKELY(i != 0) {
76     if (i & 2) {
77       const float*restrict w = weights;
78       const int32_t* dmap = widx_dmap;
79       const uint32_t* nnzmap = nidx_nnzmap;
80       size_t j = n;
81       do {
82         uint32_t nnz = *nnzmap++;
83         float32x2_t vacc01 = vld1_dup_f32(w); w += 1;
84         if XNN_LIKELY(nnz != 0) {
85           do {
86             const intptr_t diff = *dmap++;
87             const float32x2_t va01 = vld1_f32(a);
88             a = (const float*restrict) ((uintptr_t) a + (uintptr_t) diff);
89             const float32x2_t vb = vld1_dup_f32(w); w += 1;
90             vacc01 = vfma_f32(vacc01, va01, vb);
91           } while (--nnz != 0);
92         }
93         float32x2_t vout01 = vmin_f32(vacc01, vget_low_f32(vmax));
94         vout01 = vmax_f32(vout01, vget_low_f32(vmin));
95         vst1_f32(c, vout01);
96         c += m;
97       } while (--j != 0);
98       c -= m * n;
99       c += 2;
100       a += 2;
101     }
102     if (i & 1) {
103       const float*restrict w = weights;
104       const int32_t* dmap = widx_dmap;
105       const uint32_t* nnzmap = nidx_nnzmap;
106       size_t j = n;
107       do {
108         uint32_t nnz = *nnzmap++;
109         float32x2_t vacc0 = vld1_dup_f32(w); w += 1;
110         if XNN_LIKELY(nnz != 0) {
111           do {
112             const intptr_t diff = *dmap++;
113             const float32x2_t va0 = vld1_dup_f32(a);
114             a = (const float*restrict) ((uintptr_t) a + (uintptr_t) diff);
115             const float32x2_t vb = vld1_dup_f32(w); w += 1;
116             vacc0 = vfma_f32(vacc0, va0, vb);
117           } while (--nnz != 0);
118         }
119         float32x2_t vout0 = vmin_f32(vacc0, vget_low_f32(vmax));
120         vout0 = vmax_f32(vout0, vget_low_f32(vmin));
121         vst1_lane_f32(c, vout0, 0);
122         c += m;
123       } while (--j != 0);
124       c -= m * n;
125       c += 1;
126       a += 1;
127     }
128   }
129 }
130