Commit 71f47614 authored by Lei Huang's avatar Lei Huang
Browse files

[PowerPC][compiler-rt][builtins]Fix __fixunstfti builtin on PowerPC

__fixunstfti converts a long double (IBM double-double) to an unsigned 128 bit
integer.  This patch enables it to handle a previously unhandled case in which
a negative low double may impact the result of the conversion.

Collaborated with @masoud.ataei and @renenkel.
Patch By: Baptiste Saleil

Differential Revision: https://reviews.llvm.org/D69193
parent 8204d9ff
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -34,9 +34,9 @@ __uint128_t __fixunstfti(long double input) {
  } ldUnion;

  // If the long double is less than 1.0 or negative,
  // return 0.0.
  // return 0.
  if (input < 1.0)
    return 0.0;
    return 0;

  // Retrieve the 64-bit patterns of high and low doubles.
  // Compute the unbiased exponent of both high and low doubles by
@@ -99,6 +99,16 @@ __uint128_t __fixunstfti(long double input) {
    loResult <<= shift;
  }

  // If the low double is negative, it may change the integer value of the
  // whole number if the absolute value of its fractional part is bigger than
  // the fractional part of the high double. Because both doubles cannot
  // overlap, this situation only occurs when the high double has no
  // fractional part.
  ldUnion.ld = input;
  if ((ldUnion.d[0] == (double)hiResult) &&
      (ldUnion.d[1] < (double)((__int128_t)loResult)))
    loResult--;

  // Add the high and low doublewords together to form a 128 bit integer.
  result = loResult + hiResult;
  return result;
+650 −8

File changed.

Preview size limit exceeded, changes collapsed.