floatdixf.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //===-- floatdixf.c - Implement __floatdixf -------------------------------===//
  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 __floatdixf 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 di_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 __floatdixf(di_int a) {
  21. if (a == 0)
  22. return 0.0;
  23. const unsigned N = sizeof(di_int) * CHAR_BIT;
  24. const di_int s = a >> (N - 1);
  25. a = (a ^ s) - s;
  26. int clz = __builtin_clzll(a);
  27. int e = (N - 1) - clz; // exponent
  28. xf_bits fb;
  29. fb.u.high.s.low = ((su_int)s & 0x00008000) | // sign
  30. (e + 16383); // exponent
  31. fb.u.low.all = a << clz; // mantissa
  32. return fb.f;
  33. }
  34. #endif // !_ARCH_PPC