floatunsitf.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //===-- lib/floatunsitf.c - uint -> quad-precision conversion -----*- C -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements unsigned integer to quad-precision conversion for the
  11. // compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
  12. // mode.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #define QUAD_PRECISION
  16. #include "fp_lib.h"
  17. #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
  18. COMPILER_RT_ABI fp_t __floatunsitf(unsigned int a) {
  19. const int aWidth = sizeof a * CHAR_BIT;
  20. // Handle zero as a special case to protect clz
  21. if (a == 0) return fromRep(0);
  22. // Exponent of (fp_t)a is the width of abs(a).
  23. const int exponent = (aWidth - 1) - __builtin_clz(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. #endif