1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vsigmoid/neon-lut2048-p1.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
18 extern XNN_INTERNAL const float xnn_table_exp2minus_k_over_2048[2048];
19
xnn_f32_vsigmoid_ukernel__neonfma_rr1_lut2048_p1_nr1recps1fma_x4(size_t n,const float * x,float * y,const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS (1)])20 void xnn_f32_vsigmoid_ukernel__neonfma_rr1_lut2048_p1_nr1recps1fma_x4(
21 size_t n,
22 const float* x,
23 float* y,
24 const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
25 {
26 assert(n % sizeof(float) == 0);
27
28 const float32x4_t vmagic_bias = vld1q_dup_f32(¶ms->neonfma_rr1_lut2048_p1.magic_bias);
29 const float32x4_t vminus_log2e = vld1q_dup_f32(¶ms->neonfma_rr1_lut2048_p1.minus_log2e);
30 const int32x4_t vindex_mask = vmovq_n_s32(INT32_C(0x7FF));
31 const float32x4_t vln2 = vld1q_dup_f32(¶ms->neonfma_rr1_lut2048_p1.ln2);
32 const float32x4_t vc1 = vld1q_dup_f32(¶ms->neonfma_rr1_lut2048_p1.c1);
33 const float32x4_t vone = vmovq_n_f32(1.0f);
34 const float32x4_t vdenorm_cutoff = vld1q_dup_f32(¶ms->neonfma_rr1_lut2048_p1.denorm_cutoff);
35
36 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
37 const float32x4_t vx = vld1q_f32(x); x += 4;
38
39 const float32x4_t vz = vabsq_f32(vx);
40
41 float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vminus_log2e);
42 const int32x4_t ve = vshlq_n_s32(vreinterpretq_s32_f32(vn), 12);
43
44 const uint64x2_t vidx = vreinterpretq_u64_s32(vandq_s32(vreinterpretq_s32_f32(vn), vindex_mask));
45 const uint64_t vidx_lo = vgetq_lane_u64(vidx, 0);
46 const uint64_t vidx_hi = vgetq_lane_u64(vidx, 1);
47 float32x2_t vl_lo = vld1_dup_f32(&xnn_table_exp2minus_k_over_2048[(uint32_t) vidx_lo]);
48 float32x2_t vl_hi = vld1_dup_f32(&xnn_table_exp2minus_k_over_2048[(uint32_t) vidx_hi]);
49 vl_lo = vld1_lane_f32(&xnn_table_exp2minus_k_over_2048[(uint32_t) (vidx_lo >> 32)], vl_lo, 1);
50 vl_hi = vld1_lane_f32(&xnn_table_exp2minus_k_over_2048[(uint32_t) (vidx_hi >> 32)], vl_hi, 1);
51 const float32x4_t vl = vcombine_f32(vl_lo, vl_hi);
52
53 const float32x4_t vs = vreinterpretq_f32_s32(vaddq_s32(vreinterpretq_s32_f32(vl), ve));
54 vn = vsubq_f32(vn, vmagic_bias);
55 float32x4_t vt = vfmaq_f32(vz, vn, vln2);
56
57 const float32x4_t vp = vmulq_f32(vt, vc1);
58
59 const float32x4_t vy = vfmaq_f32(vs, vs, vp);
60 const float32x4_t vd = vaddq_f32(vy, vone);
61
62 float32x4_t vr = vrecpeq_f32(vd);
63 vr = vmulq_f32(vr, vrecpsq_f32(vr, vd));
64 vr = vfmaq_f32(vr, vr, vfmsq_f32(vone, vr, vd));
65
66 float32x4_t vf = vmulq_f32(vy, vr);
67 vf = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf), vcagtq_f32(vx, vdenorm_cutoff)));
68 const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f));
69 vf = vbslq_f32(vm, vf, vsubq_f32(vone, vf));
70
71 vst1q_f32(y, vf); y += 4;
72 }
73 if XNN_UNLIKELY(n != 0) {
74 const float32x4_t vx = vld1q_f32(x);
75
76 const float32x4_t vz = vabsq_f32(vx);
77
78 float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vminus_log2e);
79 const int32x4_t ve = vshlq_n_s32(vreinterpretq_s32_f32(vn), 12);
80
81 const uint64x2_t vidx = vreinterpretq_u64_s32(vandq_s32(vreinterpretq_s32_f32(vn), vindex_mask));
82 const uint64_t vidx_lo = vgetq_lane_u64(vidx, 0);
83 const uint64_t vidx_hi = vgetq_lane_u64(vidx, 1);
84 float32x2_t vl_lo = vld1_dup_f32(&xnn_table_exp2minus_k_over_2048[(uint32_t) vidx_lo]);
85 float32x2_t vl_hi = vld1_dup_f32(&xnn_table_exp2minus_k_over_2048[(uint32_t) vidx_hi]);
86 vl_lo = vld1_lane_f32(&xnn_table_exp2minus_k_over_2048[(uint32_t) (vidx_lo >> 32)], vl_lo, 1);
87 vl_hi = vld1_lane_f32(&xnn_table_exp2minus_k_over_2048[(uint32_t) (vidx_hi >> 32)], vl_hi, 1);
88 const float32x4_t vl = vcombine_f32(vl_lo, vl_hi);
89
90 const float32x4_t vs = vreinterpretq_f32_s32(vaddq_s32(vreinterpretq_s32_f32(vl), ve));
91 vn = vsubq_f32(vn, vmagic_bias);
92 float32x4_t vt = vfmaq_f32(vz, vn, vln2);
93
94 const float32x4_t vp = vmulq_f32(vt, vc1);
95
96 const float32x4_t vy = vfmaq_f32(vs, vs, vp);
97 const float32x4_t vd = vaddq_f32(vy, vone);
98
99 float32x4_t vr = vrecpeq_f32(vd);
100 vr = vmulq_f32(vr, vrecpsq_f32(vr, vd));
101 vr = vfmaq_f32(vr, vr, vfmsq_f32(vone, vr, vd));
102
103 float32x4_t vf = vmulq_f32(vy, vr);
104 vf = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf), vcagtq_f32(vx, vdenorm_cutoff)));
105 const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f));
106 vf = vbslq_f32(vm, vf, vsubq_f32(vone, vf));
107
108 float32x2_t vf_lo = vget_low_f32(vf);
109 if (n & (2 * sizeof(float))) {
110 vst1_f32(y, vf_lo); y += 2;
111 vf_lo = vget_high_f32(vf);
112 }
113 if (n & (1 * sizeof(float))) {
114 vst1_lane_f32(y, vf_lo, 0);
115 }
116 }
117 }
118