1 // Auto-generated file. Do not edit!
2 // Template: src/f32-velu/avx512f-rr1-p6.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 <immintrin.h>
13
14 #include <xnnpack/common.h>
15 #include <xnnpack/intrinsics-polyfill.h>
16 #include <xnnpack/vunary.h>
17
18
xnn_f32_velu_ukernel__avx512f_rr1_p6_x128(size_t n,const float * x,float * y,const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f32_velu_ukernel__avx512f_rr1_p6_x128(
20 size_t n,
21 const float* x,
22 float* y,
23 const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)])
24 {
25 assert(n != 0);
26 assert(n % sizeof(float) == 0);
27
28 const __m512 vprescale = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.prescale));
29 const __m512 valpha = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.alpha));
30 const __m512 vbeta = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.beta));
31
32 const __m512 vsat_cutoff = _mm512_set1_ps(-0x1.154246p+4f);
33 const __m512 vmagic_bias = _mm512_set1_ps(0x1.8000FEp23f);
34 const __m512 vlog2e = _mm512_set1_ps(0x1.715476p+0f);
35 const __m512 vminus_ln2 = _mm512_set1_ps(-0x1.62E43p-1f);
36 const __m512 vc6 = _mm512_set1_ps(0x1.6b7338p-10f);
37 const __m512 vc5 = _mm512_set1_ps(0x1.12278Ep-7f);
38 const __m512 vc4 = _mm512_set1_ps(0x1.555716p-5f);
39 const __m512 vc3 = _mm512_set1_ps(0x1.5554B0p-3f);
40 const __m512 vc2 = _mm512_set1_ps(0x1.FFFFFEp-2f);
41
42 for (; n >= 128 * sizeof(float); n -= 128 * sizeof(float)) {
43 __m512 vx0 = _mm512_loadu_ps(x);
44 __m512 vx1 = _mm512_loadu_ps(x + 16);
45 __m512 vx2 = _mm512_loadu_ps(x + 32);
46 __m512 vx3 = _mm512_loadu_ps(x + 48);
47 __m512 vx4 = _mm512_loadu_ps(x + 64);
48 __m512 vx5 = _mm512_loadu_ps(x + 80);
49 __m512 vx6 = _mm512_loadu_ps(x + 96);
50 __m512 vx7 = _mm512_loadu_ps(x + 112);
51 x += 128;
52
53 const __m512 vz0 = _mm512_max_ps(vsat_cutoff, _mm512_mul_ps(vx0, vprescale));
54 const __m512 vz1 = _mm512_max_ps(vsat_cutoff, _mm512_mul_ps(vx1, vprescale));
55 const __m512 vz2 = _mm512_max_ps(vsat_cutoff, _mm512_mul_ps(vx2, vprescale));
56 const __m512 vz3 = _mm512_max_ps(vsat_cutoff, _mm512_mul_ps(vx3, vprescale));
57 const __m512 vz4 = _mm512_max_ps(vsat_cutoff, _mm512_mul_ps(vx4, vprescale));
58 const __m512 vz5 = _mm512_max_ps(vsat_cutoff, _mm512_mul_ps(vx5, vprescale));
59 const __m512 vz6 = _mm512_max_ps(vsat_cutoff, _mm512_mul_ps(vx6, vprescale));
60 const __m512 vz7 = _mm512_max_ps(vsat_cutoff, _mm512_mul_ps(vx7, vprescale));
61
62 __m512 vn0 = _mm512_fmadd_ps(vz0, vlog2e, vmagic_bias);
63 __m512 vn1 = _mm512_fmadd_ps(vz1, vlog2e, vmagic_bias);
64 __m512 vn2 = _mm512_fmadd_ps(vz2, vlog2e, vmagic_bias);
65 __m512 vn3 = _mm512_fmadd_ps(vz3, vlog2e, vmagic_bias);
66 __m512 vn4 = _mm512_fmadd_ps(vz4, vlog2e, vmagic_bias);
67 __m512 vn5 = _mm512_fmadd_ps(vz5, vlog2e, vmagic_bias);
68 __m512 vn6 = _mm512_fmadd_ps(vz6, vlog2e, vmagic_bias);
69 __m512 vn7 = _mm512_fmadd_ps(vz7, vlog2e, vmagic_bias);
70
71 __m512 vs0 = _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_castps_si512(vn0), 23));
72 vn0 = _mm512_sub_ps(vn0, vmagic_bias);
73 __m512 vs1 = _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_castps_si512(vn1), 23));
74 vn1 = _mm512_sub_ps(vn1, vmagic_bias);
75 __m512 vs2 = _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_castps_si512(vn2), 23));
76 vn2 = _mm512_sub_ps(vn2, vmagic_bias);
77 __m512 vs3 = _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_castps_si512(vn3), 23));
78 vn3 = _mm512_sub_ps(vn3, vmagic_bias);
79 __m512 vs4 = _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_castps_si512(vn4), 23));
80 vn4 = _mm512_sub_ps(vn4, vmagic_bias);
81 __m512 vs5 = _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_castps_si512(vn5), 23));
82 vn5 = _mm512_sub_ps(vn5, vmagic_bias);
83 __m512 vs6 = _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_castps_si512(vn6), 23));
84 vn6 = _mm512_sub_ps(vn6, vmagic_bias);
85 __m512 vs7 = _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_castps_si512(vn7), 23));
86 vn7 = _mm512_sub_ps(vn7, vmagic_bias);
87
88 __m512 vt0 = _mm512_fmadd_ps(vn0, vminus_ln2, vz0);
89 __m512 vt1 = _mm512_fmadd_ps(vn1, vminus_ln2, vz1);
90 __m512 vt2 = _mm512_fmadd_ps(vn2, vminus_ln2, vz2);
91 __m512 vt3 = _mm512_fmadd_ps(vn3, vminus_ln2, vz3);
92 __m512 vt4 = _mm512_fmadd_ps(vn4, vminus_ln2, vz4);
93 __m512 vt5 = _mm512_fmadd_ps(vn5, vminus_ln2, vz5);
94 __m512 vt6 = _mm512_fmadd_ps(vn6, vminus_ln2, vz6);
95 __m512 vt7 = _mm512_fmadd_ps(vn7, vminus_ln2, vz7);
96
97 __m512 vp0 = _mm512_fmadd_ps(vc6, vt0, vc5);
98 __m512 vp1 = _mm512_fmadd_ps(vc6, vt1, vc5);
99 __m512 vp2 = _mm512_fmadd_ps(vc6, vt2, vc5);
100 __m512 vp3 = _mm512_fmadd_ps(vc6, vt3, vc5);
101 __m512 vp4 = _mm512_fmadd_ps(vc6, vt4, vc5);
102 __m512 vp5 = _mm512_fmadd_ps(vc6, vt5, vc5);
103 __m512 vp6 = _mm512_fmadd_ps(vc6, vt6, vc5);
104 __m512 vp7 = _mm512_fmadd_ps(vc6, vt7, vc5);
105
106 vp0 = _mm512_fmadd_ps(vp0, vt0, vc4);
107 vp1 = _mm512_fmadd_ps(vp1, vt1, vc4);
108 vp2 = _mm512_fmadd_ps(vp2, vt2, vc4);
109 vp3 = _mm512_fmadd_ps(vp3, vt3, vc4);
110 vp4 = _mm512_fmadd_ps(vp4, vt4, vc4);
111 vp5 = _mm512_fmadd_ps(vp5, vt5, vc4);
112 vp6 = _mm512_fmadd_ps(vp6, vt6, vc4);
113 vp7 = _mm512_fmadd_ps(vp7, vt7, vc4);
114
115 vp0 = _mm512_fmadd_ps(vp0, vt0, vc3);
116 vp1 = _mm512_fmadd_ps(vp1, vt1, vc3);
117 vp2 = _mm512_fmadd_ps(vp2, vt2, vc3);
118 vp3 = _mm512_fmadd_ps(vp3, vt3, vc3);
119 vp4 = _mm512_fmadd_ps(vp4, vt4, vc3);
120 vp5 = _mm512_fmadd_ps(vp5, vt5, vc3);
121 vp6 = _mm512_fmadd_ps(vp6, vt6, vc3);
122 vp7 = _mm512_fmadd_ps(vp7, vt7, vc3);
123
124 vp0 = _mm512_fmadd_ps(vp0, vt0, vc2);
125 vp1 = _mm512_fmadd_ps(vp1, vt1, vc2);
126 vp2 = _mm512_fmadd_ps(vp2, vt2, vc2);
127 vp3 = _mm512_fmadd_ps(vp3, vt3, vc2);
128 vp4 = _mm512_fmadd_ps(vp4, vt4, vc2);
129 vp5 = _mm512_fmadd_ps(vp5, vt5, vc2);
130 vp6 = _mm512_fmadd_ps(vp6, vt6, vc2);
131 vp7 = _mm512_fmadd_ps(vp7, vt7, vc2);
132
133 vp0 = _mm512_mul_ps(vp0, vt0);
134 vt0 = _mm512_mul_ps(vt0, vs0);
135 vp1 = _mm512_mul_ps(vp1, vt1);
136 vt1 = _mm512_mul_ps(vt1, vs1);
137 vp2 = _mm512_mul_ps(vp2, vt2);
138 vt2 = _mm512_mul_ps(vt2, vs2);
139 vp3 = _mm512_mul_ps(vp3, vt3);
140 vt3 = _mm512_mul_ps(vt3, vs3);
141 vp4 = _mm512_mul_ps(vp4, vt4);
142 vt4 = _mm512_mul_ps(vt4, vs4);
143 vp5 = _mm512_mul_ps(vp5, vt5);
144 vt5 = _mm512_mul_ps(vt5, vs5);
145 vp6 = _mm512_mul_ps(vp6, vt6);
146 vt6 = _mm512_mul_ps(vt6, vs6);
147 vp7 = _mm512_mul_ps(vp7, vt7);
148 vt7 = _mm512_mul_ps(vt7, vs7);
149
150 vs0 = _mm512_fmsub_ps(vs0, valpha, valpha);
151 vs1 = _mm512_fmsub_ps(vs1, valpha, valpha);
152 vs2 = _mm512_fmsub_ps(vs2, valpha, valpha);
153 vs3 = _mm512_fmsub_ps(vs3, valpha, valpha);
154 vs4 = _mm512_fmsub_ps(vs4, valpha, valpha);
155 vs5 = _mm512_fmsub_ps(vs5, valpha, valpha);
156 vs6 = _mm512_fmsub_ps(vs6, valpha, valpha);
157 vs7 = _mm512_fmsub_ps(vs7, valpha, valpha);
158
159 vp0 = _mm512_fmadd_ps(vp0, vt0, vt0);
160 vp1 = _mm512_fmadd_ps(vp1, vt1, vt1);
161 vp2 = _mm512_fmadd_ps(vp2, vt2, vt2);
162 vp3 = _mm512_fmadd_ps(vp3, vt3, vt3);
163 vp4 = _mm512_fmadd_ps(vp4, vt4, vt4);
164 vp5 = _mm512_fmadd_ps(vp5, vt5, vt5);
165 vp6 = _mm512_fmadd_ps(vp6, vt6, vt6);
166 vp7 = _mm512_fmadd_ps(vp7, vt7, vt7);
167
168 const __m512 vzero = _mm512_setzero_ps();
169 __m512 vy0 = _mm512_fmadd_ps(vp0, valpha, vs0);
170 const __mmask16 vsign0 = _mm512_cmp_ps_mask(vx0, vzero, _CMP_NLT_US);
171 __m512 vy1 = _mm512_fmadd_ps(vp1, valpha, vs1);
172 const __mmask16 vsign1 = _mm512_cmp_ps_mask(vx1, vzero, _CMP_NLT_US);
173 __m512 vy2 = _mm512_fmadd_ps(vp2, valpha, vs2);
174 const __mmask16 vsign2 = _mm512_cmp_ps_mask(vx2, vzero, _CMP_NLT_US);
175 __m512 vy3 = _mm512_fmadd_ps(vp3, valpha, vs3);
176 const __mmask16 vsign3 = _mm512_cmp_ps_mask(vx3, vzero, _CMP_NLT_US);
177 __m512 vy4 = _mm512_fmadd_ps(vp4, valpha, vs4);
178 const __mmask16 vsign4 = _mm512_cmp_ps_mask(vx4, vzero, _CMP_NLT_US);
179 __m512 vy5 = _mm512_fmadd_ps(vp5, valpha, vs5);
180 const __mmask16 vsign5 = _mm512_cmp_ps_mask(vx5, vzero, _CMP_NLT_US);
181 __m512 vy6 = _mm512_fmadd_ps(vp6, valpha, vs6);
182 const __mmask16 vsign6 = _mm512_cmp_ps_mask(vx6, vzero, _CMP_NLT_US);
183 __m512 vy7 = _mm512_fmadd_ps(vp7, valpha, vs7);
184 const __mmask16 vsign7 = _mm512_cmp_ps_mask(vx7, vzero, _CMP_NLT_US);
185
186 vy0 = _mm512_mask_mul_ps(vy0, vsign0, vx0, vbeta);
187 vy1 = _mm512_mask_mul_ps(vy1, vsign1, vx1, vbeta);
188 vy2 = _mm512_mask_mul_ps(vy2, vsign2, vx2, vbeta);
189 vy3 = _mm512_mask_mul_ps(vy3, vsign3, vx3, vbeta);
190 vy4 = _mm512_mask_mul_ps(vy4, vsign4, vx4, vbeta);
191 vy5 = _mm512_mask_mul_ps(vy5, vsign5, vx5, vbeta);
192 vy6 = _mm512_mask_mul_ps(vy6, vsign6, vx6, vbeta);
193 vy7 = _mm512_mask_mul_ps(vy7, vsign7, vx7, vbeta);
194
195 _mm512_storeu_ps(y, vy0);
196 _mm512_storeu_ps(y + 16, vy1);
197 _mm512_storeu_ps(y + 32, vy2);
198 _mm512_storeu_ps(y + 48, vy3);
199 _mm512_storeu_ps(y + 64, vy4);
200 _mm512_storeu_ps(y + 80, vy5);
201 _mm512_storeu_ps(y + 96, vy6);
202 _mm512_storeu_ps(y + 112, vy7);
203 y += 128;
204 }
205 for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
206 __m512 vx = _mm512_loadu_ps(x);
207 x += 16;
208
209 const __m512 vz = _mm512_max_ps(vsat_cutoff, _mm512_mul_ps(vx, vprescale));
210 const __mmask16 vsign = _mm512_cmp_ps_mask(vx, _mm512_setzero_ps(), _CMP_NLT_US);
211
212 __m512 vn = _mm512_fmadd_ps(vz, vlog2e, vmagic_bias);
213 __m512 vs = _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_castps_si512(vn), 23));
214 vn = _mm512_sub_ps(vn, vmagic_bias);
215
216 __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2, vz);
217
218 __m512 vp = _mm512_fmadd_ps(vc6, vt, vc5);
219 vp = _mm512_fmadd_ps(vp, vt, vc4);
220 vp = _mm512_fmadd_ps(vp, vt, vc3);
221 vp = _mm512_fmadd_ps(vp, vt, vc2);
222 vp = _mm512_mul_ps(vp, vt);
223
224 vt = _mm512_mul_ps(vt, vs);
225 vs = _mm512_fmsub_ps(vs, valpha, valpha);
226 vp = _mm512_fmadd_ps(vp, vt, vt);
227 __m512 vy = _mm512_fmadd_ps(vp, valpha, vs);
228
229 vy = _mm512_mask_mul_ps(vy, vsign, vx, vbeta);
230
231 _mm512_storeu_ps(y, vy);
232 y += 16;
233 }
234 if XNN_UNLIKELY(n != 0) {
235 assert(n >= 1 * sizeof(float));
236 assert(n <= 15 * sizeof(float));
237 // Prepare mask for valid 32-bit elements (depends on n).
238 n >>= 2 /* log2(sizeof(float)) */;
239 const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << n) - UINT32_C(1)));
240
241 __m512 vx = _mm512_maskz_loadu_ps(vmask, x);
242
243 const __m512 vz = _mm512_max_ps(vsat_cutoff, _mm512_mul_ps(vx, vprescale));
244 const __mmask16 vsign = _mm512_cmp_ps_mask(vx, _mm512_setzero_ps(), _CMP_NLT_US);
245
246 __m512 vn = _mm512_fmadd_ps(vz, vlog2e, vmagic_bias);
247 __m512 vs = _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_castps_si512(vn), 23));
248 vn = _mm512_sub_ps(vn, vmagic_bias);
249
250 __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2, vz);
251
252 __m512 vp = _mm512_fmadd_ps(vc6, vt, vc5);
253 vp = _mm512_fmadd_ps(vp, vt, vc4);
254 vp = _mm512_fmadd_ps(vp, vt, vc3);
255 vp = _mm512_fmadd_ps(vp, vt, vc2);
256 vp = _mm512_mul_ps(vp, vt);
257
258 vt = _mm512_mul_ps(vt, vs);
259 vs = _mm512_fmsub_ps(vs, valpha, valpha);
260 vp = _mm512_fmadd_ps(vp, vt, vt);
261 __m512 vy = _mm512_fmadd_ps(vp, valpha, vs);
262
263 vy = _mm512_mask_mul_ps(vy, vsign, vx, vbeta);
264
265 _mm512_mask_storeu_ps(y, vmask, vy);
266 }
267 }
268