Debian Codegraph @

src/f16-f32-vcvt/gen/f16-f32-vcvt-scalar-u4.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-f32-vcvt/scalar.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 "xnnpack/common.h"
13 #include "xnnpack/math.h"
14 #include "xnnpack/vcvt.h"
15
16
17 void xnn_f16_f32_vcvt_ukernel__scalar_u4(
18 size_t batch,
19 const xnn_float16* input,
20 float* output,
21 const void* params)
22 {
23 assert(batch != 0);
24 assert(batch % sizeof(uint16_t) == 0);
25 assert(input != NULL);
26 assert(output != NULL);
27
28 const uint32_t vsign_mask = 0x80000000;
29 const uint32_t vexp_offset = 0x70000000;
30 const float vexp_scale = 0x1.0p-112f;
31 const uint32_t vmagic_mask = 0x3F000000;
32 const float vmagic_bias = 0.5f;
33 const uint32_t vdenorm_cutoff = 0x08000000;
34
35 const uint16_t* i = (const uint16_t*) input;
36 uint32_t* o = (uint32_t*) output;
37 for (; batch >= 4 * sizeof(uint16_t); batch -= 4 * sizeof(uint16_t)) {
38 const uint16_t vh0 = i[0];
39 const uint16_t vh1 = i[1];
40 const uint16_t vh2 = i[2];
41 const uint16_t vh3 = i[3];
42 i += 4;
43
44 const uint32_t vw0 = (uint32_t) vh0 << 16;
45 const uint32_t vw1 = (uint32_t) vh1 << 16;
46 const uint32_t vw2 = (uint32_t) vh2 << 16;
47 const uint32_t vw3 = (uint32_t) vh3 << 16;
48
49 const uint32_t vsign0 = vw0 & vsign_mask;
50 const uint32_t vsign1 = vw1 & vsign_mask;
51 const uint32_t vsign2 = vw2 & vsign_mask;
52 const uint32_t vsign3 = vw3 & vsign_mask;
53
54 const uint32_t v2w0 = vw0 + vw0;
55 const uint32_t v2w1 = vw1 + vw1;
56 const uint32_t v2w2 = vw2 + vw2;
57 const uint32_t v2w3 = vw3 + vw3;
58
59 const uint32_t vnorm0 = float_as_uint32(uint32_as_float((v2w0 >> 4) + vexp_offset) * vexp_scale);
60 const uint32_t vnorm1 = float_as_uint32(uint32_as_float((v2w1 >> 4) + vexp_offset) * vexp_scale);
61 const uint32_t vnorm2 = float_as_uint32(uint32_as_float((v2w2 >> 4) + vexp_offset) * vexp_scale);
62 const uint32_t vnorm3 = float_as_uint32(uint32_as_float((v2w3 >> 4) + vexp_offset) * vexp_scale);
63
64 const uint32_t vdenorm0 = float_as_uint32(uint32_as_float((v2w0 >> 17) | vmagic_mask) - vmagic_bias);
65 const uint32_t vdenorm1 = float_as_uint32(uint32_as_float((v2w1 >> 17) | vmagic_mask) - vmagic_bias);
66 const uint32_t vdenorm2 = float_as_uint32(uint32_as_float((v2w2 >> 17) | vmagic_mask) - vmagic_bias);
67 const uint32_t vdenorm3 = float_as_uint32(uint32_as_float((v2w3 >> 17) | vmagic_mask) - vmagic_bias);
68
69 const uint32_t vf0 = vsign0 | (XNN_UNPREDICTABLE(v2w0 < vdenorm_cutoff) ? vdenorm0 : vnorm0);
70 const uint32_t vf1 = vsign1 | (XNN_UNPREDICTABLE(v2w1 < vdenorm_cutoff) ? vdenorm1 : vnorm1);
71 const uint32_t vf2 = vsign2 | (XNN_UNPREDICTABLE(v2w2 < vdenorm_cutoff) ? vdenorm2 : vnorm2);
72 const uint32_t vf3 = vsign3 | (XNN_UNPREDICTABLE(v2w3 < vdenorm_cutoff) ? vdenorm3 : vnorm3);
73
74 o[0] = vf0;
75 o[1] = vf1;
76 o[2] = vf2;
77 o[3] = vf3;
78 o += 4;
79 }
80 if XNN_UNLIKELY(batch != 0) {
81 do {
82 const uint16_t vh = *i++;
83
84 const uint32_t vw = (uint32_t) vh << 16;
85 const uint32_t vsign = vw & vsign_mask;
86 const uint32_t v2w = vw + vw;
87 const uint32_t vnorm = float_as_uint32(uint32_as_float((v2w >> 4) + vexp_offset) * vexp_scale);
88 const uint32_t vdenorm = float_as_uint32(uint32_as_float((v2w >> 17) | vmagic_mask) - vmagic_bias);
89 const uint32_t vf = vsign | (XNN_UNPREDICTABLE(v2w < vdenorm_cutoff) ? vdenorm : vnorm);
90
91 *o++ = vf;
92
93 batch -= sizeof(uint16_t);
94 } while (batch != 0);
95 }
96 }