Debian Codegraph @

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

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-velu/wasmsimd-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
12 #include <wasm_simd128.h>
13
14 #include "xnnpack/vunary.h"
15 #include "xnnpack/common.h"
16
17
18 extern XNN_INTERNAL const float xnn_table_exp2minus_k_over_16[16];
19
20 void xnn_f32_velu_ukernel__wasmsimd_x86_rr2_lut16_p3_u4(
21 size_t batch,
22 const float* input,
23 float* output,
24 const struct xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
25 {
26 assert(batch != 0);
27 assert(batch % sizeof(float) == 0);
28 assert(input != NULL);
29 assert(output != NULL);
30
31 const v128_t vsat_cutoff = wasm_f32x4_const_splat(-0x1.154246p+4f);
32 const v128_t vmagic_bias = wasm_f32x4_const_splat(0x1.800000p19f);
33 const v128_t vlog2e = wasm_f32x4_const_splat(0x1.715476p+0f);
34 const v128_t vindex_mask = wasm_u32x4_const_splat(UINT32_C(0xF));
35 const v128_t vminus_ln2_hi = wasm_f32x4_const_splat(-0x1.62E400p-1f);
36 const v128_t vminus_ln2_lo = wasm_f32x4_const_splat(-0x1.7F7D1Cp-20f);
37 const v128_t vc3 = wasm_f32x4_const_splat(0x1.55561Cp-3f);
38 const v128_t vc2 = wasm_f32x4_const_splat(0x1.0001ECp-1f);
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(vindex_mask);
45 XNN_FORCE_REALIZATION(vminus_ln2_hi);
46 XNN_FORCE_REALIZATION(vminus_ln2_lo);
47 XNN_FORCE_REALIZATION(vc3);
48 XNN_FORCE_REALIZATION(vc2);
49 XNN_FORCE_REALIZATION(vone);
50
51 const v128_t vprescale = wasm_v128_load32_splat(&params->scalar.prescale);
52 const v128_t valpha = wasm_v128_load32_splat(&params->scalar.alpha);
53 const v128_t vbeta = wasm_v128_load32_splat(&params->scalar.beta);
54
55 for (; batch >= 4 * sizeof(float); batch -= 4 * sizeof(float)) {
56 v128_t vx = wasm_v128_load(input);
57 input += 4;
58
59 const v128_t vz = wasm_f32x4_pmax(vsat_cutoff, wasm_f32x4_mul(vx, vprescale));
60
61 v128_t vn = wasm_f32x4_add(vmagic_bias, wasm_f32x4_mul(vz, vlog2e));
62 const v128_t vidx = wasm_i32x4_shl(wasm_v128_and(vn, vindex_mask), 2);
63 const v128_t ven = wasm_i32x4_shl(vn, 19);
64
65 const uint32_t vidx0 = wasm_u32x4_extract_lane(vidx, 0);
66 v128_t vl = wasm_v128_load32_zero((const void*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx0));
67
68 const uint32_t vidx1 = wasm_u32x4_extract_lane(vidx, 1);
69 vl = wasm_v128_load32_lane((const void*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx1), vl, 1);
70
71 const uint32_t vidx2 = wasm_u32x4_extract_lane(vidx, 2);
72 vl = wasm_v128_load32_lane((const void*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx2), vl, 2);
73
74 const uint32_t vidx3 = wasm_u32x4_extract_lane(vidx, 3);
75 vl = wasm_v128_load32_lane((const void*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx3), vl, 3);
76
77 v128_t vs = wasm_i32x4_add(vl, ven);
78 vn = wasm_f32x4_sub(vn, vmagic_bias);
79
80 v128_t vt = wasm_f32x4_add(vz, wasm_f32x4_mul(vn, vminus_ln2_hi));
81 vt = wasm_f32x4_add(vt, wasm_f32x4_mul(vn, vminus_ln2_lo));
82
83 v128_t vp = wasm_f32x4_add(vc2, wasm_f32x4_mul(vc3, vt));
84 vp = wasm_f32x4_mul(vp, vt);
85
86 vt = wasm_f32x4_mul(vt, vs);
87 vs = wasm_f32x4_sub(vs, vone);
88 vp = wasm_f32x4_add(vt, wasm_f32x4_mul(vp, vt));
89 const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
90
91 const v128_t vsignm = wasm_i32x4_shr(vx, 31);
92 vx = wasm_f32x4_mul(vx, vbeta);
93 const v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
94
95 wasm_v128_store(output, vy);
96 output += 4;
97 }
98 if XNN_UNLIKELY(batch != 0) {
99 v128_t vx = wasm_v128_load(input);
100
101 const v128_t vz = wasm_f32x4_pmax(vsat_cutoff, wasm_f32x4_mul(vx, vprescale));
102
103 v128_t vn = wasm_f32x4_add(vmagic_bias, wasm_f32x4_mul(vz, vlog2e));
104 const v128_t vidx = wasm_i32x4_shl(wasm_v128_and(vn, vindex_mask), 2);
105 const v128_t ven = wasm_i32x4_shl(vn, 19);
106
107 const uint32_t vidx0 = wasm_u32x4_extract_lane(vidx, 0);
108 v128_t vl = wasm_v128_load32_zero((const void*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx0));
109
110 const uint32_t vidx1 = wasm_u32x4_extract_lane(vidx, 1);
111 vl = wasm_v128_load32_lane((const void*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx1), vl, 1);
112
113 const uint32_t vidx2 = wasm_u32x4_extract_lane(vidx, 2);
114 vl = wasm_v128_load32_lane((const void*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx2), vl, 2);
115
116 const uint32_t vidx3 = wasm_u32x4_extract_lane(vidx, 3);
117 vl = wasm_v128_load32_lane((const void*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx3), vl, 3);
118
119 v128_t vs = wasm_i32x4_add(vl, ven);
120 vn = wasm_f32x4_sub(vn, vmagic_bias);
121
122 v128_t vt = wasm_f32x4_add(vz, wasm_f32x4_mul(vn, vminus_ln2_hi));
123 vt = wasm_f32x4_add(vt, wasm_f32x4_mul(vn, vminus_ln2_lo));
124
125 v128_t vp = wasm_f32x4_add(vc2, wasm_f32x4_mul(vc3, vt));
126 vp = wasm_f32x4_mul(vp, vt);
127
128 vt = wasm_f32x4_mul(vt, vs);
129 vs = wasm_f32x4_sub(vs, vone);
130 vp = wasm_f32x4_add(vt, wasm_f32x4_mul(vp, vt));
131 const v128_t ve = wasm_f32x4_mul(wasm_f32x4_add(vp, vs), valpha);
132
133 const v128_t vsignm = wasm_i32x4_shr(vx, 31);
134 vx = wasm_f32x4_mul(vx, vbeta);
135 v128_t vy = wasm_v128_bitselect(ve, vx, vsignm);
136
137 if (batch & (2 * sizeof(float))) {
138 wasm_v128_store64_lane(output, vy, 0);
139 vy = wasm_v64x2_shuffle(vy, vy, 1, 1);
140 output += 2;
141 }
142 if (batch & (1 * sizeof(float))) {
143 wasm_v128_store32_lane(output, vy, 0);
144 }
145 }
146 }