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