floatunsidf.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //===-- lib/floatunsidf.c - uint -> double-precision conversion ---*- C -*-===//
  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 unsigned integer to double-precision conversion for the
  10. // compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
  11. // mode.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #define DOUBLE_PRECISION
  15. #include "fp_lib.h"
  16. #include "int_lib.h"
  17. COMPILER_RT_ABI fp_t __floatunsidf(su_int a) {
  18. const int aWidth = sizeof a * CHAR_BIT;
  19. // Handle zero as a special case to protect clz
  20. if (a == 0)
  21. return fromRep(0);
  22. // Exponent of (fp_t)a is the width of abs(a).
  23. const int exponent = (aWidth - 1) - clzsi(a);
  24. rep_t result;
  25. // Shift a into the significand field and clear the implicit bit.
  26. const int shift = significandBits - exponent;
  27. result = (rep_t)a << shift ^ implicitBit;
  28. // Insert the exponent
  29. result += (rep_t)(exponent + exponentBias) << significandBits;
  30. return fromRep(result);
  31. }
  32. #if defined(__ARM_EABI__)
  33. #if defined(COMPILER_RT_ARMHF_TARGET)
  34. AEABI_RTABI fp_t __aeabi_ui2d(su_int a) { return __floatunsidf(a); }
  35. #else
  36. COMPILER_RT_ALIAS(__floatunsidf, __aeabi_ui2d)
  37. #endif
  38. #endif