1 // Auto-generated file. Do not edit!
2 // Template: src/f32-velu/scalar-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 #include <math.h>
12
13 #include <xnnpack/common.h>
14 #include <xnnpack/vunary.h>
15
16 #include <fp16/bitcasts.h>
17
18
xnn_f32_velu_ukernel__wasm_rr2_p6_x5(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__wasm_rr2_p6_x5(
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 % sizeof(float) == 0);
26
27 const float vprescale = params->scalar.prescale;
28 const float valpha = params->scalar.alpha;
29 const float vbeta = params->scalar.beta;
30
31 const float vmagic_bias = 0x1.8000FEp23f;
32 const float vlog2e = 0x1.715476p+0f;
33 const float vsat_cutoff = -0x1.154246p+4f;
34 const float vminus_ln2_hi = -0x1.62E440p-1f;
35 const float vminus_ln2_lo = 0x1.0105C6p-21f;
36 const float vc6 = 0x1.6b7338p-10f;
37 const float vc5 = 0x1.12278Ep-7f;
38 const float vc4 = 0x1.555716p-5f;
39 const float vc3 = 0x1.5554B0p-3f;
40 const float vc2 = 0x1.FFFFFEp-2f;
41 const float vone = 1.0f;
42
43 for (; n >= 5 * sizeof(float); n -= 5 * sizeof(float)) {
44 float vx0 = x[0];
45 float vx1 = x[1];
46 float vx2 = x[2];
47 float vx3 = x[3];
48 float vx4 = x[4];
49 x += 5;
50
51 const float vz0 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx0 * vprescale, vsat_cutoff), 0.0f);
52 const float vz1 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx1 * vprescale, vsat_cutoff), 0.0f);
53 const float vz2 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx2 * vprescale, vsat_cutoff), 0.0f);
54 const float vz3 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx3 * vprescale, vsat_cutoff), 0.0f);
55 const float vz4 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx4 * vprescale, vsat_cutoff), 0.0f);
56
57 float vn0 = vz0 * vlog2e + vmagic_bias;
58 float vn1 = vz1 * vlog2e + vmagic_bias;
59 float vn2 = vz2 * vlog2e + vmagic_bias;
60 float vn3 = vz3 * vlog2e + vmagic_bias;
61 float vn4 = vz4 * vlog2e + vmagic_bias;
62
63 float vs0 = fp32_from_bits(fp32_to_bits(vn0) << 23);
64 vn0 -= vmagic_bias;
65 float vs1 = fp32_from_bits(fp32_to_bits(vn1) << 23);
66 vn1 -= vmagic_bias;
67 float vs2 = fp32_from_bits(fp32_to_bits(vn2) << 23);
68 vn2 -= vmagic_bias;
69 float vs3 = fp32_from_bits(fp32_to_bits(vn3) << 23);
70 vn3 -= vmagic_bias;
71 float vs4 = fp32_from_bits(fp32_to_bits(vn4) << 23);
72 vn4 -= vmagic_bias;
73
74 float vt0 = vn0 * vminus_ln2_hi + vz0;
75 float vt1 = vn1 * vminus_ln2_hi + vz1;
76 float vt2 = vn2 * vminus_ln2_hi + vz2;
77 float vt3 = vn3 * vminus_ln2_hi + vz3;
78 float vt4 = vn4 * vminus_ln2_hi + vz4;
79
80 vt0 = vn0 * vminus_ln2_lo + vt0;
81 vt1 = vn1 * vminus_ln2_lo + vt1;
82 vt2 = vn2 * vminus_ln2_lo + vt2;
83 vt3 = vn3 * vminus_ln2_lo + vt3;
84 vt4 = vn4 * vminus_ln2_lo + vt4;
85
86
87 float vp0 = vc6 * vt0 + vc5;
88 float vp1 = vc6 * vt1 + vc5;
89 float vp2 = vc6 * vt2 + vc5;
90 float vp3 = vc6 * vt3 + vc5;
91 float vp4 = vc6 * vt4 + vc5;
92
93 vp0 = vp0 * vt0 + vc4;
94 vp1 = vp1 * vt1 + vc4;
95 vp2 = vp2 * vt2 + vc4;
96 vp3 = vp3 * vt3 + vc4;
97 vp4 = vp4 * vt4 + vc4;
98
99 vp0 = vp0 * vt0 + vc3;
100 vp1 = vp1 * vt1 + vc3;
101 vp2 = vp2 * vt2 + vc3;
102 vp3 = vp3 * vt3 + vc3;
103 vp4 = vp4 * vt4 + vc3;
104
105 vp0 = vp0 * vt0 + vc2;
106 vp1 = vp1 * vt1 + vc2;
107 vp2 = vp2 * vt2 + vc2;
108 vp3 = vp3 * vt3 + vc2;
109 vp4 = vp4 * vt4 + vc2;
110
111 vp0 *= vt0;
112 vp1 *= vt1;
113 vp2 *= vt2;
114 vp3 *= vt3;
115 vp4 *= vt4;
116
117 vt0 *= vs0;
118 vs0 -= vone;
119 vt1 *= vs1;
120 vs1 -= vone;
121 vt2 *= vs2;
122 vs2 -= vone;
123 vt3 *= vs3;
124 vs3 -= vone;
125 vt4 *= vs4;
126 vs4 -= vone;
127
128 vp0 = vp0 * vt0 + vt0;
129 vp1 = vp1 * vt1 + vt1;
130 vp2 = vp2 * vt2 + vt2;
131 vp3 = vp3 * vt3 + vt3;
132 vp4 = vp4 * vt4 + vt4;
133
134 const float ve0 = (vp0 + vs0) * valpha;
135 float vy0 = __builtin_wasm_max_f32(vx0 * vbeta, 0.0f);
136 const float ve1 = (vp1 + vs1) * valpha;
137 float vy1 = __builtin_wasm_max_f32(vx1 * vbeta, 0.0f);
138 const float ve2 = (vp2 + vs2) * valpha;
139 float vy2 = __builtin_wasm_max_f32(vx2 * vbeta, 0.0f);
140 const float ve3 = (vp3 + vs3) * valpha;
141 float vy3 = __builtin_wasm_max_f32(vx3 * vbeta, 0.0f);
142 const float ve4 = (vp4 + vs4) * valpha;
143 float vy4 = __builtin_wasm_max_f32(vx4 * vbeta, 0.0f);
144
145 vy0 += __builtin_wasm_min_f32(ve0, 0.0f);
146 vy1 += __builtin_wasm_min_f32(ve1, 0.0f);
147 vy2 += __builtin_wasm_min_f32(ve2, 0.0f);
148 vy3 += __builtin_wasm_min_f32(ve3, 0.0f);
149 vy4 += __builtin_wasm_min_f32(ve4, 0.0f);
150
151 y[0] = vy0;
152 y[1] = vy1;
153 y[2] = vy2;
154 y[3] = vy3;
155 y[4] = vy4;
156 y += 5;
157 }
158 if XNN_UNLIKELY(n != 0) {
159 do {
160 float vx = *x++;
161
162 const float vz = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx * vprescale, vsat_cutoff), 0.0f);
163
164 float vn = vz * vlog2e + vmagic_bias;
165 float vs = fp32_from_bits(fp32_to_bits(vn) << 23);
166 vn -= vmagic_bias;
167
168 float vt = vn * vminus_ln2_hi + vz;
169 vt = vn * vminus_ln2_lo + vt;
170
171
172 float vp = vc6 * vt + vc5;
173 vp = vp * vt + vc4;
174 vp = vp * vt + vc3;
175 vp = vp * vt + vc2;
176 vp *= vt;
177
178 vt *= vs;
179 vs -= vone;
180 vp = vp * vt + vt;
181 const float ve = (vp + vs) * valpha;
182
183 float vy = __builtin_wasm_max_f32(vx * vbeta, 0.0f);
184 vy += __builtin_wasm_min_f32(ve, 0.0f);
185
186 *y++ = vy;
187
188 n -= sizeof(float);
189 } while (n != 0);
190 }
191 }
192