Debian Codegraph @

src/f32-spmm/gen/f32-spmm-16x1-minmax-neon-x2.c

raw
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/prefetch.h"
15 #include "xnnpack/spmm.h"
16
17
18 void xnn_f32_spmm_minmax_ukernel_16x1__neon_x2(
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 - 16 * sizeof(float);
44 while XNN_LIKELY(mc >= 16 * 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 do {
50 uint32_t nnz = *nnzmap++;
51 float32x4_t vacc0123x0 = vld1q_dup_f32(w); w += 1;
52 float32x4_t vacc0123x1 = vmovq_n_f32(0.0f);
53 float32x4_t vacc4567x0 = vacc0123x0;
54 float32x4_t vacc4567x1 = vmovq_n_f32(0.0f);
55 float32x4_t vacc89ABx0 = vacc0123x0;
56 float32x4_t vacc89ABx1 = vmovq_n_f32(0.0f);
57 float32x4_t vaccCDEFx0 = vacc0123x0;
58 float32x4_t vaccCDEFx1 = vmovq_n_f32(0.0f);
59 for (; nnz >= 2; nnz -= 2) {
60 const intptr_t diff0 = dmap[0];
61 const intptr_t diff1 = dmap[1];
62 dmap += 2;
63 const float32x4_t vi0123x0 = vld1q_f32(input);
64 const float32x4_t vi4567x0 = vld1q_f32(input + 4);
65 const float32x4_t vi89ABx0 = vld1q_f32(input + 8);
66 const float32x4_t viCDEFx0 = vld1q_f32(input + 12);
67 input = (const float*) ((uintptr_t) input + (uintptr_t) diff0);
68 xnn_prefetch_to_l1(input + 16);
69 const float32x4_t vw0 = vld1q_dup_f32(w); w += 1;
70 xnn_prefetch_to_l1(w + 32);
71 vacc0123x0 = vmlaq_f32(vacc0123x0, vi0123x0, vw0);
72 vacc4567x0 = vmlaq_f32(vacc4567x0, vi4567x0, vw0);
73 vacc89ABx0 = vmlaq_f32(vacc89ABx0, vi89ABx0, vw0);
74 vaccCDEFx0 = vmlaq_f32(vaccCDEFx0, viCDEFx0, vw0);
75 const float32x4_t vi0123x1 = vld1q_f32(input);
76 const float32x4_t vi4567x1 = vld1q_f32(input + 4);
77 const float32x4_t vi89ABx1 = vld1q_f32(input + 8);
78 const float32x4_t viCDEFx1 = vld1q_f32(input + 12);
79 input = (const float*) ((uintptr_t) input + (uintptr_t) diff1);
80 xnn_prefetch_to_l1(input + 16);
81 const float32x4_t vw1 = vld1q_dup_f32(w); w += 1;
82 xnn_prefetch_to_l1(w + 32);
83 vacc0123x1 = vmlaq_f32(vacc0123x1, vi0123x1, vw1);
84 vacc4567x1 = vmlaq_f32(vacc4567x1, vi4567x1, vw1);
85 vacc89ABx1 = vmlaq_f32(vacc89ABx1, vi89ABx1, vw1);
86 vaccCDEFx1 = vmlaq_f32(vaccCDEFx1, viCDEFx1, vw1);
87 }
88 float32x4_t vacc0123 = vacc0123x0;
89 float32x4_t vacc4567 = vacc4567x0;
90 float32x4_t vacc89AB = vacc89ABx0;
91 float32x4_t vaccCDEF = vaccCDEFx0;
92 vacc0123 = vaddq_f32(vacc0123, vacc0123x1);
93 vacc4567 = vaddq_f32(vacc4567, vacc4567x1);
94 vacc89AB = vaddq_f32(vacc89AB, vacc89ABx1);
95 vaccCDEF = vaddq_f32(vaccCDEF, vaccCDEFx1);
96 if XNN_LIKELY(nnz != 0) {
97 do {
98 const intptr_t diff = *dmap++;
99 const float32x4_t vi0123 = vld1q_f32(input);
100 const float32x4_t vi4567 = vld1q_f32(input + 4);
101 const float32x4_t vi89AB = vld1q_f32(input + 8);
102 const float32x4_t viCDEF = vld1q_f32(input + 12);
103 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
104 xnn_prefetch_to_l1(input + 16);
105 const float32x4_t vw = vld1q_dup_f32(w); w += 1;
106 xnn_prefetch_to_l1(w + 32);
107 vacc0123 = vmlaq_f32(vacc0123, vi0123, vw);
108 vacc4567 = vmlaq_f32(vacc4567, vi4567, vw);
109 vacc89AB = vmlaq_f32(vacc89AB, vi89AB, vw);
110 vaccCDEF = vmlaq_f32(vaccCDEF, viCDEF, vw);
111 } while (--nnz != 0);
112 }
113 float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
114 float32x4_t vout4567 = vminq_f32(vacc4567, vmax);
115 float32x4_t vout89AB = vminq_f32(vacc89AB, vmax);
116 float32x4_t voutCDEF = vminq_f32(vaccCDEF, vmax);
117 vout0123 = vmaxq_f32(vout0123, vmin);
118 vout4567 = vmaxq_f32(vout4567, vmin);
119 vout89AB = vmaxq_f32(vout89AB, vmin);
120 voutCDEF = vmaxq_f32(voutCDEF, vmin);
121 vst1q_f32(output, vout0123);
122 vst1q_f32(output + 4, vout4567);
123 vst1q_f32(output + 8, vout89AB);
124 vst1q_f32(output + 12, voutCDEF);
125 output = (float*) ((uintptr_t) output + output_stride);
126 } while (--n != 0);
127 output = (float*) ((uintptr_t) output - output_decrement);
128 input += 16;
129 mc -= 16 * sizeof(float);
130 }
131 if XNN_UNLIKELY(mc != 0) {
132 output_decrement += 8 * sizeof(float);
133 if (mc & (8 * sizeof(float))) {
134 const float* w = weights;
135 const int32_t* dmap = widx_dmap;
136 const uint32_t* nnzmap = nidx_nnzmap;
137 size_t n = nc;
138 do {
139 uint32_t nnz = *nnzmap++;
140 float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1;
141 float32x4_t vacc4567 = vacc0123;
142 if XNN_LIKELY(nnz != 0) {
143 do {
144 const intptr_t diff = *dmap++;
145 const float32x4_t vi0123 = vld1q_f32(input);
146 const float32x4_t vi4567 = vld1q_f32(input + 4);
147 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
148 const float32x4_t vw = vld1q_dup_f32(w); w += 1;
149 vacc0123 = vmlaq_f32(vacc0123, vi0123, vw);
150 vacc4567 = vmlaq_f32(vacc4567, vi4567, vw);
151 } while (--nnz != 0);
152 }
153 float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
154 float32x4_t vout4567 = vminq_f32(vacc4567, vmax);
155 vout0123 = vmaxq_f32(vout0123, vmin);
156 vout4567 = vmaxq_f32(vout4567, vmin);
157 vst1q_f32(output, vout0123);
158 vst1q_f32(output + 4, vout4567);
159 output = (float*) ((uintptr_t) output + output_stride);
160 } while (--n != 0);
161 output = (float*) ((uintptr_t) output - output_decrement);
162 input += 8;
163 }
164 output_decrement += 4 * sizeof(float);
165 if (mc & (4 * sizeof(float))) {
166 const float* w = weights;
167 const int32_t* dmap = widx_dmap;
168 const uint32_t* nnzmap = nidx_nnzmap;
169 size_t n = nc;
170 do {
171 uint32_t nnz = *nnzmap++;
172 float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1;
173 if XNN_LIKELY(nnz != 0) {
174 do {
175 const intptr_t diff = *dmap++;
176 const float32x4_t vi0123 = vld1q_f32(input);
177 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
178 const float32x4_t vw = vld1q_dup_f32(w); w += 1;
179 vacc0123 = vmlaq_f32(vacc0123, vi0123, vw);
180 } while (--nnz != 0);
181 }
182 float32x4_t vout0123 = vminq_f32(vacc0123, vmax);
183 vout0123 = vmaxq_f32(vout0123, vmin);
184 vst1q_f32(output, vout0123);
185 output = (float*) ((uintptr_t) output + output_stride);
186 } while (--n != 0);
187 output = (float*) ((uintptr_t) output - output_decrement);
188 input += 4;
189 }
190 output_decrement += 2 * sizeof(float);
191 if (mc & (2 * sizeof(float))) {
192 const float* w = weights;
193 const int32_t* dmap = widx_dmap;
194 const uint32_t* nnzmap = nidx_nnzmap;
195 size_t n = nc;
196 do {
197 uint32_t nnz = *nnzmap++;
198 float32x2_t vacc01 = vld1_dup_f32(w); w += 1;
199 if XNN_LIKELY(nnz != 0) {
200 do {
201 const intptr_t diff = *dmap++;
202 const float32x2_t vi01 = vld1_f32(input);
203 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
204 const float32x2_t vw = vld1_dup_f32(w); w += 1;
205 vacc01 = vmla_f32(vacc01, vi01, vw);
206 } while (--nnz != 0);
207 }
208 float32x2_t vout01 = vmin_f32(vacc01, vget_low_f32(vmax));
209 vout01 = vmax_f32(vout01, vget_low_f32(vmin));
210 vst1_f32(output, vout01);
211 output = (float*) ((uintptr_t) output + output_stride);
212 } while (--n != 0);
213 output = (float*) ((uintptr_t) output - output_decrement);
214 input += 2;
215 }
216 output_decrement += 1 * sizeof(float);
217 if (mc & (1 * sizeof(float))) {
218 const float* w = weights;
219 const int32_t* dmap = widx_dmap;
220 const uint32_t* nnzmap = nidx_nnzmap;
221 size_t n = nc;
222 do {
223 uint32_t nnz = *nnzmap++;
224 float32x2_t vacc0 = vld1_dup_f32(w); w += 1;
225 if XNN_LIKELY(nnz != 0) {
226 do {
227 const intptr_t diff = *dmap++;
228 const float32x2_t vi0 = vld1_dup_f32(input);
229 input = (const float*) ((uintptr_t) input + (uintptr_t) diff);
230 const float32x2_t vw = vld1_dup_f32(w); w += 1;
231 vacc0 = vmla_f32(vacc0, vi0, vw);
232 } while (--nnz != 0);
233 }
234 float32x2_t vout0 = vmin_f32(vacc0, vget_low_f32(vmax));
235 vout0 = vmax_f32(vout0, vget_low_f32(vmin));
236 vst1_lane_f32(output, vout0, 0);
237 output = (float*) ((uintptr_t) output + output_stride);
238 } while (--n != 0);
239 output = (float*) ((uintptr_t) output - output_decrement);
240 input += 1;
241 }
242 }
243 }