1 // Auto-generated file. Do not edit!
2 // Template: src/f32-velu/wasmsimd-rr2-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 <wasm_simd128.h>
13
14 #include <xnnpack/vunary.h>
15 #include <xnnpack/common.h>
16
17
xnn_f32_velu_ukernel__wasmsimd_x86_rr2_p6_x24(size_t n,const float * x,float * y,const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_velu_ukernel__wasmsimd_x86_rr2_p6_x24(
19 size_t n,
20 const float* x,
21 float* y,
22 const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
23 {
24 assert(n != 0);
25 assert(n % sizeof(float) == 0);
26 assert(x != NULL);
27 assert(y != NULL);
28
29 const v128_t vprescale = wasm_v32x4_load_splat(¶ms->scalar.prescale);
30 const v128_t valpha = wasm_v32x4_load_splat(¶ms->scalar.alpha);
31 const v128_t vbeta = wasm_v32x4_load_splat(¶ms->scalar.beta);
32
33 const v128_t vsat_cutoff = wasm_f32x4_splat(-0x1.154246p+4f);
34 const v128_t vmagic_bias = wasm_f32x4_splat(0x1.8000FEp23f);
35 const v128_t vlog2e = wasm_f32x4_splat(0x1.715476p+0f);
36 const v128_t vminus_ln2_hi = wasm_f32x4_splat(-0x1.62E440p-1f);
37 const v128_t vminus_ln2_lo = wasm_f32x4_splat(0x1.0105C6p-21f);
38 const v128_t vc6 = wasm_f32x4_splat(0x1.6b7338p-10f);
39 const v128_t vc5 = wasm_f32x4_splat(0x1.12278Ep-7f);
40 const v128_t vc4 = wasm_f32x4_splat(0x1.555716p-5f);
41 const v128_t vc3 = wasm_f32x4_splat(0x1.5554B0p-3f);
42 const v128_t vc2 = wasm_f32x4_splat(0x1.FFFFFEp-2f);
43 const v128_t vone = wasm_f32x4_splat(1.0f);
44
45 for (; n >= 24 * sizeof(float); n -= 24 * sizeof(float)) {
46 v128_t vx0123 = wasm_v128_load(x);
47 v128_t vx4567 = wasm_v128_load(x + 4);
48 v128_t vx89AB = wasm_v128_load(x + 8);
49 v128_t vxCDEF = wasm_v128_load(x + 12);
50 v128_t vxGHIJ = wasm_v128_load(x + 16);
51 v128_t vxKLMN = wasm_v128_load(x + 20);
52 x += 24;
53
54 const v128_t vz0123 = wasm_f32x4_mul(vx0123, vprescale);
55 const v128_t vz4567 = wasm_f32x4_mul(vx4567, vprescale);
56 const v128_t vz89AB = wasm_f32x4_mul(vx89AB, vprescale);
57 const v128_t vzCDEF = wasm_f32x4_mul(vxCDEF, vprescale);
58 const v128_t vzGHIJ = wasm_f32x4_mul(vxGHIJ, vprescale);
59 const v128_t vzKLMN = wasm_f32x4_mul(vxKLMN, vprescale);
60
61 v128_t vn0123 = wasm_f32x4_add(wasm_f32x4_mul(vz0123, vlog2e), vmagic_bias);
62 v128_t vn4567 = wasm_f32x4_add(wasm_f32x4_mul(vz4567, vlog2e), vmagic_bias);
63 v128_t vn89AB = wasm_f32x4_add(wasm_f32x4_mul(vz89AB, vlog2e), vmagic_bias);
64 v128_t vnCDEF = wasm_f32x4_add(wasm_f32x4_mul(vzCDEF, vlog2e), vmagic_bias);
65 v128_t vnGHIJ = wasm_f32x4_add(wasm_f32x4_mul(vzGHIJ, vlog2e), vmagic_bias);
66 v128_t vnKLMN = wasm_f32x4_add(wasm_f32x4_mul(vzKLMN, vlog2e), vmagic_bias);
67
68 v128_t vs0123 = wasm_i32x4_shl(vn0123, 23);
69 v128_t vs4567 = wasm_i32x4_shl(vn4567, 23);
70 v128_t vs89AB = wasm_i32x4_shl(vn89AB, 23);
71 v128_t vsCDEF = wasm_i32x4_shl(vnCDEF, 23);
72 v128_t vsGHIJ = wasm_i32x4_shl(vnGHIJ, 23);
73 v128_t vsKLMN = wasm_i32x4_shl(vnKLMN, 23);
74
75 vn0123 = wasm_f32x4_sub(vn0123, vmagic_bias);
76 vn4567 = wasm_f32x4_sub(vn4567, vmagic_bias);
77 vn89AB = wasm_f32x4_sub(vn89AB, vmagic_bias);
78 vnCDEF = wasm_f32x4_sub(vnCDEF, vmagic_bias);
79 vnGHIJ = wasm_f32x4_sub(vnGHIJ, vmagic_bias);
80 vnKLMN = wasm_f32x4_sub(vnKLMN, vmagic_bias);
81
82 v128_t vt0123 = wasm_f32x4_add(wasm_f32x4_mul(vn0123, vminus_ln2_hi), vz0123);
83 const v128_t vsatm0123 = wasm_f32x4_le(vz0123, vsat_cutoff);
84 v128_t vt4567 = wasm_f32x4_add(wasm_f32x4_mul(vn4567, vminus_ln2_hi), vz4567);
85 const v128_t vsatm4567 = wasm_f32x4_le(vz4567, vsat_cutoff);
86 v128_t vt89AB = wasm_f32x4_add(wasm_f32x4_mul(vn89AB, vminus_ln2_hi), vz89AB);
87 const v128_t vsatm89AB = wasm_f32x4_le(vz89AB, vsat_cutoff);
88 v128_t vtCDEF = wasm_f32x4_add(wasm_f32x4_mul(vnCDEF, vminus_ln2_hi), vzCDEF);
89 const v128_t vsatmCDEF = wasm_f32x4_le(vzCDEF, vsat_cutoff);
90 v128_t vtGHIJ = wasm_f32x4_add(wasm_f32x4_mul(vnGHIJ, vminus_ln2_hi), vzGHIJ);
91 const v128_t vsatmGHIJ = wasm_f32x4_le(vzGHIJ, vsat_cutoff);
92 v128_t vtKLMN = wasm_f32x4_add(wasm_f32x4_mul(vnKLMN, vminus_ln2_hi), vzKLMN);
93 const v128_t vsatmKLMN = wasm_f32x4_le(vzKLMN, vsat_cutoff);
94
95 vt0123 = wasm_f32x4_add(wasm_f32x4_mul(vn0123, vminus_ln2_lo), vt0123);
96 vs0123 = wasm_v128_andnot(vs0123, vsatm0123);
97 vt4567 = wasm_f32x4_add(wasm_f32x4_mul(vn4567, vminus_ln2_lo), vt4567);
98 vs4567 = wasm_v128_andnot(vs4567, vsatm4567);
99 vt89AB = wasm_f32x4_add(wasm_f32x4_mul(vn89AB, vminus_ln2_lo), vt89AB);
100 vs89AB = wasm_v128_andnot(vs89AB, vsatm89AB);
101 vtCDEF = wasm_f32x4_add(wasm_f32x4_mul(vnCDEF, vminus_ln2_lo), vtCDEF);
102 vsCDEF = wasm_v128_andnot(vsCDEF, vsatmCDEF);
103 vtGHIJ = wasm_f32x4_add(wasm_f32x4_mul(vnGHIJ, vminus_ln2_lo), vtGHIJ);
104 vsGHIJ = wasm_v128_andnot(vsGHIJ, vsatmGHIJ);
105 vtKLMN = wasm_f32x4_add(wasm_f32x4_mul(vnKLMN, vminus_ln2_lo), vtKLMN);
106 vsKLMN = wasm_v128_andnot(vsKLMN, vsatmKLMN);
107
108 vt0123 = wasm_v128_andnot(vt0123, vsatm0123);
109 v128_t vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt0123), vc5);
110 vt4567 = wasm_v128_andnot(vt4567, vsatm4567);
111 v128_t vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt4567), vc5);
112 vt89AB = wasm_v128_andnot(vt89AB, vsatm89AB);
113 v128_t vp89AB = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt89AB), vc5);
114 vtCDEF = wasm_v128_andnot(vtCDEF, vsatmCDEF);
115 v128_t vpCDEF = wasm_f32x4_add(wasm_f32x4_mul(vc6, vtCDEF), vc5);
116 vtGHIJ = wasm_v128_andnot(vtGHIJ, vsatmGHIJ);
117 v128_t vpGHIJ = wasm_f32x4_add(wasm_f32x4_mul(vc6, vtGHIJ), vc5);
118 vtKLMN = wasm_v128_andnot(vtKLMN, vsatmKLMN);
119 v128_t vpKLMN = wasm_f32x4_add(wasm_f32x4_mul(vc6, vtKLMN), vc5);
120
121 vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vc4);
122 vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vc4);
123 vp89AB = wasm_f32x4_add(wasm_f32x4_mul(vp89AB, vt89AB), vc4);
124 vpCDEF = wasm_f32x4_add(wasm_f32x4_mul(vpCDEF, vtCDEF), vc4);
125 vpGHIJ = wasm_f32x4_add(wasm_f32x4_mul(vpGHIJ, vtGHIJ), vc4);
126 vpKLMN = wasm_f32x4_add(wasm_f32x4_mul(vpKLMN, vtKLMN), vc4);
127
128 vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vc3);
129 vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vc3);
130 vp89AB = wasm_f32x4_add(wasm_f32x4_mul(vp89AB, vt89AB), vc3);
131 vpCDEF = wasm_f32x4_add(wasm_f32x4_mul(vpCDEF, vtCDEF), vc3);
132 vpGHIJ = wasm_f32x4_add(wasm_f32x4_mul(vpGHIJ, vtGHIJ), vc3);
133 vpKLMN = wasm_f32x4_add(wasm_f32x4_mul(vpKLMN, vtKLMN), vc3);
134
135 vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vc2);
136 vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vc2);
137 vp89AB = wasm_f32x4_add(wasm_f32x4_mul(vp89AB, vt89AB), vc2);
138 vpCDEF = wasm_f32x4_add(wasm_f32x4_mul(vpCDEF, vtCDEF), vc2);
139 vpGHIJ = wasm_f32x4_add(wasm_f32x4_mul(vpGHIJ, vtGHIJ), vc2);
140 vpKLMN = wasm_f32x4_add(wasm_f32x4_mul(vpKLMN, vtKLMN), vc2);
141
142 vp0123 = wasm_f32x4_mul(vp0123, vt0123);
143 vp4567 = wasm_f32x4_mul(vp4567, vt4567);
144 vp89AB = wasm_f32x4_mul(vp89AB, vt89AB);
145 vpCDEF = wasm_f32x4_mul(vpCDEF, vtCDEF);
146 vpGHIJ = wasm_f32x4_mul(vpGHIJ, vtGHIJ);
147 vpKLMN = wasm_f32x4_mul(vpKLMN, vtKLMN);
148
149 vt0123 = wasm_f32x4_mul(vt0123, vs0123);
150 vs0123 = wasm_f32x4_sub(vs0123, vone);
151 vt4567 = wasm_f32x4_mul(vt4567, vs4567);
152 vs4567 = wasm_f32x4_sub(vs4567, vone);
153 vt89AB = wasm_f32x4_mul(vt89AB, vs89AB);
154 vs89AB = wasm_f32x4_sub(vs89AB, vone);
155 vtCDEF = wasm_f32x4_mul(vtCDEF, vsCDEF);
156 vsCDEF = wasm_f32x4_sub(vsCDEF, vone);
157 vtGHIJ = wasm_f32x4_mul(vtGHIJ, vsGHIJ);
158 vsGHIJ = wasm_f32x4_sub(vsGHIJ, vone);
159 vtKLMN = wasm_f32x4_mul(vtKLMN, vsKLMN);
160 vsKLMN = wasm_f32x4_sub(vsKLMN, vone);
161
162 vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vt0123);
163 vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vt4567);
164 vp89AB = wasm_f32x4_add(wasm_f32x4_mul(vp89AB, vt89AB), vt89AB);
165 vpCDEF = wasm_f32x4_add(wasm_f32x4_mul(vpCDEF, vtCDEF), vtCDEF);
166 vpGHIJ = wasm_f32x4_add(wasm_f32x4_mul(vpGHIJ, vtGHIJ), vtGHIJ);
167 vpKLMN = wasm_f32x4_add(wasm_f32x4_mul(vpKLMN, vtKLMN), vtKLMN);
168
169 const v128_t ve0123 = wasm_f32x4_mul(wasm_f32x4_add(vp0123, vs0123), valpha);
170 const v128_t ve4567 = wasm_f32x4_mul(wasm_f32x4_add(vp4567, vs4567), valpha);
171 const v128_t ve89AB = wasm_f32x4_mul(wasm_f32x4_add(vp89AB, vs89AB), valpha);
172 const v128_t veCDEF = wasm_f32x4_mul(wasm_f32x4_add(vpCDEF, vsCDEF), valpha);
173 const v128_t veGHIJ = wasm_f32x4_mul(wasm_f32x4_add(vpGHIJ, vsGHIJ), valpha);
174 const v128_t veKLMN = wasm_f32x4_mul(wasm_f32x4_add(vpKLMN, vsKLMN), valpha);
175
176 const v128_t vsignm0123 = wasm_i32x4_shr(vx0123, 31);
177 vx0123 = wasm_f32x4_mul(vx0123, vbeta);
178 const v128_t vsignm4567 = wasm_i32x4_shr(vx4567, 31);
179 vx4567 = wasm_f32x4_mul(vx4567, vbeta);
180 const v128_t vsignm89AB = wasm_i32x4_shr(vx89AB, 31);
181 vx89AB = wasm_f32x4_mul(vx89AB, vbeta);
182 const v128_t vsignmCDEF = wasm_i32x4_shr(vxCDEF, 31);
183 vxCDEF = wasm_f32x4_mul(vxCDEF, vbeta);
184 const v128_t vsignmGHIJ = wasm_i32x4_shr(vxGHIJ, 31);
185 vxGHIJ = wasm_f32x4_mul(vxGHIJ, vbeta);
186 const v128_t vsignmKLMN = wasm_i32x4_shr(vxKLMN, 31);
187 vxKLMN = wasm_f32x4_mul(vxKLMN, vbeta);
188
189 const v128_t vy0123 = wasm_v128_bitselect(ve0123, vx0123, vsignm0123);
190 const v128_t vy4567 = wasm_v128_bitselect(ve4567, vx4567, vsignm4567);
191 const v128_t vy89AB = wasm_v128_bitselect(ve89AB, vx89AB, vsignm89AB);
192 const v128_t vyCDEF = wasm_v128_bitselect(veCDEF, vxCDEF, vsignmCDEF);
193 const v128_t vyGHIJ = wasm_v128_bitselect(veGHIJ, vxGHIJ, vsignmGHIJ);
194 const v128_t vyKLMN = wasm_v128_bitselect(veKLMN, vxKLMN, vsignmKLMN);
195
196 wasm_v128_store(y, vy0123);
197 wasm_v128_store(y + 4, vy4567);
198 wasm_v128_store(y + 8, vy89AB);
199 wasm_v128_store(y + 12, vyCDEF);
200 wasm_v128_store(y + 16, vyGHIJ);
201 wasm_v128_store(y + 20, vyKLMN);
202 y += 24;
203 }
204 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
205 v128_t vx = wasm_v128_load(x);
206 x += 4;
207
208 const v128_t vz = wasm_f32x4_mul(vx, vprescale);
209
210 v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
211 v128_t vs = wasm_i32x4_shl(vn, 23);
212 vn = wasm_f32x4_sub(vn, vmagic_bias);
213
214 v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
215 const v128_t vsatm = wasm_f32x4_le(vz, vsat_cutoff);
216 vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
217 vs = wasm_v128_andnot(vs, vsatm);
218 vt = wasm_v128_andnot(vt, vsatm);
219
220 v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt), vc5);
221 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc4);
222 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc3);
223 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc2);
224 vp = wasm_f32x4_mul(vp, vt);
225
226 vt = wasm_f32x4_mul(vt, vs);
227 vs = wasm_f32x4_sub(vs, vone);
228 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
229 const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
230
231 const v128_t vsignm = wasm_i32x4_shr(vx, 31);
232 vx = wasm_f32x4_mul(vx, vbeta);
233 const v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
234
235 wasm_v128_store(y, vy);
236 y += 4;
237 }
238 if XNN_UNLIKELY(n != 0) {
239 v128_t vx = wasm_v128_load(x);
240
241 const v128_t vz = wasm_f32x4_mul(vx, vprescale);
242
243 v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
244 v128_t vs = wasm_i32x4_shl(vn, 23);
245 vn = wasm_f32x4_sub(vn, vmagic_bias);
246
247 v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
248 const v128_t vsatm = wasm_f32x4_le(vz, vsat_cutoff);
249 vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
250 vs = wasm_v128_andnot(vs, vsatm);
251 vt = wasm_v128_andnot(vt, vsatm);
252
253 v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt), vc5);
254 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc4);
255 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc3);
256 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc2);
257 vp = wasm_f32x4_mul(vp, vt);
258
259 vt = wasm_f32x4_mul(vt, vs);
260 vs = wasm_f32x4_sub(vs, vone);
261 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
262 const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
263
264 const v128_t vsignm = wasm_i32x4_shr(vx, 31);
265 vx = wasm_f32x4_mul(vx, vbeta);
266 v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
267
268 if (n & (2 * sizeof(float))) {
269 *((double*) y) = wasm_f64x2_extract_lane(vy, 0);
270 vy = wasm_v32x4_shuffle(vy, vy, 2, 3, 2, 3);
271 y += 2;
272 }
273 if (n & (1 * sizeof(float))) {
274 *y = wasm_f32x4_extract_lane(vy, 0);
275 }
276 }
277 }
278