• 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(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(
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 vacc0123 = vld1q_dup_f32(w); w += 1;
40       if XNN_LIKELY(nnz != 0) {
41         do {
42           const intptr_t diff = *dmap++;
43           const float32x4_t va0123 = vld1q_f32(a);
44           a = (const float*restrict) ((uintptr_t) a + (uintptr_t) diff);
45           const float32x4_t vb = vld1q_dup_f32(w); w += 1;
46           vacc0123 = vfmaq_f32(vacc0123, va0123, vb);
47         } while (--nnz != 0);
48       }
49       float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
50       vout0123 = vmaxq_f32(vout0123, vmin);
51       vst1q_f32(c, vout0123);
52       c += m;
53     } while (--j != 0);
54     c -= m * n;
55     c += 4;
56     a += 4;
57     i -= 4;
58   }
59   if XNN_UNLIKELY(i != 0) {
60     if (i & 2) {
61       const float*restrict w = weights;
62       const int32_t* dmap = widx_dmap;
63       const uint32_t* nnzmap = nidx_nnzmap;
64       size_t j = n;
65       do {
66         uint32_t nnz = *nnzmap++;
67         float32x2_t vacc01 = vld1_dup_f32(w); w += 1;
68         if XNN_LIKELY(nnz != 0) {
69           do {
70             const intptr_t diff = *dmap++;
71             const float32x2_t va01 = vld1_f32(a);
72             a = (const float*restrict) ((uintptr_t) a + (uintptr_t) diff);
73             const float32x2_t vb = vld1_dup_f32(w); w += 1;
74             vacc01 = vfma_f32(vacc01, va01, vb);
75           } while (--nnz != 0);
76         }
77         float32x2_t vout01 = vmin_f32(vacc01, vget_low_f32(vmax));
78         vout01 = vmax_f32(vout01, vget_low_f32(vmin));
79         vst1_f32(c, vout01);
80         c += m;
81       } while (--j != 0);
82       c -= m * n;
83       c += 2;
84       a += 2;
85     }
86     if (i & 1) {
87       const float*restrict w = weights;
88       const int32_t* dmap = widx_dmap;
89       const uint32_t* nnzmap = nidx_nnzmap;
90       size_t j = n;
91       do {
92         uint32_t nnz = *nnzmap++;
93         float32x2_t vacc0 = vld1_dup_f32(w); w += 1;
94         if XNN_LIKELY(nnz != 0) {
95           do {
96             const intptr_t diff = *dmap++;
97             const float32x2_t va0 = vld1_dup_f32(a);
98             a = (const float*restrict) ((uintptr_t) a + (uintptr_t) diff);
99             const float32x2_t vb = vld1_dup_f32(w); w += 1;
100             vacc0 = vfma_f32(vacc0, va0, vb);
101           } while (--nnz != 0);
102         }
103         float32x2_t vout0 = vmin_f32(vacc0, vget_low_f32(vmax));
104         vout0 = vmax_f32(vout0, vget_low_f32(vmin));
105         vst1_lane_f32(c, vout0, 0);
106         c += m;
107       } while (--j != 0);
108       c -= m * n;
109       c += 1;
110       a += 1;
111     }
112   }
113 }
114