Debian Codegraph @

src/f16-f32-vcvt/gen/f16-f32-vcvt-wasmrelaxedsimd-int32-u24.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_u24(
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 >= 24 * sizeof(uint16_t); batch -= 24 * 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 i += 24;
47
48 const v128_t vzero = wasm_i16x8_const_splat(0);
49 const v128_t vw0 = wasm_v16x8_shuffle(vzero, vh0, 0, 8, 1, 9, 2, 10, 3, 11);
50 const v128_t vw1 = wasm_v16x8_shuffle(vzero, vh0, 4, 12, 5, 13, 6, 14, 7, 15);
51 const v128_t vw2 = wasm_v16x8_shuffle(vzero, vh1, 0, 8, 1, 9, 2, 10, 3, 11);
52 const v128_t vw3 = wasm_v16x8_shuffle(vzero, vh1, 4, 12, 5, 13, 6, 14, 7, 15);
53 const v128_t vw4 = wasm_v16x8_shuffle(vzero, vh2, 0, 8, 1, 9, 2, 10, 3, 11);
54 const v128_t vw5 = wasm_v16x8_shuffle(vzero, vh2, 4, 12, 5, 13, 6, 14, 7, 15);
55
56 const v128_t vsign0 = wasm_v128_and(vw0, vsign_mask);
57 const v128_t vsign1 = wasm_v128_and(vw1, vsign_mask);
58 const v128_t vsign2 = wasm_v128_and(vw2, vsign_mask);
59 const v128_t vsign3 = wasm_v128_and(vw3, vsign_mask);
60 const v128_t vsign4 = wasm_v128_and(vw4, vsign_mask);
61 const v128_t vsign5 = wasm_v128_and(vw5, vsign_mask);
62
63 const v128_t vnonsign0 = wasm_v128_xor(vw0, vsign0);
64 const v128_t vnonsign1 = wasm_v128_xor(vw1, vsign1);
65 const v128_t vnonsign2 = wasm_v128_xor(vw2, vsign2);
66 const v128_t vnonsign3 = wasm_v128_xor(vw3, vsign3);
67 const v128_t vnonsign4 = wasm_v128_xor(vw4, vsign4);
68 const v128_t vnonsign5 = wasm_v128_xor(vw5, vsign5);
69
70 const v128_t vnorm0 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign0, 3), vexp_offset), vexp_scale);
71 const v128_t vnorm1 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign1, 3), vexp_offset), vexp_scale);
72 const v128_t vnorm2 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign2, 3), vexp_offset), vexp_scale);
73 const v128_t vnorm3 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign3, 3), vexp_offset), vexp_scale);
74 const v128_t vnorm4 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign4, 3), vexp_offset), vexp_scale);
75 const v128_t vnorm5 = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign5, 3), vexp_offset), vexp_scale);
76
77 const v128_t vdenorm0 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign0, 16), vmagic_bias), vmagic_bias);
78 const v128_t vdenorm1 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign1, 16), vmagic_bias), vmagic_bias);
79 const v128_t vdenorm2 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign2, 16), vmagic_bias), vmagic_bias);
80 const v128_t vdenorm3 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign3, 16), vmagic_bias), vmagic_bias);
81 const v128_t vdenorm4 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign4, 16), vmagic_bias), vmagic_bias);
82 const v128_t vdenorm5 = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign5, 16), vmagic_bias), vmagic_bias);
83
84 const v128_t vxmask0 = wasm_i32x4_gt(vnonsign0, vdenorm_cutoff);
85 const v128_t vxmask1 = wasm_i32x4_gt(vnonsign1, vdenorm_cutoff);
86 const v128_t vxmask2 = wasm_i32x4_gt(vnonsign2, vdenorm_cutoff);
87 const v128_t vxmask3 = wasm_i32x4_gt(vnonsign3, vdenorm_cutoff);
88 const v128_t vxmask4 = wasm_i32x4_gt(vnonsign4, vdenorm_cutoff);
89 const v128_t vxmask5 = wasm_i32x4_gt(vnonsign5, vdenorm_cutoff);
90
91 const v128_t vf0 = wasm_v128_or(vsign0, wasm_v128_bitselect(vnorm0, vdenorm0, vxmask0));
92 const v128_t vf1 = wasm_v128_or(vsign1, wasm_v128_bitselect(vnorm1, vdenorm1, vxmask1));
93 const v128_t vf2 = wasm_v128_or(vsign2, wasm_v128_bitselect(vnorm2, vdenorm2, vxmask2));
94 const v128_t vf3 = wasm_v128_or(vsign3, wasm_v128_bitselect(vnorm3, vdenorm3, vxmask3));
95 const v128_t vf4 = wasm_v128_or(vsign4, wasm_v128_bitselect(vnorm4, vdenorm4, vxmask4));
96 const v128_t vf5 = wasm_v128_or(vsign5, wasm_v128_bitselect(vnorm5, vdenorm5, vxmask5));
97
98 wasm_v128_store(output, vf0);
99 wasm_v128_store(output + 4, vf1);
100 wasm_v128_store(output + 8, vf2);
101 wasm_v128_store(output + 12, vf3);
102 wasm_v128_store(output + 16, vf4);
103 wasm_v128_store(output + 20, vf5);
104 output += 24;
105 }
106 for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) {
107 const v128_t vh = wasm_v128_load(i);
108 i += 8;
109
110 const v128_t vzero = wasm_i16x8_const_splat(0);
111 const v128_t vw_lo = wasm_v16x8_shuffle(vzero, vh, 0, 8, 1, 9, 2, 10, 3, 11);
112 const v128_t vw_hi = wasm_v16x8_shuffle(vzero, vh, 4, 12, 5, 13, 6, 14, 7, 15);
113
114 const v128_t vsign_lo = wasm_v128_and(vw_lo, vsign_mask);
115 const v128_t vsign_hi = wasm_v128_and(vw_hi, vsign_mask);
116
117 const v128_t vnonsign_lo = wasm_v128_xor(vw_lo, vsign_lo);
118 const v128_t vnonsign_hi = wasm_v128_xor(vw_hi, vsign_hi);
119
120 const v128_t vnorm_lo = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign_lo, 3), vexp_offset), vexp_scale);
121 const v128_t vnorm_hi = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign_hi, 3), vexp_offset), vexp_scale);
122
123 const v128_t vdenorm_lo = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign_lo, 16), vmagic_bias), vmagic_bias);
124 const v128_t vdenorm_hi = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign_hi, 16), vmagic_bias), vmagic_bias);
125
126 const v128_t vxmask_lo = wasm_i32x4_gt(vnonsign_lo, vdenorm_cutoff);
127 const v128_t vxmask_hi = wasm_i32x4_gt(vnonsign_hi, vdenorm_cutoff);
128
129 const v128_t vf_lo = wasm_v128_or(vsign_lo, wasm_v128_bitselect(vnorm_lo, vdenorm_lo, vxmask_lo));
130 const v128_t vf_hi = wasm_v128_or(vsign_hi, wasm_v128_bitselect(vnorm_hi, vdenorm_hi, vxmask_hi));
131
132 wasm_v128_store(output, vf_lo);
133 wasm_v128_store(output + 4, vf_hi);
134 output += 8;
135 }
136 if XNN_UNLIKELY(batch != 0) {
137 assert(batch >= 1 * sizeof(uint16_t));
138 assert(batch <= 7 * sizeof(uint16_t));
139 const v128_t vh = wasm_v128_load(i);
140
141 const v128_t vzero = wasm_i16x8_const_splat(0);
142 const v128_t vw_lo = wasm_v16x8_shuffle(vzero, vh, 0, 8, 1, 9, 2, 10, 3, 11);
143 const v128_t vw_hi = wasm_v16x8_shuffle(vzero, vh, 4, 12, 5, 13, 6, 14, 7, 15);
144
145 const v128_t vsign_lo = wasm_v128_and(vw_lo, vsign_mask);
146 const v128_t vsign_hi = wasm_v128_and(vw_hi, vsign_mask);
147
148 const v128_t vnonsign_lo = wasm_v128_xor(vw_lo, vsign_lo);
149 const v128_t vnonsign_hi = wasm_v128_xor(vw_hi, vsign_hi);
150
151 const v128_t vnorm_lo = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign_lo, 3), vexp_offset), vexp_scale);
152 const v128_t vnorm_hi = wasm_f32x4_mul(wasm_i32x4_add(wasm_u32x4_shr(vnonsign_hi, 3), vexp_offset), vexp_scale);
153
154 const v128_t vdenorm_lo = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign_lo, 16), vmagic_bias), vmagic_bias);
155 const v128_t vdenorm_hi = wasm_f32x4_sub(wasm_v128_or(wasm_u32x4_shr(vnonsign_hi, 16), vmagic_bias), vmagic_bias);
156
157 const v128_t vxmask_lo = wasm_i32x4_gt(vnonsign_lo, vdenorm_cutoff);
158 v128_t vf = wasm_v128_or(vsign_lo, wasm_v128_bitselect(vnorm_lo, vdenorm_lo, vxmask_lo));
159
160 if (batch & (4 * sizeof(uint16_t))) {
161 wasm_v128_store(output, vf);
162 output += 4;
163
164 const v128_t vxmask_hi = wasm_i32x4_gt(vnonsign_hi, vdenorm_cutoff);
165 vf = wasm_v128_or(vsign_hi, wasm_v128_bitselect(vnorm_hi, vdenorm_hi, vxmask_hi));
166 }
167 if (batch & (2 * sizeof(uint16_t))) {
168 wasm_v128_store64_lane(output, vf, 0);
169 vf = wasm_v64x2_shuffle(vf, vf, 1, 1);
170 output += 2;
171 }
172 if (batch & (1 * sizeof(uint16_t))) {
173 wasm_v128_store32_lane(output, vf, 0);
174 }
175 }
176 }