Debian Codegraph @

src/f32-velu/gen/f32-velu-wasmsimd-x86-rr2-p6-u4.c

raw symbols SCIP
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
18 void xnn_f32_velu_ukernel__wasmsimd_x86_rr2_p6_u4(
19 size_t batch,
20 const float* input,
21 float* output,
22 const struct xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 assert(batch != 0);
25 assert(batch % sizeof(float) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const v128_t vsat_cutoff = wasm_f32x4_const_splat(-0x1.154246p+4f);
30 const v128_t vmagic_bias = wasm_f32x4_const_splat(0x1.8000FEp23f);
31 const v128_t vlog2e = wasm_f32x4_const_splat(0x1.715476p+0f);
32 const v128_t vminus_ln2_hi = wasm_f32x4_const_splat(-0x1.62E440p-1f);
33 const v128_t vminus_ln2_lo = wasm_f32x4_const_splat(0x1.0105C6p-21f);
34 const v128_t vc6 = wasm_f32x4_const_splat(0x1.6b7338p-10f);
35 const v128_t vc5 = wasm_f32x4_const_splat(0x1.12278Ep-7f);
36 const v128_t vc4 = wasm_f32x4_const_splat(0x1.555716p-5f);
37 const v128_t vc3 = wasm_f32x4_const_splat(0x1.5554B0p-3f);
38 const v128_t vc2 = wasm_f32x4_const_splat(0x1.FFFFFEp-2f);
39 const v128_t vone = wasm_f32x4_const_splat(1.0f);
40
41 XNN_FORCE_REALIZATION(vsat_cutoff);
42 XNN_FORCE_REALIZATION(vmagic_bias);
43 XNN_FORCE_REALIZATION(vlog2e);
44 XNN_FORCE_REALIZATION(vminus_ln2_hi);
45 XNN_FORCE_REALIZATION(vminus_ln2_lo);
46 XNN_FORCE_REALIZATION(vc6);
47 XNN_FORCE_REALIZATION(vc5);
48 XNN_FORCE_REALIZATION(vc4);
49 XNN_FORCE_REALIZATION(vc3);
50 XNN_FORCE_REALIZATION(vc2);
51 XNN_FORCE_REALIZATION(vone);
52
53 const v128_t vprescale = wasm_v128_load32_splat(&params->scalar.prescale);
54 const v128_t valpha = wasm_v128_load32_splat(&params->scalar.alpha);
55 const v128_t vbeta = wasm_v128_load32_splat(&params->scalar.beta);
56
57 for (; batch >= 4 * sizeof(float); batch -= 4 * sizeof(float)) {
58 v128_t vx = wasm_v128_load(input);
59 input += 4;
60
61 const v128_t vz = wasm_f32x4_pmax(vsat_cutoff, wasm_f32x4_mul(vx, vprescale));
62
63 v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
64 v128_t vs = wasm_i32x4_shl(vn, 23);
65 vn = wasm_f32x4_sub(vn, vmagic_bias);
66
67 v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
68 vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
69
70 v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt), vc5);
71 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc4);
72 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc3);
73 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc2);
74 vp = wasm_f32x4_mul(vp, vt);
75
76 vt = wasm_f32x4_mul(vt, vs);
77 vs = wasm_f32x4_sub(vs, vone);
78 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
79 const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
80
81 const v128_t vsignm = wasm_i32x4_shr(vx, 31);
82 vx = wasm_f32x4_mul(vx, vbeta);
83 const v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
84
85 wasm_v128_store(output, vy);
86 output += 4;
87 }
88 if XNN_UNLIKELY(batch != 0) {
89 v128_t vx = wasm_v128_load(input);
90
91 const v128_t vz = wasm_f32x4_pmax(wasm_f32x4_mul(vx, vprescale), vsat_cutoff);
92
93 v128_t vn = wasm_f32x4_add(wasm_f32x4_mul(vz, vlog2e), vmagic_bias);
94 v128_t vs = wasm_i32x4_shl(vn, 23);
95 vn = wasm_f32x4_sub(vn, vmagic_bias);
96
97 v128_t vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_hi), vz);
98 vt = wasm_f32x4_add(wasm_f32x4_mul(vn, vminus_ln2_lo), vt);
99
100 v128_t vp = wasm_f32x4_add(wasm_f32x4_mul(vc6, vt), vc5);
101 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc4);
102 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc3);
103 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vc2);
104 vp = wasm_f32x4_mul(vp, vt);
105
106 vt = wasm_f32x4_mul(vt, vs);
107 vs = wasm_f32x4_sub(vs, vone);
108 vp = wasm_f32x4_add(wasm_f32x4_mul(vp, vt), vt);
109 const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
110
111 const v128_t vsignm = wasm_i32x4_shr(vx, 31);
112 vx = wasm_f32x4_mul(vx, vbeta);
113 v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
114
115 if (batch & (2 * sizeof(float))) {
116 wasm_v128_store64_lane(output, vy, 0);
117 vy = wasm_v64x2_shuffle(vy, vy, 1, 1);
118 output += 2;
119 }
120 if (batch & (1 * sizeof(float))) {
121 wasm_v128_store32_lane(output, vy, 0);
122 }
123 }
124 }