1//===-- int_to_fp.h - integer to floating point conversion ----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Set source and destination defines in order to use a correctly
10// parameterised floatXiYf implementation.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef INT_TO_FP_H
15#define INT_TO_FP_H
16
17#include "int_lib.h"
18
19#if defined SRC_I64
20typedef int64_t src_t;
21typedef uint64_t usrc_t;
22static __inline int clzSrcT(usrc_t x) { return __builtin_clzll(x); }
23
24#elif defined SRC_U64
25typedef uint64_t src_t;
26typedef uint64_t usrc_t;
27static __inline int clzSrcT(usrc_t x) { return __builtin_clzll(x); }
28
29#elif defined SRC_I128
30typedef __int128_t src_t;
31typedef __uint128_t usrc_t;
32static __inline int clzSrcT(usrc_t x) { return __clzti2(x); }
33
34#elif defined SRC_U128
35typedef __uint128_t src_t;
36typedef __uint128_t usrc_t;
37static __inline int clzSrcT(usrc_t x) { return __clzti2(a: x); }
38
39#else
40#error Source should be a handled integer type.
41#endif
42
43#if defined DST_SINGLE
44typedef float dst_t;
45typedef uint32_t dst_rep_t;
46#define DST_REP_C UINT32_C
47
48enum {
49 dstSigBits = 23,
50};
51
52#elif defined DST_DOUBLE
53typedef double dst_t;
54typedef uint64_t dst_rep_t;
55#define DST_REP_C UINT64_C
56
57enum {
58 dstSigBits = 52,
59};
60
61#elif defined DST_QUAD
62typedef tf_float dst_t;
63typedef __uint128_t dst_rep_t;
64#define DST_REP_C (__uint128_t)
65
66enum {
67 dstSigBits = 112,
68};
69
70#else
71#error Destination should be a handled floating point type
72#endif
73
74static __inline dst_t dstFromRep(dst_rep_t x) {
75 const union {
76 dst_t f;
77 dst_rep_t i;
78 } rep = {.i = x};
79 return rep.f;
80}
81
82#endif // INT_TO_FP_H
83

source code of compiler-rt/lib/builtins/int_to_fp.h