1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vsigmoid/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_vsigmoid_ukernel__neonfma_rr1_p5_div_x8(size_t n,const float * x,float * y,const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_vsigmoid_ukernel__neonfma_rr1_p5_div_x8(
19 size_t n,
20 const float* x,
21 float* y,
22 const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 assert(n % sizeof(float) == 0);
25
26 const float32x4_t vmagic_bias = vld1q_dup_f32(¶ms->neonfma_rr1_p5.magic_bias);
27 const float32x4_t vminus_log2e = vld1q_dup_f32(¶ms->neonfma_rr1_p5.minus_log2e);
28 const float32x4_t vln2 = vld1q_dup_f32(¶ms->neonfma_rr1_p5.ln2);
29 const float32x4_t vc5 = vld1q_dup_f32(¶ms->neonfma_rr1_p5.c5);
30 const float32x4_t vc4 = vld1q_dup_f32(¶ms->neonfma_rr1_p5.c4);
31 const float32x4_t vc3 = vld1q_dup_f32(¶ms->neonfma_rr1_p5.c3);
32 const float32x4_t vc2 = vld1q_dup_f32(¶ms->neonfma_rr1_p5.c2);
33 const float32x4_t vc1 = vld1q_dup_f32(¶ms->neonfma_rr1_p5.c1);
34 const float32x4_t vone = vmovq_n_f32(1.0f);
35 const float32x4_t vdenorm_cutoff = vld1q_dup_f32(¶ms->neonfma_rr1_p5.denorm_cutoff);
36
37 for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
38 const float32x4_t vx0123 = vld1q_f32(x); x += 4;
39 const float32x4_t vx4567 = vld1q_f32(x); x += 4;
40
41 const float32x4_t vz0123 = vabsq_f32(vx0123);
42 const float32x4_t vz4567 = vabsq_f32(vx4567);
43
44 float32x4_t vn0123 = vfmaq_f32(vmagic_bias, vz0123, vminus_log2e);
45 float32x4_t vn4567 = vfmaq_f32(vmagic_bias, vz4567, vminus_log2e);
46
47 const float32x4_t vs0123 = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn0123), 23));
48 const float32x4_t vs4567 = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn4567), 23));
49
50 vn0123 = vsubq_f32(vn0123, vmagic_bias);
51 vn4567 = vsubq_f32(vn4567, vmagic_bias);
52
53 float32x4_t vt0123 = vfmaq_f32(vz0123, vn0123, vln2);
54 float32x4_t vt4567 = vfmaq_f32(vz4567, vn4567, vln2);
55
56 float32x4_t vp0123 = vfmaq_f32(vc4, vc5, vt0123);
57 float32x4_t vp4567 = vfmaq_f32(vc4, vc5, vt4567);
58
59 vp0123 = vfmaq_f32(vc3, vp0123, vt0123);
60 vp4567 = vfmaq_f32(vc3, vp4567, vt4567);
61
62 vp0123 = vfmaq_f32(vc2, vp0123, vt0123);
63 vp4567 = vfmaq_f32(vc2, vp4567, vt4567);
64
65 vp0123 = vfmaq_f32(vc1, vp0123, vt0123);
66 vp4567 = vfmaq_f32(vc1, vp4567, vt4567);
67
68 vt0123 = vmulq_f32(vt0123, vs0123);
69 vt4567 = vmulq_f32(vt4567, vs4567);
70
71 const float32x4_t ve0123 = vfmaq_f32(vs0123, vp0123, vt0123);
72 const float32x4_t ve4567 = vfmaq_f32(vs4567, vp4567, vt4567);
73
74 const float32x4_t vd0123 = vaddq_f32(ve0123, vone);
75 const float32x4_t vd4567 = vaddq_f32(ve4567, vone);
76
77 float32x4_t vf0123 = vdivq_f32(ve0123, vd0123);
78 float32x4_t vf4567 = vdivq_f32(ve4567, vd4567);
79
80 vf0123 = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf0123), vcagtq_f32(vx0123, vdenorm_cutoff)));
81 vf4567 = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf4567), vcagtq_f32(vx4567, vdenorm_cutoff)));
82
83 const uint32x4_t vm0123 = vcltq_f32(vx0123, vmovq_n_f32(0.0f));
84 const uint32x4_t vm4567 = vcltq_f32(vx4567, vmovq_n_f32(0.0f));
85
86 vf0123 = vbslq_f32(vm0123, vf0123, vsubq_f32(vone, vf0123));
87 vf4567 = vbslq_f32(vm4567, vf4567, vsubq_f32(vone, vf4567));
88
89 vst1q_f32(y, vf0123); y += 4;
90 vst1q_f32(y, vf4567); y += 4;
91 }
92 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
93 const float32x4_t vx = vld1q_f32(x); x += 4;
94
95 const float32x4_t vz = vabsq_f32(vx);
96
97 float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vminus_log2e);
98 const float32x4_t vs = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn), 23));
99 vn = vsubq_f32(vn, vmagic_bias);
100 float32x4_t vt = vfmaq_f32(vz, vn, vln2);
101
102 float32x4_t vp = vfmaq_f32(vc4, vc5, vt);
103 vp = vfmaq_f32(vc3, vp, vt);
104 vp = vfmaq_f32(vc2, vp, vt);
105 vp = vfmaq_f32(vc1, vp, vt);
106
107 vt = vmulq_f32(vt, vs);
108 const float32x4_t ve = vfmaq_f32(vs, vp, vt);
109 const float32x4_t vd = vaddq_f32(ve, vone);
110
111 float32x4_t vf = vdivq_f32(ve, vd);
112 vf = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf), vcagtq_f32(vx, vdenorm_cutoff)));
113 const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f));
114 vf = vbslq_f32(vm, vf, vsubq_f32(vone, vf));
115
116 vst1q_f32(y, vf); y += 4;
117 }
118 if XNN_UNLIKELY(n != 0) {
119 const float32x4_t vx = vld1q_f32(x);
120
121 const float32x4_t vz = vabsq_f32(vx);
122
123 float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vminus_log2e);
124 const float32x4_t vs = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn), 23));
125 vn = vsubq_f32(vn, vmagic_bias);
126 float32x4_t vt = vfmaq_f32(vz, vn, vln2);
127
128 float32x4_t vp = vfmaq_f32(vc4, vc5, vt);
129 vp = vfmaq_f32(vc3, vp, vt);
130 vp = vfmaq_f32(vc2, vp, vt);
131 vp = vfmaq_f32(vc1, vp, vt);
132
133 vt = vmulq_f32(vt, vs);
134 const float32x4_t ve = vfmaq_f32(vs, vp, vt);
135 const float32x4_t vd = vaddq_f32(ve, vone);
136
137 float32x4_t vf = vdivq_f32(ve, vd);
138 vf = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf), vcagtq_f32(vx, vdenorm_cutoff)));
139 const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f));
140 vf = vbslq_f32(vm, vf, vsubq_f32(vone, vf));
141
142 float32x2_t vf_lo = vget_low_f32(vf);
143 if (n & (2 * sizeof(float))) {
144 vst1_f32(y, vf_lo); y += 2;
145 vf_lo = vget_high_f32(vf);
146 }
147 if (n & (1 * sizeof(float))) {
148 vst1_lane_f32(y, vf_lo, 0);
149 }
150 }
151 }
152