Debian Codegraph @

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

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-spmm/neonfp16arith.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_f16_spmm_minmax_ukernel_32x1__neonfp16arith(
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 size_t n = nc;
53 do {
54 uint32_t nnz = *nnzmap++;
55 float16x8_t vacc01234567 = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
56 float16x8_t vacc89ABCDEF = vacc01234567;
57 float16x8_t vaccGHIJKLMN = vacc01234567;
58 float16x8_t vaccOPQRSTUV = vacc01234567;
59 if XNN_LIKELY(nnz != 0) {
60 do {
61 const intptr_t diff = *dmap++;
62 const float16x8_t va01234567 = vreinterpretq_f16_u16(vld1q_u16(i));
63 const float16x8_t va89ABCDEF = vreinterpretq_f16_u16(vld1q_u16(i + 8));
64 const float16x8_t vaGHIJKLMN = vreinterpretq_f16_u16(vld1q_u16(i + 16));
65 const float16x8_t vaOPQRSTUV = vreinterpretq_f16_u16(vld1q_u16(i + 24));
66 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
67 xnn_prefetch_to_l1(i + 32);
68 const float16x8_t vw = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
69 xnn_prefetch_to_l1(w + 64);
70 vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vw);
71 vacc89ABCDEF = vfmaq_f16(vacc89ABCDEF, va89ABCDEF, vw);
72 vaccGHIJKLMN = vfmaq_f16(vaccGHIJKLMN, vaGHIJKLMN, vw);
73 vaccOPQRSTUV = vfmaq_f16(vaccOPQRSTUV, vaOPQRSTUV, vw);
74 } while (--nnz != 0);
75 }
76 float16x8_t vout01234567 = vminq_f16(vacc01234567, vmax);
77 float16x8_t vout89ABCDEF = vminq_f16(vacc89ABCDEF, vmax);
78 float16x8_t voutGHIJKLMN = vminq_f16(vaccGHIJKLMN, vmax);
79 float16x8_t voutOPQRSTUV = vminq_f16(vaccOPQRSTUV, vmax);
80 vout01234567 = vmaxq_f16(vout01234567, vmin);
81 vout89ABCDEF = vmaxq_f16(vout89ABCDEF, vmin);
82 voutGHIJKLMN = vmaxq_f16(voutGHIJKLMN, vmin);
83 voutOPQRSTUV = vmaxq_f16(voutOPQRSTUV, vmin);
84 vst1q_u16(o, vreinterpretq_u16_f16(vout01234567));
85 vst1q_u16(o + 8, vreinterpretq_u16_f16(vout89ABCDEF));
86 vst1q_u16(o + 16, vreinterpretq_u16_f16(voutGHIJKLMN));
87 vst1q_u16(o + 24, vreinterpretq_u16_f16(voutOPQRSTUV));
88 o = (uint16_t*) ((uintptr_t) o + output_stride);
89 } while (--n != 0);
90 o = (uint16_t*) ((uintptr_t) o - output_decrement);
91 i += 32;
92 mc -= 32 * sizeof(uint16_t);
93 }
94 if XNN_UNLIKELY(mc != 0) {
95 output_decrement += 16 * sizeof(uint16_t);
96 if (mc & (16 * sizeof(uint16_t))) {
97 const uint16_t* w = (const uint16_t*) weights;
98 const int32_t* dmap = widx_dmap;
99 const uint32_t* nnzmap = nidx_nnzmap;
100 size_t n = nc;
101 do {
102 uint32_t nnz = *nnzmap++;
103 float16x8_t vacc01234567 = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
104 float16x8_t vacc89ABCDEF = vacc01234567;
105 if XNN_LIKELY(nnz != 0) {
106 do {
107 const intptr_t diff = *dmap++;
108 const float16x8_t va01234567 = vreinterpretq_f16_u16(vld1q_u16(i));
109 const float16x8_t va89ABCDEF = vreinterpretq_f16_u16(vld1q_u16(i + 8));
110 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
111 const float16x8_t vw = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
112 vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vw);
113 vacc89ABCDEF = vfmaq_f16(vacc89ABCDEF, va89ABCDEF, vw);
114 } while (--nnz != 0);
115 }
116 float16x8_t vout01234567 = vminq_f16(vacc01234567, vmax);
117 float16x8_t vout89ABCDEF = vminq_f16(vacc89ABCDEF, vmax);
118 vout01234567 = vmaxq_f16(vout01234567, vmin);
119 vout89ABCDEF = vmaxq_f16(vout89ABCDEF, vmin);
120 vst1q_u16(o, vreinterpretq_u16_f16(vout01234567));
121 vst1q_u16(o + 8, vreinterpretq_u16_f16(vout89ABCDEF));
122 o = (uint16_t*) ((uintptr_t) o + output_stride);
123 } while (--n != 0);
124 o = (uint16_t*) ((uintptr_t) o - output_decrement);
125 i += 16;
126 }
127 output_decrement += 8 * sizeof(uint16_t);
128 if (mc & (8 * sizeof(uint16_t))) {
129 const uint16_t* w = (const uint16_t*) weights;
130 const int32_t* dmap = widx_dmap;
131 const uint32_t* nnzmap = nidx_nnzmap;
132 size_t n = nc;
133 do {
134 uint32_t nnz = *nnzmap++;
135 float16x8_t vacc01234567 = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
136 if XNN_LIKELY(nnz != 0) {
137 do {
138 const intptr_t diff = *dmap++;
139 const float16x8_t va01234567 = vreinterpretq_f16_u16(vld1q_u16(i));
140 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
141 const float16x8_t vw = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
142 vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vw);
143 } while (--nnz != 0);
144 }
145 float16x8_t vout01234567 = vminq_f16(vacc01234567, vmax);
146 vout01234567 = vmaxq_f16(vout01234567, vmin);
147 vst1q_u16(o, vreinterpretq_u16_f16(vout01234567));
148 o = (uint16_t*) ((uintptr_t) o + output_stride);
149 } while (--n != 0);
150 o = (uint16_t*) ((uintptr_t) o - output_decrement);
151 i += 8;
152 }
153 output_decrement += 4 * sizeof(uint16_t);
154 if (mc & (4 * sizeof(uint16_t))) {
155 const uint16_t* w = (const uint16_t*) weights;
156 const int32_t* dmap = widx_dmap;
157 const uint32_t* nnzmap = nidx_nnzmap;
158 size_t n = nc;
159 do {
160 uint32_t nnz = *nnzmap++;
161 float16x4_t vacc0123 = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
162 if XNN_LIKELY(nnz != 0) {
163 do {
164 const intptr_t diff = *dmap++;
165 const float16x4_t va0123 = vreinterpret_f16_u16(vld1_u16(i));
166 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
167 const float16x4_t vw = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
168 vacc0123 = vfma_f16(vacc0123, va0123, vw);
169 } while (--nnz != 0);
170 }
171 float16x4_t vout0123 = vmin_f16(vacc0123, vget_low_f16(vmax));
172 vout0123 = vmax_f16(vout0123, vget_low_f16(vmin));
173 vst1_u16(o, vreinterpret_u16_f16(vout0123));
174 o = (uint16_t*) ((uintptr_t) o + output_stride);
175 } while (--n != 0);
176 o = (uint16_t*) ((uintptr_t) o - output_decrement);
177 i += 4;
178 }
179 output_decrement += 2 * sizeof(uint16_t);
180 if (mc & (2 * sizeof(uint16_t))) {
181 const uint16_t* w = (const uint16_t*) weights;
182 const int32_t* dmap = widx_dmap;
183 const uint32_t* nnzmap = nidx_nnzmap;
184 size_t n = nc;
185 do {
186 uint32_t nnz = *nnzmap++;
187 float16x4_t vacc01 = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
188 if XNN_LIKELY(nnz != 0) {
189 do {
190 const intptr_t diff = *dmap++;
191 const float16x4_t va01 = vreinterpret_f16_u32(vld1_dup_u32((const void*) i));
192 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
193 const float16x4_t vw = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
194 vacc01 = vfma_f16(vacc01, va01, vw);
195 } while (--nnz != 0);
196 }
197 float16x4_t vout01 = vmin_f16(vacc01, vget_low_f16(vmax));
198 vout01 = vmax_f16(vout01, vget_low_f16(vmin));
199 vst1_lane_u32((void*) o, vreinterpret_u32_f16(vout01), 0);
200 o = (uint16_t*) ((uintptr_t) o + output_stride);
201 } while (--n != 0);
202 o = (uint16_t*) ((uintptr_t) o - output_decrement);
203 i += 2;
204 }
205 output_decrement += 1 * sizeof(uint16_t);
206 if (mc & (1 * sizeof(uint16_t))) {
207 const uint16_t* w = (const uint16_t*) weights;
208 const int32_t* dmap = widx_dmap;
209 const uint32_t* nnzmap = nidx_nnzmap;
210 size_t n = nc;
211 do {
212 uint32_t nnz = *nnzmap++;
213 float16x4_t vacc0 = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
214 if XNN_LIKELY(nnz != 0) {
215 do {
216 const intptr_t diff = *dmap++;
217 const float16x4_t va0 = vreinterpret_f16_u16(vld1_dup_u16(i));
218 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
219 const float16x4_t vw = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
220 vacc0 = vfma_f16(vacc0, va0, vw);
221 } while (--nnz != 0);
222 }
223 float16x4_t vout0 = vmin_f16(vacc0, vget_low_f16(vmax));
224 vout0 = vmax_f16(vout0, vget_low_f16(vmin));
225 vst1_lane_u16(o, vreinterpret_u16_f16(vout0), 0);
226 o = (uint16_t*) ((uintptr_t) o + output_stride);
227 } while (--n != 0);
228 o = (uint16_t*) ((uintptr_t) o - output_decrement);
229 i += 1;
230 }
231 }
232 }