floatdidf.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //===-- floatdidf.c - Implement __floatdidf -------------------------------===//
  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 __floatdidf for the compiler_rt library.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "int_lib.h"
  13. // Returns: convert a to a double, rounding toward even.
  14. // Assumption: double is a IEEE 64 bit floating point type
  15. // di_int is a 64 bit integral type
  16. // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm
  17. // mmmm
  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 __floatdidf(di_int a) {
  22. static const double twop52 = 4503599627370496.0; // 0x1.0p52
  23. static const double twop32 = 4294967296.0; // 0x1.0p32
  24. union {
  25. int64_t x;
  26. double d;
  27. } low = {.d = twop52};
  28. const double high = (int32_t)(a >> 32) * twop32;
  29. low.x |= a & INT64_C(0x00000000ffffffff);
  30. const double result = (high - twop52) + low.d;
  31. return result;
  32. }
  33. #else
  34. // Support for systems that don't have hardware floating-point; there are no
  35. // flags to set, and we don't want to code-gen to an unknown soft-float
  36. // implementation.
  37. #define SRC_I64
  38. #define DST_DOUBLE
  39. #include "int_to_fp_impl.inc"
  40. COMPILER_RT_ABI double __floatdidf(di_int a) { return __floatXiYf__(a); }
  41. #endif
  42. #if defined(__ARM_EABI__)
  43. #if defined(COMPILER_RT_ARMHF_TARGET)
  44. AEABI_RTABI double __aeabi_l2d(di_int a) { return __floatdidf(a); }
  45. #else
  46. COMPILER_RT_ALIAS(__floatdidf, __aeabi_l2d)
  47. #endif
  48. #endif
  49. #if defined(__MINGW32__) && defined(__arm__)
  50. COMPILER_RT_ALIAS(__floatdidf, __i64tod)
  51. #endif