• 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_x20(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_x20(
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 >= 20 * sizeof(float); n -= 20 * 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     __m128 vxGHIJ = _mm_loadu_ps(x + 16);
51     x += 20;
52 
53     const __m128 vz0123 = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx0123, vprescale));
54     const __m128 vz4567 = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx4567, vprescale));
55     const __m128 vz89AB = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx89AB, vprescale));
56     const __m128 vzCDEF = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vxCDEF, vprescale));
57     const __m128 vzGHIJ = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vxGHIJ, vprescale));
58 
59     __m128 vn0123 = _mm_add_ps(_mm_mul_ps(vz0123, vlog2e), vmagic_bias);
60     __m128 vn4567 = _mm_add_ps(_mm_mul_ps(vz4567, vlog2e), vmagic_bias);
61     __m128 vn89AB = _mm_add_ps(_mm_mul_ps(vz89AB, vlog2e), vmagic_bias);
62     __m128 vnCDEF = _mm_add_ps(_mm_mul_ps(vzCDEF, vlog2e), vmagic_bias);
63     __m128 vnGHIJ = _mm_add_ps(_mm_mul_ps(vzGHIJ, vlog2e), vmagic_bias);
64 
65     const __m128i vidx0123 = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vn0123), vindex_mask), 2);
66     const __m128i ven0123 = _mm_slli_epi32(_mm_castps_si128(vn0123), 19);
67     const __m128i vidx4567 = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vn4567), vindex_mask), 2);
68     const __m128i ven4567 = _mm_slli_epi32(_mm_castps_si128(vn4567), 19);
69     const __m128i vidx89AB = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vn89AB), vindex_mask), 2);
70     const __m128i ven89AB = _mm_slli_epi32(_mm_castps_si128(vn89AB), 19);
71     const __m128i vidxCDEF = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vnCDEF), vindex_mask), 2);
72     const __m128i venCDEF = _mm_slli_epi32(_mm_castps_si128(vnCDEF), 19);
73     const __m128i vidxGHIJ = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vnGHIJ), vindex_mask), 2);
74     const __m128i venGHIJ = _mm_slli_epi32(_mm_castps_si128(vnGHIJ), 19);
75 
76     #if XNN_ARCH_X86_64
77       const uint64_t vidx01 = (uint64_t) _mm_cvtsi128_si64(vidx0123);
78       const uint64_t vidx23 = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidx0123, vidx0123));
79       const __m128i vl0   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx01)));
80       const __m128i vl2 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx23)));
81       const __m128i vl1 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx01 >> 32))));
82       const __m128i vl01 = _mm_unpacklo_epi32(vl0, vl1);
83       const __m128i vl3 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx23 >> 32))));
84       const __m128i vl23 = _mm_unpacklo_epi32(vl2, vl3);
85       const __m128i vl0123 = _mm_unpacklo_epi64(vl01, vl23);
86       const uint64_t vidx45 = (uint64_t) _mm_cvtsi128_si64(vidx4567);
87       const uint64_t vidx67 = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidx4567, vidx4567));
88       const __m128i vl4   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx45)));
89       const __m128i vl6 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx67)));
90       const __m128i vl5 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx45 >> 32))));
91       const __m128i vl45 = _mm_unpacklo_epi32(vl4, vl5);
92       const __m128i vl7 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx67 >> 32))));
93       const __m128i vl67 = _mm_unpacklo_epi32(vl6, vl7);
94       const __m128i vl4567 = _mm_unpacklo_epi64(vl45, vl67);
95       const uint64_t vidx89 = (uint64_t) _mm_cvtsi128_si64(vidx89AB);
96       const uint64_t vidxAB = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidx89AB, vidx89AB));
97       const __m128i vl8   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx89)));
98       const __m128i vlA = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxAB)));
99       const __m128i vl9 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx89 >> 32))));
100       const __m128i vl89 = _mm_unpacklo_epi32(vl8, vl9);
101       const __m128i vlB = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxAB >> 32))));
102       const __m128i vlAB = _mm_unpacklo_epi32(vlA, vlB);
103       const __m128i vl89AB = _mm_unpacklo_epi64(vl89, vlAB);
104       const uint64_t vidxCD = (uint64_t) _mm_cvtsi128_si64(vidxCDEF);
105       const uint64_t vidxEF = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidxCDEF, vidxCDEF));
106       const __m128i vlC   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxCD)));
107       const __m128i vlE = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxEF)));
108       const __m128i vlD = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxCD >> 32))));
109       const __m128i vlCD = _mm_unpacklo_epi32(vlC, vlD);
110       const __m128i vlF = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxEF >> 32))));
111       const __m128i vlEF = _mm_unpacklo_epi32(vlE, vlF);
112       const __m128i vlCDEF = _mm_unpacklo_epi64(vlCD, vlEF);
113       const uint64_t vidxGH = (uint64_t) _mm_cvtsi128_si64(vidxGHIJ);
114       const uint64_t vidxIJ = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidxGHIJ, vidxGHIJ));
115       const __m128i vlG   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxGH)));
116       const __m128i vlI = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxIJ)));
117       const __m128i vlH = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxGH >> 32))));
118       const __m128i vlGH = _mm_unpacklo_epi32(vlG, vlH);
119       const __m128i vlJ = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxIJ >> 32))));
120       const __m128i vlIJ = _mm_unpacklo_epi32(vlI, vlJ);
121       const __m128i vlGHIJ = _mm_unpacklo_epi64(vlGH, vlIJ);
122     #else  // !XNN_ARCH_X86_64
123       const uint32_t vidx0 = (uint32_t) _mm_cvtsi128_si32(vidx0123);
124       const uint32_t vidx1 = (uint32_t) _mm_extract_epi16(vidx0123, 2);
125       const uint32_t vidx2 = (uint32_t) _mm_extract_epi16(vidx0123, 4);
126       const uint32_t vidx3 = (uint32_t) _mm_extract_epi16(vidx0123, 6);
127       const __m128i vl0   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx0)));
128       const __m128i vl2 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx2)));
129       const __m128i vl1 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx1)));
130       const __m128i vl01 = _mm_unpacklo_epi32(vl0, vl1);
131       const __m128i vl3 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx3)));
132       const __m128i vl23 = _mm_unpacklo_epi32(vl2, vl3);
133       const __m128i vl0123 = _mm_unpacklo_epi64(vl01, vl23);
134       const uint32_t vidx4 = (uint32_t) _mm_cvtsi128_si32(vidx4567);
135       const uint32_t vidx5 = (uint32_t) _mm_extract_epi16(vidx4567, 2);
136       const uint32_t vidx6 = (uint32_t) _mm_extract_epi16(vidx4567, 4);
137       const uint32_t vidx7 = (uint32_t) _mm_extract_epi16(vidx4567, 6);
138       const __m128i vl4   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx4)));
139       const __m128i vl6 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx6)));
140       const __m128i vl5 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx5)));
141       const __m128i vl45 = _mm_unpacklo_epi32(vl4, vl5);
142       const __m128i vl7 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx7)));
143       const __m128i vl67 = _mm_unpacklo_epi32(vl6, vl7);
144       const __m128i vl4567 = _mm_unpacklo_epi64(vl45, vl67);
145       const uint32_t vidx8 = (uint32_t) _mm_cvtsi128_si32(vidx89AB);
146       const uint32_t vidx9 = (uint32_t) _mm_extract_epi16(vidx89AB, 2);
147       const uint32_t vidxA = (uint32_t) _mm_extract_epi16(vidx89AB, 4);
148       const uint32_t vidxB = (uint32_t) _mm_extract_epi16(vidx89AB, 6);
149       const __m128i vl8   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx8)));
150       const __m128i vlA = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxA)));
151       const __m128i vl9 = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidx9)));
152       const __m128i vl89 = _mm_unpacklo_epi32(vl8, vl9);
153       const __m128i vlB = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxB)));
154       const __m128i vlAB = _mm_unpacklo_epi32(vlA, vlB);
155       const __m128i vl89AB = _mm_unpacklo_epi64(vl89, vlAB);
156       const uint32_t vidxC = (uint32_t) _mm_cvtsi128_si32(vidxCDEF);
157       const uint32_t vidxD = (uint32_t) _mm_extract_epi16(vidxCDEF, 2);
158       const uint32_t vidxE = (uint32_t) _mm_extract_epi16(vidxCDEF, 4);
159       const uint32_t vidxF = (uint32_t) _mm_extract_epi16(vidxCDEF, 6);
160       const __m128i vlC   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxC)));
161       const __m128i vlE = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxE)));
162       const __m128i vlD = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxD)));
163       const __m128i vlCD = _mm_unpacklo_epi32(vlC, vlD);
164       const __m128i vlF = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxF)));
165       const __m128i vlEF = _mm_unpacklo_epi32(vlE, vlF);
166       const __m128i vlCDEF = _mm_unpacklo_epi64(vlCD, vlEF);
167       const uint32_t vidxG = (uint32_t) _mm_cvtsi128_si32(vidxGHIJ);
168       const uint32_t vidxH = (uint32_t) _mm_extract_epi16(vidxGHIJ, 2);
169       const uint32_t vidxI = (uint32_t) _mm_extract_epi16(vidxGHIJ, 4);
170       const uint32_t vidxJ = (uint32_t) _mm_extract_epi16(vidxGHIJ, 6);
171       const __m128i vlG   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxG)));
172       const __m128i vlI = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxI)));
173       const __m128i vlH = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxH)));
174       const __m128i vlGH = _mm_unpacklo_epi32(vlG, vlH);
175       const __m128i vlJ = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + vidxJ)));
176       const __m128i vlIJ = _mm_unpacklo_epi32(vlI, vlJ);
177       const __m128i vlGHIJ = _mm_unpacklo_epi64(vlGH, vlIJ);
178     #endif  // XNN_ARCH_X86_64
179 
180     vn0123 = _mm_sub_ps(vn0123, vmagic_bias);
181     __m128 vs0123 = _mm_castsi128_ps(_mm_add_epi32(vl0123, ven0123));
182     vn4567 = _mm_sub_ps(vn4567, vmagic_bias);
183     __m128 vs4567 = _mm_castsi128_ps(_mm_add_epi32(vl4567, ven4567));
184     vn89AB = _mm_sub_ps(vn89AB, vmagic_bias);
185     __m128 vs89AB = _mm_castsi128_ps(_mm_add_epi32(vl89AB, ven89AB));
186     vnCDEF = _mm_sub_ps(vnCDEF, vmagic_bias);
187     __m128 vsCDEF = _mm_castsi128_ps(_mm_add_epi32(vlCDEF, venCDEF));
188     vnGHIJ = _mm_sub_ps(vnGHIJ, vmagic_bias);
189     __m128 vsGHIJ = _mm_castsi128_ps(_mm_add_epi32(vlGHIJ, venGHIJ));
190 
191     __m128 vt0123 = _mm_add_ps(_mm_mul_ps(vn0123, vminus_ln2_hi), vz0123);
192     __m128 vt4567 = _mm_add_ps(_mm_mul_ps(vn4567, vminus_ln2_hi), vz4567);
193     __m128 vt89AB = _mm_add_ps(_mm_mul_ps(vn89AB, vminus_ln2_hi), vz89AB);
194     __m128 vtCDEF = _mm_add_ps(_mm_mul_ps(vnCDEF, vminus_ln2_hi), vzCDEF);
195     __m128 vtGHIJ = _mm_add_ps(_mm_mul_ps(vnGHIJ, vminus_ln2_hi), vzGHIJ);
196 
197     vt0123 = _mm_add_ps(_mm_mul_ps(vn0123, vminus_ln2_lo), vt0123);
198     vt4567 = _mm_add_ps(_mm_mul_ps(vn4567, vminus_ln2_lo), vt4567);
199     vt89AB = _mm_add_ps(_mm_mul_ps(vn89AB, vminus_ln2_lo), vt89AB);
200     vtCDEF = _mm_add_ps(_mm_mul_ps(vnCDEF, vminus_ln2_lo), vtCDEF);
201     vtGHIJ = _mm_add_ps(_mm_mul_ps(vnGHIJ, vminus_ln2_lo), vtGHIJ);
202 
203     __m128 vp0123 = _mm_add_ps(_mm_mul_ps(vc3, vt0123), vc2);
204     __m128 vp4567 = _mm_add_ps(_mm_mul_ps(vc3, vt4567), vc2);
205     __m128 vp89AB = _mm_add_ps(_mm_mul_ps(vc3, vt89AB), vc2);
206     __m128 vpCDEF = _mm_add_ps(_mm_mul_ps(vc3, vtCDEF), vc2);
207     __m128 vpGHIJ = _mm_add_ps(_mm_mul_ps(vc3, vtGHIJ), vc2);
208 
209     vp0123 = _mm_mul_ps(vp0123, vt0123);
210     vp4567 = _mm_mul_ps(vp4567, vt4567);
211     vp89AB = _mm_mul_ps(vp89AB, vt89AB);
212     vpCDEF = _mm_mul_ps(vpCDEF, vtCDEF);
213     vpGHIJ = _mm_mul_ps(vpGHIJ, vtGHIJ);
214 
215     vt0123 = _mm_mul_ps(vt0123, vs0123);
216     vs0123 = _mm_sub_ps(vs0123, vone);
217     vt4567 = _mm_mul_ps(vt4567, vs4567);
218     vs4567 = _mm_sub_ps(vs4567, vone);
219     vt89AB = _mm_mul_ps(vt89AB, vs89AB);
220     vs89AB = _mm_sub_ps(vs89AB, vone);
221     vtCDEF = _mm_mul_ps(vtCDEF, vsCDEF);
222     vsCDEF = _mm_sub_ps(vsCDEF, vone);
223     vtGHIJ = _mm_mul_ps(vtGHIJ, vsGHIJ);
224     vsGHIJ = _mm_sub_ps(vsGHIJ, vone);
225 
226     vp0123 = _mm_add_ps(_mm_mul_ps(vp0123, vt0123), vt0123);
227     vp4567 = _mm_add_ps(_mm_mul_ps(vp4567, vt4567), vt4567);
228     vp89AB = _mm_add_ps(_mm_mul_ps(vp89AB, vt89AB), vt89AB);
229     vpCDEF = _mm_add_ps(_mm_mul_ps(vpCDEF, vtCDEF), vtCDEF);
230     vpGHIJ = _mm_add_ps(_mm_mul_ps(vpGHIJ, vtGHIJ), vtGHIJ);
231 
232     const __m128 ve0123 = _mm_mul_ps(_mm_add_ps(vp0123, vs0123), valpha);
233     const __m128 ve4567 = _mm_mul_ps(_mm_add_ps(vp4567, vs4567), valpha);
234     const __m128 ve89AB = _mm_mul_ps(_mm_add_ps(vp89AB, vs89AB), valpha);
235     const __m128 veCDEF = _mm_mul_ps(_mm_add_ps(vpCDEF, vsCDEF), valpha);
236     const __m128 veGHIJ = _mm_mul_ps(_mm_add_ps(vpGHIJ, vsGHIJ), valpha);
237 
238     const __m128 vm0123 = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx0123)));
239     vx0123 = _mm_mul_ps(vx0123, vbeta);
240     const __m128 vm4567 = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx4567)));
241     vx4567 = _mm_mul_ps(vx4567, vbeta);
242     const __m128 vm89AB = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx89AB)));
243     vx89AB = _mm_mul_ps(vx89AB, vbeta);
244     const __m128 vmCDEF = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vxCDEF)));
245     vxCDEF = _mm_mul_ps(vxCDEF, vbeta);
246     const __m128 vmGHIJ = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vxGHIJ)));
247     vxGHIJ = _mm_mul_ps(vxGHIJ, vbeta);
248 
249     const __m128 vy0123 = _mm_or_ps(_mm_and_ps(ve0123, vm0123), _mm_andnot_ps(vm0123, vx0123));
250     const __m128 vy4567 = _mm_or_ps(_mm_and_ps(ve4567, vm4567), _mm_andnot_ps(vm4567, vx4567));
251     const __m128 vy89AB = _mm_or_ps(_mm_and_ps(ve89AB, vm89AB), _mm_andnot_ps(vm89AB, vx89AB));
252     const __m128 vyCDEF = _mm_or_ps(_mm_and_ps(veCDEF, vmCDEF), _mm_andnot_ps(vmCDEF, vxCDEF));
253     const __m128 vyGHIJ = _mm_or_ps(_mm_and_ps(veGHIJ, vmGHIJ), _mm_andnot_ps(vmGHIJ, vxGHIJ));
254 
255     _mm_storeu_ps(y, vy0123);
256     _mm_storeu_ps(y + 4, vy4567);
257     _mm_storeu_ps(y + 8, vy89AB);
258     _mm_storeu_ps(y + 12, vyCDEF);
259     _mm_storeu_ps(y + 16, vyGHIJ);
260     y += 20;
261   }
262   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
263     __m128 vx = _mm_loadu_ps(x);
264     x += 4;
265 
266     const __m128 vz = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx, vprescale));
267 
268     __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
269 
270     const __m128i ven = _mm_slli_epi32(_mm_castps_si128(vn), 19);
271     const __m128i vidx = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vn), vindex_mask), 2);
272     #if XNN_ARCH_X86_64
273       const uint64_t vidx_lo = (uint64_t) _mm_cvtsi128_si64(vidx);
274       const uint64_t vidx_hi = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidx, vidx));
275       const __m128i vl_ll   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_lo)));
276       const __m128i vl_hl = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_hi)));
277       const __m128i vl_lh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_lo >> 32))));
278       const __m128i vl_lo = _mm_unpacklo_epi32(vl_ll, vl_lh);
279       const __m128i vl_hh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_hi >> 32))));
280       const __m128i vl_hi = _mm_unpacklo_epi32(vl_hl, vl_hh);
281     #else  // !XNN_ARCH_X86_64
282       const __m128i vl_ll = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_cvtsi128_si32(vidx))));
283       const __m128i vl_hl = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_extract_epi16(vidx, 4))));
284       const __m128i vl_lh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_extract_epi16(vidx, 2))));
285       const __m128i vl_lo = _mm_unpacklo_epi32(vl_ll, vl_lh);
286       const __m128i vl_hh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_extract_epi16(vidx, 6))));
287       const __m128i vl_hi = _mm_unpacklo_epi32(vl_hl, vl_hh);
288     #endif  // XNN_ARCH_X86_64
289     const __m128i vl = _mm_unpacklo_epi64(vl_lo, vl_hi);
290     __m128 vs = _mm_castsi128_ps(_mm_add_epi32(vl, ven));
291     vn = _mm_sub_ps(vn, vmagic_bias);
292 
293     __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
294     vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
295 
296     __m128 vp = _mm_add_ps(_mm_mul_ps(vc3, vt), vc2);
297     vp = _mm_mul_ps(vp, vt);
298 
299     vt = _mm_mul_ps(vt, vs);
300     vs = _mm_sub_ps(vs, vone);
301     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vt);
302     const __m128 ve = _mm_mul_ps(_mm_add_ps(vp, vs), valpha);
303 
304     const __m128 vm = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx)));
305     vx = _mm_mul_ps(vx, vbeta);
306     const __m128 vy = _mm_or_ps(_mm_and_ps(ve, vm), _mm_andnot_ps(vm, vx));
307 
308     _mm_storeu_ps(y, vy);
309     y += 4;
310   }
311   if XNN_UNLIKELY(n != 0) {
312     __m128 vx = _mm_loadu_ps(x);
313 
314     const __m128 vz = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx, vprescale));
315 
316     __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
317 
318     const __m128i ven = _mm_slli_epi32(_mm_castps_si128(vn), 19);
319     const __m128i vidx = _mm_slli_epi32(_mm_and_si128(_mm_castps_si128(vn), vindex_mask), 2);
320     #if XNN_ARCH_X86_64
321       const uint64_t vidx_lo = (uint64_t) _mm_cvtsi128_si64(vidx);
322       const uint64_t vidx_hi = (uint64_t) _mm_cvtsi128_si64(_mm_unpackhi_epi64(vidx, vidx));
323       const __m128i vl_ll   = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_lo)));
324       const __m128i vl_hl = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_hi)));
325       const __m128i vl_lh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_lo >> 32))));
326       const __m128i vl_lo = _mm_unpacklo_epi32(vl_ll, vl_lh);
327       const __m128i vl_hh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_hi >> 32))));
328       const __m128i vl_hi = _mm_unpacklo_epi32(vl_hl, vl_hh);
329     #else  // !XNN_ARCH_X86_64
330       const __m128i vl_ll = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_cvtsi128_si32(vidx))));
331       const __m128i vl_hl = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_extract_epi16(vidx, 4))));
332       const __m128i vl_lh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_extract_epi16(vidx, 2))));
333       const __m128i vl_lo = _mm_unpacklo_epi32(vl_ll, vl_lh);
334       const __m128i vl_hh = _mm_cvtsi32_si128(*((const int*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) _mm_extract_epi16(vidx, 6))));
335       const __m128i vl_hi = _mm_unpacklo_epi32(vl_hl, vl_hh);
336     #endif  // XNN_ARCH_X86_64
337     const __m128i vl = _mm_unpacklo_epi64(vl_lo, vl_hi);
338     __m128 vs = _mm_castsi128_ps(_mm_add_epi32(vl, ven));
339     vn = _mm_sub_ps(vn, vmagic_bias);
340 
341     __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
342     vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
343 
344     __m128 vp = _mm_add_ps(_mm_mul_ps(vc3, vt), vc2);
345     vp = _mm_mul_ps(vp, vt);
346 
347     vt = _mm_mul_ps(vt, vs);
348     vs = _mm_sub_ps(vs, vone);
349     vp = _mm_add_ps(_mm_mul_ps(vp, vt), vt);
350     const __m128 ve = _mm_mul_ps(_mm_add_ps(vp, vs), valpha);
351 
352     const __m128 vm = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx)));
353     vx = _mm_mul_ps(vx, vbeta);
354     __m128 vy = _mm_or_ps(_mm_and_ps(ve, vm), _mm_andnot_ps(vm, vx));
355 
356     if (n & (2 * sizeof(float))) {
357       _mm_storel_pi((__m64*) y, vy);
358       vy = _mm_movehl_ps(vy, vy);
359       y += 2;
360     }
361     if (n & (1 * sizeof(float))) {
362       _mm_store_ss(y, vy);
363     }
364   }
365 }
366