Debian Codegraph @

src/f32-velu/gen/f32-velu-wasmsimd-arm-rr2-p6-u12.c

raw symbols SCIP
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
18 void xnn_f32_velu_ukernel__wasmsimd_arm_rr2_p6_u12(
19 size_t batch,
20 const float* input,
21 float* output,
22 const struct xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 assert(batch != 0);
25 assert(batch % sizeof(float) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const v128_t vsat_cutoff = wasm_f32x4_const_splat(-0x1.154246p+4f);
30 const v128_t vmagic_bias = wasm_f32x4_const_splat(0x1.8000FEp23f);
31 const v128_t vlog2e = wasm_f32x4_const_splat(0x1.715476p+0f);
32 const v128_t vminus_ln2_hi = wasm_f32x4_const_splat(-0x1.62E440p-1f);
33 const v128_t vminus_ln2_lo = wasm_f32x4_const_splat(0x1.0105C6p-21f);
34 const v128_t vc6 = wasm_f32x4_const_splat(0x1.6b7338p-10f);
35 const v128_t vc5 = wasm_f32x4_const_splat(0x1.12278Ep-7f);
36 const v128_t vc4 = wasm_f32x4_const_splat(0x1.555716p-5f);
37 const v128_t vc3 = wasm_f32x4_const_splat(0x1.5554B0p-3f);
38 const v128_t vc2 = wasm_f32x4_const_splat(0x1.FFFFFEp-2f);
39 const v128_t vone = wasm_f32x4_const_splat(1.0f);
40
41 XNN_FORCE_REALIZATION(vsat_cutoff);
42 XNN_FORCE_REALIZATION(vmagic_bias);
43 XNN_FORCE_REALIZATION(vlog2e);
44 XNN_FORCE_REALIZATION(vminus_ln2_hi);
45 XNN_FORCE_REALIZATION(vminus_ln2_lo);
46 XNN_FORCE_REALIZATION(vc6);
47 XNN_FORCE_REALIZATION(vc5);
48 XNN_FORCE_REALIZATION(vc4);
49 XNN_FORCE_REALIZATION(vc3);
50 XNN_FORCE_REALIZATION(vc2);
51 XNN_FORCE_REALIZATION(vone);
52
53 const v128_t vprescale = wasm_v128_load32_splat(&params->scalar.prescale);
54 const v128_t valpha = wasm_v128_load32_splat(&params->scalar.alpha);
55 const v128_t vbeta = wasm_v128_load32_splat(&params->scalar.beta);
56
57 for (; batch >= 12 * sizeof(float); batch -= 12 * sizeof(float)) {
58 v128_t vx0123 = wasm_v128_load(input);
59 v128_t vx4567 = wasm_v128_load(input + 4);
60 v128_t vx89AB = wasm_v128_load(input + 8);
61 input += 12;
62
63 const v128_t vz0123 = wasm_f32x4_max(vsat_cutoff, wasm_f32x4_mul(vx0123, vprescale));
64 const v128_t vz4567 = wasm_f32x4_max(vsat_cutoff, wasm_f32x4_mul(vx4567, vprescale));
65 const v128_t vz89AB = wasm_f32x4_max(vsat_cutoff, wasm_f32x4_mul(vx89AB, vprescale));
66
67 v128_t vn0123 = wasm_f32x4_add(wasm_f32x4_mul(vz0123, vlog2e), vmagic_bias);
68 v128_t vn4567 = wasm_f32x4_add(wasm_f32x4_mul(vz4567, vlog2e), vmagic_bias);
69 v128_t vn89AB = wasm_f32x4_add(wasm_f32x4_mul(vz89AB, vlog2e), vmagic_bias);
70
71 v128_t vs0123 = wasm_i32x4_shl(vn0123, 23);
72 v128_t vs4567 = wasm_i32x4_shl(vn4567, 23);
73 v128_t vs89AB = wasm_i32x4_shl(vn89AB, 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
79 v128_t vt0123 = wasm_f32x4_add(wasm_f32x4_mul(vn0123, vminus_ln2_hi), vz0123);
80 v128_t vt4567 = wasm_f32x4_add(wasm_f32x4_mul(vn4567, vminus_ln2_hi), vz4567);
81 v128_t vt89AB = wasm_f32x4_add(wasm_f32x4_mul(vn89AB, vminus_ln2_hi), vz89AB);
82
83 vt0123 = wasm_f32x4_add(wasm_f32x4_mul(vn0123, vminus_ln2_lo), vt0123);
84 vt4567 = wasm_f32x4_add(wasm_f32x4_mul(vn4567, vminus_ln2_lo), vt4567);
85 vt89AB = wasm_f32x4_add(wasm_f32x4_mul(vn89AB, vminus_ln2_lo), vt89AB);
86
87 v128_t vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt0123), vc5);
88 v128_t vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt4567), vc5);
89 v128_t vp89AB = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt89AB), vc5);
90
91 vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vc4);
92 vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vc4);
93 vp89AB = wasm_f32x4_add(wasm_f32x4_mul(vp89AB, vt89AB), vc4);
94
95 vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vc3);
96 vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vc3);
97 vp89AB = wasm_f32x4_add(wasm_f32x4_mul(vp89AB, vt89AB), vc3);
98
99 vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vc2);
100 vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vc2);
101 vp89AB = wasm_f32x4_add(wasm_f32x4_mul(vp89AB, vt89AB), vc2);
102
103 vp0123 = wasm_f32x4_mul(vp0123, vt0123);
104 vp4567 = wasm_f32x4_mul(vp4567, vt4567);
105 vp89AB = wasm_f32x4_mul(vp89AB, vt89AB);
106
107 vt0123 = wasm_f32x4_mul(vt0123, vs0123);
108 vs0123 = wasm_f32x4_sub(vs0123, vone);
109 vt4567 = wasm_f32x4_mul(vt4567, vs4567);
110 vs4567 = wasm_f32x4_sub(vs4567, vone);
111 vt89AB = wasm_f32x4_mul(vt89AB, vs89AB);
112 vs89AB = wasm_f32x4_sub(vs89AB, vone);
113
114 vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vt0123);
115 vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vt4567);
116 vp89AB = wasm_f32x4_add(wasm_f32x4_mul(vp89AB, vt89AB), vt89AB);
117
118 const v128_t ve0123 = wasm_f32x4_mul(wasm_f32x4_add(vp0123, vs0123), valpha);
119 const v128_t ve4567 = wasm_f32x4_mul(wasm_f32x4_add(vp4567, vs4567), valpha);
120 const v128_t ve89AB = wasm_f32x4_mul(wasm_f32x4_add(vp89AB, vs89AB), valpha);
121
122 const v128_t vsignm0123 = wasm_i32x4_shr(vx0123, 31);
123 vx0123 = wasm_f32x4_mul(vx0123, vbeta);
124 const v128_t vsignm4567 = wasm_i32x4_shr(vx4567, 31);
125 vx4567 = wasm_f32x4_mul(vx4567, vbeta);
126 const v128_t vsignm89AB = wasm_i32x4_shr(vx89AB, 31);
127 vx89AB = wasm_f32x4_mul(vx89AB, vbeta);
128
129 const v128_t vy0123 = wasm_v128_bitselect(ve0123, vx0123, vsignm0123);
130 const v128_t vy4567 = wasm_v128_bitselect(ve4567, vx4567, vsignm4567);
131 const v128_t vy89AB = wasm_v128_bitselect(ve89AB, vx89AB, vsignm89AB);
132
133 wasm_v128_store(output, vy0123);
134 wasm_v128_store(output + 4, vy4567);
135 wasm_v128_store(output + 8, vy89AB);
136 output += 12;
137 }
138 for (; batch >= 4 * sizeof(float); batch -= 4 * sizeof(float)) {
139 v128_t vx = wasm_v128_load(input);
140 input += 4;
141
142 const v128_t vz = wasm_f32x4_max(vsat_cutoff, wasm_f32x4_mul(vx, vprescale));
143
144 v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
145 v128_t vs = wasm_i32x4_shl(vn, 23);
146 vn = wasm_f32x4_sub(vn, vmagic_bias);
147
148 v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
149 vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
150
151 v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt), vc5);
152 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc4);
153 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc3);
154 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc2);
155 vp = wasm_f32x4_mul(vp, vt);
156
157 vt = wasm_f32x4_mul(vt, vs);
158 vs = wasm_f32x4_sub(vs, vone);
159 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
160 const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
161
162 const v128_t vsignm = wasm_i32x4_shr(vx, 31);
163 vx = wasm_f32x4_mul(vx, vbeta);
164 const v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
165
166 wasm_v128_store(output, vy);
167 output += 4;
168 }
169 if XNN_UNLIKELY(batch != 0) {
170 v128_t vx = wasm_v128_load(input);
171
172 const v128_t vz = wasm_f32x4_max(wasm_f32x4_mul(vx, vprescale), vsat_cutoff);
173
174 v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
175 v128_t vs = wasm_i32x4_shl(vn, 23);
176 vn = wasm_f32x4_sub(vn, vmagic_bias);
177
178 v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
179 vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
180
181 v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt), vc5);
182 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc4);
183 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc3);
184 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc2);
185 vp = wasm_f32x4_mul(vp, vt);
186
187 vt = wasm_f32x4_mul(vt, vs);
188 vs = wasm_f32x4_sub(vs, vone);
189 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
190 const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
191
192 const v128_t vsignm = wasm_i32x4_shr(vx, 31);
193 vx = wasm_f32x4_mul(vx, vbeta);
194 v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
195
196 if (batch & (2 * sizeof(float))) {
197 wasm_v128_store64_lane(output, vy, 0);
198 vy = wasm_v64x2_shuffle(vy, vy, 1, 1);
199 output += 2;
200 }
201 if (batch & (1 * sizeof(float))) {
202 wasm_v128_store32_lane(output, vy, 0);
203 }
204 }
205 }