1 // Auto-generated file. Do not edit!
2 // Template: src/f32-velu/wasmsimd-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 <wasm_simd128.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__wasmsimd_arm_rr2_lut16_p3_x16(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__wasmsimd_arm_rr2_lut16_p3_x16(
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 v128_t vprescale = wasm_v128_load64_splat(params->wasmsimd_rr2_lut16_p3.prescale);
32 const v128_t valpha = wasm_v128_load64_splat(params->wasmsimd_rr2_lut16_p3.alpha);
33 const v128_t vbeta = wasm_v128_load64_splat(params->wasmsimd_rr2_lut16_p3.beta);
34 const v128_t vsat_cutoff = wasm_v128_load64_splat(params->wasmsimd_rr2_lut16_p3.sat_cutoff);
35 const v128_t vmagic_bias = wasm_v128_load64_splat(params->wasmsimd_rr2_lut16_p3.magic_bias);
36 const v128_t vlog2e = wasm_v128_load64_splat(params->wasmsimd_rr2_lut16_p3.log2e);
37 const v128_t vindex_mask = wasm_v128_load64_splat(params->wasmsimd_rr2_lut16_p3.index_mask);
38 const v128_t vminus_ln2_hi = wasm_v128_load64_splat(params->wasmsimd_rr2_lut16_p3.minus_ln2_hi);
39 const v128_t vminus_ln2_lo = wasm_v128_load64_splat(params->wasmsimd_rr2_lut16_p3.minus_ln2_lo);
40 const v128_t vc3 = wasm_v128_load64_splat(params->wasmsimd_rr2_lut16_p3.c3);
41 const v128_t vc2 = wasm_v128_load64_splat(params->wasmsimd_rr2_lut16_p3.c2);
42 const v128_t vone = wasm_v128_load64_splat(params->wasmsimd_rr2_lut16_p3.one);
43
44 for (; n >= 16 * sizeof(float); n -= 16 * 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 x += 16;
50
51 const v128_t vz0123 = wasm_f32x4_max(wasm_f32x4_mul(vx0123, vprescale), vsat_cutoff);
52 const v128_t vz4567 = wasm_f32x4_max(wasm_f32x4_mul(vx4567, vprescale), vsat_cutoff);
53 const v128_t vz89AB = wasm_f32x4_max(wasm_f32x4_mul(vx89AB, vprescale), vsat_cutoff);
54 const v128_t vzCDEF = wasm_f32x4_max(wasm_f32x4_mul(vxCDEF, vprescale), vsat_cutoff);
55
56 v128_t vn0123 = wasm_f32x4_add(wasm_f32x4_mul(vz0123, vlog2e), vmagic_bias);
57 v128_t vn4567 = wasm_f32x4_add(wasm_f32x4_mul(vz4567, vlog2e), vmagic_bias);
58 v128_t vn89AB = wasm_f32x4_add(wasm_f32x4_mul(vz89AB, vlog2e), vmagic_bias);
59 v128_t vnCDEF = wasm_f32x4_add(wasm_f32x4_mul(vzCDEF, vlog2e), vmagic_bias);
60
61 const v128_t vidx0123 = wasm_i32x4_shl(wasm_v128_and(vn0123, vindex_mask), 2);
62 const v128_t ven0123 = wasm_i32x4_shl(vn0123, 19);
63 const v128_t vidx4567 = wasm_i32x4_shl(wasm_v128_and(vn4567, vindex_mask), 2);
64 const v128_t ven4567 = wasm_i32x4_shl(vn4567, 19);
65 const v128_t vidx89AB = wasm_i32x4_shl(wasm_v128_and(vn89AB, vindex_mask), 2);
66 const v128_t ven89AB = wasm_i32x4_shl(vn89AB, 19);
67 const v128_t vidxCDEF = wasm_i32x4_shl(wasm_v128_and(vnCDEF, vindex_mask), 2);
68 const v128_t venCDEF = wasm_i32x4_shl(vnCDEF, 19);
69
70 const uint64_t vidx01 = wasm_i64x2_extract_lane(vidx0123, 0);
71 const uint64_t vidx23 = wasm_i64x2_extract_lane(vidx0123, 1);
72 const float vl0 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx01));
73 const float vl1 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx01 >> 32)));
74 const float vl2 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx23));
75 const float vl3 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx23 >> 32)));
76 const v128_t vl0123 = wasm_f32x4_make(vl0, vl1, vl2, vl3);
77 const uint64_t vidx45 = wasm_i64x2_extract_lane(vidx4567, 0);
78 const uint64_t vidx67 = wasm_i64x2_extract_lane(vidx4567, 1);
79 const float vl4 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx45));
80 const float vl5 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx45 >> 32)));
81 const float vl6 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx67));
82 const float vl7 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx67 >> 32)));
83 const v128_t vl4567 = wasm_f32x4_make(vl4, vl5, vl6, vl7);
84 const uint64_t vidx89 = wasm_i64x2_extract_lane(vidx89AB, 0);
85 const uint64_t vidxAB = wasm_i64x2_extract_lane(vidx89AB, 1);
86 const float vl8 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx89));
87 const float vl9 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx89 >> 32)));
88 const float vlA = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxAB));
89 const float vlB = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxAB >> 32)));
90 const v128_t vl89AB = wasm_f32x4_make(vl8, vl9, vlA, vlB);
91 const uint64_t vidxCD = wasm_i64x2_extract_lane(vidxCDEF, 0);
92 const uint64_t vidxEF = wasm_i64x2_extract_lane(vidxCDEF, 1);
93 const float vlC = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxCD));
94 const float vlD = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxCD >> 32)));
95 const float vlE = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxEF));
96 const float vlF = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxEF >> 32)));
97 const v128_t vlCDEF = wasm_f32x4_make(vlC, vlD, vlE, vlF);
98
99 vn0123 = wasm_f32x4_sub(vn0123, vmagic_bias);
100 v128_t vs0123 = wasm_i32x4_add(vl0123, ven0123);
101 vn4567 = wasm_f32x4_sub(vn4567, vmagic_bias);
102 v128_t vs4567 = wasm_i32x4_add(vl4567, ven4567);
103 vn89AB = wasm_f32x4_sub(vn89AB, vmagic_bias);
104 v128_t vs89AB = wasm_i32x4_add(vl89AB, ven89AB);
105 vnCDEF = wasm_f32x4_sub(vnCDEF, vmagic_bias);
106 v128_t vsCDEF = wasm_i32x4_add(vlCDEF, venCDEF);
107
108 v128_t vt0123 = wasm_f32x4_add(wasm_f32x4_mul(vn0123, vminus_ln2_hi), vz0123);
109 v128_t vt4567 = wasm_f32x4_add(wasm_f32x4_mul(vn4567, vminus_ln2_hi), vz4567);
110 v128_t vt89AB = wasm_f32x4_add(wasm_f32x4_mul(vn89AB, vminus_ln2_hi), vz89AB);
111 v128_t vtCDEF = wasm_f32x4_add(wasm_f32x4_mul(vnCDEF, vminus_ln2_hi), vzCDEF);
112
113 vt0123 = wasm_f32x4_add(wasm_f32x4_mul(vn0123, vminus_ln2_lo), vt0123);
114 vt4567 = wasm_f32x4_add(wasm_f32x4_mul(vn4567, vminus_ln2_lo), vt4567);
115 vt89AB = wasm_f32x4_add(wasm_f32x4_mul(vn89AB, vminus_ln2_lo), vt89AB);
116 vtCDEF = wasm_f32x4_add(wasm_f32x4_mul(vnCDEF, vminus_ln2_lo), vtCDEF);
117
118 v128_t vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vc3, vt0123), vc2);
119 v128_t vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vc3, vt4567), vc2);
120 v128_t vp89AB = wasm_f32x4_add(wasm_f32x4_mul(vc3, vt89AB), vc2);
121 v128_t vpCDEF = wasm_f32x4_add(wasm_f32x4_mul(vc3, vtCDEF), vc2);
122
123 vp0123 = wasm_f32x4_mul(vp0123, vt0123);
124 vp4567 = wasm_f32x4_mul(vp4567, vt4567);
125 vp89AB = wasm_f32x4_mul(vp89AB, vt89AB);
126 vpCDEF = wasm_f32x4_mul(vpCDEF, vtCDEF);
127
128 vt0123 = wasm_f32x4_mul(vt0123, vs0123);
129 vs0123 = wasm_f32x4_sub(vs0123, vone);
130 vt4567 = wasm_f32x4_mul(vt4567, vs4567);
131 vs4567 = wasm_f32x4_sub(vs4567, vone);
132 vt89AB = wasm_f32x4_mul(vt89AB, vs89AB);
133 vs89AB = wasm_f32x4_sub(vs89AB, vone);
134 vtCDEF = wasm_f32x4_mul(vtCDEF, vsCDEF);
135 vsCDEF = wasm_f32x4_sub(vsCDEF, vone);
136
137 vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vt0123);
138 vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vt4567);
139 vp89AB = wasm_f32x4_add(wasm_f32x4_mul(vp89AB, vt89AB), vt89AB);
140 vpCDEF = wasm_f32x4_add(wasm_f32x4_mul(vpCDEF, vtCDEF), vtCDEF);
141
142 const v128_t ve0123 = wasm_f32x4_mul(wasm_f32x4_add(vp0123, vs0123), valpha);
143 const v128_t ve4567 = wasm_f32x4_mul(wasm_f32x4_add(vp4567, vs4567), valpha);
144 const v128_t ve89AB = wasm_f32x4_mul(wasm_f32x4_add(vp89AB, vs89AB), valpha);
145 const v128_t veCDEF = wasm_f32x4_mul(wasm_f32x4_add(vpCDEF, vsCDEF), valpha);
146
147 const v128_t vsignm0123 = wasm_i32x4_shr(vx0123, 31);
148 vx0123 = wasm_f32x4_mul(vx0123, vbeta);
149 const v128_t vsignm4567 = wasm_i32x4_shr(vx4567, 31);
150 vx4567 = wasm_f32x4_mul(vx4567, vbeta);
151 const v128_t vsignm89AB = wasm_i32x4_shr(vx89AB, 31);
152 vx89AB = wasm_f32x4_mul(vx89AB, vbeta);
153 const v128_t vsignmCDEF = wasm_i32x4_shr(vxCDEF, 31);
154 vxCDEF = wasm_f32x4_mul(vxCDEF, vbeta);
155
156 const v128_t vy0123 = wasm_v128_bitselect(ve0123, vx0123, vsignm0123);
157 const v128_t vy4567 = wasm_v128_bitselect(ve4567, vx4567, vsignm4567);
158 const v128_t vy89AB = wasm_v128_bitselect(ve89AB, vx89AB, vsignm89AB);
159 const v128_t vyCDEF = wasm_v128_bitselect(veCDEF, vxCDEF, vsignmCDEF);
160
161 wasm_v128_store(y, vy0123);
162 wasm_v128_store(y + 4, vy4567);
163 wasm_v128_store(y + 8, vy89AB);
164 wasm_v128_store(y + 12, vyCDEF);
165 y += 16;
166 }
167 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
168 v128_t vx = wasm_v128_load(x);
169 x += 4;
170
171 const v128_t vz = wasm_f32x4_max(wasm_f32x4_mul(vx, vprescale), vsat_cutoff);
172
173 v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
174 const v128_t vidx = wasm_i32x4_shl(wasm_v128_and(vn, vindex_mask), 2);
175 const v128_t ven = wasm_i32x4_shl(vn, 19);
176
177 const uint64_t vidx_lo = wasm_i64x2_extract_lane(vidx, 0);
178 const uint64_t vidx_hi = wasm_i64x2_extract_lane(vidx, 1);
179 const float vl0 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_lo));
180 const float vl1 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_lo >> 32)));
181 const float vl2 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_hi));
182 const float vl3 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_hi >> 32)));
183 const v128_t vl = wasm_f32x4_make(vl0, vl1, vl2, vl3);
184
185 v128_t vs = wasm_i32x4_add(vl, ven);
186 vn = wasm_f32x4_sub(vn, vmagic_bias);
187
188 v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
189 vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
190
191 v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc3, vt), vc2);
192 vp = wasm_f32x4_mul(vp, vt);
193
194 vt = wasm_f32x4_mul(vt, vs);
195 vs = wasm_f32x4_sub(vs, vone);
196 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
197 const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
198
199 const v128_t vsignm = wasm_i32x4_shr(vx, 31);
200 vx = wasm_f32x4_mul(vx, vbeta);
201 const v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
202
203 wasm_v128_store(y, vy);
204 y += 4;
205 }
206 if XNN_UNLIKELY(n != 0) {
207 v128_t vx = wasm_v128_load(x);
208
209 const v128_t vz = wasm_f32x4_max(wasm_f32x4_mul(vx, vprescale), vsat_cutoff);
210
211 v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
212 const v128_t vidx = wasm_i32x4_shl(wasm_v128_and(vn, vindex_mask), 2);
213 const v128_t ven = wasm_i32x4_shl(vn, 19);
214
215 const uint64_t vidx_lo = wasm_i64x2_extract_lane(vidx, 0);
216 const uint64_t vidx_hi = wasm_i64x2_extract_lane(vidx, 1);
217 const float vl0 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_lo));
218 const float vl1 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_lo >> 32)));
219 const float vl2 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_hi));
220 const float vl3 = *((const float*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_hi >> 32)));
221 const v128_t vl = wasm_f32x4_make(vl0, vl1, vl2, vl3);
222
223 v128_t vs = wasm_i32x4_add(vl, ven);
224 vn = wasm_f32x4_sub(vn, vmagic_bias);
225
226 v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
227 vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
228
229 v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc3, vt), vc2);
230 vp = wasm_f32x4_mul(vp, vt);
231
232 vt = wasm_f32x4_mul(vt, vs);
233 vs = wasm_f32x4_sub(vs, vone);
234 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
235 const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
236
237 const v128_t vsignm = wasm_i32x4_shr(vx, 31);
238 vx = wasm_f32x4_mul(vx, vbeta);
239 v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
240
241 if (n & (2 * sizeof(float))) {
242 *((double*) y) = wasm_f64x2_extract_lane(vy, 0);
243 vy = wasm_v32x4_shuffle(vy, vy, 2, 3, 2, 3);
244 y += 2;
245 }
246 if (n & (1 * sizeof(float))) {
247 *y = wasm_f32x4_extract_lane(vy, 0);
248 }
249 }
250 }
251