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 /unittests | |
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 'unittests')
-rw-r--r-- | unittests/ADT/APIntTest.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp index f129fa71c8..3c0dfe1440 100644 --- a/unittests/ADT/APIntTest.cpp +++ b/unittests/ADT/APIntTest.cpp @@ -532,4 +532,69 @@ TEST(APIntTest, Splat) { EXPECT_EQ(APInt(15, 0xDB6D), APInt::getSplat(15, ValB)); } +TEST(APIntTest, tcDecrement) { + // Test single word decrement. + + // No out borrow. + { + integerPart singleWord = ~integerPart(0) << (integerPartWidth - 1); + integerPart carry = APInt::tcDecrement(&singleWord, 1); + EXPECT_EQ(carry, integerPart(0)); + EXPECT_EQ(singleWord, ~integerPart(0) >> 1); + } + + // With out borrow. + { + integerPart singleWord = 0; + integerPart carry = APInt::tcDecrement(&singleWord, 1); + EXPECT_EQ(carry, integerPart(1)); + EXPECT_EQ(singleWord, ~integerPart(0)); + } + + // Test multiword decrement. + + // No across word borrow, no out borrow. + { + integerPart test[4] = {0x1, 0x1, 0x1, 0x1}; + integerPart expected[4] = {0x0, 0x1, 0x1, 0x1}; + APInt::tcDecrement(test, 4); + EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0); + } + + // 1 across word borrow, no out borrow. + { + integerPart test[4] = {0x0, 0xF, 0x1, 0x1}; + integerPart expected[4] = {~integerPart(0), 0xE, 0x1, 0x1}; + integerPart carry = APInt::tcDecrement(test, 4); + EXPECT_EQ(carry, integerPart(0)); + EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0); + } + + // 2 across word borrow, no out borrow. + { + integerPart test[4] = {0x0, 0x0, 0xC, 0x1}; + integerPart expected[4] = {~integerPart(0), ~integerPart(0), 0xB, 0x1}; + integerPart carry = APInt::tcDecrement(test, 4); + EXPECT_EQ(carry, integerPart(0)); + EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0); + } + + // 3 across word borrow, no out borrow. + { + integerPart test[4] = {0x0, 0x0, 0x0, 0x1}; + integerPart expected[4] = {~integerPart(0), ~integerPart(0), ~integerPart(0), 0x0}; + integerPart carry = APInt::tcDecrement(test, 4); + EXPECT_EQ(carry, integerPart(0)); + EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0); + } + + // 3 across word borrow, with out borrow. + { + integerPart test[4] = {0x0, 0x0, 0x0, 0x0}; + integerPart expected[4] = {~integerPart(0), ~integerPart(0), ~integerPart(0), ~integerPart(0)}; + integerPart carry = APInt::tcDecrement(test, 4); + EXPECT_EQ(carry, integerPart(1)); + EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0); + } +} } |