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