| 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 |
| 20 | typedef int64_t src_t; |
| 21 | typedef uint64_t usrc_t; |
| 22 | static __inline int clzSrcT(usrc_t x) { return __builtin_clzll(x); } |
| 23 | |
| 24 | #elif defined SRC_U64 |
| 25 | typedef uint64_t src_t; |
| 26 | typedef uint64_t usrc_t; |
| 27 | static __inline int clzSrcT(usrc_t x) { return __builtin_clzll(x); } |
| 28 | |
| 29 | #elif defined SRC_I128 |
| 30 | typedef __int128_t src_t; |
| 31 | typedef __uint128_t usrc_t; |
| 32 | static __inline int clzSrcT(usrc_t x) { return __clzti2(x); } |
| 33 | |
| 34 | #elif defined SRC_U128 |
| 35 | typedef __uint128_t src_t; |
| 36 | typedef __uint128_t usrc_t; |
| 37 | static __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 |
| 44 | typedef float dst_t; |
| 45 | typedef uint32_t dst_rep_t; |
| 46 | #define DST_REP_C UINT32_C |
| 47 | |
| 48 | enum { |
| 49 | dstSigBits = 23, |
| 50 | }; |
| 51 | |
| 52 | #elif defined DST_DOUBLE |
| 53 | typedef double dst_t; |
| 54 | typedef uint64_t dst_rep_t; |
| 55 | #define DST_REP_C UINT64_C |
| 56 | |
| 57 | enum { |
| 58 | dstSigBits = 52, |
| 59 | }; |
| 60 | |
| 61 | #elif defined DST_QUAD |
| 62 | typedef tf_float dst_t; |
| 63 | typedef __uint128_t dst_rep_t; |
| 64 | #define DST_REP_C (__uint128_t) |
| 65 | |
| 66 | enum { |
| 67 | dstSigBits = 112, |
| 68 | }; |
| 69 | |
| 70 | #else |
| 71 | #error Destination should be a handled floating point type |
| 72 | #endif |
| 73 | |
| 74 | static __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 | |