Debian Codegraph @

src/f32-f16-vcvt/gen/f32-f16-vcvt-scalar-bitcast-u1.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-f16-vcvt/scalar-bitcast.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_f32_f16_vcvt_ukernel__scalar_bitcast_u1(
18 size_t batch,
19 const float* input,
20 xnn_float16* output,
21 const void* params)
22 {
23 assert(batch != 0);
24 assert(batch % sizeof(float) == 0);
25 assert(input != NULL);
26 assert(output != NULL);
27
28 const uint32_t vnonsign_mask = UINT32_C(0x7FFFFFFF);
29 const uint32_t vexp_bias = UINT32_C(0x07800000);
30 const float vscale_to_inf = 0x1.0p+112f;
31 const uint32_t vexpw_max = UINT32_C(0x7F800000);
32 const float vscale_to_zero = 0x1.0p-110f;
33 const uint32_t vbias_min = UINT32_C(0x40000000);
34 const uint16_t vexph_mask = UINT16_C(0x7C00);
35 const uint16_t vmanth_mask = UINT16_C(0x0FFF);
36 const uint16_t vnanh = UINT16_C(0x7E00);
37
38 const uint32_t* i = (const uint32_t*) input;
39 uint16_t* o = (uint16_t*) output;
40 do {
41 const uint32_t vw = *i++;
42
43 const uint32_t vnonsignw = vw & vnonsign_mask;
44
45 float vf = uint32_as_float(vnonsignw);
46 const uint32_t vsignw = vw ^ vnonsignw;
47 uint32_t vbias = vnonsignw + vexp_bias;
48
49 vf *= vscale_to_inf;
50 vbias &= vexpw_max;
51
52 vf *= vscale_to_zero;
53 vbias = math_max_u32(vbias, vbias_min);
54
55 vf += uint32_as_float(vbias);
56
57 const uint32_t vbits = float_as_uint32(vf);
58
59 const uint16_t vexph = (uint16_t) (vbits >> 13) & vexph_mask;
60 const uint16_t vmanth = (uint16_t) vbits & vmanth_mask;
61 const uint16_t vsignh = (uint16_t) (vsignw >> 16);
62
63 uint16_t vh = vexph + vmanth;
64 if XNN_UNPREDICTABLE(vnonsignw > vexpw_max) {
65 vh = vnanh;
66 }
67 vh |= vsignh;
68
69 *o++ = vh;
70
71 batch -= sizeof(float);
72 } while (batch != 0);
73 }