1 // Auto-generated file. Do not edit!
2 // Template: src/f32-sigmoid/neon-p5.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/common.h>
15 #include <xnnpack/vunary.h>
16
17
xnn_f32_sigmoid_ukernel__neonfma_rr1_p5_nr2fma_x24(size_t n,const float * x,float * y,const void * params)18 void xnn_f32_sigmoid_ukernel__neonfma_rr1_p5_nr2fma_x24(
19 size_t n,
20 const float* x,
21 float* y,
22 const void* params)
23 {
24 assert(n % sizeof(float) == 0);
25
26 const float32x4_t vmagic_bias = vmovq_n_f32(0x1.8000FEp23f);
27 // The largest z for which sigmoidf(-z) is normalized.
28 // This number is also the largest z for which expf(-z) is normalized.
29 const float32x4_t vdenorm_cutoff = vmovq_n_f32(0x1.5D589Ep+6f);
30 const float32x4_t vminus_log2e = vmovq_n_f32(-0x1.715476p+0f);
31 const float32x4_t vln2 = vmovq_n_f32(0x1.62E43p-1f);
32 const float32x4_t vone = vmovq_n_f32(1.0f);
33
34 const float32x4_t vc1 = vmovq_n_f32(-0x1.FFFFF6p-1f);
35 const float32x4_t vc2 = vmovq_n_f32(0x1.FFFDC6p-2f);
36 const float32x4_t vc3 = vmovq_n_f32(-0x1.555A80p-3f);
37 const float32x4_t vc4 = vmovq_n_f32(0x1.573A1Ap-5f);
38 const float32x4_t vc5 = vmovq_n_f32(-0x1.0F9F9Cp-7f);
39
40 for (; n >= 24 * sizeof(float); n -= 24 * sizeof(float)) {
41 const float32x4_t vx0123 = vld1q_f32(x); x += 4;
42 const float32x4_t vx4567 = vld1q_f32(x); x += 4;
43 const float32x4_t vx89AB = vld1q_f32(x); x += 4;
44 const float32x4_t vxCDEF = vld1q_f32(x); x += 4;
45 const float32x4_t vxGHIJ = vld1q_f32(x); x += 4;
46 const float32x4_t vxKLMN = vld1q_f32(x); x += 4;
47
48 // General structure of the algorithm:
49 // / exp(x) / (1 + exp(x)) if x <= 0
50 // f[x] :=
51 // \ 1 - f[-x] if x >= 0
52 //
53 // First we compute f[z] := exp(-z) / (1 + exp(-z)) where z = abs(x),
54 // then replace result with 1 - f[z] if x >= 0.
55 const float32x4_t vz0123 = vabsq_f32(vx0123);
56 const float32x4_t vz4567 = vabsq_f32(vx4567);
57 const float32x4_t vz89AB = vabsq_f32(vx89AB);
58 const float32x4_t vzCDEF = vabsq_f32(vxCDEF);
59 const float32x4_t vzGHIJ = vabsq_f32(vxGHIJ);
60 const float32x4_t vzKLMN = vabsq_f32(vxKLMN);
61
62 // Compute reduced argument n := round(-z / log(2)).
63 // We do it by adding a large number (magic bias), which cause rounding of result to an integer, then subtracing the
64 // large number back. The first addition is combined with multiplication by log2e into a single FMA instruction.
65 // The trick with adding large number is valid only within certain bounds (|x| <= 2**22), but thats ok, because
66 // inputs x outside of [-87.336544, 17.328678] (i.e. z outsize [0, 87.336544]) underflow or saturate sigmoidf(x)
67 // anyway. We fixup the result for such inputs at the very end of the algorithm.
68 float32x4_t vn0123 = vfmaq_f32(vmagic_bias, vz0123, vminus_log2e);
69 float32x4_t vn4567 = vfmaq_f32(vmagic_bias, vz4567, vminus_log2e);
70 float32x4_t vn89AB = vfmaq_f32(vmagic_bias, vz89AB, vminus_log2e);
71 float32x4_t vnCDEF = vfmaq_f32(vmagic_bias, vzCDEF, vminus_log2e);
72 float32x4_t vnGHIJ = vfmaq_f32(vmagic_bias, vzGHIJ, vminus_log2e);
73 float32x4_t vnKLMN = vfmaq_f32(vmagic_bias, vzKLMN, vminus_log2e);
74
75 // Create a floating-point number s (scale) such that s == 2**n for inputs which don't cause underflow, i.e.
76 // -87.336544 <= -z <= 0.0, and -126 <= n <= 0 accordingly.
77 const float32x4_t vs0123 = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn0123), 23));
78 const float32x4_t vs4567 = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn4567), 23));
79 const float32x4_t vs89AB = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn89AB), 23));
80 const float32x4_t vsCDEF = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vnCDEF), 23));
81 const float32x4_t vsGHIJ = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vnGHIJ), 23));
82 const float32x4_t vsKLMN = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vnKLMN), 23));
83
84 // Subtract the large number back to get final n := round(-z / log(2)).
85 vn0123 = vsubq_f32(vn0123, vmagic_bias);
86 vn4567 = vsubq_f32(vn4567, vmagic_bias);
87 vn89AB = vsubq_f32(vn89AB, vmagic_bias);
88 vnCDEF = vsubq_f32(vnCDEF, vmagic_bias);
89 vnGHIJ = vsubq_f32(vnGHIJ, vmagic_bias);
90 vnKLMN = vsubq_f32(vnKLMN, vmagic_bias);
91
92 // Compute reduced argument -t := -z - n * log(2) = -(z + n * log(2)).
93 float32x4_t vt0123 = vfmaq_f32(vz0123, vn0123, vln2);
94 float32x4_t vt4567 = vfmaq_f32(vz4567, vn4567, vln2);
95 float32x4_t vt89AB = vfmaq_f32(vz89AB, vn89AB, vln2);
96 float32x4_t vtCDEF = vfmaq_f32(vzCDEF, vnCDEF, vln2);
97 float32x4_t vtGHIJ = vfmaq_f32(vzGHIJ, vnGHIJ, vln2);
98 float32x4_t vtKLMN = vfmaq_f32(vzKLMN, vnKLMN, vln2);
99
100 // Compute degree-5 polynomial approxiatmion for exp(-t) on [-log(2)/2, log(2)/2].
101 float32x4_t vp0123 = vfmaq_f32(vc4, vc5, vt0123);
102 float32x4_t vp4567 = vfmaq_f32(vc4, vc5, vt4567);
103 float32x4_t vp89AB = vfmaq_f32(vc4, vc5, vt89AB);
104 float32x4_t vpCDEF = vfmaq_f32(vc4, vc5, vtCDEF);
105 float32x4_t vpGHIJ = vfmaq_f32(vc4, vc5, vtGHIJ);
106 float32x4_t vpKLMN = vfmaq_f32(vc4, vc5, vtKLMN);
107
108 vp0123 = vfmaq_f32(vc3, vp0123, vt0123);
109 vp4567 = vfmaq_f32(vc3, vp4567, vt4567);
110 vp89AB = vfmaq_f32(vc3, vp89AB, vt89AB);
111 vpCDEF = vfmaq_f32(vc3, vpCDEF, vtCDEF);
112 vpGHIJ = vfmaq_f32(vc3, vpGHIJ, vtGHIJ);
113 vpKLMN = vfmaq_f32(vc3, vpKLMN, vtKLMN);
114
115 vp0123 = vfmaq_f32(vc2, vp0123, vt0123);
116 vp4567 = vfmaq_f32(vc2, vp4567, vt4567);
117 vp89AB = vfmaq_f32(vc2, vp89AB, vt89AB);
118 vpCDEF = vfmaq_f32(vc2, vpCDEF, vtCDEF);
119 vpGHIJ = vfmaq_f32(vc2, vpGHIJ, vtGHIJ);
120 vpKLMN = vfmaq_f32(vc2, vpKLMN, vtKLMN);
121
122 vp0123 = vfmaq_f32(vc1, vp0123, vt0123);
123 vp4567 = vfmaq_f32(vc1, vp4567, vt4567);
124 vp89AB = vfmaq_f32(vc1, vp89AB, vt89AB);
125 vpCDEF = vfmaq_f32(vc1, vpCDEF, vtCDEF);
126 vpGHIJ = vfmaq_f32(vc1, vpGHIJ, vtGHIJ);
127 vpKLMN = vfmaq_f32(vc1, vpKLMN, vtKLMN);
128
129 // Reconstruct the exp(-z) value:
130 // e = s * (1 + t * (c1 + t * (c2 + t * (c3 + t * (c4 + t * c5)))))
131 // = s + (t * s) * (c1 + t * (c2 + t * (c3 + t * (c4 + t * c5))))
132 // = s + (t * s) * p
133 vt0123 = vmulq_f32(vt0123, vs0123);
134 vt4567 = vmulq_f32(vt4567, vs4567);
135 vt89AB = vmulq_f32(vt89AB, vs89AB);
136 vtCDEF = vmulq_f32(vtCDEF, vsCDEF);
137 vtGHIJ = vmulq_f32(vtGHIJ, vsGHIJ);
138 vtKLMN = vmulq_f32(vtKLMN, vsKLMN);
139
140 float32x4_t ve0123 = vfmaq_f32(vs0123, vp0123, vt0123);
141 float32x4_t ve4567 = vfmaq_f32(vs4567, vp4567, vt4567);
142 float32x4_t ve89AB = vfmaq_f32(vs89AB, vp89AB, vt89AB);
143 float32x4_t veCDEF = vfmaq_f32(vsCDEF, vpCDEF, vtCDEF);
144 float32x4_t veGHIJ = vfmaq_f32(vsGHIJ, vpGHIJ, vtGHIJ);
145 float32x4_t veKLMN = vfmaq_f32(vsKLMN, vpKLMN, vtKLMN);
146
147 // Denominator of the sigmoid fraction: 1.0 + exp(-z)
148 float32x4_t vd0123 = vaddq_f32(ve0123, vone);
149 float32x4_t vd4567 = vaddq_f32(ve4567, vone);
150 float32x4_t vd89AB = vaddq_f32(ve89AB, vone);
151 float32x4_t vdCDEF = vaddq_f32(veCDEF, vone);
152 float32x4_t vdGHIJ = vaddq_f32(veGHIJ, vone);
153 float32x4_t vdKLMN = vaddq_f32(veKLMN, vone);
154
155 // Use Newton-Raphson method (2 iterations) to compute reciprocal of denominator.
156 // Note: 1 < d <= 2, because z >= 0.0 and 0 < exp(-z) <= 1.0.
157 // Thus the reciprocal of the denominator never overflows.
158 float32x4_t vr0123 = vrecpeq_f32(vd0123);
159 float32x4_t vr4567 = vrecpeq_f32(vd4567);
160 float32x4_t vr89AB = vrecpeq_f32(vd89AB);
161 float32x4_t vrCDEF = vrecpeq_f32(vdCDEF);
162 float32x4_t vrGHIJ = vrecpeq_f32(vdGHIJ);
163 float32x4_t vrKLMN = vrecpeq_f32(vdKLMN);
164
165 vr0123 = vfmaq_f32(vr0123, vr0123, vfmsq_f32(vone, vr0123, vd0123));
166 vr4567 = vfmaq_f32(vr4567, vr4567, vfmsq_f32(vone, vr4567, vd4567));
167 vr89AB = vfmaq_f32(vr89AB, vr89AB, vfmsq_f32(vone, vr89AB, vd89AB));
168 vrCDEF = vfmaq_f32(vrCDEF, vrCDEF, vfmsq_f32(vone, vrCDEF, vdCDEF));
169 vrGHIJ = vfmaq_f32(vrGHIJ, vrGHIJ, vfmsq_f32(vone, vrGHIJ, vdGHIJ));
170 vrKLMN = vfmaq_f32(vrKLMN, vrKLMN, vfmsq_f32(vone, vrKLMN, vdKLMN));
171
172 vr0123 = vfmaq_f32(vr0123, vr0123, vfmsq_f32(vone, vr0123, vd0123));
173 vr4567 = vfmaq_f32(vr4567, vr4567, vfmsq_f32(vone, vr4567, vd4567));
174 vr89AB = vfmaq_f32(vr89AB, vr89AB, vfmsq_f32(vone, vr89AB, vd89AB));
175 vrCDEF = vfmaq_f32(vrCDEF, vrCDEF, vfmsq_f32(vone, vrCDEF, vdCDEF));
176 vrGHIJ = vfmaq_f32(vrGHIJ, vrGHIJ, vfmsq_f32(vone, vrGHIJ, vdGHIJ));
177 vrKLMN = vfmaq_f32(vrKLMN, vrKLMN, vfmsq_f32(vone, vrKLMN, vdKLMN));
178
179 // Reconstruct sigmoid(-z) = exp(-z) / (1.0 + exp(-z))
180 float32x4_t vf0123 = vmulq_f32(ve0123, vr0123);
181 float32x4_t vf4567 = vmulq_f32(ve4567, vr4567);
182 float32x4_t vf89AB = vmulq_f32(ve89AB, vr89AB);
183 float32x4_t vfCDEF = vmulq_f32(veCDEF, vrCDEF);
184 float32x4_t vfGHIJ = vmulq_f32(veGHIJ, vrGHIJ);
185 float32x4_t vfKLMN = vmulq_f32(veKLMN, vrKLMN);
186
187 // For inputs below denormal cutoff, replace output with +0.0f.
188 // Note that for NaN inputs, comparison result is false, and outputs are left unchanged.
189 vf0123 = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf0123), vcagtq_f32(vx0123, vdenorm_cutoff)));
190 vf4567 = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf4567), vcagtq_f32(vx4567, vdenorm_cutoff)));
191 vf89AB = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf89AB), vcagtq_f32(vx89AB, vdenorm_cutoff)));
192 vfCDEF = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vfCDEF), vcagtq_f32(vxCDEF, vdenorm_cutoff)));
193 vfGHIJ = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vfGHIJ), vcagtq_f32(vxGHIJ, vdenorm_cutoff)));
194 vfKLMN = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vfKLMN), vcagtq_f32(vxKLMN, vdenorm_cutoff)));
195
196 // Reconstruct sigmoid(x) = x < 0 ? sigmoid(-z) : 1.0 - sigmoid(-z)
197 const uint32x4_t vm0123 = vcltq_f32(vx0123, vmovq_n_f32(0.0f));
198 const uint32x4_t vm4567 = vcltq_f32(vx4567, vmovq_n_f32(0.0f));
199 const uint32x4_t vm89AB = vcltq_f32(vx89AB, vmovq_n_f32(0.0f));
200 const uint32x4_t vmCDEF = vcltq_f32(vxCDEF, vmovq_n_f32(0.0f));
201 const uint32x4_t vmGHIJ = vcltq_f32(vxGHIJ, vmovq_n_f32(0.0f));
202 const uint32x4_t vmKLMN = vcltq_f32(vxKLMN, vmovq_n_f32(0.0f));
203
204 vf0123 = vbslq_f32(vm0123, vf0123, vsubq_f32(vone, vf0123));
205 vf4567 = vbslq_f32(vm4567, vf4567, vsubq_f32(vone, vf4567));
206 vf89AB = vbslq_f32(vm89AB, vf89AB, vsubq_f32(vone, vf89AB));
207 vfCDEF = vbslq_f32(vmCDEF, vfCDEF, vsubq_f32(vone, vfCDEF));
208 vfGHIJ = vbslq_f32(vmGHIJ, vfGHIJ, vsubq_f32(vone, vfGHIJ));
209 vfKLMN = vbslq_f32(vmKLMN, vfKLMN, vsubq_f32(vone, vfKLMN));
210
211 vst1q_f32(y, vf0123); y += 4;
212 vst1q_f32(y, vf4567); y += 4;
213 vst1q_f32(y, vf89AB); y += 4;
214 vst1q_f32(y, vfCDEF); y += 4;
215 vst1q_f32(y, vfGHIJ); y += 4;
216 vst1q_f32(y, vfKLMN); y += 4;
217 }
218 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
219 const float32x4_t vx = vld1q_f32(x); x += 4;
220
221 // General structure of the algorithm:
222 // / exp(x) / (1 + exp(x)) if x <= 0
223 // f[x] :=
224 // \ 1 - f[-x] if x >= 0
225 //
226 // First we compute f[z] := exp(-z) / (1 + exp(-z)) where z = abs(x),
227 // then replace result with 1 - f[z] if x <= 0.
228 const float32x4_t vz = vabsq_f32(vx);
229
230 // Compute reduced argument n := round(-z / log(2)).
231 // We do it by adding a large number (magic bias), which cause rounding of result to an integer, then subtracing the
232 // large number back. The first addition is combined with multiplication by log2e into a single FMA instruction.
233 // The trick with adding large number is valid only within certain bounds (|x| <= 2**22), but thats ok, because
234 // inputs x outside of [-87.336544, 17.328678] (i.e. z outsize [0, 87.336544]) underflow or saturate sigmoidf(x)
235 // anyway. We fixup the result for such inputs at the very end of the algorithm.
236 float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vminus_log2e);
237
238 // Create a floating-point number s (scale) such that s == 2**n for inputs which don't cause underflow, i.e.
239 // -87.336544 <= -z <= 0.0, and -126 <= n <= 0 accordingly.
240 const float32x4_t vs = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn), 23));
241
242 // Subtract the large number back to get final n := round(-z / log(2)).
243 vn = vsubq_f32(vn, vmagic_bias);
244
245 // Compute reduced argument -t := -z - n * log(2) = -(z + n * log(2)).
246 float32x4_t vt = vfmaq_f32(vz, vn, vln2);
247
248 // Compute degree-5 polynomial approxiatmion for exp(-t) on [-log(2)/2, log(2)/2].
249 float32x4_t vp = vfmaq_f32(vc4, vc5, vt);
250 vp = vfmaq_f32(vc3, vp, vt);
251 vp = vfmaq_f32(vc2, vp, vt);
252 vp = vfmaq_f32(vc1, vp, vt);
253
254 // Reconstruct the exp(-z) value:
255 // e = s * (1 + t * (c1 + t * (c2 + t * (c3 + t * (c4 + t * c5)))))
256 // = s + (t * s) * (c1 + t * (c2 + t * (c3 + t * (c4 + t * c5))))
257 // = s + (t * s) * p
258 vt = vmulq_f32(vt, vs);
259 float32x4_t ve = vfmaq_f32(vs, vp, vt);
260
261 // Denominator of the sigmoid fraction: 1.0 + exp(-z)
262 float32x4_t vd = vaddq_f32(ve, vone);
263
264 // Use Newton-Raphson method (2 iterations) to compute reciprocal of denominator.
265 // Note: 1 < d <= 2, because z >= 0.0 and 0 < exp(-z) <= 1.0.
266 // Thus the reciprocal of the denominator never overflows.
267 float32x4_t vr = vrecpeq_f32(vd);
268
269 vr = vfmaq_f32(vr, vr, vfmsq_f32(vone, vr, vd));
270
271 vr = vfmaq_f32(vr, vr, vfmsq_f32(vone, vr, vd));
272
273 // Reconstruct sigmoid(-z) = exp(-z) / (1.0 + exp(-z))
274 float32x4_t vf = vmulq_f32(ve, vr);
275
276 // For inputs below denormal cutoff, replace output with +0.0f.
277 // Note that for NaN inputs, comparison result is false, and outputs are left unchanged.
278 vf = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf), vcagtq_f32(vx, vdenorm_cutoff)));
279
280 // Reconstruct sigmoid(x) = x < 0 ? sigmoid(-z) : 1.0 - sigmoid(-z)
281 const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f));
282 vf = vbslq_f32(vm, vf, vsubq_f32(vone, vf));
283
284 vst1q_f32(y, vf); y += 4;
285 }
286 if XNN_UNLIKELY(n != 0) {
287 const float32x4_t vx = vld1q_f32(x);
288
289 // General structure of the algorithm:
290 // / exp(x) / (1 + exp(x)) if x <= 0
291 // f[x] :=
292 // \ 1 - f[-x] if x >= 0
293 //
294 // First we compute f[z] := exp(-z) / (1 + exp(-z)) where z = abs(x),
295 // then replace result with 1 - f[z] if x <= 0.
296 const float32x4_t vz = vabsq_f32(vx);
297
298 // Compute reduced argument n := round(-z / log(2)).
299 // We do it by adding a large number (magic bias), which cause rounding of result to an integer, then subtracing the
300 // large number back. The first addition is combined with multiplication by log2e into a single FMA instruction.
301 // The trick with adding large number is valid only within certain bounds (|x| <= 2**22), but thats ok, because
302 // inputs x outside of [-87.336544, 17.328678] (i.e. z outsize [0, 87.336544]) underflow or saturate sigmoidf(x)
303 // anyway. We fixup the result for such inputs at the very end of the algorithm.
304 float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vminus_log2e);
305
306 // Create a floating-point number s (scale) such that s == 2**n for inputs which don't cause underflow, i.e.
307 // -87.336544 <= -z <= 0.0, and -126 <= n <= 0 accordingly.
308 const float32x4_t vs = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn), 23));
309
310 // Subtract the large number back to get final n := round(-z / log(2)).
311 vn = vsubq_f32(vn, vmagic_bias);
312
313 // Compute reduced argument -t := -z - n * log(2) = -(z + n * log(2)).
314 float32x4_t vt = vfmaq_f32(vz, vn, vln2);
315
316 // Compute degree-5 polynomial approxiatmion for exp(-t) on [-log(2)/2, log(2)/2].
317 float32x4_t vp = vfmaq_f32(vc4, vc5, vt);
318 vp = vfmaq_f32(vc3, vp, vt);
319 vp = vfmaq_f32(vc2, vp, vt);
320 vp = vfmaq_f32(vc1, vp, vt);
321
322 // Reconstruct the exp(-z) value:
323 // e = s * (1 + t * (c1 + t * (c2 + t * (c3 + t * (c4 + t * c5)))))
324 // = s + (t * s) * (c1 + t * (c2 + t * (c3 + t * (c4 + t * c5))))
325 // = s + (t * s) * p
326 vt = vmulq_f32(vt, vs);
327 float32x4_t ve = vfmaq_f32(vs, vp, vt);
328
329 // Denominator of the sigmoid fraction: 1.0 + exp(-z)
330 float32x4_t vd = vaddq_f32(ve, vone);
331
332 // Use Newton-Raphson method (2 iterations) to compute reciprocal of denominator.
333 // Note: 1 < d <= 2, because z >= 0.0 and 0 < exp(-z) <= 1.0.
334 // Thus the reciprocal of the denominator never overflows.
335 float32x4_t vr = vrecpeq_f32(vd);
336
337 vr = vfmaq_f32(vr, vr, vfmsq_f32(vone, vr, vd));
338
339 vr = vfmaq_f32(vr, vr, vfmsq_f32(vone, vr, vd));
340
341 // Reconstruct sigmoid(-z) = exp(-z) / (1.0 + exp(-z))
342 float32x4_t vf = vmulq_f32(ve, vr);
343
344 // For inputs below denormal cutoff, replace output with +0.0f.
345 // Note that for NaN inputs, comparison result is false, and outputs are left unchanged.
346 vf = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf), vcagtq_f32(vx, vdenorm_cutoff)));
347
348 // Reconstruct sigmoid(x) = x < 0 ? sigmoid(-z) : 1.0 - sigmoid(-z)
349 const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f));
350 vf = vbslq_f32(vm, vf, vsubq_f32(vone, vf));
351
352 float32x2_t vf_lo = vget_low_f32(vf);
353 if (n & (2 * sizeof(float))) {
354 vst1_f32(y, vf_lo); y += 2;
355 vf_lo = vget_high_f32(vf);
356 }
357 if (n & (1 * sizeof(float))) {
358 vst1_lane_f32(y, vf_lo, 0);
359 }
360 }
361 }
362