• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
xnn_f32_velu_ukernel__wasm_rr2_lut16_p3_x5(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__wasm_rr2_lut16_p3_x5(
21     size_t n,
22     const float* x,
23     float* y,
24     const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)])
25 {
26   assert(n % sizeof(float) == 0);
27 
28   const float vprescale = params->scalar_rr2_lut16_p3.prescale;
29   const float valpha = params->scalar_rr2_lut16_p3.alpha;
30   const float vbeta = params->scalar_rr2_lut16_p3.beta;
31   const float vmagic_bias = params->scalar_rr2_lut16_p3.magic_bias;
32   const float vlog2e = params->scalar_rr2_lut16_p3.log2e;
33   const uint32_t vindex_mask = UINT32_C(0xF);
34   const float vsat_cutoff = params->scalar_rr2_lut16_p3.sat_cutoff;
35   const float vminus_ln2_hi = params->scalar_rr2_lut16_p3.minus_ln2_hi;
36   const float vminus_ln2_lo = params->scalar_rr2_lut16_p3.minus_ln2_lo;
37   const float vc3 = params->scalar_rr2_lut16_p3.c3;
38   const float vc2 = params->scalar_rr2_lut16_p3.c2;
39   const float vone = params->scalar_rr2_lut16_p3.one;
40 
41   for (; n >= 5 * sizeof(float); n -= 5 * sizeof(float)) {
42     float vx0 = x[0];
43     float vx1 = x[1];
44     float vx2 = x[2];
45     float vx3 = x[3];
46     float vx4 = x[4];
47     x += 5;
48 
49     const float vz0 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx0 * vprescale, vsat_cutoff), 0.0f);
50     const float vz1 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx1 * vprescale, vsat_cutoff), 0.0f);
51     const float vz2 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx2 * vprescale, vsat_cutoff), 0.0f);
52     const float vz3 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx3 * vprescale, vsat_cutoff), 0.0f);
53     const float vz4 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx4 * 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     float vn3 = vz3 * vlog2e + vmagic_bias;
59     float vn4 = vz4 * vlog2e + vmagic_bias;
60 
61     const uint32_t ven0 = float_as_uint32(vn0) << 19;
62     const uint32_t vidx0 = float_as_uint32(vn0) & vindex_mask;
63     vn0 -= vmagic_bias;
64     const uint32_t ven1 = float_as_uint32(vn1) << 19;
65     const uint32_t vidx1 = float_as_uint32(vn1) & vindex_mask;
66     vn1 -= vmagic_bias;
67     const uint32_t ven2 = float_as_uint32(vn2) << 19;
68     const uint32_t vidx2 = float_as_uint32(vn2) & vindex_mask;
69     vn2 -= vmagic_bias;
70     const uint32_t ven3 = float_as_uint32(vn3) << 19;
71     const uint32_t vidx3 = float_as_uint32(vn3) & vindex_mask;
72     vn3 -= vmagic_bias;
73     const uint32_t ven4 = float_as_uint32(vn4) << 19;
74     const uint32_t vidx4 = float_as_uint32(vn4) & vindex_mask;
75     vn4 -= vmagic_bias;
76 
77     float vt0 = vn0 * vminus_ln2_hi + vz0;
78     float vs0 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx0] + ven0);
79     float vt1 = vn1 * vminus_ln2_hi + vz1;
80     float vs1 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx1] + ven1);
81     float vt2 = vn2 * vminus_ln2_hi + vz2;
82     float vs2 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx2] + ven2);
83     float vt3 = vn3 * vminus_ln2_hi + vz3;
84     float vs3 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx3] + ven3);
85     float vt4 = vn4 * vminus_ln2_hi + vz4;
86     float vs4 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx4] + ven4);
87 
88     vt0 = vn0 * vminus_ln2_lo + vt0;
89     vt1 = vn1 * vminus_ln2_lo + vt1;
90     vt2 = vn2 * vminus_ln2_lo + vt2;
91     vt3 = vn3 * vminus_ln2_lo + vt3;
92     vt4 = vn4 * vminus_ln2_lo + vt4;
93 
94     float vp0 = vc3 * vt0 + vc2;
95     float vp1 = vc3 * vt1 + vc2;
96     float vp2 = vc3 * vt2 + vc2;
97     float vp3 = vc3 * vt3 + vc2;
98     float vp4 = vc3 * vt4 + vc2;
99 
100     vp0 *= vt0;
101     vp1 *= vt1;
102     vp2 *= vt2;
103     vp3 *= vt3;
104     vp4 *= vt4;
105 
106     vt0 *= vs0;
107     vs0 -= vone;
108     vt1 *= vs1;
109     vs1 -= vone;
110     vt2 *= vs2;
111     vs2 -= vone;
112     vt3 *= vs3;
113     vs3 -= vone;
114     vt4 *= vs4;
115     vs4 -= vone;
116 
117     vp0 = vp0 * vt0 + vt0;
118     vp1 = vp1 * vt1 + vt1;
119     vp2 = vp2 * vt2 + vt2;
120     vp3 = vp3 * vt3 + vt3;
121     vp4 = vp4 * vt4 + vt4;
122 
123     const float ve0 = (vp0 + vs0) * valpha;
124     float vy0 = __builtin_wasm_max_f32(vx0 * vbeta, 0.0f);
125     const float ve1 = (vp1 + vs1) * valpha;
126     float vy1 = __builtin_wasm_max_f32(vx1 * vbeta, 0.0f);
127     const float ve2 = (vp2 + vs2) * valpha;
128     float vy2 = __builtin_wasm_max_f32(vx2 * vbeta, 0.0f);
129     const float ve3 = (vp3 + vs3) * valpha;
130     float vy3 = __builtin_wasm_max_f32(vx3 * vbeta, 0.0f);
131     const float ve4 = (vp4 + vs4) * valpha;
132     float vy4 = __builtin_wasm_max_f32(vx4 * vbeta, 0.0f);
133 
134     vy0 += __builtin_wasm_min_f32(ve0, 0.0f);
135     vy1 += __builtin_wasm_min_f32(ve1, 0.0f);
136     vy2 += __builtin_wasm_min_f32(ve2, 0.0f);
137     vy3 += __builtin_wasm_min_f32(ve3, 0.0f);
138     vy4 += __builtin_wasm_min_f32(ve4, 0.0f);
139 
140     y[0] = vy0;
141     y[1] = vy1;
142     y[2] = vy2;
143     y[3] = vy3;
144     y[4] = vy4;
145     y += 5;
146   }
147   if XNN_UNLIKELY(n != 0) {
148     do {
149       float vx = *x++;
150 
151       const float vz = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx * vprescale, vsat_cutoff), 0.0f);
152 
153       float vn = vz * vlog2e + vmagic_bias;
154       const uint32_t ven = float_as_uint32(vn) << 19;
155       const uint32_t vidx = float_as_uint32(vn) & vindex_mask;
156       vn -= vmagic_bias;
157 
158       float vt = vn * vminus_ln2_hi + vz;
159       float vs = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx] + ven);
160 
161       vt = vn * vminus_ln2_lo + vt;
162 
163       float vp = vc3 * vt + vc2;
164       vp *= vt;
165 
166       vt *= vs;
167       vs -= vone;
168       vp = vp * vt + vt;
169       const float ve = (vp + vs) * valpha;
170 
171       float vy = __builtin_wasm_max_f32(vx * vbeta, 0.0f);
172       vy += __builtin_wasm_min_f32(ve, 0.0f);
173 
174       *y++ = vy;
175 
176       n -= sizeof(float);
177     } while (n != 0);
178   }
179 }
180