floatundixf.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //===-- floatundixf.c - Implement __floatundixf ---------------------------===//
  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 __floatundixf for the compiler_rt library.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #if !_ARCH_PPC
  13. #include "int_lib.h"
  14. // Returns: convert a to a long double, rounding toward even.
  15. // Assumption: long double is a IEEE 80 bit floating point type padded to 128
  16. // bits du_int is a 64 bit integral type
  17. // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee
  18. // eeee | 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm
  19. // mmmm mmmm mmmm
  20. COMPILER_RT_ABI xf_float __floatundixf(du_int a) {
  21. if (a == 0)
  22. return 0.0;
  23. const unsigned N = sizeof(du_int) * CHAR_BIT;
  24. int clz = __builtin_clzll(a);
  25. int e = (N - 1) - clz; // exponent
  26. xf_bits fb;
  27. fb.u.high.s.low = (e + 16383); // exponent
  28. fb.u.low.all = a << clz; // mantissa
  29. return fb.f;
  30. }
  31. #endif // _ARCH_PPC