diff options
author | Michael Gottesman <mgottesman@apple.com> | 2013-05-28 19:50:20 +0000 |
---|---|---|
committer | Michael Gottesman <mgottesman@apple.com> | 2013-05-28 19:50:20 +0000 |
commit | a32edcfbc5b99b808b67360311d513af650eab44 (patch) | |
tree | 21971c0faaaaf4ca5befa11c45bac79ccd174be6 /lib/Support/APInt.cpp | |
parent | e274b476de33ee4f2e90a3eb3a56b5cdd619eb82 (diff) | |
download | llvm-a32edcfbc5b99b808b67360311d513af650eab44.tar.gz llvm-a32edcfbc5b99b808b67360311d513af650eab44.tar.bz2 llvm-a32edcfbc5b99b808b67360311d513af650eab44.tar.xz |
[APInt] Implement tcDecrement as a counterpart to tcIncrement. This is for use in APFloat IEEE-754R 2008 nextUp/nextDown function.
rdar://13852078
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182801 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/APInt.cpp')
-rw-r--r-- | lib/Support/APInt.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 71c509592c..108675d1e9 100644 --- a/lib/Support/APInt.cpp +++ b/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 |