Debian Codegraph @

src/f32-velu/gen/f32-velu-wasm-rr2-lut16-p3-u3.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-velu/scalar-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 #include <math.h>
12
13 #include "xnnpack/common.h"
14 #include "xnnpack/math.h"
15 #include "xnnpack/vunary.h"
16
17
18 extern XNN_INTERNAL const uint32_t xnn_table_exp2minus_k_over_16[16];
19
20 void xnn_f32_velu_ukernel__wasm_rr2_lut16_p3_u3(
21 size_t batch,
22 const float* input,
23 float* output,
24 const struct xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)])
25 {
26 assert(batch != 0);
27 assert(batch % sizeof(float) == 0);
28 assert(input != NULL);
29 assert(output != NULL);
30
31 const float vsat_cutoff = -0x1.154246p+4f;
32 const float vmagic_bias = 0x1.800000p19f;
33 const float vlog2e = 0x1.715476p+0f;
34 const float vminus_ln2_hi = -0x1.62E400p-1f;
35 const float vminus_ln2_lo = -0x1.7F7D1Cp-20f;
36 const uint32_t vindex_mask = UINT32_C(0xF);
37 const float vc3 = 0x1.55561Cp-3f;
38 const float vc2 = 0x1.0001ECp-1f;
39 const float vone = 1.0f;
40
41 const float vprescale = params->scalar.prescale;
42 const float valpha = params->scalar.alpha;
43 const float vbeta = params->scalar.beta;
44
45 for (; batch >= 3 * sizeof(float); batch -= 3 * sizeof(float)) {
46 float vx0 = input[0];
47 float vx1 = input[1];
48 float vx2 = input[2];
49 input += 3;
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
55 float vn0 = vz0 * vlog2e + vmagic_bias;
56 float vn1 = vz1 * vlog2e + vmagic_bias;
57 float vn2 = vz2 * vlog2e + vmagic_bias;
58
59 const uint32_t ven0 = float_as_uint32(vn0) << 19;
60 const uint32_t vidx0 = float_as_uint32(vn0) & vindex_mask;
61 vn0 -= vmagic_bias;
62 const uint32_t ven1 = float_as_uint32(vn1) << 19;
63 const uint32_t vidx1 = float_as_uint32(vn1) & vindex_mask;
64 vn1 -= vmagic_bias;
65 const uint32_t ven2 = float_as_uint32(vn2) << 19;
66 const uint32_t vidx2 = float_as_uint32(vn2) & vindex_mask;
67 vn2 -= vmagic_bias;
68
69 float vt0 = vn0 * vminus_ln2_hi + vz0;
70 float vs0 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx0] + ven0);
71 float vt1 = vn1 * vminus_ln2_hi + vz1;
72 float vs1 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx1] + ven1);
73 float vt2 = vn2 * vminus_ln2_hi + vz2;
74 float vs2 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx2] + ven2);
75
76 vt0 = vn0 * vminus_ln2_lo + vt0;
77 vt1 = vn1 * vminus_ln2_lo + vt1;
78 vt2 = vn2 * vminus_ln2_lo + vt2;
79
80 float vp0 = vc3 * vt0 + vc2;
81 float vp1 = vc3 * vt1 + vc2;
82 float vp2 = vc3 * vt2 + vc2;
83
84 vp0 *= vt0;
85 vp1 *= vt1;
86 vp2 *= vt2;
87
88 vt0 *= vs0;
89 vs0 -= vone;
90 vt1 *= vs1;
91 vs1 -= vone;
92 vt2 *= vs2;
93 vs2 -= vone;
94
95 vp0 = vp0 * vt0 + vt0;
96 vp1 = vp1 * vt1 + vt1;
97 vp2 = vp2 * vt2 + vt2;
98
99 const float ve0 = (vp0 + vs0) * valpha;
100 float vy0 = __builtin_wasm_max_f32(vx0 * vbeta, 0.0f);
101 const float ve1 = (vp1 + vs1) * valpha;
102 float vy1 = __builtin_wasm_max_f32(vx1 * vbeta, 0.0f);
103 const float ve2 = (vp2 + vs2) * valpha;
104 float vy2 = __builtin_wasm_max_f32(vx2 * vbeta, 0.0f);
105
106 vy0 += __builtin_wasm_min_f32(ve0, 0.0f);
107 vy1 += __builtin_wasm_min_f32(ve1, 0.0f);
108 vy2 += __builtin_wasm_min_f32(ve2, 0.0f);
109
110 output[0] = vy0;
111 output[1] = vy1;
112 output[2] = vy2;
113 output += 3;
114 }
115 if XNN_UNLIKELY(batch != 0) {
116 do {
117 float vx = *input++;
118
119 const float vz = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx * vprescale, vsat_cutoff), 0.0f);
120
121 float vn = vz * vlog2e + vmagic_bias;
122 const uint32_t ven = float_as_uint32(vn) << 19;
123 const uint32_t vidx = float_as_uint32(vn) & vindex_mask;
124 vn -= vmagic_bias;
125
126 float vt = vn * vminus_ln2_hi + vz;
127 float vs = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx] + ven);
128
129 vt = vn * vminus_ln2_lo + vt;
130
131 float vp = vc3 * vt + vc2;
132 vp *= vt;
133
134 vt *= vs;
135 vs -= vone;
136 vp = vp * vt + vt;
137 const float ve = (vp + vs) * valpha;
138
139 float vy = __builtin_wasm_max_f32(vx * vbeta, 0.0f);
140 vy += __builtin_wasm_min_f32(ve, 0.0f);
141
142 *output++ = vy;
143
144 batch -= sizeof(float);
145 } while (batch != 0);
146 }
147 }