Add back convertFromSignExtendedInteger.
authorNeil Booth <neil@daikokuya.co.uk>
Sun, 7 Oct 2007 12:15:41 +0000 (12:15 +0000)
committerNeil Booth <neil@daikokuya.co.uk>
Sun, 7 Oct 2007 12:15:41 +0000 (12:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42735 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APFloat.h
lib/Support/APFloat.cpp

index 67c979cece5f0740e1ce814f069ba829c3e807c2..f5511f42805ea292f8d2fbd5e17ee9d23e0b95ab 100644 (file)
@@ -194,6 +194,8 @@ namespace llvm {
     opStatus convert(const fltSemantics &, roundingMode);
     opStatus convertToInteger(integerPart *, unsigned int, bool,
                              roundingMode) const;
+    opStatus convertFromSignExtendedInteger(const integerPart *, unsigned int,
+                                            bool, roundingMode);
     opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int,
                                             bool, roundingMode);
     opStatus convertFromString(const char *, roundingMode);
index 8343ffe39b7f1bafaf01b09324565d7b09bb7fc9..388bbd7aa2444c2dd633f6c577cf334a02577e26 100644 (file)
@@ -1587,6 +1587,36 @@ APFloat::convertFromUnsignedParts(const integerPart *src,
   return normalize(rounding_mode, lost_fraction);
 }
 
+/* Convert a two's complement integer SRC to a floating point number,
+   rounding according to ROUNDING_MODE.  ISSIGNED is true if the
+   integer is signed, in which case it must be sign-extended.  */
+APFloat::opStatus
+APFloat::convertFromSignExtendedInteger(const integerPart *src,
+                                        unsigned int srcCount,
+                                        bool isSigned,
+                                        roundingMode rounding_mode)
+{
+  opStatus status;
+
+  if (isSigned
+      && APInt::tcExtractBit(src, srcCount * integerPartWidth - 1)) {
+    integerPart *copy;
+
+    /* If we're signed and negative negate a copy.  */
+    sign = true;
+    copy = new integerPart[srcCount];
+    APInt::tcAssign(copy, src, srcCount);
+    APInt::tcNegate(copy, srcCount);
+    status = convertFromUnsignedParts(copy, srcCount, rounding_mode);
+    delete [] copy;
+  } else {
+    sign = false;
+    status = convertFromUnsignedParts(src, srcCount, rounding_mode);
+  }
+
+  return status;
+}
+
 /* FIXME: should this just take a const APInt reference?  */
 APFloat::opStatus
 APFloat::convertFromZeroExtendedInteger(const integerPart *parts,