• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-sigmoid/sse-p5-div.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 <smmintrin.h>
13 
14 #include <xnnpack/common.h>
15 #include <xnnpack/vunary.h>
16 
17 
xnn_f32_sigmoid_ukernel__sse41_p5_div_x4(size_t n,const float * x,float * y,const void * params)18 void xnn_f32_sigmoid_ukernel__sse41_p5_div_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 __m128 vsign_mask = _mm_set1_ps(-0.0f);
27   const __m128 vmagic_bias = _mm_set1_ps(0x1.8000FEp23f);
28   const __m128 vlog2e = _mm_set1_ps(0x1.715476p0f);
29   const __m128 vminus_ln2_hi = _mm_set1_ps(-0x1.62E400p-1f);
30   const __m128 vminus_ln2_lo = _mm_set1_ps(-0x1.7F7D1Cp-20f);
31   const __m128 vc5 = _mm_set1_ps(0x1.0F9F9Cp-7f);
32   const __m128 vc4 = _mm_set1_ps(0x1.573A1Ap-5f);
33   const __m128 vc3 = _mm_set1_ps(0x1.555A80p-3f);
34   const __m128 vc2 = _mm_set1_ps(0x1.FFFDC6p-2f);
35   const __m128 vc1 = _mm_set1_ps(0x1.FFFFF6p-1f);
36   const __m128 vone = _mm_set1_ps(1.0f);
37   const __m128 vdenorm_cutoff = _mm_set1_ps(-0x1.5D589Ep+6f);
38 
39   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
40     const __m128 vx = _mm_loadu_ps(x);
41 
42     const __m128 vz = _mm_or_ps(vx, vsign_mask);
43 
44     __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
45     const __m128 vs = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn), 23));
46     vn = _mm_sub_ps(vn, vmagic_bias);
47 
48     __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
49     vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
50 
51     __m128 vp = _mm_add_ps(_mm_mul_ps(vc5, vt), vc4);
52     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc3);
53     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc2);
54     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc1);
55 
56     vt = _mm_mul_ps(vt, vs);
57     __m128 ve = _mm_add_ps(_mm_mul_ps(vt, vp), vs);
58 
59     __m128 vd = _mm_add_ps(ve, vone);
60     __m128 vf = _mm_div_ps(ve, vd);
61 
62     vf = _mm_andnot_ps(_mm_cmplt_ps(vz, vdenorm_cutoff), vf);
63     vf = _mm_blendv_ps(_mm_sub_ps(vone, vf), vf, vx);
64 
65     _mm_storeu_ps(y, vf);
66 
67     x += 4;
68     y += 4;
69   }
70   if XNN_UNLIKELY(n != 0) {
71     const __m128 vx = _mm_loadu_ps(x);
72 
73     const __m128 vz = _mm_or_ps(vx, vsign_mask);
74 
75     __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
76     const __m128 vs = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn), 23));
77     vn = _mm_sub_ps(vn, vmagic_bias);
78 
79     __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
80     vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
81 
82     __m128 vp = _mm_add_ps(_mm_mul_ps(vc5, vt), vc4);
83     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc3);
84     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc2);
85     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc1);
86 
87     vt = _mm_mul_ps(vt, vs);
88     __m128 ve = _mm_add_ps(_mm_mul_ps(vt, vp), vs);
89 
90     __m128 vd = _mm_add_ps(ve, vone);
91     __m128 vf = _mm_div_ps(ve, vd);
92 
93     vf = _mm_andnot_ps(_mm_cmplt_ps(vz, vdenorm_cutoff), vf);
94     vf = _mm_blendv_ps(_mm_sub_ps(vone, vf), vf, vx);
95 
96     if (n & (2 * sizeof(float))) {
97       _mm_storel_pi((__m64*) y, vf);
98       vf = _mm_movehl_ps(vf, vf);
99       y += 2;
100     }
101     if (n & (1 * sizeof(float))) {
102       _mm_store_ss(y, vf);
103     }
104   }
105 }
106