aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorMichael Gottesman <mgottesman@apple.com>2013-05-28 19:50:20 +0000
committerMichael Gottesman <mgottesman@apple.com>2013-05-28 19:50:20 +0000
commit9d406f4ec7dfa7da99a5d3160b02f724df34a4be (patch)
tree2ee2c9c4489f176c24b4574cc9a07ad06da19ba7 /llvm/lib/Support/APInt.cpp
parent3b684d835939c9d9104b708388c2b1f22959e493 (diff)
downloadllvm-9d406f4ec7dfa7da99a5d3160b02f724df34a4be.zip
llvm-9d406f4ec7dfa7da99a5d3160b02f724df34a4be.tar.gz
llvm-9d406f4ec7dfa7da99a5d3160b02f724df34a4be.tar.bz2
[APInt] Implement tcDecrement as a counterpart to tcIncrement. This is for use in APFloat IEEE-754R 2008 nextUp/nextDown function.
rdar://13852078 llvm-svn: 182801
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 71c5095..108675d 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -2888,6 +2888,20 @@ APInt::tcIncrement(integerPart *dst, unsigned int parts)
return i == parts;
}
+/* Decrement a bignum in-place, return the borrow flag. */
+integerPart
+APInt::tcDecrement(integerPart *dst, unsigned int parts) {
+ for (unsigned int i = 0; i < parts; i++) {
+ // If the current word is non-zero, then the decrement has no effect on the
+ // higher-order words of the integer and no borrow can occur. Exit early.
+ if (dst[i]--)
+ return 0;
+ }
+ // If every word was zero, then there is a borrow.
+ return 1;
+}
+
+
/* Set the least significant BITS bits of a bignum, clear the
rest. */
void