• 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_x4(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_x4(
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_OOB_READS
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_v128_load64_splat(params->wasmsimd_rr2_p6.prescale);
30   const v128_t valpha = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.alpha);
31   const v128_t vbeta = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.beta);
32   const v128_t vsat_cutoff = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.sat_cutoff);
33   const v128_t vmagic_bias = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.magic_bias);
34   const v128_t vlog2e = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.log2e);
35   const v128_t vminus_ln2_hi = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.minus_ln2_hi);
36   const v128_t vminus_ln2_lo = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.minus_ln2_lo);
37   const v128_t vc6 = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.c6);
38   const v128_t vc5 = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.c5);
39   const v128_t vc4 = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.c4);
40   const v128_t vc3 = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.c3);
41   const v128_t vc2 = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.c2);
42   const v128_t vone = wasm_v128_load64_splat(params->wasmsimd_rr2_p6.one);
43 
44   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
45     v128_t vx = wasm_v128_load(x);
46     x += 4;
47 
48     const v128_t vz = wasm_f32x4_max(wasm_f32x4_mul(vx, vprescale), vsat_cutoff);
49 
50     v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
51     v128_t vs = wasm_i32x4_shl(vn, 23);
52     vn = wasm_f32x4_sub(vn, vmagic_bias);
53 
54     v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
55     vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
56 
57     v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt), vc5);
58     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc4);
59     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc3);
60     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc2);
61     vp = wasm_f32x4_mul(vp, vt);
62 
63     vt = wasm_f32x4_mul(vt, vs);
64     vs = wasm_f32x4_sub(vs, vone);
65     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
66     const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
67 
68     const v128_t vsignm = wasm_i32x4_shr(vx, 31);
69     vx = wasm_f32x4_mul(vx, vbeta);
70     const v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
71 
72     wasm_v128_store(y, vy);
73     y += 4;
74   }
75   if XNN_UNLIKELY(n != 0) {
76     v128_t vx = wasm_v128_load(x);
77 
78     const v128_t vz = wasm_f32x4_max(wasm_f32x4_mul(vx, vprescale), vsat_cutoff);
79 
80     v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
81     v128_t vs = wasm_i32x4_shl(vn, 23);
82     vn = wasm_f32x4_sub(vn, vmagic_bias);
83 
84     v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
85     vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
86 
87     v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt), vc5);
88     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc4);
89     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc3);
90     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc2);
91     vp = wasm_f32x4_mul(vp, vt);
92 
93     vt = wasm_f32x4_mul(vt, vs);
94     vs = wasm_f32x4_sub(vs, vone);
95     vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
96     const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
97 
98     const v128_t vsignm = wasm_i32x4_shr(vx, 31);
99     vx = wasm_f32x4_mul(vx, vbeta);
100     v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
101 
102     if (n & (2 * sizeof(float))) {
103       *((double*) y) = wasm_f64x2_extract_lane(vy, 0);
104       vy = wasm_v32x4_shuffle(vy, vy, 2, 3, 2, 3);
105       y += 2;
106     }
107     if (n & (1 * sizeof(float))) {
108       *y = wasm_f32x4_extract_lane(vy, 0);
109     }
110   }
111 }
112