diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2013-12-22 00:04:03 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2013-12-22 00:04:03 +0000 | 
| commit | f8af5cf600354830d4ccf59732403f0f073eccb9 (patch) | |
| tree | 2ba0398b4c42ad4f55561327538044fd2c925a8b /unittests/ADT/APIntTest.cpp | |
| parent | 59d6cff90eecf31cb3dd860c4e786674cfdd42eb (diff) | |
Notes
Diffstat (limited to 'unittests/ADT/APIntTest.cpp')
| -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 f129fa71c8e0..3c0dfe144044 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); +  } +}  } | 
