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