• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
xnn_f32_velu_ukernel__wasmsimd_arm_rr2_p6_x8(size_t n,const float * x,float * y,const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_velu_ukernel__wasmsimd_arm_rr2_p6_x8(
19     size_t n,
20     const float* x,
21     float* y,
22     const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
23 {
24   assert(n != 0);
25   assert(n % sizeof(float) == 0);
26   assert(x != NULL);
27   assert(y != NULL);
28 
29   const v128_t vprescale = wasm_v32x4_load_splat(&params->scalar.prescale);
30   const v128_t valpha = wasm_v32x4_load_splat(&params->scalar.alpha);
31   const v128_t vbeta = wasm_v32x4_load_splat(&params->scalar.beta);
32 
33   const v128_t vsat_cutoff = wasm_f32x4_splat(-0x1.154246p+4f);
34   const v128_t vmagic_bias = wasm_f32x4_splat(0x1.8000FEp23f);
35   const v128_t vlog2e = wasm_f32x4_splat(0x1.715476p+0f);
36   const v128_t vminus_ln2_hi = wasm_f32x4_splat(-0x1.62E440p-1f);
37   const v128_t vminus_ln2_lo = wasm_f32x4_splat(0x1.0105C6p-21f);
38   const v128_t vc6 = wasm_f32x4_splat(0x1.6b7338p-10f);
39   const v128_t vc5 = wasm_f32x4_splat(0x1.12278Ep-7f);
40   const v128_t vc4 = wasm_f32x4_splat(0x1.555716p-5f);
41   const v128_t vc3 = wasm_f32x4_splat(0x1.5554B0p-3f);
42   const v128_t vc2 = wasm_f32x4_splat(0x1.FFFFFEp-2f);
43   const v128_t vone = wasm_f32x4_splat(1.0f);
44 
45   for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
46     v128_t vx0123 = wasm_v128_load(x);
47     v128_t vx4567 = wasm_v128_load(x + 4);
48     x += 8;
49 
50     const v128_t vz0123 = wasm_f32x4_max(wasm_f32x4_mul(vx0123, vprescale), vsat_cutoff);
51     const v128_t vz4567 = wasm_f32x4_max(wasm_f32x4_mul(vx4567, vprescale), vsat_cutoff);
52 
53     v128_t vn0123 = wasm_f32x4_add(wasm_f32x4_mul(vz0123, vlog2e), vmagic_bias);
54     v128_t vn4567 = wasm_f32x4_add(wasm_f32x4_mul(vz4567, vlog2e), vmagic_bias);
55 
56     v128_t vs0123 = wasm_i32x4_shl(vn0123, 23);
57     v128_t vs4567 = wasm_i32x4_shl(vn4567, 23);
58 
59     vn0123 = wasm_f32x4_sub(vn0123, vmagic_bias);
60     vn4567 = wasm_f32x4_sub(vn4567, vmagic_bias);
61 
62     v128_t vt0123 = wasm_f32x4_add(wasm_f32x4_mul(vn0123, vminus_ln2_hi), vz0123);
63     v128_t vt4567 = wasm_f32x4_add(wasm_f32x4_mul(vn4567, vminus_ln2_hi), vz4567);
64 
65     vt0123 = wasm_f32x4_add(wasm_f32x4_mul(vn0123, vminus_ln2_lo), vt0123);
66     vt4567 = wasm_f32x4_add(wasm_f32x4_mul(vn4567, vminus_ln2_lo), vt4567);
67 
68     v128_t vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt0123), vc5);
69     v128_t vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt4567), vc5);
70 
71     vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vc4);
72     vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vc4);
73 
74     vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vc3);
75     vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vc3);
76 
77     vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vc2);
78     vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vc2);
79 
80     vp0123 = wasm_f32x4_mul(vp0123, vt0123);
81     vp4567 = wasm_f32x4_mul(vp4567, vt4567);
82 
83     vt0123 = wasm_f32x4_mul(vt0123, vs0123);
84     vs0123 = wasm_f32x4_sub(vs0123, vone);
85     vt4567 = wasm_f32x4_mul(vt4567, vs4567);
86     vs4567 = wasm_f32x4_sub(vs4567, vone);
87 
88     vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vt0123);
89     vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vt4567);
90 
91     const v128_t ve0123 = wasm_f32x4_mul(wasm_f32x4_add(vp0123, vs0123), valpha);
92     const v128_t ve4567 = wasm_f32x4_mul(wasm_f32x4_add(vp4567, vs4567), valpha);
93 
94     const v128_t vsignm0123 = wasm_i32x4_shr(vx0123, 31);
95     vx0123 = wasm_f32x4_mul(vx0123, vbeta);
96     const v128_t vsignm4567 = wasm_i32x4_shr(vx4567, 31);
97     vx4567 = wasm_f32x4_mul(vx4567, vbeta);
98 
99     const v128_t vy0123 = wasm_v128_bitselect(ve0123, vx0123, vsignm0123);
100     const v128_t vy4567 = wasm_v128_bitselect(ve4567, vx4567, vsignm4567);
101 
102     wasm_v128_store(y, vy0123);
103     wasm_v128_store(y + 4, vy4567);
104     y += 8;
105   }
106   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
107     v128_t vx = wasm_v128_load(x);
108     x += 4;
109 
110     const v128_t vz = wasm_f32x4_max(wasm_f32x4_mul(vx, vprescale), vsat_cutoff);
111 
112     v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
113     v128_t vs = wasm_i32x4_shl(vn, 23);
114     vn = wasm_f32x4_sub(vn, vmagic_bias);
115 
116     v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
117     vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
118 
119     v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt), vc5);
120     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc4);
121     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc3);
122     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc2);
123     vp = wasm_f32x4_mul(vp, vt);
124 
125     vt = wasm_f32x4_mul(vt, vs);
126     vs = wasm_f32x4_sub(vs, vone);
127     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
128     const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
129 
130     const v128_t vsignm = wasm_i32x4_shr(vx, 31);
131     vx = wasm_f32x4_mul(vx, vbeta);
132     const v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
133 
134     wasm_v128_store(y, vy);
135     y += 4;
136   }
137   if XNN_UNLIKELY(n != 0) {
138     v128_t vx = wasm_v128_load(x);
139 
140     const v128_t vz = wasm_f32x4_max(wasm_f32x4_mul(vx, vprescale), vsat_cutoff);
141 
142     v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
143     v128_t vs = wasm_i32x4_shl(vn, 23);
144     vn = wasm_f32x4_sub(vn, vmagic_bias);
145 
146     v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
147     vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
148 
149     v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt), vc5);
150     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc4);
151     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc3);
152     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc2);
153     vp = wasm_f32x4_mul(vp, vt);
154 
155     vt = wasm_f32x4_mul(vt, vs);
156     vs = wasm_f32x4_sub(vs, vone);
157     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
158     const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
159 
160     const v128_t vsignm = wasm_i32x4_shr(vx, 31);
161     vx = wasm_f32x4_mul(vx, vbeta);
162     v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
163 
164     if (n & (2 * sizeof(float))) {
165       *((double*) y) = wasm_f64x2_extract_lane(vy, 0);
166       vy = wasm_v32x4_shuffle(vy, vy, 2, 3, 2, 3);
167       y += 2;
168     }
169     if (n & (1 * sizeof(float))) {
170       *y = wasm_f32x4_extract_lane(vy, 0);
171     }
172   }
173 }
174