Debian Codegraph @

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

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-f16-vcvt/wasmsimd.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_f32_f16_vcvt_ukernel__wasmrelaxedsimd_u32(
19 size_t batch,
20 const float* input,
21 xnn_float16* output,
22 const void* params) 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 vexp_bias = wasm_u32x4_const_splat(UINT32_C(0x07800000));
30 const v128_t vscale_to_inf = wasm_f32x4_const_splat(0x1.0p+112f);
31 const v128_t vexpw_max = wasm_u32x4_const_splat(UINT32_C(0x7F800000));
32 const v128_t vscale_to_zero = wasm_f32x4_const_splat(0x1.0p-110f);
33 const v128_t vbias_min = wasm_u32x4_const_splat(UINT32_C(0x40008000));
34 const v128_t vmanth_mask = wasm_u32x4_const_splat(UINT32_C(0x00000FFF));
35 const v128_t vexph_mask = wasm_u32x4_const_splat(UINT32_C(0x00007C00));
36 const v128_t vnanh = wasm_u16x8_const_splat(UINT16_C(0x7E00));
37
38 XNN_FORCE_REALIZATION(vexp_bias);
39 XNN_FORCE_REALIZATION(vscale_to_inf);
40 XNN_FORCE_REALIZATION(vexpw_max);
41 XNN_FORCE_REALIZATION(vscale_to_zero);
42 XNN_FORCE_REALIZATION(vbias_min);
43 XNN_FORCE_REALIZATION(vmanth_mask);
44 XNN_FORCE_REALIZATION(vexph_mask);
45 XNN_FORCE_REALIZATION(vnanh);
46
47 uint16_t* o = (uint16_t*) output;
48 for (; batch >= 32 * sizeof(float); batch -= 32 * sizeof(float)) {
49 const v128_t vx0 = wasm_v128_load(input);
50 const v128_t vx1 = wasm_v128_load(input + 4);
51 const v128_t vx2 = wasm_v128_load(input + 8);
52 const v128_t vx3 = wasm_v128_load(input + 12);
53 const v128_t vx4 = wasm_v128_load(input + 16);
54 const v128_t vx5 = wasm_v128_load(input + 20);
55 const v128_t vx6 = wasm_v128_load(input + 24);
56 const v128_t vx7 = wasm_v128_load(input + 28);
57 input += 32;
58
59 const v128_t vabsx0 = wasm_f32x4_abs(vx0);
60 const v128_t vabsx1 = wasm_f32x4_abs(vx1);
61 const v128_t vabsx2 = wasm_f32x4_abs(vx2);
62 const v128_t vabsx3 = wasm_f32x4_abs(vx3);
63 const v128_t vabsx4 = wasm_f32x4_abs(vx4);
64 const v128_t vabsx5 = wasm_f32x4_abs(vx5);
65 const v128_t vabsx6 = wasm_f32x4_abs(vx6);
66 const v128_t vabsx7 = wasm_f32x4_abs(vx7);
67
68 const v128_t vsignx0 = wasm_v128_xor(vx0, vabsx0);
69 const v128_t vsignx1 = wasm_v128_xor(vx1, vabsx1);
70 const v128_t vsignx2 = wasm_v128_xor(vx2, vabsx2);
71 const v128_t vsignx3 = wasm_v128_xor(vx3, vabsx3);
72 const v128_t vsignx4 = wasm_v128_xor(vx4, vabsx4);
73 const v128_t vsignx5 = wasm_v128_xor(vx5, vabsx5);
74 const v128_t vsignx6 = wasm_v128_xor(vx6, vabsx6);
75 const v128_t vsignx7 = wasm_v128_xor(vx7, vabsx7);
76
77 v128_t vbias0 = wasm_i32x4_add(vabsx0, vexp_bias);
78 v128_t vbias1 = wasm_i32x4_add(vabsx1, vexp_bias);
79 v128_t vbias2 = wasm_i32x4_add(vabsx2, vexp_bias);
80 v128_t vbias3 = wasm_i32x4_add(vabsx3, vexp_bias);
81 v128_t vbias4 = wasm_i32x4_add(vabsx4, vexp_bias);
82 v128_t vbias5 = wasm_i32x4_add(vabsx5, vexp_bias);
83 v128_t vbias6 = wasm_i32x4_add(vabsx6, vexp_bias);
84 v128_t vbias7 = wasm_i32x4_add(vabsx7, vexp_bias);
85
86 v128_t vf0 = wasm_f32x4_mul(vabsx0, vscale_to_inf);
87 v128_t vf1 = wasm_f32x4_mul(vabsx1, vscale_to_inf);
88 v128_t vf2 = wasm_f32x4_mul(vabsx2, vscale_to_inf);
89 v128_t vf3 = wasm_f32x4_mul(vabsx3, vscale_to_inf);
90 v128_t vf4 = wasm_f32x4_mul(vabsx4, vscale_to_inf);
91 v128_t vf5 = wasm_f32x4_mul(vabsx5, vscale_to_inf);
92 v128_t vf6 = wasm_f32x4_mul(vabsx6, vscale_to_inf);
93 v128_t vf7 = wasm_f32x4_mul(vabsx7, vscale_to_inf);
94
95 const v128_t vnanmaskw0 = wasm_i32x4_gt(vabsx0, vexpw_max);
96 const v128_t vnanmaskw1 = wasm_i32x4_gt(vabsx1, vexpw_max);
97 const v128_t vnanmaskw2 = wasm_i32x4_gt(vabsx2, vexpw_max);
98 const v128_t vnanmaskw3 = wasm_i32x4_gt(vabsx3, vexpw_max);
99 const v128_t vnanmaskw4 = wasm_i32x4_gt(vabsx4, vexpw_max);
100 const v128_t vnanmaskw5 = wasm_i32x4_gt(vabsx5, vexpw_max);
101 const v128_t vnanmaskw6 = wasm_i32x4_gt(vabsx6, vexpw_max);
102 const v128_t vnanmaskw7 = wasm_i32x4_gt(vabsx7, vexpw_max);
103
104 vbias0 = wasm_v128_and(vbias0, vexpw_max);
105 vbias1 = wasm_v128_and(vbias1, vexpw_max);
106 vbias2 = wasm_v128_and(vbias2, vexpw_max);
107 vbias3 = wasm_v128_and(vbias3, vexpw_max);
108 vbias4 = wasm_v128_and(vbias4, vexpw_max);
109 vbias5 = wasm_v128_and(vbias5, vexpw_max);
110 vbias6 = wasm_v128_and(vbias6, vexpw_max);
111 vbias7 = wasm_v128_and(vbias7, vexpw_max);
112
113 vf0 = wasm_f32x4_mul(vf0, vscale_to_zero);
114 vf1 = wasm_f32x4_mul(vf1, vscale_to_zero);
115 vf2 = wasm_f32x4_mul(vf2, vscale_to_zero);
116 vf3 = wasm_f32x4_mul(vf3, vscale_to_zero);
117 vf4 = wasm_f32x4_mul(vf4, vscale_to_zero);
118 vf5 = wasm_f32x4_mul(vf5, vscale_to_zero);
119 vf6 = wasm_f32x4_mul(vf6, vscale_to_zero);
120 vf7 = wasm_f32x4_mul(vf7, vscale_to_zero);
121
122 const v128_t vnanmaskh0 = wasm_i16x8_narrow_i32x4(vnanmaskw0, vnanmaskw1);
123 const v128_t vnanmaskh1 = wasm_i16x8_narrow_i32x4(vnanmaskw2, vnanmaskw3);
124 const v128_t vnanmaskh2 = wasm_i16x8_narrow_i32x4(vnanmaskw4, vnanmaskw5);
125 const v128_t vnanmaskh3 = wasm_i16x8_narrow_i32x4(vnanmaskw6, vnanmaskw7);
126
127 const v128_t vsignh0 = wasm_i16x8_narrow_i32x4(vsignx0, vsignx1);
128 const v128_t vsignh1 = wasm_i16x8_narrow_i32x4(vsignx2, vsignx3);
129 const v128_t vsignh2 = wasm_i16x8_narrow_i32x4(vsignx4, vsignx5);
130 const v128_t vsignh3 = wasm_i16x8_narrow_i32x4(vsignx6, vsignx7);
131
132 vbias0 = wasm_i16x8_max(vbias0, vbias_min);
133 vbias1 = wasm_i16x8_max(vbias1, vbias_min);
134 vbias2 = wasm_i16x8_max(vbias2, vbias_min);
135 vbias3 = wasm_i16x8_max(vbias3, vbias_min);
136 vbias4 = wasm_i16x8_max(vbias4, vbias_min);
137 vbias5 = wasm_i16x8_max(vbias5, vbias_min);
138 vbias6 = wasm_i16x8_max(vbias6, vbias_min);
139 vbias7 = wasm_i16x8_max(vbias7, vbias_min);
140
141 vf0 = wasm_f32x4_add(vf0, vbias0);
142 vf1 = wasm_f32x4_add(vf1, vbias1);
143 vf2 = wasm_f32x4_add(vf2, vbias2);
144 vf3 = wasm_f32x4_add(vf3, vbias3);
145 vf4 = wasm_f32x4_add(vf4, vbias4);
146 vf5 = wasm_f32x4_add(vf5, vbias5);
147 vf6 = wasm_f32x4_add(vf6, vbias6);
148 vf7 = wasm_f32x4_add(vf7, vbias7);
149
150 v128_t vexpw0 = wasm_i32x4_shr(vf0, 13);
151 v128_t vexpw1 = wasm_i32x4_shr(vf1, 13);
152 v128_t vexpw2 = wasm_i32x4_shr(vf2, 13);
153 v128_t vexpw3 = wasm_i32x4_shr(vf3, 13);
154 v128_t vexpw4 = wasm_i32x4_shr(vf4, 13);
155 v128_t vexpw5 = wasm_i32x4_shr(vf5, 13);
156 v128_t vexpw6 = wasm_i32x4_shr(vf6, 13);
157 v128_t vexpw7 = wasm_i32x4_shr(vf7, 13);
158
159 const v128_t vmantw0 = wasm_v128_and(vf0, vmanth_mask);
160 const v128_t vmantw1 = wasm_v128_and(vf1, vmanth_mask);
161 const v128_t vmantw2 = wasm_v128_and(vf2, vmanth_mask);
162 const v128_t vmantw3 = wasm_v128_and(vf3, vmanth_mask);
163 const v128_t vmantw4 = wasm_v128_and(vf4, vmanth_mask);
164 const v128_t vmantw5 = wasm_v128_and(vf5, vmanth_mask);
165 const v128_t vmantw6 = wasm_v128_and(vf6, vmanth_mask);
166 const v128_t vmantw7 = wasm_v128_and(vf7, vmanth_mask);
167
168 vexpw0 = wasm_v128_and(vexpw0, vexph_mask);
169 vexpw1 = wasm_v128_and(vexpw1, vexph_mask);
170 vexpw2 = wasm_v128_and(vexpw2, vexph_mask);
171 vexpw3 = wasm_v128_and(vexpw3, vexph_mask);
172 vexpw4 = wasm_v128_and(vexpw4, vexph_mask);
173 vexpw5 = wasm_v128_and(vexpw5, vexph_mask);
174 vexpw6 = wasm_v128_and(vexpw6, vexph_mask);
175 vexpw7 = wasm_v128_and(vexpw7, vexph_mask);
176
177 const v128_t vnonsignw0 = wasm_i32x4_add(vmantw0, vexpw0);
178 const v128_t vnonsignw1 = wasm_i32x4_add(vmantw1, vexpw1);
179 const v128_t vnonsignw2 = wasm_i32x4_add(vmantw2, vexpw2);
180 const v128_t vnonsignw3 = wasm_i32x4_add(vmantw3, vexpw3);
181 const v128_t vnonsignw4 = wasm_i32x4_add(vmantw4, vexpw4);
182 const v128_t vnonsignw5 = wasm_i32x4_add(vmantw5, vexpw5);
183 const v128_t vnonsignw6 = wasm_i32x4_add(vmantw6, vexpw6);
184 const v128_t vnonsignw7 = wasm_i32x4_add(vmantw7, vexpw7);
185
186 const v128_t vnonsignh0 = wasm_i16x8_narrow_i32x4(vnonsignw0, vnonsignw1);
187 const v128_t vnonsignh1 = wasm_i16x8_narrow_i32x4(vnonsignw2, vnonsignw3);
188 const v128_t vnonsignh2 = wasm_i16x8_narrow_i32x4(vnonsignw4, vnonsignw5);
189 const v128_t vnonsignh3 = wasm_i16x8_narrow_i32x4(vnonsignw6, vnonsignw7);
190
191 const v128_t vabsh0 = wasm_i16x8_relaxed_laneselect(vnanh, vnonsignh0, vnanmaskh0);
192 const v128_t vabsh1 = wasm_i16x8_relaxed_laneselect(vnanh, vnonsignh1, vnanmaskh1);
193 const v128_t vabsh2 = wasm_i16x8_relaxed_laneselect(vnanh, vnonsignh2, vnanmaskh2);
194 const v128_t vabsh3 = wasm_i16x8_relaxed_laneselect(vnanh, vnonsignh3, vnanmaskh3);
195
196 const v128_t vh0 = wasm_v128_or(vabsh0, vsignh0);
197 const v128_t vh1 = wasm_v128_or(vabsh1, vsignh1);
198 const v128_t vh2 = wasm_v128_or(vabsh2, vsignh2);
199 const v128_t vh3 = wasm_v128_or(vabsh3, vsignh3);
200
201 wasm_v128_store(o, vh0);
202 wasm_v128_store(o + 8, vh1);
203 wasm_v128_store(o + 16, vh2);
204 wasm_v128_store(o + 24, vh3);
205 o += 32;
206 }
207 for (; batch >= 8 * sizeof(float); batch -= 8 * sizeof(float)) {
208 const v128_t vx_lo = wasm_v128_load(input);
209 const v128_t vx_hi = wasm_v128_load(input + 4);
210 input += 8;
211
212 const v128_t vabsx_lo = wasm_f32x4_abs(vx_lo);
213 const v128_t vabsx_hi = wasm_f32x4_abs(vx_hi);
214
215 const v128_t vsignx_lo = wasm_v128_xor(vx_lo, vabsx_lo);
216 const v128_t vsignx_hi = wasm_v128_xor(vx_hi, vabsx_hi);
217 v128_t vbias_lo = wasm_i32x4_add(vabsx_lo, vexp_bias);
218 v128_t vbias_hi = wasm_i32x4_add(vabsx_hi, vexp_bias);
219 v128_t vf_lo = wasm_f32x4_mul(vabsx_lo, vscale_to_inf);
220 v128_t vf_hi = wasm_f32x4_mul(vabsx_hi, vscale_to_inf);
221 const v128_t vnanmaskw_lo = wasm_i32x4_gt(vabsx_lo, vexpw_max);
222 const v128_t vnanmaskw_hi = wasm_i32x4_gt(vabsx_hi, vexpw_max);
223
224 vbias_lo = wasm_v128_and(vbias_lo, vexpw_max);
225 vbias_hi = wasm_v128_and(vbias_hi, vexpw_max);
226 vf_lo = wasm_f32x4_mul(vf_lo, vscale_to_zero);
227 vf_hi = wasm_f32x4_mul(vf_hi, vscale_to_zero);
228 const v128_t vnanmaskh = wasm_i16x8_narrow_i32x4(vnanmaskw_lo, vnanmaskw_hi);
229 const v128_t vsignh = wasm_i16x8_narrow_i32x4(vsignx_lo, vsignx_hi);
230
231 vbias_lo = wasm_i16x8_max(vbias_lo, vbias_min);
232 vbias_hi = wasm_i16x8_max(vbias_hi, vbias_min);
233
234 vf_lo = wasm_f32x4_add(vf_lo, vbias_lo);
235 vf_hi = wasm_f32x4_add(vf_hi, vbias_hi);
236
237 v128_t vexpw_lo = wasm_i32x4_shr(vf_lo, 13);
238 v128_t vexpw_hi = wasm_i32x4_shr(vf_hi, 13);
239 const v128_t vmantw_lo = wasm_v128_and(vf_lo, vmanth_mask);
240 const v128_t vmantw_hi = wasm_v128_and(vf_hi, vmanth_mask);
241
242 vexpw_lo = wasm_v128_and(vexpw_lo, vexph_mask);
243 vexpw_hi = wasm_v128_and(vexpw_hi, vexph_mask);
244
245 const v128_t vnonsignw_lo = wasm_i32x4_add(vmantw_lo, vexpw_lo);
246 const v128_t vnonsignw_hi = wasm_i32x4_add(vmantw_hi, vexpw_hi);
247
248 const v128_t vnonsignh = wasm_i16x8_narrow_i32x4(vnonsignw_lo, vnonsignw_hi);
249
250 const v128_t vabsh = wasm_i16x8_relaxed_laneselect(vnanh, vnonsignh, vnanmaskh);
251
252 const v128_t vh = wasm_v128_or(vabsh, vsignh);
253
254 wasm_v128_store(o, vh);
255 o += 8;
256 }
257 if XNN_UNPREDICTABLE(batch != 0) {
258 const v128_t vx_lo = wasm_v128_load(input);
259 const float* input_hi = (const float*) ((uintptr_t) input + (batch & (4 * sizeof(float))));
260 const v128_t vx_hi = wasm_v128_load(input_hi);
261
262 const v128_t vabsx_lo = wasm_f32x4_abs(vx_lo);
263 const v128_t vabsx_hi = wasm_f32x4_abs(vx_hi);
264
265 const v128_t vsignx_lo = wasm_v128_xor(vx_lo, vabsx_lo);
266 const v128_t vsignx_hi = wasm_v128_xor(vx_hi, vabsx_hi);
267 v128_t vbias_lo = wasm_i32x4_add(vabsx_lo, vexp_bias);
268 v128_t vbias_hi = wasm_i32x4_add(vabsx_hi, vexp_bias);
269 v128_t vf_lo = wasm_f32x4_mul(vabsx_lo, vscale_to_inf);
270 v128_t vf_hi = wasm_f32x4_mul(vabsx_hi, vscale_to_inf);
271 const v128_t vnanmaskw_lo = wasm_i32x4_gt(vabsx_lo, vexpw_max);
272 const v128_t vnanmaskw_hi = wasm_i32x4_gt(vabsx_hi, vexpw_max);
273
274 vbias_lo = wasm_v128_and(vbias_lo, vexpw_max);
275 vbias_hi = wasm_v128_and(vbias_hi, vexpw_max);
276 vf_lo = wasm_f32x4_mul(vf_lo, vscale_to_zero);
277 vf_hi = wasm_f32x4_mul(vf_hi, vscale_to_zero);
278 const v128_t vnanmaskh = wasm_i16x8_narrow_i32x4(vnanmaskw_lo, vnanmaskw_hi);
279 const v128_t vsignh = wasm_i16x8_narrow_i32x4(vsignx_lo, vsignx_hi);
280
281 vbias_lo = wasm_i16x8_max(vbias_lo, vbias_min);
282 vbias_hi = wasm_i16x8_max(vbias_hi, vbias_min);
283
284 vf_lo = wasm_f32x4_add(vf_lo, vbias_lo);
285 vf_hi = wasm_f32x4_add(vf_hi, vbias_hi);
286
287 v128_t vexpw_lo = wasm_i32x4_shr(vf_lo, 13);
288 v128_t vexpw_hi = wasm_i32x4_shr(vf_hi, 13);
289 const v128_t vmantw_lo = wasm_v128_and(vf_lo, vmanth_mask);
290 const v128_t vmantw_hi = wasm_v128_and(vf_hi, vmanth_mask);
291
292 vexpw_lo = wasm_v128_and(vexpw_lo, vexph_mask);
293 vexpw_hi = wasm_v128_and(vexpw_hi, vexph_mask);
294
295 const v128_t vnonsignw_lo = wasm_i32x4_add(vmantw_lo, vexpw_lo);
296 const v128_t vnonsignw_hi = wasm_i32x4_add(vmantw_hi, vexpw_hi);
297
298 const v128_t vnonsignh = wasm_i16x8_narrow_i32x4(vnonsignw_lo, vnonsignw_hi);
299
300 const v128_t vabsh = wasm_i16x8_relaxed_laneselect(vnanh, vnonsignh, vnanmaskh);
301
302 v128_t vh = wasm_v128_or(vabsh, vsignh);
303
304 if (batch & (4 * sizeof(float))) {
305 wasm_v128_store64_lane(o, vh, 0);
306 vh = wasm_v64x2_shuffle(vh, vh, 1, 1);
307 o += 4;
308 }
309 if (batch & (2 * sizeof(float))) {
310 wasm_v128_store32_lane(o, vh, 0);
311 vh = wasm_i64x2_shr(vh, 32);
312 o += 2;
313 }
314 if (batch & (1 * sizeof(float))) {
315 wasm_v128_store16_lane(o, vh, 0);
316 }
317 }
318 }