floatundidf.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //===-- floatundidf.c - Implement __floatundidf ---------------------------===//
  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. // This file implements __floatundidf for the compiler_rt library.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. // Returns: convert a to a double, rounding toward even.
  13. // Assumption: double is a IEEE 64 bit floating point type
  14. // du_int is a 64 bit integral type
  15. // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm
  16. // mmmm
  17. #include "int_lib.h"
  18. #ifndef __SOFTFP__
  19. // Support for systems that have hardware floating-point; we'll set the inexact
  20. // flag as a side-effect of this computation.
  21. COMPILER_RT_ABI double __floatundidf(du_int a) {
  22. static const double twop52 = 4503599627370496.0; // 0x1.0p52
  23. static const double twop84 = 19342813113834066795298816.0; // 0x1.0p84
  24. static const double twop84_plus_twop52 =
  25. 19342813118337666422669312.0; // 0x1.00000001p84
  26. union {
  27. uint64_t x;
  28. double d;
  29. } high = {.d = twop84};
  30. union {
  31. uint64_t x;
  32. double d;
  33. } low = {.d = twop52};
  34. high.x |= a >> 32;
  35. low.x |= a & UINT64_C(0x00000000ffffffff);
  36. const double result = (high.d - twop84_plus_twop52) + low.d;
  37. return result;
  38. }
  39. #else
  40. // Support for systems that don't have hardware floating-point; there are no
  41. // flags to set, and we don't want to code-gen to an unknown soft-float
  42. // implementation.
  43. #define SRC_U64
  44. #define DST_DOUBLE
  45. #include "int_to_fp_impl.inc"
  46. COMPILER_RT_ABI double __floatundidf(du_int a) { return __floatXiYf__(a); }
  47. #endif
  48. #if defined(__ARM_EABI__)
  49. #if defined(COMPILER_RT_ARMHF_TARGET)
  50. AEABI_RTABI double __aeabi_ul2d(du_int a) { return __floatundidf(a); }
  51. #else
  52. COMPILER_RT_ALIAS(__floatundidf, __aeabi_ul2d)
  53. #endif
  54. #endif
  55. #if defined(__MINGW32__) && defined(__arm__)
  56. COMPILER_RT_ALIAS(__floatundidf, __u64tod)
  57. #endif