Debian Codegraph @

src/f32-spmm/gen/f32-spmm-4x2-minmax-aarch64-neonfma.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-spmm/neon-blocked.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/prefetch.h"
15 #include "xnnpack/spmm.h"
16
17
18 void xnn_f32_spmm_minmax_ukernel_4x2__aarch64_neonfma(
19 size_t mc,
20 size_t nc,
21 const float* input,
22 const float* weights,
23 const int32_t* widx_dmap,
24 const uint32_t* nidx_nnzmap,
25 float* output,
26 size_t output_stride,
27 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
28 {
29 assert(mc != 0);
30 assert(mc % sizeof(float) == 0);
31 assert(nc != 0);
32
33 #if XNN_ARCH_ARM64
34 const float32x4x2_t vminmax = vld2q_dup_f32(&params->scalar.min);
35 const float32x4_t vmin = vminmax.val[0];
36 const float32x4_t vmax = vminmax.val[1];
37 #else
38 const float32x2x2_t vminmax = vld2_dup_f32(&params->scalar.min);
39 const float32x4_t vmin = vcombine_f32(vminmax.val[0], vminmax.val[0]);
40 const float32x4_t vmax = vcombine_f32(vminmax.val[1], vminmax.val[1]);
41 #endif
42
43 size_t output_decrement = output_stride * nc - 4 * sizeof(float);
44 while XNN_LIKELY(mc >= 4 * sizeof(float)) {
45 const float* w = weights;
46 const int32_t* dmap = widx_dmap;
47 const uint32_t* nnzmap = nidx_nnzmap;
48 size_t n = nc;
49 while (n >= 2) {
50 uint32_t nnz = *nnzmap++;
51 float32x4_t vacc0123n0 = vld1q_dup_f32(w); w += 1;
52 float32x4_t vacc0123n1 = vld1q_dup_f32(w); w += 1;
53 if XNN_LIKELY(nnz != 0) {
54 do {
55 const intptr_t diff = *dmap++;
56 const float32x4_t vi0123 = vld1q_f32(input);
57 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
58 xnn_prefetch_to_l1(input + 16);
59 const float32x2_t vw = vld1_f32(w); w += 2;
60 xnn_prefetch_to_l1(w + 32);
61 vacc0123n0 = vfmaq_lane_f32(vacc0123n0, vi0123, vw, 0);
62 vacc0123n1 = vfmaq_lane_f32(vacc0123n1, vi0123, vw, 1);
63 } while (--nnz != 0);
64 }
65 float32x4_t vout0123n0 = vminq_f32(vacc0123n0, vmax);
66 float32x4_t vout0123n1 = vminq_f32(vacc0123n1, vmax);
67
68 vout0123n0 = vmaxq_f32(vout0123n0, vmin);
69 vout0123n1 = vmaxq_f32(vout0123n1, vmin);
70
71 vst1q_f32(output + 0, vout0123n0);
72 output = (float*) ((uintptr_t) output + output_stride);
73 vst1q_f32(output + 0, vout0123n1);
74 output = (float*) ((uintptr_t) output + output_stride);
75 n -= 2;
76 }
77
78 // clean up loop, fall back to nr=1
79 if XNN_UNLIKELY(n != 0) {
80 do {
81 uint32_t nnz = *nnzmap++;
82 float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1;
83 if XNN_LIKELY(nnz != 0) {
84 do {
85 const intptr_t diff = *dmap++;
86 const float32x4_t vi0123 = vld1q_f32(input);
87 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
88 xnn_prefetch_to_l1(input + 16);
89 const float32x4_t vw = vld1q_dup_f32(w); w += 1;
90 xnn_prefetch_to_l1(w + 32);
91 vacc0123 = vfmaq_f32(vacc0123, vi0123, vw);
92 } while (--nnz != 0);
93 }
94 float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
95
96 vout0123 = vmaxq_f32(vout0123, vmin);
97
98 vst1q_f32(output + 0, vout0123);
99 output = (float*) ((uintptr_t) output + output_stride);
100 n -= 1;
101 } while (n != 0);
102 }
103 output = (float*) ((uintptr_t) output - output_decrement);
104 input += 4;
105 mc -= 4 * sizeof(float);
106 }
107 if XNN_UNLIKELY(mc != 0) {
108 output_decrement += 2 * sizeof(float);
109 if (mc & (2 * sizeof(float))) {
110 const float* w = weights;
111 const int32_t* dmap = widx_dmap;
112 const uint32_t* nnzmap = nidx_nnzmap;
113 size_t n = nc;
114 while (n >= 2) {
115 uint32_t nnz = *nnzmap++;
116 float32x2_t vacc01n0 = vld1_dup_f32(w); w += 1;
117 float32x2_t vacc01n1 = vld1_dup_f32(w); w += 1;
118 if XNN_LIKELY(nnz != 0) {
119 do {
120 const intptr_t diff = *dmap++;
121 const float32x2_t vi01 = vld1_f32(input);
122 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
123 const float32x2_t vw = vld1_f32(w); w += 2;
124
125 vacc01n0 = vfma_lane_f32(vacc01n0, vi01, vw, 0);
126 vacc01n1 = vfma_lane_f32(vacc01n1, vi01, vw, 1);
127 } while (--nnz != 0);
128 }
129 float32x2_t vout01n0 = vmin_f32(vacc01n0, vget_low_f32(vmax));
130 float32x2_t vout01n1 = vmin_f32(vacc01n1, vget_low_f32(vmax));
131
132 vout01n0 = vmax_f32(vout01n0, vget_low_f32(vmin));
133 vout01n1 = vmax_f32(vout01n1, vget_low_f32(vmin));
134
135 vst1_f32(output + 0, vout01n0);
136 output = (float*) ((uintptr_t) output + output_stride);
137 vst1_f32(output + 0, vout01n1);
138 output = (float*) ((uintptr_t) output + output_stride);
139 n -= 2;
140 }
141
142 // clean up loop, fall back to nr=1
143 if XNN_UNLIKELY(n != 0) {
144 do {
145 uint32_t nnz = *nnzmap++;
146 float32x2_t vacc01 = vld1_dup_f32(w); w += 1;
147 if XNN_LIKELY(nnz != 0) {
148 do {
149 const intptr_t diff = *dmap++;
150 const float32x2_t vi01 = vld1_f32(input);
151 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
152 const float32x2_t vw = vld1_dup_f32(w); w += 1;
153 vacc01 = vfma_f32(vacc01, vi01, vw);
154 } while (--nnz != 0);
155 }
156 float32x2_t vout01 = vmin_f32(vacc01, vget_low_f32(vmax));
157 vout01 = vmax_f32(vout01, vget_low_f32(vmin));
158
159 vst1_f32(output, vout01);
160 output = (float*) ((uintptr_t) output + output_stride);
161 n -= 1;
162 } while (n != 0);
163 }
164 output = (float*) ((uintptr_t) output - output_decrement);
165 input += 2;
166 }
167 output_decrement += 1 * sizeof(float);
168 if (mc & (1 * sizeof(float))) {
169 const float* w = weights;
170 const int32_t* dmap = widx_dmap;
171 const uint32_t* nnzmap = nidx_nnzmap;
172 size_t n = nc;
173 while (n >= 2) {
174 uint32_t nnz = *nnzmap++;
175 float32x2_t vacc0n0 = vld1_dup_f32(w); w += 1;
176 float32x2_t vacc0n1 = vld1_dup_f32(w); w += 1;
177 if XNN_LIKELY(nnz != 0) {
178 do {
179 const intptr_t diff = *dmap++;
180 const float32x2_t vi0 = vld1_dup_f32(input);
181 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
182 const float32x2_t vw = vld1_f32(w); w += 2;
183
184 vacc0n0 = vfma_lane_f32(vacc0n0, vi0, vw, 0);
185 vacc0n1 = vfma_lane_f32(vacc0n1, vi0, vw, 1);
186 } while (--nnz != 0);
187 }
188 float32x2_t vout0n0 = vmin_f32(vacc0n0, vget_low_f32(vmax));
189 float32x2_t vout0n1 = vmin_f32(vacc0n1, vget_low_f32(vmax));
190
191 vout0n0 = vmax_f32(vout0n0, vget_low_f32(vmin));
192 vout0n1 = vmax_f32(vout0n1, vget_low_f32(vmin));
193
194 vst1_lane_f32(output + 0, vout0n0, 0);
195 output = (float*) ((uintptr_t) output + output_stride);
196 vst1_lane_f32(output + 0, vout0n1, 0);
197 output = (float*) ((uintptr_t) output + output_stride);
198 n -= 2;
199 }
200
201 // clean up loop, fall back to nr=1
202 if XNN_UNLIKELY(n != 0) {
203 do {
204 uint32_t nnz = *nnzmap++;
205 float32x2_t vacc0 = vld1_dup_f32(w); w += 1;
206 if XNN_LIKELY(nnz != 0) {
207 do {
208 const intptr_t diff = *dmap++;
209 const float32x2_t vi0 = vld1_dup_f32(input);
210 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
211 const float32x2_t vw = vld1_dup_f32(w); w += 1;
212 vacc0 = vfma_f32(vacc0, vi0, vw);
213 } while (--nnz != 0);
214 }
215 float32x2_t vout0 = vmin_f32(vacc0, vget_low_f32(vmax));
216 vout0 = vmax_f32(vout0, vget_low_f32(vmin));
217
218 vst1_lane_f32(output, vout0, 1);
219 output = (float*) ((uintptr_t) output + output_stride);
220 n -= 1;
221 } while (n != 0);
222 }
223 output = (float*) ((uintptr_t) output - output_decrement);
224 input += 1;
225 }
226 }
227 }