• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-velu/sse-rr2-lut16-p3.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2020 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 <emmintrin.h>
13 
14 #include <xnnpack/vunary.h>
15 #include <xnnpack/common.h>
16 
17 
18 extern XNN_INTERNAL const float xnn_table_exp2minus_k_over_16[16];
19 
xnn_f32_velu_ukernel__sse2_rr2_lut16_p3_x16(size_t n,const float * x,float * y,const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS (1)])20 void xnn_f32_velu_ukernel__sse2_rr2_lut16_p3_x16(
21     size_t n,
22     const float* x,
23     float* y,
24     const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
25 {
26   assert(n != 0);
27   assert(n % sizeof(float) == 0);
28   assert(x != NULL);
29   assert(y != NULL);
30 
31   const __m128 vprescale = _mm_load_ps(params->sse.prescale);
32   const __m128 valpha = _mm_load_ps(params->sse.alpha);
33   const __m128 vbeta = _mm_load_ps(params->sse.beta);
34 
35   const __m128 vsat_cutoff = _mm_set1_ps(-0x1.154246p+4f);
36   const __m128 vmagic_bias = _mm_set1_ps(0x1.800000p19f);
37   const __m128 vlog2e = _mm_set1_ps(0x1.715476p+0f);
38   const __m128i vindex_mask = _mm_set1_epi32(0xF);
39   const __m128 vminus_ln2_hi = _mm_set1_ps(-0x1.62E400p-1f);
40   const __m128 vminus_ln2_lo = _mm_set1_ps(-0x1.7F7D1Cp-20f);
41   const __m128 vc3 = _mm_set1_ps(0x1.55561Cp-3f);
42   const __m128 vc2 = _mm_set1_ps(0x1.0001ECp-1f);
43   const __m128 vone = _mm_set1_ps(1.0f);
44 
45   for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
46     __m128 vx0123 = _mm_loadu_ps(x);
47     __m128 vx4567 = _mm_loadu_ps(x + 4);
48     __m128 vx89AB = _mm_loadu_ps(x + 8);
49     __m128 vxCDEF = _mm_loadu_ps(x + 12);
50     x += 16;
51 
52     const __m128 vz0123 = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx0123, vprescale));
53     const __m128 vz4567 = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx4567, vprescale));
54     const __m128 vz89AB = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx89AB, vprescale));
55     const __m128 vzCDEF = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vxCDEF, vprescale));
56 
57     __m128 vn0123 = _mm_add_ps(_mm_mul_ps(vz0123, vlog2e), vmagic_bias);
58     __m128 vn4567 = _mm_add_ps(_mm_mul_ps(vz4567, vlog2e), vmagic_bias);
59     __m128 vn89AB = _mm_add_ps(_mm_mul_ps(vz89AB, vlog2e), vmagic_bias);
60     __m128 vnCDEF = _mm_add_ps(_mm_mul_ps(vzCDEF, vlog2e), vmagic_bias);
61 
62     const __m128i vidx0123 = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vn0123), vindex_mask), 2);
63     const __m128i ven0123 = _mm_slli_epi32(_mm_castps_si128(vn0123), 19);
64     const __m128i vidx4567 = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vn4567), vindex_mask), 2);
65     const __m128i ven4567 = _mm_slli_epi32(_mm_castps_si128(vn4567), 19);
66     const __m128i vidx89AB = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vn89AB), vindex_mask), 2);
67     const __m128i ven89AB = _mm_slli_epi32(_mm_castps_si128(vn89AB), 19);
68     const __m128i vidxCDEF = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vnCDEF), vindex_mask), 2);
69     const __m128i venCDEF = _mm_slli_epi32(_mm_castps_si128(vnCDEF), 19);
70 
71     #if XNN_ARCH_X86_64
72       const uint64_t vidx01 = (uint64_t) _mm_cvtsi128_si64(vidx0123);
73       const uint64_t vidx23 = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidx0123, vidx0123));
74       const __m128i vl0   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx01)));
75       const __m128i vl2 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx23)));
76       const __m128i vl1 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx01 >> 32))));
77       const __m128i vl01 = _mm_unpacklo_epi32(vl0, vl1);
78       const __m128i vl3 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx23 >> 32))));
79       const __m128i vl23 = _mm_unpacklo_epi32(vl2, vl3);
80       const __m128i vl0123 = _mm_unpacklo_epi64(vl01, vl23);
81       const uint64_t vidx45 = (uint64_t) _mm_cvtsi128_si64(vidx4567);
82       const uint64_t vidx67 = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidx4567, vidx4567));
83       const __m128i vl4   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx45)));
84       const __m128i vl6 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx67)));
85       const __m128i vl5 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx45 >> 32))));
86       const __m128i vl45 = _mm_unpacklo_epi32(vl4, vl5);
87       const __m128i vl7 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx67 >> 32))));
88       const __m128i vl67 = _mm_unpacklo_epi32(vl6, vl7);
89       const __m128i vl4567 = _mm_unpacklo_epi64(vl45, vl67);
90       const uint64_t vidx89 = (uint64_t) _mm_cvtsi128_si64(vidx89AB);
91       const uint64_t vidxAB = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidx89AB, vidx89AB));
92       const __m128i vl8   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx89)));
93       const __m128i vlA = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxAB)));
94       const __m128i vl9 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx89 >> 32))));
95       const __m128i vl89 = _mm_unpacklo_epi32(vl8, vl9);
96       const __m128i vlB = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxAB >> 32))));
97       const __m128i vlAB = _mm_unpacklo_epi32(vlA, vlB);
98       const __m128i vl89AB = _mm_unpacklo_epi64(vl89, vlAB);
99       const uint64_t vidxCD = (uint64_t) _mm_cvtsi128_si64(vidxCDEF);
100       const uint64_t vidxEF = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidxCDEF, vidxCDEF));
101       const __m128i vlC   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxCD)));
102       const __m128i vlE = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxEF)));
103       const __m128i vlD = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxCD >> 32))));
104       const __m128i vlCD = _mm_unpacklo_epi32(vlC, vlD);
105       const __m128i vlF = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxEF >> 32))));
106       const __m128i vlEF = _mm_unpacklo_epi32(vlE, vlF);
107       const __m128i vlCDEF = _mm_unpacklo_epi64(vlCD, vlEF);
108     #else  // !XNN_ARCH_X86_64
109       const uint32_t vidx0 = (uint32_t) _mm_cvtsi128_si32(vidx0123);
110       const uint32_t vidx1 = (uint32_t) _mm_extract_epi16(vidx0123, 2);
111       const uint32_t vidx2 = (uint32_t) _mm_extract_epi16(vidx0123, 4);
112       const uint32_t vidx3 = (uint32_t) _mm_extract_epi16(vidx0123, 6);
113       const __m128i vl0   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx0)));
114       const __m128i vl2 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx2)));
115       const __m128i vl1 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx1)));
116       const __m128i vl01 = _mm_unpacklo_epi32(vl0, vl1);
117       const __m128i vl3 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx3)));
118       const __m128i vl23 = _mm_unpacklo_epi32(vl2, vl3);
119       const __m128i vl0123 = _mm_unpacklo_epi64(vl01, vl23);
120       const uint32_t vidx4 = (uint32_t) _mm_cvtsi128_si32(vidx4567);
121       const uint32_t vidx5 = (uint32_t) _mm_extract_epi16(vidx4567, 2);
122       const uint32_t vidx6 = (uint32_t) _mm_extract_epi16(vidx4567, 4);
123       const uint32_t vidx7 = (uint32_t) _mm_extract_epi16(vidx4567, 6);
124       const __m128i vl4   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx4)));
125       const __m128i vl6 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx6)));
126       const __m128i vl5 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx5)));
127       const __m128i vl45 = _mm_unpacklo_epi32(vl4, vl5);
128       const __m128i vl7 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx7)));
129       const __m128i vl67 = _mm_unpacklo_epi32(vl6, vl7);
130       const __m128i vl4567 = _mm_unpacklo_epi64(vl45, vl67);
131       const uint32_t vidx8 = (uint32_t) _mm_cvtsi128_si32(vidx89AB);
132       const uint32_t vidx9 = (uint32_t) _mm_extract_epi16(vidx89AB, 2);
133       const uint32_t vidxA = (uint32_t) _mm_extract_epi16(vidx89AB, 4);
134       const uint32_t vidxB = (uint32_t) _mm_extract_epi16(vidx89AB, 6);
135       const __m128i vl8   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx8)));
136       const __m128i vlA = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxA)));
137       const __m128i vl9 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx9)));
138       const __m128i vl89 = _mm_unpacklo_epi32(vl8, vl9);
139       const __m128i vlB = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxB)));
140       const __m128i vlAB = _mm_unpacklo_epi32(vlA, vlB);
141       const __m128i vl89AB = _mm_unpacklo_epi64(vl89, vlAB);
142       const uint32_t vidxC = (uint32_t) _mm_cvtsi128_si32(vidxCDEF);
143       const uint32_t vidxD = (uint32_t) _mm_extract_epi16(vidxCDEF, 2);
144       const uint32_t vidxE = (uint32_t) _mm_extract_epi16(vidxCDEF, 4);
145       const uint32_t vidxF = (uint32_t) _mm_extract_epi16(vidxCDEF, 6);
146       const __m128i vlC   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxC)));
147       const __m128i vlE = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxE)));
148       const __m128i vlD = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxD)));
149       const __m128i vlCD = _mm_unpacklo_epi32(vlC, vlD);
150       const __m128i vlF = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxF)));
151       const __m128i vlEF = _mm_unpacklo_epi32(vlE, vlF);
152       const __m128i vlCDEF = _mm_unpacklo_epi64(vlCD, vlEF);
153     #endif  // XNN_ARCH_X86_64
154 
155     vn0123 = _mm_sub_ps(vn0123, vmagic_bias);
156     __m128 vs0123 = _mm_castsi128_ps(_mm_add_epi32(vl0123, ven0123));
157     vn4567 = _mm_sub_ps(vn4567, vmagic_bias);
158     __m128 vs4567 = _mm_castsi128_ps(_mm_add_epi32(vl4567, ven4567));
159     vn89AB = _mm_sub_ps(vn89AB, vmagic_bias);
160     __m128 vs89AB = _mm_castsi128_ps(_mm_add_epi32(vl89AB, ven89AB));
161     vnCDEF = _mm_sub_ps(vnCDEF, vmagic_bias);
162     __m128 vsCDEF = _mm_castsi128_ps(_mm_add_epi32(vlCDEF, venCDEF));
163 
164     __m128 vt0123 = _mm_add_ps(_mm_mul_ps(vn0123, vminus_ln2_hi), vz0123);
165     __m128 vt4567 = _mm_add_ps(_mm_mul_ps(vn4567, vminus_ln2_hi), vz4567);
166     __m128 vt89AB = _mm_add_ps(_mm_mul_ps(vn89AB, vminus_ln2_hi), vz89AB);
167     __m128 vtCDEF = _mm_add_ps(_mm_mul_ps(vnCDEF, vminus_ln2_hi), vzCDEF);
168 
169     vt0123 = _mm_add_ps(_mm_mul_ps(vn0123, vminus_ln2_lo), vt0123);
170     vt4567 = _mm_add_ps(_mm_mul_ps(vn4567, vminus_ln2_lo), vt4567);
171     vt89AB = _mm_add_ps(_mm_mul_ps(vn89AB, vminus_ln2_lo), vt89AB);
172     vtCDEF = _mm_add_ps(_mm_mul_ps(vnCDEF, vminus_ln2_lo), vtCDEF);
173 
174     __m128 vp0123 = _mm_add_ps(_mm_mul_ps(vc3, vt0123), vc2);
175     __m128 vp4567 = _mm_add_ps(_mm_mul_ps(vc3, vt4567), vc2);
176     __m128 vp89AB = _mm_add_ps(_mm_mul_ps(vc3, vt89AB), vc2);
177     __m128 vpCDEF = _mm_add_ps(_mm_mul_ps(vc3, vtCDEF), vc2);
178 
179     vp0123 = _mm_mul_ps(vp0123, vt0123);
180     vp4567 = _mm_mul_ps(vp4567, vt4567);
181     vp89AB = _mm_mul_ps(vp89AB, vt89AB);
182     vpCDEF = _mm_mul_ps(vpCDEF, vtCDEF);
183 
184     vt0123 = _mm_mul_ps(vt0123, vs0123);
185     vs0123 = _mm_sub_ps(vs0123, vone);
186     vt4567 = _mm_mul_ps(vt4567, vs4567);
187     vs4567 = _mm_sub_ps(vs4567, vone);
188     vt89AB = _mm_mul_ps(vt89AB, vs89AB);
189     vs89AB = _mm_sub_ps(vs89AB, vone);
190     vtCDEF = _mm_mul_ps(vtCDEF, vsCDEF);
191     vsCDEF = _mm_sub_ps(vsCDEF, vone);
192 
193     vp0123 = _mm_add_ps(_mm_mul_ps(vp0123, vt0123), vt0123);
194     vp4567 = _mm_add_ps(_mm_mul_ps(vp4567, vt4567), vt4567);
195     vp89AB = _mm_add_ps(_mm_mul_ps(vp89AB, vt89AB), vt89AB);
196     vpCDEF = _mm_add_ps(_mm_mul_ps(vpCDEF, vtCDEF), vtCDEF);
197 
198     const __m128 ve0123 = _mm_mul_ps(_mm_add_ps(vp0123, vs0123), valpha);
199     const __m128 ve4567 = _mm_mul_ps(_mm_add_ps(vp4567, vs4567), valpha);
200     const __m128 ve89AB = _mm_mul_ps(_mm_add_ps(vp89AB, vs89AB), valpha);
201     const __m128 veCDEF = _mm_mul_ps(_mm_add_ps(vpCDEF, vsCDEF), valpha);
202 
203     const __m128 vm0123 = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx0123)));
204     vx0123 = _mm_mul_ps(vx0123, vbeta);
205     const __m128 vm4567 = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx4567)));
206     vx4567 = _mm_mul_ps(vx4567, vbeta);
207     const __m128 vm89AB = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx89AB)));
208     vx89AB = _mm_mul_ps(vx89AB, vbeta);
209     const __m128 vmCDEF = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vxCDEF)));
210     vxCDEF = _mm_mul_ps(vxCDEF, vbeta);
211 
212     const __m128 vy0123 = _mm_or_ps(_mm_and_ps(ve0123, vm0123), _mm_andnot_ps(vm0123, vx0123));
213     const __m128 vy4567 = _mm_or_ps(_mm_and_ps(ve4567, vm4567), _mm_andnot_ps(vm4567, vx4567));
214     const __m128 vy89AB = _mm_or_ps(_mm_and_ps(ve89AB, vm89AB), _mm_andnot_ps(vm89AB, vx89AB));
215     const __m128 vyCDEF = _mm_or_ps(_mm_and_ps(veCDEF, vmCDEF), _mm_andnot_ps(vmCDEF, vxCDEF));
216 
217     _mm_storeu_ps(y, vy0123);
218     _mm_storeu_ps(y + 4, vy4567);
219     _mm_storeu_ps(y + 8, vy89AB);
220     _mm_storeu_ps(y + 12, vyCDEF);
221     y += 16;
222   }
223   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
224     __m128 vx = _mm_loadu_ps(x);
225     x += 4;
226 
227     const __m128 vz = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx, vprescale));
228 
229     __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
230 
231     const __m128i ven = _mm_slli_epi32(_mm_castps_si128(vn), 19);
232     const __m128i vidx = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vn), vindex_mask), 2);
233     #if XNN_ARCH_X86_64
234       const uint64_t vidx_lo = (uint64_t) _mm_cvtsi128_si64(vidx);
235       const uint64_t vidx_hi = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidx, vidx));
236       const __m128i vl_ll   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_lo)));
237       const __m128i vl_hl = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_hi)));
238       const __m128i vl_lh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_lo >> 32))));
239       const __m128i vl_lo = _mm_unpacklo_epi32(vl_ll, vl_lh);
240       const __m128i vl_hh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_hi >> 32))));
241       const __m128i vl_hi = _mm_unpacklo_epi32(vl_hl, vl_hh);
242     #else  // !XNN_ARCH_X86_64
243       const __m128i vl_ll = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_cvtsi128_si32(vidx))));
244       const __m128i vl_hl = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_extract_epi16(vidx, 4))));
245       const __m128i vl_lh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_extract_epi16(vidx, 2))));
246       const __m128i vl_lo = _mm_unpacklo_epi32(vl_ll, vl_lh);
247       const __m128i vl_hh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_extract_epi16(vidx, 6))));
248       const __m128i vl_hi = _mm_unpacklo_epi32(vl_hl, vl_hh);
249     #endif  // XNN_ARCH_X86_64
250     const __m128i vl = _mm_unpacklo_epi64(vl_lo, vl_hi);
251     __m128 vs = _mm_castsi128_ps(_mm_add_epi32(vl, ven));
252     vn = _mm_sub_ps(vn, vmagic_bias);
253 
254     __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
255     vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
256 
257     __m128 vp = _mm_add_ps(_mm_mul_ps(vc3, vt), vc2);
258     vp = _mm_mul_ps(vp, vt);
259 
260     vt = _mm_mul_ps(vt, vs);
261     vs = _mm_sub_ps(vs, vone);
262     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vt);
263     const __m128 ve = _mm_mul_ps(_mm_add_ps(vp, vs), valpha);
264 
265     const __m128 vm = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx)));
266     vx = _mm_mul_ps(vx, vbeta);
267     const __m128 vy = _mm_or_ps(_mm_and_ps(ve, vm), _mm_andnot_ps(vm, vx));
268 
269     _mm_storeu_ps(y, vy);
270     y += 4;
271   }
272   if XNN_UNLIKELY(n != 0) {
273     __m128 vx = _mm_loadu_ps(x);
274 
275     const __m128 vz = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx, vprescale));
276 
277     __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
278 
279     const __m128i ven = _mm_slli_epi32(_mm_castps_si128(vn), 19);
280     const __m128i vidx = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vn), vindex_mask), 2);
281     #if XNN_ARCH_X86_64
282       const uint64_t vidx_lo = (uint64_t) _mm_cvtsi128_si64(vidx);
283       const uint64_t vidx_hi = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidx, vidx));
284       const __m128i vl_ll   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_lo)));
285       const __m128i vl_hl = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_hi)));
286       const __m128i vl_lh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_lo >> 32))));
287       const __m128i vl_lo = _mm_unpacklo_epi32(vl_ll, vl_lh);
288       const __m128i vl_hh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_hi >> 32))));
289       const __m128i vl_hi = _mm_unpacklo_epi32(vl_hl, vl_hh);
290     #else  // !XNN_ARCH_X86_64
291       const __m128i vl_ll = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_cvtsi128_si32(vidx))));
292       const __m128i vl_hl = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_extract_epi16(vidx, 4))));
293       const __m128i vl_lh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_extract_epi16(vidx, 2))));
294       const __m128i vl_lo = _mm_unpacklo_epi32(vl_ll, vl_lh);
295       const __m128i vl_hh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_extract_epi16(vidx, 6))));
296       const __m128i vl_hi = _mm_unpacklo_epi32(vl_hl, vl_hh);
297     #endif  // XNN_ARCH_X86_64
298     const __m128i vl = _mm_unpacklo_epi64(vl_lo, vl_hi);
299     __m128 vs = _mm_castsi128_ps(_mm_add_epi32(vl, ven));
300     vn = _mm_sub_ps(vn, vmagic_bias);
301 
302     __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
303     vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
304 
305     __m128 vp = _mm_add_ps(_mm_mul_ps(vc3, vt), vc2);
306     vp = _mm_mul_ps(vp, vt);
307 
308     vt = _mm_mul_ps(vt, vs);
309     vs = _mm_sub_ps(vs, vone);
310     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vt);
311     const __m128 ve = _mm_mul_ps(_mm_add_ps(vp, vs), valpha);
312 
313     const __m128 vm = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx)));
314     vx = _mm_mul_ps(vx, vbeta);
315     __m128 vy = _mm_or_ps(_mm_and_ps(ve, vm), _mm_andnot_ps(vm, vx));
316 
317     if (n & (2 * sizeof(float))) {
318       _mm_storel_pi((__m64*) y, vy);
319       vy = _mm_movehl_ps(vy, vy);
320       y += 2;
321     }
322     if (n & (1 * sizeof(float))) {
323       _mm_store_ss(y, vy);
324     }
325   }
326 }
327