• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_nr1recps1fma_x4(size_t n,const float * x,float * y,const void * params)18 void xnn_f32_sigmoid_ukernel__neonfma_rr1_p5_nr1recps1fma_x4(
19     size_t n,
20     const float* x,
21     float* y,
22     const void* params) XNN_DISABLE_TSAN
23 {
24   assert(n % sizeof(float) == 0);
25 
26   const float32x4_t vmagic_bias = vmovq_n_f32(0x1.8000FEp23f);
27   const float32x4_t vminus_log2e = vmovq_n_f32(-0x1.715476p+0f);
28   const float32x4_t vln2 = vmovq_n_f32(0x1.62E43p-1f);
29   const float32x4_t vc5 = vmovq_n_f32(-0x1.0F9F9Cp-7f);
30   const float32x4_t vc4 = vmovq_n_f32(0x1.573A1Ap-5f);
31   const float32x4_t vc3 = vmovq_n_f32(-0x1.555A80p-3f);
32   const float32x4_t vc2 = vmovq_n_f32(0x1.FFFDC6p-2f);
33   const float32x4_t vc1 = vmovq_n_f32(-0x1.FFFFF6p-1f);
34   const float32x4_t vone = vmovq_n_f32(1.0f);
35   const float32x4_t vdenorm_cutoff = vmovq_n_f32(-0x1.5D589Ep+6f);
36 
37   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
38     const float32x4_t vx = vld1q_f32(x); x += 4;
39 
40     const float32x4_t vz = vabsq_f32(vx);
41 
42     float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vminus_log2e);
43     const float32x4_t vs = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn), 23));
44     vn = vsubq_f32(vn, vmagic_bias);
45     float32x4_t vt = vfmaq_f32(vz, vn, vln2);
46 
47     float32x4_t vp = vfmaq_f32(vc4, vc5, vt);
48     vp = vfmaq_f32(vc3, vp, vt);
49     vp = vfmaq_f32(vc2, vp, vt);
50     vp = vfmaq_f32(vc1, vp, vt);
51 
52     vt = vmulq_f32(vt, vs);
53     const float32x4_t ve = vfmaq_f32(vs, vp, vt);
54     const float32x4_t vd = vaddq_f32(ve, vone);
55 
56     float32x4_t vr = vrecpeq_f32(vd);
57     vr = vmulq_f32(vr, vrecpsq_f32(vr, vd));
58     vr = vfmaq_f32(vr, vr, vfmsq_f32(vone, vr, vd));
59 
60     float32x4_t vf = vmulq_f32(ve, vr);
61     vf = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf), vcagtq_f32(vx, vdenorm_cutoff)));
62     const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f));
63     vf = vbslq_f32(vm, vf, vsubq_f32(vone, vf));
64 
65     vst1q_f32(y, vf); y += 4;
66   }
67   if XNN_UNLIKELY(n != 0) {
68     const float32x4_t vx = vld1q_f32(x);
69 
70     const float32x4_t vz = vabsq_f32(vx);
71 
72     float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vminus_log2e);
73     const float32x4_t vs = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn), 23));
74     vn = vsubq_f32(vn, vmagic_bias);
75     float32x4_t vt = vfmaq_f32(vz, vn, vln2);
76 
77     float32x4_t vp = vfmaq_f32(vc4, vc5, vt);
78     vp = vfmaq_f32(vc3, vp, vt);
79     vp = vfmaq_f32(vc2, vp, vt);
80     vp = vfmaq_f32(vc1, vp, vt);
81 
82     vt = vmulq_f32(vt, vs);
83     const float32x4_t ve = vfmaq_f32(vs, vp, vt);
84     const float32x4_t vd = vaddq_f32(ve, vone);
85 
86     float32x4_t vr = vrecpeq_f32(vd);
87     vr = vmulq_f32(vr, vrecpsq_f32(vr, vd));
88     vr = vfmaq_f32(vr, vr, vfmsq_f32(vone, vr, vd));
89 
90     float32x4_t vf = vmulq_f32(ve, vr);
91     vf = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf), vcagtq_f32(vx, vdenorm_cutoff)));
92     const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f));
93     vf = vbslq_f32(vm, vf, vsubq_f32(vone, vf));
94 
95     float32x2_t vf_lo = vget_low_f32(vf);
96     if (n & (2 * sizeof(float))) {
97       vst1_f32(y, vf_lo); y += 2;
98       vf_lo = vget_high_f32(vf);
99     }
100     if (n & (1 * sizeof(float))) {
101       vst1_lane_f32(y, vf_lo, 0);
102     }
103   }
104 }
105