Debian Codegraph @

src/f16-f32-vcvt/gen/f16-f32-vcvt-wasmrelaxedsimd-int32-u32.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-f32-vcvt/wasmsimd-int32.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 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/common.h"
15 #include "xnnpack/vcvt.h"
16
17
18 void xnn_f16_f32_vcvt_ukernel__wasmrelaxedsimd_int32_u32(
19 size_t batch,
20 const xnn_float16* input,
21 float* output,
22 const void* params) XNN_OOB_READS
23 {
24 assert(batch != 0);
25 assert(batch % sizeof(uint16_t) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const v128_t vsign_mask = wasm_i32x4_const_splat(UINT32_C(0x80000000));
30 const v128_t vexp_offset = wasm_i32x4_const_splat(UINT32_C(0x70000000));
31 const v128_t vexp_scale = wasm_f32x4_const_splat(0x1.0p-112f);
32 const v128_t vmagic_bias = wasm_f32x4_const_splat(0.5f);
33 const v128_t vdenorm_cutoff = wasm_i32x4_const_splat(UINT32_C(0x08000000));
34
35 XNN_FORCE_REALIZATION(vsign_mask);
36 XNN_FORCE_REALIZATION(vexp_offset);
37 XNN_FORCE_REALIZATION(vexp_scale);
38 XNN_FORCE_REALIZATION(vmagic_bias);
39 XNN_FORCE_REALIZATION(vdenorm_cutoff);
40
41 const uint16_t* i = (const uint16_t*) input;
42 for (; batch >= 32 * sizeof(uint16_t); batch -= 32 * sizeof(uint16_t)) {
43 const v128_t vh0 = wasm_v128_load(i);
44 const v128_t vh1 = wasm_v128_load(i + 8);
45 const v128_t vh2 = wasm_v128_load(i + 16);
46 const v128_t vh3 = wasm_v128_load(i + 24);
47 i += 32;
48
49 const v128_t vzero = wasm_i16x8_const_splat(0);
50 const v128_t vw0 = wasm_v16x8_shuffle(vzero, vh0, 0, 8, 1, 9, 2, 10, 3, 11);
51 const v128_t vw1 = wasm_v16x8_shuffle(vzero, vh0, 4, 12, 5, 13, 6, 14, 7, 15);
52 const v128_t vw2 = wasm_v16x8_shuffle(vzero, vh1, 0, 8, 1, 9, 2, 10, 3, 11);
53 const v128_t vw3 = wasm_v16x8_shuffle(vzero, vh1, 4, 12, 5, 13, 6, 14, 7, 15);
54 const v128_t vw4 = wasm_v16x8_shuffle(vzero, vh2, 0, 8, 1, 9, 2, 10, 3, 11);
55 const v128_t vw5 = wasm_v16x8_shuffle(vzero, vh2, 4, 12, 5, 13, 6, 14, 7, 15);
56 const v128_t vw6 = wasm_v16x8_shuffle(vzero, vh3, 0, 8, 1, 9, 2, 10, 3, 11);
57 const v128_t vw7 = wasm_v16x8_shuffle(vzero, vh3, 4, 12, 5, 13, 6, 14, 7, 15);
58
59 const v128_t vsign0 = wasm_v128_and(vw0, vsign_mask);
60 const v128_t vsign1 = wasm_v128_and(vw1, vsign_mask);
61 const v128_t vsign2 = wasm_v128_and(vw2, vsign_mask);
62 const v128_t vsign3 = wasm_v128_and(vw3, vsign_mask);
63 const v128_t vsign4 = wasm_v128_and(vw4, vsign_mask);
64 const v128_t vsign5 = wasm_v128_and(vw5, vsign_mask);
65 const v128_t vsign6 = wasm_v128_and(vw6, vsign_mask);
66 const v128_t vsign7 = wasm_v128_and(vw7, vsign_mask);
67
68 const v128_t vnonsign0 = wasm_v128_xor(vw0, vsign0);
69 const v128_t vnonsign1 = wasm_v128_xor(vw1, vsign1);
70 const v128_t vnonsign2 = wasm_v128_xor(vw2, vsign2);
71 const v128_t vnonsign3 = wasm_v128_xor(vw3, vsign3);
72 const v128_t vnonsign4 = wasm_v128_xor(vw4, vsign4);
73 const v128_t vnonsign5 = wasm_v128_xor(vw5, vsign5);
74 const v128_t vnonsign6 = wasm_v128_xor(vw6, vsign6);
75 const v128_t vnonsign7 = wasm_v128_xor(vw7, vsign7);
76
77 const v128_t vnorm0 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign0, 3), vexp_offset), vexp_scale);
78 const v128_t vnorm1 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign1, 3), vexp_offset), vexp_scale);
79 const v128_t vnorm2 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign2, 3), vexp_offset), vexp_scale);
80 const v128_t vnorm3 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign3, 3), vexp_offset), vexp_scale);
81 const v128_t vnorm4 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign4, 3), vexp_offset), vexp_scale);
82 const v128_t vnorm5 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign5, 3), vexp_offset), vexp_scale);
83 const v128_t vnorm6 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign6, 3), vexp_offset), vexp_scale);
84 const v128_t vnorm7 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign7, 3), vexp_offset), vexp_scale);
85
86 const v128_t vdenorm0 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign0, 16), vmagic_bias), vmagic_bias);
87 const v128_t vdenorm1 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign1, 16), vmagic_bias), vmagic_bias);
88 const v128_t vdenorm2 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign2, 16), vmagic_bias), vmagic_bias);
89 const v128_t vdenorm3 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign3, 16), vmagic_bias), vmagic_bias);
90 const v128_t vdenorm4 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign4, 16), vmagic_bias), vmagic_bias);
91 const v128_t vdenorm5 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign5, 16), vmagic_bias), vmagic_bias);
92 const v128_t vdenorm6 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign6, 16), vmagic_bias), vmagic_bias);
93 const v128_t vdenorm7 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign7, 16), vmagic_bias), vmagic_bias);
94
95 const v128_t vxmask0 = wasm_i32x4_gt(vnonsign0, vdenorm_cutoff);
96 const v128_t vxmask1 = wasm_i32x4_gt(vnonsign1, vdenorm_cutoff);
97 const v128_t vxmask2 = wasm_i32x4_gt(vnonsign2, vdenorm_cutoff);
98 const v128_t vxmask3 = wasm_i32x4_gt(vnonsign3, vdenorm_cutoff);
99 const v128_t vxmask4 = wasm_i32x4_gt(vnonsign4, vdenorm_cutoff);
100 const v128_t vxmask5 = wasm_i32x4_gt(vnonsign5, vdenorm_cutoff);
101 const v128_t vxmask6 = wasm_i32x4_gt(vnonsign6, vdenorm_cutoff);
102 const v128_t vxmask7 = wasm_i32x4_gt(vnonsign7, vdenorm_cutoff);
103
104 const v128_t vf0 = wasm_v128_or(vsign0, wasm_v128_bitselect(vnorm0, vdenorm0, vxmask0));
105 const v128_t vf1 = wasm_v128_or(vsign1, wasm_v128_bitselect(vnorm1, vdenorm1, vxmask1));
106 const v128_t vf2 = wasm_v128_or(vsign2, wasm_v128_bitselect(vnorm2, vdenorm2, vxmask2));
107 const v128_t vf3 = wasm_v128_or(vsign3, wasm_v128_bitselect(vnorm3, vdenorm3, vxmask3));
108 const v128_t vf4 = wasm_v128_or(vsign4, wasm_v128_bitselect(vnorm4, vdenorm4, vxmask4));
109 const v128_t vf5 = wasm_v128_or(vsign5, wasm_v128_bitselect(vnorm5, vdenorm5, vxmask5));
110 const v128_t vf6 = wasm_v128_or(vsign6, wasm_v128_bitselect(vnorm6, vdenorm6, vxmask6));
111 const v128_t vf7 = wasm_v128_or(vsign7, wasm_v128_bitselect(vnorm7, vdenorm7, vxmask7));
112
113 wasm_v128_store(output, vf0);
114 wasm_v128_store(output + 4, vf1);
115 wasm_v128_store(output + 8, vf2);
116 wasm_v128_store(output + 12, vf3);
117 wasm_v128_store(output + 16, vf4);
118 wasm_v128_store(output + 20, vf5);
119 wasm_v128_store(output + 24, vf6);
120 wasm_v128_store(output + 28, vf7);
121 output += 32;
122 }
123 for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) {
124 const v128_t vh = wasm_v128_load(i);
125 i += 8;
126
127 const v128_t vzero = wasm_i16x8_const_splat(0);
128 const v128_t vw_lo = wasm_v16x8_shuffle(vzero, vh, 0, 8, 1, 9, 2, 10, 3, 11);
129 const v128_t vw_hi = wasm_v16x8_shuffle(vzero, vh, 4, 12, 5, 13, 6, 14, 7, 15);
130
131 const v128_t vsign_lo = wasm_v128_and(vw_lo, vsign_mask);
132 const v128_t vsign_hi = wasm_v128_and(vw_hi, vsign_mask);
133
134 const v128_t vnonsign_lo = wasm_v128_xor(vw_lo, vsign_lo);
135 const v128_t vnonsign_hi = wasm_v128_xor(vw_hi, vsign_hi);
136
137 const v128_t vnorm_lo = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign_lo, 3), vexp_offset), vexp_scale);
138 const v128_t vnorm_hi = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign_hi, 3), vexp_offset), vexp_scale);
139
140 const v128_t vdenorm_lo = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign_lo, 16), vmagic_bias), vmagic_bias);
141 const v128_t vdenorm_hi = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign_hi, 16), vmagic_bias), vmagic_bias);
142
143 const v128_t vxmask_lo = wasm_i32x4_gt(vnonsign_lo, vdenorm_cutoff);
144 const v128_t vxmask_hi = wasm_i32x4_gt(vnonsign_hi, vdenorm_cutoff);
145
146 const v128_t vf_lo = wasm_v128_or(vsign_lo, wasm_v128_bitselect(vnorm_lo, vdenorm_lo, vxmask_lo));
147 const v128_t vf_hi = wasm_v128_or(vsign_hi, wasm_v128_bitselect(vnorm_hi, vdenorm_hi, vxmask_hi));
148
149 wasm_v128_store(output, vf_lo);
150 wasm_v128_store(output + 4, vf_hi);
151 output += 8;
152 }
153 if XNN_UNLIKELY(batch != 0) {
154 assert(batch >= 1 * sizeof(uint16_t));
155 assert(batch <= 7 * sizeof(uint16_t));
156 const v128_t vh = wasm_v128_load(i);
157
158 const v128_t vzero = wasm_i16x8_const_splat(0);
159 const v128_t vw_lo = wasm_v16x8_shuffle(vzero, vh, 0, 8, 1, 9, 2, 10, 3, 11);
160 const v128_t vw_hi = wasm_v16x8_shuffle(vzero, vh, 4, 12, 5, 13, 6, 14, 7, 15);
161
162 const v128_t vsign_lo = wasm_v128_and(vw_lo, vsign_mask);
163 const v128_t vsign_hi = wasm_v128_and(vw_hi, vsign_mask);
164
165 const v128_t vnonsign_lo = wasm_v128_xor(vw_lo, vsign_lo);
166 const v128_t vnonsign_hi = wasm_v128_xor(vw_hi, vsign_hi);
167
168 const v128_t vnorm_lo = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign_lo, 3), vexp_offset), vexp_scale);
169 const v128_t vnorm_hi = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign_hi, 3), vexp_offset), vexp_scale);
170
171 const v128_t vdenorm_lo = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign_lo, 16), vmagic_bias), vmagic_bias);
172 const v128_t vdenorm_hi = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign_hi, 16), vmagic_bias), vmagic_bias);
173
174 const v128_t vxmask_lo = wasm_i32x4_gt(vnonsign_lo, vdenorm_cutoff);
175 v128_t vf = wasm_v128_or(vsign_lo, wasm_v128_bitselect(vnorm_lo, vdenorm_lo, vxmask_lo));
176
177 if (batch & (4 * sizeof(uint16_t))) {
178 wasm_v128_store(output, vf);
179 output += 4;
180
181 const v128_t vxmask_hi = wasm_i32x4_gt(vnonsign_hi, vdenorm_cutoff);
182 vf = wasm_v128_or(vsign_hi, wasm_v128_bitselect(vnorm_hi, vdenorm_hi, vxmask_hi));
183 }
184 if (batch & (2 * sizeof(uint16_t))) {
185 wasm_v128_store64_lane(output, vf, 0);
186 vf = wasm_v64x2_shuffle(vf, vf, 1, 1);
187 output += 2;
188 }
189 if (batch & (1 * sizeof(uint16_t))) {
190 wasm_v128_store32_lane(output, vf, 0);
191 }
192 }
193 }