diff --git a/Source/UnitTests/Common/BitUtilsTest.cpp b/Source/UnitTests/Common/BitUtilsTest.cpp index 26232ca26e..4785f9dcef 100644 --- a/Source/UnitTests/Common/BitUtilsTest.cpp +++ b/Source/UnitTests/Common/BitUtilsTest.cpp @@ -58,6 +58,44 @@ TEST(BitUtils, ExtractBits) EXPECT_EQ((Common::ExtractBits<0, 31, s32, s32>(negative_one)), -1); } +TEST(BitUtils, RotateLeft) +{ + EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0, 0), 0xF0F0F0F0); + EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0, 4), 0x0F0F0F0F); + EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0, 8), 0xF0F0F0F0); + EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0F0F0F0F0, 0), 0xF0F0F0F0F0F0F0F0); + EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0F0F0F0F0, 4), 0x0F0F0F0F0F0F0F0F); + EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0F0F0F0F0, 8), 0xF0F0F0F0F0F0F0F0); + + EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1, 1), 0xE3E3E3E3); + EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1, 2), 0xC7C7C7C7); + EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1, 3), 0x8F8F8F8F); + EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1, 4), 0x1F1F1F1F); + EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1F1F1F1F1, 1), 0xE3E3E3E3E3E3E3E3); + EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1F1F1F1F1, 2), 0xC7C7C7C7C7C7C7C7); + EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1F1F1F1F1, 3), 0x8F8F8F8F8F8F8F8F); + EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1F1F1F1F1, 4), 0x1F1F1F1F1F1F1F1F); +} + +TEST(BitUtils, RotateRight) +{ + EXPECT_EQ(Common::RotateRight(0xF0F0F0F0, 0), 0xF0F0F0F0); + EXPECT_EQ(Common::RotateRight(0xF0F0F0F0, 4), 0x0F0F0F0F); + EXPECT_EQ(Common::RotateRight(0xF0F0F0F0, 8), 0xF0F0F0F0); + EXPECT_EQ(Common::RotateRight(0xF0F0F0F0F0F0F0F0, 0), 0xF0F0F0F0F0F0F0F0); + EXPECT_EQ(Common::RotateRight(0xF0F0F0F0F0F0F0F0, 4), 0x0F0F0F0F0F0F0F0F); + EXPECT_EQ(Common::RotateRight(0xF0F0F0F0F0F0F0F0, 8), 0xF0F0F0F0F0F0F0F0); + + EXPECT_EQ(Common::RotateRight(0xF1F1F1F1, 1), 0xF8F8F8F8); + EXPECT_EQ(Common::RotateRight(0xF1F1F1F1, 2), 0x7C7C7C7C); + EXPECT_EQ(Common::RotateRight(0xF1F1F1F1, 3), 0x3E3E3E3E); + EXPECT_EQ(Common::RotateRight(0xF1F1F1F1, 4), 0x1F1F1F1F); + EXPECT_EQ(Common::RotateRight(0xF1F1F1F1F1F1F1F1, 1), 0xF8F8F8F8F8F8F8F8); + EXPECT_EQ(Common::RotateRight(0xF1F1F1F1F1F1F1F1, 2), 0x7C7C7C7C7C7C7C7C); + EXPECT_EQ(Common::RotateRight(0xF1F1F1F1F1F1F1F1, 3), 0x3E3E3E3E3E3E3E3E); + EXPECT_EQ(Common::RotateRight(0xF1F1F1F1F1F1F1F1, 4), 0x1F1F1F1F1F1F1F1F); +} + TEST(BitUtils, IsValidLowMask) { EXPECT_TRUE(Common::IsValidLowMask(0b0u));