1 //===-lib/fp_extend.h - low precision -> high precision conversion -*- C
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 // Set source and destination setting
12 //===----------------------------------------------------------------------===//
14 #ifndef FP_EXTEND_HEADER
15 #define FP_EXTEND_HEADER
19 #if defined SRC_SINGLE
21 typedef uint32_t src_rep_t;
22 #define SRC_REP_C UINT32_C
23 static const int srcSigBits = 23;
24 #define src_rep_t_clz __builtin_clz
26 #elif defined SRC_DOUBLE
28 typedef uint64_t src_rep_t;
29 #define SRC_REP_C UINT64_C
30 static const int srcSigBits = 52;
31 static __inline int src_rep_t_clz(src_rep_t a) {
33 return __builtin_clzl(a);
35 if (a & REP_C(0xffffffff00000000))
36 return __builtin_clz(a >> 32);
38 return 32 + __builtin_clz(a & REP_C(0xffffffff));
42 #elif defined SRC_HALF
43 typedef uint16_t src_t;
44 typedef uint16_t src_rep_t;
45 #define SRC_REP_C UINT16_C
46 static const int srcSigBits = 10;
47 #define src_rep_t_clz __builtin_clz
50 #error Source should be half, single, or double precision!
51 #endif // end source precision
53 #if defined DST_SINGLE
55 typedef uint32_t dst_rep_t;
56 #define DST_REP_C UINT32_C
57 static const int dstSigBits = 23;
59 #elif defined DST_DOUBLE
61 typedef uint64_t dst_rep_t;
62 #define DST_REP_C UINT64_C
63 static const int dstSigBits = 52;
65 #elif defined DST_QUAD
66 typedef long double dst_t;
67 typedef __uint128_t dst_rep_t;
68 #define DST_REP_C (__uint128_t)
69 static const int dstSigBits = 112;
72 #error Destination should be single, double, or quad precision!
73 #endif // end destination precision
75 // End of specialization parameters. Two helper routines for conversion to and
76 // from the representation of floating-point data as integer values follow.
78 static __inline src_rep_t srcToRep(src_t x) {
86 static __inline dst_t dstFromRep(dst_rep_t x) {
93 // End helper routines. Conversion implementation follows.
95 #endif // FP_EXTEND_HEADER