• Home
  • History
  • Annotate
  • 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_x86_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_x86_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_mul(vx0123, vprescale);
51     const v128_t vz4567 = wasm_f32x4_mul(vx4567, vprescale);
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     const v128_t vsatm0123 = wasm_f32x4_le(vz0123, vsat_cutoff);
64     v128_t vt4567 = wasm_f32x4_add(wasm_f32x4_mul(vn4567, vminus_ln2_hi), vz4567);
65     const v128_t vsatm4567 = wasm_f32x4_le(vz4567, vsat_cutoff);
66 
67     vt0123 = wasm_f32x4_add(wasm_f32x4_mul(vn0123, vminus_ln2_lo), vt0123);
68     vs0123 = wasm_v128_andnot(vs0123, vsatm0123);
69     vt4567 = wasm_f32x4_add(wasm_f32x4_mul(vn4567, vminus_ln2_lo), vt4567);
70     vs4567 = wasm_v128_andnot(vs4567, vsatm4567);
71 
72     vt0123 = wasm_v128_andnot(vt0123, vsatm0123);
73     v128_t vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt0123), vc5);
74     vt4567 = wasm_v128_andnot(vt4567, vsatm4567);
75     v128_t vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt4567), vc5);
76 
77     vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vc4);
78     vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vc4);
79 
80     vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vc3);
81     vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vc3);
82 
83     vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vc2);
84     vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vc2);
85 
86     vp0123 = wasm_f32x4_mul(vp0123, vt0123);
87     vp4567 = wasm_f32x4_mul(vp4567, vt4567);
88 
89     vt0123 = wasm_f32x4_mul(vt0123, vs0123);
90     vs0123 = wasm_f32x4_sub(vs0123, vone);
91     vt4567 = wasm_f32x4_mul(vt4567, vs4567);
92     vs4567 = wasm_f32x4_sub(vs4567, vone);
93 
94     vp0123 = wasm_f32x4_add(wasm_f32x4_mul(vp0123, vt0123), vt0123);
95     vp4567 = wasm_f32x4_add(wasm_f32x4_mul(vp4567, vt4567), vt4567);
96 
97     const v128_t ve0123 = wasm_f32x4_mul(wasm_f32x4_add(vp0123, vs0123), valpha);
98     const v128_t ve4567 = wasm_f32x4_mul(wasm_f32x4_add(vp4567, vs4567), valpha);
99 
100     const v128_t vsignm0123 = wasm_i32x4_shr(vx0123, 31);
101     vx0123 = wasm_f32x4_mul(vx0123, vbeta);
102     const v128_t vsignm4567 = wasm_i32x4_shr(vx4567, 31);
103     vx4567 = wasm_f32x4_mul(vx4567, vbeta);
104 
105     const v128_t vy0123 = wasm_v128_bitselect(ve0123, vx0123, vsignm0123);
106     const v128_t vy4567 = wasm_v128_bitselect(ve4567, vx4567, vsignm4567);
107 
108     wasm_v128_store(y, vy0123);
109     wasm_v128_store(y + 4, vy4567);
110     y += 8;
111   }
112   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
113     v128_t vx = wasm_v128_load(x);
114     x += 4;
115 
116     const v128_t vz = wasm_f32x4_mul(vx, vprescale);
117 
118     v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
119     v128_t vs = wasm_i32x4_shl(vn, 23);
120     vn = wasm_f32x4_sub(vn, vmagic_bias);
121 
122     v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
123     const v128_t vsatm = wasm_f32x4_le(vz, vsat_cutoff);
124     vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
125     vs = wasm_v128_andnot(vs, vsatm);
126     vt = wasm_v128_andnot(vt, vsatm);
127 
128     v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt), vc5);
129     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc4);
130     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc3);
131     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc2);
132     vp = wasm_f32x4_mul(vp, vt);
133 
134     vt = wasm_f32x4_mul(vt, vs);
135     vs = wasm_f32x4_sub(vs, vone);
136     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
137     const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
138 
139     const v128_t vsignm = wasm_i32x4_shr(vx, 31);
140     vx = wasm_f32x4_mul(vx, vbeta);
141     const v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
142 
143     wasm_v128_store(y, vy);
144     y += 4;
145   }
146   if XNN_UNLIKELY(n != 0) {
147     v128_t vx = wasm_v128_load(x);
148 
149     const v128_t vz = wasm_f32x4_mul(vx, vprescale);
150 
151     v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
152     v128_t vs = wasm_i32x4_shl(vn, 23);
153     vn = wasm_f32x4_sub(vn, vmagic_bias);
154 
155     v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
156     const v128_t vsatm = wasm_f32x4_le(vz, vsat_cutoff);
157     vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
158     vs = wasm_v128_andnot(vs, vsatm);
159     vt = wasm_v128_andnot(vt, vsatm);
160 
161     v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt), vc5);
162     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc4);
163     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc3);
164     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc2);
165     vp = wasm_f32x4_mul(vp, vt);
166 
167     vt = wasm_f32x4_mul(vt, vs);
168     vs = wasm_f32x4_sub(vs, vone);
169     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
170     const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
171 
172     const v128_t vsignm = wasm_i32x4_shr(vx, 31);
173     vx = wasm_f32x4_mul(vx, vbeta);
174     v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
175 
176     if (n & (2 * sizeof(float))) {
177       *((double*) y) = wasm_f64x2_extract_lane(vy, 0);
178       vy = wasm_v32x4_shuffle(vy, vy, 2, 3, 2, 3);
179       y += 2;
180     }
181     if (n & (1 * sizeof(float))) {
182       *y = wasm_f32x4_extract_lane(vy, 0);
183     }
184   }
185 }
186