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