• 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_minmax_ukernel_8x1__neonfma(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_8x1__neonfma(
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 - 8 * sizeof(float);
35   while XNN_LIKELY(mc >= 8 * 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       float32x4_t vacc4567 = vacc0123;
44       if XNN_LIKELY(nnz != 0) {
45         do {
46           const intptr_t diff = *dmap++;
47           const float32x4_t vi0123 = vld1q_f32(input);
48           const float32x4_t vi4567 = vld1q_f32(input + 4);
49           input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
50           __builtin_prefetch(input + 16);
51           const float32x4_t vw = vld1q_dup_f32(w); w += 1;
52           __builtin_prefetch(w + 32);
53           vacc0123 = vfmaq_f32(vacc0123, vi0123, vw);
54           vacc4567 = vfmaq_f32(vacc4567, vi4567, vw);
55         } while (--nnz != 0);
56       }
57       float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
58       float32x4_t vout4567 = vminq_f32(vacc4567, vmax);
59       vout0123 = vmaxq_f32(vout0123, vmin);
60       vout4567 = vmaxq_f32(vout4567, vmin);
61       vst1q_f32(output, vout0123);
62       vst1q_f32(output + 4, vout4567);
63       output = (float*restrict) ((uintptr_t) output + output_stride);
64     } while (--n != 0);
65     output = (float*restrict) ((uintptr_t) output - output_decrement);
66     input += 8;
67     mc -= 8 * sizeof(float);
68   }
69   if XNN_UNLIKELY(mc != 0) {
70     output_decrement += 4 * sizeof(float);
71     if (mc & (4 * sizeof(float))) {
72       const float*restrict w = weights;
73       const int32_t* dmap = widx_dmap;
74       const uint32_t* nnzmap = nidx_nnzmap;
75       size_t n = nc;
76       do {
77         uint32_t nnz = *nnzmap++;
78         float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1;
79         if XNN_LIKELY(nnz != 0) {
80           do {
81             const intptr_t diff = *dmap++;
82             const float32x4_t vi0123 = vld1q_f32(input);
83             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
84             const float32x4_t vw = vld1q_dup_f32(w); w += 1;
85             vacc0123 = vfmaq_f32(vacc0123, vi0123, vw);
86           } while (--nnz != 0);
87         }
88         float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
89         vout0123 = vmaxq_f32(vout0123, vmin);
90         vst1q_f32(output, vout0123);
91         output = (float*restrict) ((uintptr_t) output + output_stride);
92       } while (--n != 0);
93       output = (float*restrict) ((uintptr_t) output - output_decrement);
94       input += 4;
95     }
96     output_decrement += 2 * sizeof(float);
97     if (mc & (2 * 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         float32x2_t vacc01 = vld1_dup_f32(w); w += 1;
105         if XNN_LIKELY(nnz != 0) {
106           do {
107             const intptr_t diff = *dmap++;
108             const float32x2_t vi01 = vld1_f32(input);
109             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
110             const float32x2_t vw = vld1_dup_f32(w); w += 1;
111             vacc01 = vfma_f32(vacc01, vi01, vw);
112           } while (--nnz != 0);
113         }
114         float32x2_t vout01 = vmin_f32(vacc01, vget_low_f32(vmax));
115         vout01 = vmax_f32(vout01, vget_low_f32(vmin));
116         vst1_f32(output, vout01);
117         output = (float*restrict) ((uintptr_t) output + output_stride);
118       } while (--n != 0);
119       output = (float*restrict) ((uintptr_t) output - output_decrement);
120       input += 2;
121     }
122     output_decrement += 1 * sizeof(float);
123     if (mc & (1 * sizeof(float))) {
124       const float*restrict w = weights;
125       const int32_t* dmap = widx_dmap;
126       const uint32_t* nnzmap = nidx_nnzmap;
127       size_t n = nc;
128       do {
129         uint32_t nnz = *nnzmap++;
130         float32x2_t vacc0 = vld1_dup_f32(w); w += 1;
131         if XNN_LIKELY(nnz != 0) {
132           do {
133             const intptr_t diff = *dmap++;
134             const float32x2_t vi0 = vld1_dup_f32(input);
135             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
136             const float32x2_t vw = vld1_dup_f32(w); w += 1;
137             vacc0 = vfma_f32(vacc0, vi0, vw);
138           } while (--nnz != 0);
139         }
140         float32x2_t vout0 = vmin_f32(vacc0, vget_low_f32(vmax));
141         vout0 = vmax_f32(vout0, vget_low_f32(vmin));
142         vst1_lane_f32(output, vout0, 0);
143         output = (float*restrict) ((uintptr_t) output + output_stride);
144       } while (--n != 0);
145       output = (float*restrict) ((uintptr_t) output - output_decrement);
146       input += 1;
147     }
148   }
149 }
150