Debian Codegraph @

src/f16-spmm/gen/f16-spmm-32x1-minmax-neonfp16arith-pipelined.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-spmm/neonfp16arith-pipelined.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2022 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_f16_spmm_minmax_ukernel_32x1__neonfp16arith_pipelined(
19 size_t mc,
20 size_t nc,
21 const xnn_float16* input,
22 const xnn_float16* weights,
23 const int32_t* widx_dmap,
24 const uint32_t* nidx_nnzmap,
25 xnn_float16* output,
26 size_t output_stride,
27 const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
28 {
29 assert(mc != 0);
30 assert(mc % sizeof(uint16_t) == 0);
31 assert(nc != 0);
32
33 const uint16_t* i = (const uint16_t*) input;
34 uint16_t* o = (uint16_t*) output;
35
36 #if XNN_ARCH_ARM64
37 const uint16x8x2_t vminmax = vld2q_dup_u16((const uint16_t*) &params->scalar.min);
38 const float16x8_t vmin = vreinterpretq_f16_u16(vminmax.val[0]);
39 const float16x8_t vmax = vreinterpretq_f16_u16(vminmax.val[1]);
40 #else
41 // vld2_dup is to work around aarch32 clang bug with vld1q_dup
42 const uint16x4x2_t vminmax = vld2_dup_u16((const uint16_t*) &params->scalar.min);
43 const float16x8_t vmin = vreinterpretq_f16_u16(vcombine_u16(vminmax.val[0], vminmax.val[0]));
44 const float16x8_t vmax = vreinterpretq_f16_u16(vcombine_u16(vminmax.val[1], vminmax.val[1]));
45 #endif
46
47 size_t output_decrement = output_stride * nc - 32 * sizeof(uint16_t);
48 while XNN_LIKELY(mc >= 32 * sizeof(uint16_t)) {
49 const uint16_t* w = (const uint16_t*) weights;
50 const int32_t* dmap = widx_dmap;
51 const uint32_t* nnzmap = nidx_nnzmap;
52 float16x8_t vw = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
53 intptr_t diff = *dmap++;
54 float16x8_t vi01234567 = vreinterpretq_f16_u16(vld1q_u16(i));
55 float16x8_t vi89ABCDEF = vreinterpretq_f16_u16(vld1q_u16(i + 8));
56 float16x8_t viGHIJKLMN = vreinterpretq_f16_u16(vld1q_u16(i + 16));
57 float16x8_t viOPQRSTUV = vreinterpretq_f16_u16(vld1q_u16(i + 24));
58 size_t n = nc;
59 do {
60 uint32_t nnz = *nnzmap++;
61 float16x8_t vacc01234567 = vw;
62 float16x8_t vacc89ABCDEF = vw;
63 float16x8_t vaccGHIJKLMN = vw;
64 float16x8_t vaccOPQRSTUV = vw;
65 vw = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
66 if XNN_LIKELY(nnz != 0) {
67 do {
68 vacc01234567 = vfmaq_f16(vacc01234567, vi01234567, vw);
69 vacc89ABCDEF = vfmaq_f16(vacc89ABCDEF, vi89ABCDEF, vw);
70 vaccGHIJKLMN = vfmaq_f16(vaccGHIJKLMN, viGHIJKLMN, vw);
71 vaccOPQRSTUV = vfmaq_f16(vaccOPQRSTUV, viOPQRSTUV, vw);
72 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
73 xnn_prefetch_to_l1(i + 32);
74 diff = *dmap++;
75 vw = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
76 xnn_prefetch_to_l1(w + 64);
77 vi01234567 = vreinterpretq_f16_u16(vld1q_u16(i));
78 vi89ABCDEF = vreinterpretq_f16_u16(vld1q_u16(i + 8));
79 viGHIJKLMN = vreinterpretq_f16_u16(vld1q_u16(i + 16));
80 viOPQRSTUV = vreinterpretq_f16_u16(vld1q_u16(i + 24));
81 } while (--nnz != 0);
82 }
83 float16x8_t vout01234567 = vminq_f16(vacc01234567, vmax);
84 float16x8_t vout89ABCDEF = vminq_f16(vacc89ABCDEF, vmax);
85 float16x8_t voutGHIJKLMN = vminq_f16(vaccGHIJKLMN, vmax);
86 float16x8_t voutOPQRSTUV = vminq_f16(vaccOPQRSTUV, vmax);
87 vout01234567 = vmaxq_f16(vout01234567, vmin);
88 vout89ABCDEF = vmaxq_f16(vout89ABCDEF, vmin);
89 voutGHIJKLMN = vmaxq_f16(voutGHIJKLMN, vmin);
90 voutOPQRSTUV = vmaxq_f16(voutOPQRSTUV, vmin);
91 vst1q_u16(o, vreinterpretq_u16_f16(vout01234567));
92 vst1q_u16(o + 8, vreinterpretq_u16_f16(vout89ABCDEF));
93 vst1q_u16(o + 16, vreinterpretq_u16_f16(voutGHIJKLMN));
94 vst1q_u16(o + 24, vreinterpretq_u16_f16(voutOPQRSTUV));
95 o = (uint16_t*) ((uintptr_t) o + output_stride);
96 } while (--n != 0);
97 o = (uint16_t*) ((uintptr_t) o - output_decrement);
98 i += 32;
99 mc -= 32 * sizeof(uint16_t);
100 }
101 if XNN_UNLIKELY(mc != 0) {
102 output_decrement += 16 * sizeof(uint16_t);
103 if (mc & (16 * sizeof(uint16_t))) {
104 const uint16_t* w = (const uint16_t*) weights;
105 const int32_t* dmap = widx_dmap;
106 const uint32_t* nnzmap = nidx_nnzmap;
107 size_t n = nc;
108 do {
109 uint32_t nnz = *nnzmap++;
110 float16x8_t vacc01234567 = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
111 float16x8_t vacc89ABCDEF = vacc01234567;
112 if XNN_LIKELY(nnz != 0) {
113 do {
114 const intptr_t diff = *dmap++;
115 const float16x8_t va01234567 = vreinterpretq_f16_u16(vld1q_u16(i));
116 const float16x8_t va89ABCDEF = vreinterpretq_f16_u16(vld1q_u16(i + 8));
117 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
118 const float16x8_t vw = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
119 vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vw);
120 vacc89ABCDEF = vfmaq_f16(vacc89ABCDEF, va89ABCDEF, vw);
121 } while (--nnz != 0);
122 }
123 float16x8_t vout01234567 = vminq_f16(vacc01234567, vmax);
124 float16x8_t vout89ABCDEF = vminq_f16(vacc89ABCDEF, vmax);
125 vout01234567 = vmaxq_f16(vout01234567, vmin);
126 vout89ABCDEF = vmaxq_f16(vout89ABCDEF, vmin);
127 vst1q_u16(o, vreinterpretq_u16_f16(vout01234567));
128 vst1q_u16(o + 8, vreinterpretq_u16_f16(vout89ABCDEF));
129 o = (uint16_t*) ((uintptr_t) o + output_stride);
130 } while (--n != 0);
131 o = (uint16_t*) ((uintptr_t) o - output_decrement);
132 i += 16;
133 }
134 output_decrement += 8 * sizeof(uint16_t);
135 if (mc & (8 * sizeof(uint16_t))) {
136 const uint16_t* w = (const uint16_t*) weights;
137 const int32_t* dmap = widx_dmap;
138 const uint32_t* nnzmap = nidx_nnzmap;
139 size_t n = nc;
140 do {
141 uint32_t nnz = *nnzmap++;
142 float16x8_t vacc01234567 = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
143 if XNN_LIKELY(nnz != 0) {
144 do {
145 const intptr_t diff = *dmap++;
146 const float16x8_t va01234567 = vreinterpretq_f16_u16(vld1q_u16(i));
147 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
148 const float16x8_t vw = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
149 vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vw);
150 } while (--nnz != 0);
151 }
152 float16x8_t vout01234567 = vminq_f16(vacc01234567, vmax);
153 vout01234567 = vmaxq_f16(vout01234567, vmin);
154 vst1q_u16(o, vreinterpretq_u16_f16(vout01234567));
155 o = (uint16_t*) ((uintptr_t) o + output_stride);
156 } while (--n != 0);
157 o = (uint16_t*) ((uintptr_t) o - output_decrement);
158 i += 8;
159 }
160 output_decrement += 4 * sizeof(uint16_t);
161 if (mc & (4 * sizeof(uint16_t))) {
162 const uint16_t* w = (const uint16_t*) weights;
163 const int32_t* dmap = widx_dmap;
164 const uint32_t* nnzmap = nidx_nnzmap;
165 size_t n = nc;
166 do {
167 uint32_t nnz = *nnzmap++;
168 float16x4_t vacc0123 = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
169 if XNN_LIKELY(nnz != 0) {
170 do {
171 const intptr_t diff = *dmap++;
172 const float16x4_t va0123 = vreinterpret_f16_u16(vld1_u16(i));
173 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
174 const float16x4_t vw = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
175 vacc0123 = vfma_f16(vacc0123, va0123, vw);
176 } while (--nnz != 0);
177 }
178 float16x4_t vout0123 = vmin_f16(vacc0123, vget_low_f16(vmax));
179 vout0123 = vmax_f16(vout0123, vget_low_f16(vmin));
180 vst1_u16(o, vreinterpret_u16_f16(vout0123));
181 o = (uint16_t*) ((uintptr_t) o + output_stride);
182 } while (--n != 0);
183 o = (uint16_t*) ((uintptr_t) o - output_decrement);
184 i += 4;
185 }
186 output_decrement += 2 * sizeof(uint16_t);
187 if (mc & (2 * sizeof(uint16_t))) {
188 const uint16_t* w = (const uint16_t*) weights;
189 const int32_t* dmap = widx_dmap;
190 const uint32_t* nnzmap = nidx_nnzmap;
191 size_t n = nc;
192 do {
193 uint32_t nnz = *nnzmap++;
194 float16x4_t vacc01 = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
195 if XNN_LIKELY(nnz != 0) {
196 do {
197 const intptr_t diff = *dmap++;
198 const float16x4_t va01 = vreinterpret_f16_u32(vld1_dup_u32((const void*) i));
199 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
200 const float16x4_t vw = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
201 vacc01 = vfma_f16(vacc01, va01, vw);
202 } while (--nnz != 0);
203 }
204 float16x4_t vout01 = vmin_f16(vacc01, vget_low_f16(vmax));
205 vout01 = vmax_f16(vout01, vget_low_f16(vmin));
206 vst1_lane_u32((void*) o, vreinterpret_u32_f16(vout01), 0);
207 o = (uint16_t*) ((uintptr_t) o + output_stride);
208 } while (--n != 0);
209 o = (uint16_t*) ((uintptr_t) o - output_decrement);
210 i += 2;
211 }
212 output_decrement += 1 * sizeof(uint16_t);
213 if (mc & (1 * sizeof(uint16_t))) {
214 const uint16_t* w = (const uint16_t*) weights;
215 const int32_t* dmap = widx_dmap;
216 const uint32_t* nnzmap = nidx_nnzmap;
217 size_t n = nc;
218 do {
219 uint32_t nnz = *nnzmap++;
220 float16x4_t vacc0 = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
221 if XNN_LIKELY(nnz != 0) {
222 do {
223 const intptr_t diff = *dmap++;
224 const float16x4_t va0 = vreinterpret_f16_u16(vld1_dup_u16(i));
225 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
226 const float16x4_t vw = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
227 vacc0 = vfma_f16(vacc0, va0, vw);
228 } while (--nnz != 0);
229 }
230 float16x4_t vout0 = vmin_f16(vacc0, vget_low_f16(vmax));
231 vout0 = vmax_f16(vout0, vget_low_f16(vmin));
232 vst1_lane_u16(o, vreinterpret_u16_f16(vout0), 0);
233 o = (uint16_t*) ((uintptr_t) o + output_stride);
234 } while (--n != 0);
235 o = (uint16_t*) ((uintptr_t) o - output_decrement);
236 i += 1;
237 }
238 }
239 }