From 3a3a424a248717487de826ddb48f14deec1d2446 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Thu, 22 Dec 2011 22:11:19 +0000 Subject: [PATCH] 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 --- unittests/ADT/APIntTest.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp index 2195007f255..d5d2bc175fa 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)); +} + } -- 2.34.1