diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2011-12-22 22:11:19 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2011-12-22 22:11:19 +0000 |
commit | 3a3a424a248717487de826ddb48f14deec1d2446 (patch) | |
tree | 0a86c05cceb67a03e72847d9dd2ae5464a8a3d20 | |
parent | 21bcca81f4597f1c7d939e5d69067539ff804e6d (diff) | |
download | external_llvm-3a3a424a248717487de826ddb48f14deec1d2446.zip external_llvm-3a3a424a248717487de826ddb48f14deec1d2446.tar.gz external_llvm-3a3a424a248717487de826ddb48f14deec1d2446.tar.bz2 |
Some unittests for APInt rotates; patch by Cameron McInally.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147186 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | unittests/ADT/APIntTest.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp index 2195007..d5d2bc1 100644 --- a/unittests/ADT/APIntTest.cpp +++ b/unittests/ADT/APIntTest.cpp @@ -144,6 +144,12 @@ TEST(APIntTest, i1) { EXPECT_EQ(zero, one.lshr(1)); EXPECT_EQ(zero, one.ashr(1)); + // Rotates. + EXPECT_EQ(one, one.rotl(0)); + EXPECT_EQ(one, one.rotl(1)); + EXPECT_EQ(one, one.rotr(0)); + EXPECT_EQ(one, one.rotr(1)); + // Multiplies. EXPECT_EQ(neg_one, neg_one * one); EXPECT_EQ(neg_one, one * neg_one); @@ -450,4 +456,30 @@ TEST(APIntTest, mul_clear) { EXPECT_EQ(ValA.toString(10, false), ValC.toString(10, false)); } +TEST(APIntTest, Rotate) { + EXPECT_EQ(APInt(8, 1), APInt(8, 1).rotl(0)); + EXPECT_EQ(APInt(8, 2), APInt(8, 1).rotl(1)); + EXPECT_EQ(APInt(8, 4), APInt(8, 1).rotl(2)); + EXPECT_EQ(APInt(8, 16), APInt(8, 1).rotl(4)); + EXPECT_EQ(APInt(8, 1), APInt(8, 1).rotl(8)); + + EXPECT_EQ(APInt(8, 16), APInt(8, 16).rotl(0)); + EXPECT_EQ(APInt(8, 32), APInt(8, 16).rotl(1)); + EXPECT_EQ(APInt(8, 64), APInt(8, 16).rotl(2)); + EXPECT_EQ(APInt(8, 1), APInt(8, 16).rotl(4)); + EXPECT_EQ(APInt(8, 16), APInt(8, 16).rotl(8)); + + EXPECT_EQ(APInt(8, 16), APInt(8, 16).rotr(0)); + EXPECT_EQ(APInt(8, 8), APInt(8, 16).rotr(1)); + EXPECT_EQ(APInt(8, 4), APInt(8, 16).rotr(2)); + EXPECT_EQ(APInt(8, 1), APInt(8, 16).rotr(4)); + EXPECT_EQ(APInt(8, 16), APInt(8, 16).rotr(8)); + + EXPECT_EQ(APInt(8, 1), APInt(8, 1).rotr(0)); + EXPECT_EQ(APInt(8, 128), APInt(8, 1).rotr(1)); + EXPECT_EQ(APInt(8, 64), APInt(8, 1).rotr(2)); + EXPECT_EQ(APInt(8, 16), APInt(8, 1).rotr(4)); + EXPECT_EQ(APInt(8, 1), APInt(8, 1).rotr(8)); +} + } |