• 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_x12(size_t n,const float * x,float * y,const void * params)18 void xnn_f32_sigmoid_ukernel__sse41_p5_div_x12(
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 >= 12 * sizeof(float); n -= 12 * sizeof(float)) {
40     const __m128 vx0123 = _mm_loadu_ps(x);
41     const __m128 vx4567 = _mm_loadu_ps(x + 4);
42     const __m128 vx89AB = _mm_loadu_ps(x + 8);
43 
44     const __m128 vz0123 = _mm_or_ps(vx0123, vsign_mask);
45     const __m128 vz4567 = _mm_or_ps(vx4567, vsign_mask);
46     const __m128 vz89AB = _mm_or_ps(vx89AB, vsign_mask);
47 
48     __m128 vn0123 = _mm_add_ps(_mm_mul_ps(vz0123, vlog2e), vmagic_bias);
49     __m128 vn4567 = _mm_add_ps(_mm_mul_ps(vz4567, vlog2e), vmagic_bias);
50     __m128 vn89AB = _mm_add_ps(_mm_mul_ps(vz89AB, vlog2e), vmagic_bias);
51 
52     const __m128 vs0123 = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn0123), 23));
53     const __m128 vs4567 = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn4567), 23));
54     const __m128 vs89AB = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn89AB), 23));
55 
56     vn0123 = _mm_sub_ps(vn0123, vmagic_bias);
57     vn4567 = _mm_sub_ps(vn4567, vmagic_bias);
58     vn89AB = _mm_sub_ps(vn89AB, vmagic_bias);
59 
60     __m128 vt0123 = _mm_add_ps(_mm_mul_ps(vn0123, vminus_ln2_hi), vz0123);
61     __m128 vt4567 = _mm_add_ps(_mm_mul_ps(vn4567, vminus_ln2_hi), vz4567);
62     __m128 vt89AB = _mm_add_ps(_mm_mul_ps(vn89AB, vminus_ln2_hi), vz89AB);
63 
64     vt0123 = _mm_add_ps(_mm_mul_ps(vn0123, vminus_ln2_lo), vt0123);
65     vt4567 = _mm_add_ps(_mm_mul_ps(vn4567, vminus_ln2_lo), vt4567);
66     vt89AB = _mm_add_ps(_mm_mul_ps(vn89AB, vminus_ln2_lo), vt89AB);
67 
68     __m128 vp0123 = _mm_add_ps(_mm_mul_ps(vc5, vt0123), vc4);
69     __m128 vp4567 = _mm_add_ps(_mm_mul_ps(vc5, vt4567), vc4);
70     __m128 vp89AB = _mm_add_ps(_mm_mul_ps(vc5, vt89AB), vc4);
71 
72     vp0123 = _mm_add_ps(_mm_mul_ps(vp0123, vt0123), vc3);
73     vp4567 = _mm_add_ps(_mm_mul_ps(vp4567, vt4567), vc3);
74     vp89AB = _mm_add_ps(_mm_mul_ps(vp89AB, vt89AB), vc3);
75 
76     vp0123 = _mm_add_ps(_mm_mul_ps(vp0123, vt0123), vc2);
77     vp4567 = _mm_add_ps(_mm_mul_ps(vp4567, vt4567), vc2);
78     vp89AB = _mm_add_ps(_mm_mul_ps(vp89AB, vt89AB), vc2);
79 
80     vp0123 = _mm_add_ps(_mm_mul_ps(vp0123, vt0123), vc1);
81     vp4567 = _mm_add_ps(_mm_mul_ps(vp4567, vt4567), vc1);
82     vp89AB = _mm_add_ps(_mm_mul_ps(vp89AB, vt89AB), vc1);
83 
84     vt0123 = _mm_mul_ps(vt0123, vs0123);
85     vt4567 = _mm_mul_ps(vt4567, vs4567);
86     vt89AB = _mm_mul_ps(vt89AB, vs89AB);
87 
88     __m128 ve0123 = _mm_add_ps(_mm_mul_ps(vt0123, vp0123), vs0123);
89     __m128 ve4567 = _mm_add_ps(_mm_mul_ps(vt4567, vp4567), vs4567);
90     __m128 ve89AB = _mm_add_ps(_mm_mul_ps(vt89AB, vp89AB), vs89AB);
91 
92     __m128 vd0123 = _mm_add_ps(ve0123, vone);
93     __m128 vd4567 = _mm_add_ps(ve4567, vone);
94     __m128 vd89AB = _mm_add_ps(ve89AB, vone);
95 
96     __m128 vf0123 = _mm_div_ps(ve0123, vd0123);
97     __m128 vf4567 = _mm_div_ps(ve4567, vd4567);
98     __m128 vf89AB = _mm_div_ps(ve89AB, vd89AB);
99 
100     vf0123 = _mm_andnot_ps(_mm_cmplt_ps(vz0123, vdenorm_cutoff), vf0123);
101     vf4567 = _mm_andnot_ps(_mm_cmplt_ps(vz4567, vdenorm_cutoff), vf4567);
102     vf89AB = _mm_andnot_ps(_mm_cmplt_ps(vz89AB, vdenorm_cutoff), vf89AB);
103 
104     vf0123 = _mm_blendv_ps(_mm_sub_ps(vone, vf0123), vf0123, vx0123);
105     vf4567 = _mm_blendv_ps(_mm_sub_ps(vone, vf4567), vf4567, vx4567);
106     vf89AB = _mm_blendv_ps(_mm_sub_ps(vone, vf89AB), vf89AB, vx89AB);
107 
108     _mm_storeu_ps(y, vf0123);
109     _mm_storeu_ps(y + 4, vf4567);
110     _mm_storeu_ps(y + 8, vf89AB);
111 
112     x += 12;
113     y += 12;
114   }
115   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
116     const __m128 vx = _mm_loadu_ps(x);
117 
118     const __m128 vz = _mm_or_ps(vx, vsign_mask);
119 
120     __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
121     const __m128 vs = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn), 23));
122     vn = _mm_sub_ps(vn, vmagic_bias);
123 
124     __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
125     vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
126 
127     __m128 vp = _mm_add_ps(_mm_mul_ps(vc5, vt), vc4);
128     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc3);
129     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc2);
130     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc1);
131 
132     vt = _mm_mul_ps(vt, vs);
133     __m128 ve = _mm_add_ps(_mm_mul_ps(vt, vp), vs);
134 
135     __m128 vd = _mm_add_ps(ve, vone);
136     __m128 vf = _mm_div_ps(ve, vd);
137 
138     vf = _mm_andnot_ps(_mm_cmplt_ps(vz, vdenorm_cutoff), vf);
139     vf = _mm_blendv_ps(_mm_sub_ps(vone, vf), vf, vx);
140 
141     _mm_storeu_ps(y, vf);
142 
143     x += 4;
144     y += 4;
145   }
146   if XNN_UNLIKELY(n != 0) {
147     const __m128 vx = _mm_loadu_ps(x);
148 
149     const __m128 vz = _mm_or_ps(vx, vsign_mask);
150 
151     __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
152     const __m128 vs = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn), 23));
153     vn = _mm_sub_ps(vn, vmagic_bias);
154 
155     __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
156     vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
157 
158     __m128 vp = _mm_add_ps(_mm_mul_ps(vc5, vt), vc4);
159     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc3);
160     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc2);
161     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc1);
162 
163     vt = _mm_mul_ps(vt, vs);
164     __m128 ve = _mm_add_ps(_mm_mul_ps(vt, vp), vs);
165 
166     __m128 vd = _mm_add_ps(ve, vone);
167     __m128 vf = _mm_div_ps(ve, vd);
168 
169     vf = _mm_andnot_ps(_mm_cmplt_ps(vz, vdenorm_cutoff), vf);
170     vf = _mm_blendv_ps(_mm_sub_ps(vone, vf), vf, vx);
171 
172     if (n & (2 * sizeof(float))) {
173       _mm_storel_pi((__m64*) y, vf);
174       vf = _mm_movehl_ps(vf, vf);
175       y += 2;
176     }
177     if (n & (1 * sizeof(float))) {
178       _mm_store_ss(y, vf);
179     }
180   }
181 }
182