int_to_fp.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #ifndef INT_TO_FP_H
  14. #define INT_TO_FP_H
  15. #include "int_lib.h"
  16. #if defined SRC_I64
  17. typedef int64_t src_t;
  18. typedef uint64_t usrc_t;
  19. static __inline int clzSrcT(usrc_t x) { return __builtin_clzll(x); }
  20. #elif defined SRC_U64
  21. typedef uint64_t src_t;
  22. typedef uint64_t usrc_t;
  23. static __inline int clzSrcT(usrc_t x) { return __builtin_clzll(x); }
  24. #elif defined SRC_I128
  25. typedef __int128_t src_t;
  26. typedef __uint128_t usrc_t;
  27. static __inline int clzSrcT(usrc_t x) { return __clzti2(x); }
  28. #elif defined SRC_U128
  29. typedef __uint128_t src_t;
  30. typedef __uint128_t usrc_t;
  31. static __inline int clzSrcT(usrc_t x) { return __clzti2(x); }
  32. #else
  33. #error Source should be a handled integer type.
  34. #endif
  35. #if defined DST_SINGLE
  36. typedef float dst_t;
  37. typedef uint32_t dst_rep_t;
  38. #define DST_REP_C UINT32_C
  39. enum {
  40. dstSigBits = 23,
  41. };
  42. #elif defined DST_DOUBLE
  43. typedef double dst_t;
  44. typedef uint64_t dst_rep_t;
  45. #define DST_REP_C UINT64_C
  46. enum {
  47. dstSigBits = 52,
  48. };
  49. #elif defined DST_QUAD
  50. typedef tf_float dst_t;
  51. typedef __uint128_t dst_rep_t;
  52. #define DST_REP_C (__uint128_t)
  53. enum {
  54. dstSigBits = 112,
  55. };
  56. #else
  57. #error Destination should be a handled floating point type
  58. #endif
  59. static __inline dst_t dstFromRep(dst_rep_t x) {
  60. const union {
  61. dst_t f;
  62. dst_rep_t i;
  63. } rep = {.i = x};
  64. return rep.f;
  65. }
  66. #endif // INT_TO_FP_H