From 454537d53efd0579d4cd2a48108f3bdb490b08d2 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 5 Aug 2022 15:39:00 +0200 Subject: [PATCH] Replace BitUtils with C++20: RotateLeft/RotateRight Now that we've flipped the C++20 switch, let's start making use of the nice new header. I'm planning on handling this move away from BitUtils.h incrementally in a series of PRs. There may be a few functions remaining in BitUtils.h by the end that C++20 doesn't have any equivalents for. --- Source/Core/Common/Arm64Emitter.h | 11 ++--- Source/Core/Common/BitUtils.h | 44 ------------------- Source/Core/Common/Crypto/AES.cpp | 4 +- Source/Core/Common/Hash.cpp | 8 ++-- Source/Core/Core/ARDecrypt.cpp | 30 ++++++------- Source/Core/Core/HW/WiimoteEmu/Encryption.cpp | 30 ++++++------- .../Interpreter/Interpreter_Integer.cpp | 8 ++-- .../Core/Core/PowerPC/Jit64/Jit_Integer.cpp | 14 +++--- .../PowerPC/JitArm64/JitArm64_Integer.cpp | 8 ++-- Source/Core/Core/PowerPC/MMU.cpp | 9 ++-- Source/UnitTests/Common/BitUtilsTest.cpp | 38 ---------------- 11 files changed, 63 insertions(+), 141 deletions(-) diff --git a/Source/Core/Common/Arm64Emitter.h b/Source/Core/Common/Arm64Emitter.h index baaf598741..b90f7c6cab 100644 --- a/Source/Core/Common/Arm64Emitter.h +++ b/Source/Core/Common/Arm64Emitter.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include #include @@ -558,15 +559,15 @@ struct LogicalImm // pick the next sequence of ones. This ensures we get a complete element // that has not been cut-in-half due to rotation across the word boundary. - const size_t rotation = Common::CountTrailingZeros(value & (value + 1)); - const u64 normalized = Common::RotateRight(value, rotation); + const int rotation = Common::CountTrailingZeros(value & (value + 1)); + const u64 normalized = std::rotr(value, rotation); - const size_t element_size = Common::CountTrailingZeros(normalized & (normalized + 1)); - const size_t ones = Common::CountTrailingZeros(~normalized); + const int element_size = Common::CountTrailingZeros(normalized & (normalized + 1)); + const int ones = Common::CountTrailingZeros(~normalized); // Check the value is repeating; also ensures element size is a power of two. - if (Common::RotateRight(value, element_size) != value) + if (std::rotr(value, element_size) != value) { valid = false; return; diff --git a/Source/Core/Common/BitUtils.h b/Source/Core/Common/BitUtils.h index 60a6abdc25..273e2a2227 100644 --- a/Source/Core/Common/BitUtils.h +++ b/Source/Core/Common/BitUtils.h @@ -107,50 +107,6 @@ constexpr Result ExtractBits(const T src) noexcept return ExtractBits(src, begin, end); } -/// -/// Rotates a value left (ROL). -/// -/// @param value The value to rotate. -/// @param amount The number of bits to rotate the value. -/// @tparam T An unsigned type. -/// -/// @return The rotated value. -/// -template -constexpr T RotateLeft(const T value, size_t amount) noexcept -{ - static_assert(std::is_unsigned(), "Can only rotate unsigned types left."); - - amount %= BitSize(); - - if (amount == 0) - return value; - - return static_cast((value << amount) | (value >> (BitSize() - amount))); -} - -/// -/// Rotates a value right (ROR). -/// -/// @param value The value to rotate. -/// @param amount The number of bits to rotate the value. -/// @tparam T An unsigned type. -/// -/// @return The rotated value. -/// -template -constexpr T RotateRight(const T value, size_t amount) noexcept -{ - static_assert(std::is_unsigned(), "Can only rotate unsigned types right."); - - amount %= BitSize(); - - if (amount == 0) - return value; - - return static_cast((value >> amount) | (value << (BitSize() - amount))); -} - /// /// Verifies whether the supplied value is a valid bit mask of the form 0b00...0011...11. /// Both edge cases of all zeros and all ones are considered valid masks, too. diff --git a/Source/Core/Common/Crypto/AES.cpp b/Source/Core/Common/Crypto/AES.cpp index 82f7d1a9c2..3fc9a80a56 100644 --- a/Source/Core/Common/Crypto/AES.cpp +++ b/Source/Core/Common/Crypto/AES.cpp @@ -2,12 +2,12 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include #include #include "Common/Assert.h" -#include "Common/BitUtils.h" #include "Common/CPUDetect.h" #include "Common/Crypto/AES.h" @@ -294,7 +294,7 @@ public: { const uint8x16_t enc = vaeseq_u8(vreinterpretq_u8_u32(vmovq_n_u32(rk[i + 3])), vmovq_n_u8(0)); const u32 temp = vgetq_lane_u32(vreinterpretq_u32_u8(enc), 0); - rk[i + 4] = rk[i + 0] ^ Common::RotateRight(temp, 8) ^ rcon[i / Nk]; + rk[i + 4] = rk[i + 0] ^ std::rotr(temp, 8) ^ rcon[i / Nk]; rk[i + 5] = rk[i + 4] ^ rk[i + 1]; rk[i + 6] = rk[i + 5] ^ rk[i + 2]; rk[i + 7] = rk[i + 6] ^ rk[i + 3]; diff --git a/Source/Core/Common/Hash.cpp b/Source/Core/Common/Hash.cpp index f11ac4d62c..e6b421e96f 100644 --- a/Source/Core/Common/Hash.cpp +++ b/Source/Core/Common/Hash.cpp @@ -4,7 +4,9 @@ #include "Common/Hash.h" #include +#include #include + #include #include "Common/BitUtils.h" @@ -60,15 +62,15 @@ static u64 getblock(const u64* p, int i) static void bmix64(u64& h1, u64& h2, u64& k1, u64& k2, u64& c1, u64& c2) { k1 *= c1; - k1 = Common::RotateLeft(k1, 23); + k1 = std::rotl(k1, 23); k1 *= c2; h1 ^= k1; h1 += h2; - h2 = Common::RotateLeft(h2, 41); + h2 = std::rotl(h2, 41); k2 *= c2; - k2 = Common::RotateLeft(k2, 23); + k2 = std::rotl(k2, 23); k2 *= c1; h2 ^= k2; h2 += h1; diff --git a/Source/Core/Core/ARDecrypt.cpp b/Source/Core/Core/ARDecrypt.cpp index 9703ca6d18..46ca74d159 100644 --- a/Source/Core/Core/ARDecrypt.cpp +++ b/Source/Core/Core/ARDecrypt.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -17,7 +18,6 @@ #include #endif -#include "Common/BitUtils.h" #include "Common/CommonTypes.h" #include "Common/MsgHandler.h" #include "Common/StringUtil.h" @@ -249,26 +249,26 @@ static void unscramble1(u32* addr, u32* val) { u32 tmp; - *val = Common::RotateLeft(*val, 4); + *val = std::rotl(*val, 4); tmp = ((*addr ^ *val) & 0xF0F0F0F0); *addr ^= tmp; - *val = Common::RotateRight((*val ^ tmp), 0x14); + *val = std::rotr((*val ^ tmp), 0x14); tmp = ((*addr ^ *val) & 0xFFFF0000); *addr ^= tmp; - *val = Common::RotateRight((*val ^ tmp), 0x12); + *val = std::rotr((*val ^ tmp), 0x12); tmp = ((*addr ^ *val) & 0x33333333); *addr ^= tmp; - *val = Common::RotateRight((*val ^ tmp), 6); + *val = std::rotr((*val ^ tmp), 6); tmp = ((*addr ^ *val) & 0x00FF00FF); *addr ^= tmp; - *val = Common::RotateLeft((*val ^ tmp), 9); + *val = std::rotl((*val ^ tmp), 9); tmp = ((*addr ^ *val) & 0xAAAAAAAA); - *addr = Common::RotateLeft((*addr ^ tmp), 1); + *addr = std::rotl((*addr ^ tmp), 1); *val ^= tmp; } @@ -276,27 +276,27 @@ static void unscramble2(u32* addr, u32* val) { u32 tmp; - *val = Common::RotateRight(*val, 1); + *val = std::rotr(*val, 1); tmp = ((*addr ^ *val) & 0xAAAAAAAA); *val ^= tmp; - *addr = Common::RotateRight((*addr ^ tmp), 9); + *addr = std::rotr((*addr ^ tmp), 9); tmp = ((*addr ^ *val) & 0x00FF00FF); *val ^= tmp; - *addr = Common::RotateLeft((*addr ^ tmp), 6); + *addr = std::rotl((*addr ^ tmp), 6); tmp = ((*addr ^ *val) & 0x33333333); *val ^= tmp; - *addr = Common::RotateLeft((*addr ^ tmp), 0x12); + *addr = std::rotl((*addr ^ tmp), 0x12); tmp = ((*addr ^ *val) & 0xFFFF0000); *val ^= tmp; - *addr = Common::RotateLeft((*addr ^ tmp), 0x14); + *addr = std::rotl((*addr ^ tmp), 0x14); tmp = ((*addr ^ *val) & 0xF0F0F0F0); *val ^= tmp; - *addr = Common::RotateRight((*addr ^ tmp), 4); + *addr = std::rotr((*addr ^ tmp), 4); } static void decryptcode(const u32* seeds, u32* code) @@ -309,13 +309,13 @@ static void decryptcode(const u32* seeds, u32* code) unscramble1(&addr, &val); while (i < 32) { - tmp = (Common::RotateRight(val, 4) ^ seeds[i++]); + tmp = (std::rotr(val, 4) ^ seeds[i++]); tmp2 = (val ^ seeds[i++]); addr ^= (table6[tmp & 0x3F] ^ table4[(tmp >> 8) & 0x3F] ^ table2[(tmp >> 16) & 0x3F] ^ table0[(tmp >> 24) & 0x3F] ^ table7[tmp2 & 0x3F] ^ table5[(tmp2 >> 8) & 0x3F] ^ table3[(tmp2 >> 16) & 0x3F] ^ table1[(tmp2 >> 24) & 0x3F]); - tmp = (Common::RotateRight(addr, 4) ^ seeds[i++]); + tmp = (std::rotr(addr, 4) ^ seeds[i++]); tmp2 = (addr ^ seeds[i++]); val ^= (table6[tmp & 0x3F] ^ table4[(tmp >> 8) & 0x3F] ^ table2[(tmp >> 16) & 0x3F] ^ table0[(tmp >> 24) & 0x3F] ^ table7[tmp2 & 0x3F] ^ table5[(tmp2 >> 8) & 0x3F] ^ diff --git a/Source/Core/Core/HW/WiimoteEmu/Encryption.cpp b/Source/Core/Core/HW/WiimoteEmu/Encryption.cpp index d9b6ce1f13..f415408126 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Encryption.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Encryption.cpp @@ -6,8 +6,8 @@ #include "Core/HW/WiimoteEmu/Encryption.h" #include +#include -#include "Common/BitUtils.h" #include "Common/Logging/Log.h" namespace { @@ -520,15 +520,13 @@ EncryptionKey::KeyData KeyGen1stParty::GenerateKeyData(const EncryptionKey::Rand for (std::size_t i = 0; i != t0.size(); ++i) t0[i] = keygen_sbox_1st_party[rand[i]]; - auto& ror8 = Common::RotateRight; - return { - u8((ror8(ans[0] ^ t0[5], t0[2]) - t0[9]) ^ t0[4]), - u8((ror8(ans[1] ^ t0[1], t0[0]) - t0[5]) ^ t0[7]), - u8((ror8(ans[2] ^ t0[6], t0[8]) - t0[2]) ^ t0[0]), - u8((ror8(ans[3] ^ t0[4], t0[7]) - t0[3]) ^ t0[2]), - u8((ror8(ans[4] ^ t0[1], t0[6]) - t0[3]) ^ t0[4]), - u8((ror8(ans[5] ^ t0[7], t0[8]) - t0[5]) ^ t0[9]), + u8((std::rotr(ans[0] ^ t0[5], t0[2]) - t0[9]) ^ t0[4]), + u8((std::rotr(ans[1] ^ t0[1], t0[0]) - t0[5]) ^ t0[7]), + u8((std::rotr(ans[2] ^ t0[6], t0[8]) - t0[2]) ^ t0[0]), + u8((std::rotr(ans[3] ^ t0[4], t0[7]) - t0[3]) ^ t0[2]), + u8((std::rotr(ans[4] ^ t0[1], t0[6]) - t0[3]) ^ t0[4]), + u8((std::rotr(ans[5] ^ t0[7], t0[8]) - t0[5]) ^ t0[9]), }; } @@ -548,15 +546,13 @@ EncryptionKey::KeyData KeyGen3rdParty::GenerateKeyData(const EncryptionKey::Rand for (std::size_t i = 0; i != t0.size(); ++i) t0[i] = keygen_sbox_3rd_party[rand[i]]; - auto& rol8 = Common::RotateLeft; - return { - u8(t0[7] ^ (t0[6] + rol8(ans[0] ^ t0[0], t0[1]))), - u8(t0[1] ^ (t0[3] + rol8(ans[1] ^ t0[4], t0[2]))), - u8(t0[5] ^ (t0[4] + rol8(ans[2] ^ t0[2], t0[8]))), - u8(t0[0] ^ (t0[7] + rol8(ans[3] ^ t0[6], t0[9]))), - u8(t0[1] ^ (t0[8] + rol8(ans[4] ^ t0[5], t0[4]))), - u8(t0[5] ^ (t0[8] + rol8(ans[5] ^ t0[9], t0[3]))), + u8(t0[7] ^ (t0[6] + std::rotl(ans[0] ^ t0[0], t0[1]))), + u8(t0[1] ^ (t0[3] + std::rotl(ans[1] ^ t0[4], t0[2]))), + u8(t0[5] ^ (t0[4] + std::rotl(ans[2] ^ t0[2], t0[8]))), + u8(t0[0] ^ (t0[7] + std::rotl(ans[3] ^ t0[6], t0[9]))), + u8(t0[1] ^ (t0[8] + std::rotl(ans[4] ^ t0[5], t0[4]))), + u8(t0[5] ^ (t0[8] + std::rotl(ans[5] ^ t0[9], t0[3]))), }; } diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp index b10f55ab79..84f393ad3b 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp @@ -3,6 +3,8 @@ #include "Core/PowerPC/Interpreter/Interpreter.h" +#include + #include "Common/BitUtils.h" #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" @@ -151,7 +153,7 @@ void Interpreter::xoris(UGeckoInstruction inst) void Interpreter::rlwimix(UGeckoInstruction inst) { const u32 mask = MakeRotationMask(inst.MB, inst.ME); - rGPR[inst.RA] = (rGPR[inst.RA] & ~mask) | (Common::RotateLeft(rGPR[inst.RS], inst.SH) & mask); + rGPR[inst.RA] = (rGPR[inst.RA] & ~mask) | (std::rotl(rGPR[inst.RS], inst.SH) & mask); if (inst.Rc) Helper_UpdateCR0(rGPR[inst.RA]); @@ -160,7 +162,7 @@ void Interpreter::rlwimix(UGeckoInstruction inst) void Interpreter::rlwinmx(UGeckoInstruction inst) { const u32 mask = MakeRotationMask(inst.MB, inst.ME); - rGPR[inst.RA] = Common::RotateLeft(rGPR[inst.RS], inst.SH) & mask; + rGPR[inst.RA] = std::rotl(rGPR[inst.RS], inst.SH) & mask; if (inst.Rc) Helper_UpdateCR0(rGPR[inst.RA]); @@ -169,7 +171,7 @@ void Interpreter::rlwinmx(UGeckoInstruction inst) void Interpreter::rlwnmx(UGeckoInstruction inst) { const u32 mask = MakeRotationMask(inst.MB, inst.ME); - rGPR[inst.RA] = Common::RotateLeft(rGPR[inst.RS], rGPR[inst.RB] & 0x1F) & mask; + rGPR[inst.RA] = std::rotl(rGPR[inst.RS], rGPR[inst.RB] & 0x1F) & mask; if (inst.Rc) Helper_UpdateCR0(rGPR[inst.RA]); diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp index 88991867ec..34a0ab9cf8 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp @@ -4,6 +4,7 @@ #include "Core/PowerPC/Jit64/Jit.h" #include +#include #include #include @@ -2005,7 +2006,7 @@ void Jit64::rlwinmx(UGeckoInstruction inst) { u32 result = gpr.Imm32(s); if (inst.SH != 0) - result = Common::RotateLeft(result, inst.SH); + result = std::rotl(result, inst.SH); result &= MakeRotationMask(inst.MB, inst.ME); gpr.SetImmediate32(a, result); if (inst.Rc) @@ -2017,7 +2018,7 @@ void Jit64::rlwinmx(UGeckoInstruction inst) const bool right_shift = inst.SH && inst.ME == 31 && inst.MB == 32 - inst.SH; const bool field_extract = inst.SH && inst.ME == 31 && inst.MB > 32 - inst.SH; const u32 mask = MakeRotationMask(inst.MB, inst.ME); - const u32 prerotate_mask = Common::RotateRight(mask, inst.SH); + const u32 prerotate_mask = std::rotr(mask, inst.SH); const bool simple_mask = mask == 0xff || mask == 0xffff; const bool simple_prerotate_mask = prerotate_mask == 0xff || prerotate_mask == 0xffff; // In case of a merged branch, track whether or not we've set flags. @@ -2106,14 +2107,13 @@ void Jit64::rlwimix(UGeckoInstruction inst) if (gpr.IsImm(a, s)) { - gpr.SetImmediate32(a, - (gpr.Imm32(a) & ~mask) | (Common::RotateLeft(gpr.Imm32(s), inst.SH) & mask)); + gpr.SetImmediate32(a, (gpr.Imm32(a) & ~mask) | (std::rotl(gpr.Imm32(s), inst.SH) & mask)); if (inst.Rc) ComputeRC(a); } else if (gpr.IsImm(s) && mask == 0xFFFFFFFF) { - gpr.SetImmediate32(a, Common::RotateLeft(gpr.Imm32(s), inst.SH)); + gpr.SetImmediate32(a, std::rotl(gpr.Imm32(s), inst.SH)); if (inst.Rc) ComputeRC(a); @@ -2141,7 +2141,7 @@ void Jit64::rlwimix(UGeckoInstruction inst) RCX64Reg Ra = gpr.Bind(a, RCMode::ReadWrite); RegCache::Realize(Ra); AndWithMask(Ra, ~mask); - OR(32, Ra, Imm32(Common::RotateLeft(gpr.Imm32(s), inst.SH) & mask)); + OR(32, Ra, Imm32(std::rotl(gpr.Imm32(s), inst.SH) & mask)); } else if (gpr.IsImm(a)) { @@ -2244,7 +2244,7 @@ void Jit64::rlwnmx(UGeckoInstruction inst) const u32 mask = MakeRotationMask(inst.MB, inst.ME); if (gpr.IsImm(b, s)) { - gpr.SetImmediate32(a, Common::RotateLeft(gpr.Imm32(s), gpr.Imm32(b) & 0x1F) & mask); + gpr.SetImmediate32(a, std::rotl(gpr.Imm32(s), gpr.Imm32(b) & 0x1F) & mask); } else if (gpr.IsImm(b)) { diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp index c1fddee166..4d1a9d6298 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp @@ -3,6 +3,8 @@ #include "Core/PowerPC/JitArm64/Jit.h" +#include + #include "Common/Arm64Emitter.h" #include "Common/Assert.h" #include "Common/BitUtils.h" @@ -700,7 +702,7 @@ void JitArm64::rlwinmx(UGeckoInstruction inst) const u32 mask = MakeRotationMask(inst.MB, inst.ME); if (gpr.IsImm(inst.RS)) { - gpr.SetImmediate(a, Common::RotateLeft(gpr.GetImm(s), inst.SH) & mask); + gpr.SetImmediate(a, std::rotl(gpr.GetImm(s), inst.SH) & mask); if (inst.Rc) ComputeRC0(gpr.GetImm(a)); return; @@ -749,7 +751,7 @@ void JitArm64::rlwnmx(UGeckoInstruction inst) if (gpr.IsImm(b) && gpr.IsImm(s)) { - gpr.SetImmediate(a, Common::RotateLeft(gpr.GetImm(s), gpr.GetImm(b) & 0x1F) & mask); + gpr.SetImmediate(a, std::rotl(gpr.GetImm(s), gpr.GetImm(b) & 0x1F) & mask); if (inst.Rc) ComputeRC0(gpr.GetImm(a)); } @@ -1924,7 +1926,7 @@ void JitArm64::rlwimix(UGeckoInstruction inst) if (gpr.IsImm(a) && gpr.IsImm(s)) { - u32 res = (gpr.GetImm(a) & ~mask) | (Common::RotateLeft(gpr.GetImm(s), inst.SH) & mask); + u32 res = (gpr.GetImm(a) & ~mask) | (std::rotl(gpr.GetImm(s), inst.SH) & mask); gpr.SetImmediate(a, res); if (inst.Rc) ComputeRC0(res); diff --git a/Source/Core/Core/PowerPC/MMU.cpp b/Source/Core/Core/PowerPC/MMU.cpp index 4e44f8c5bf..0b9501ab63 100644 --- a/Source/Core/Core/PowerPC/MMU.cpp +++ b/Source/Core/Core/PowerPC/MMU.cpp @@ -3,6 +3,7 @@ #include "Core/PowerPC/MMU.h" +#include #include #include #include @@ -267,8 +268,8 @@ static void WriteToHardware(Memory::MemoryManager& memory, u32 em_address, const // Note that "word" means 32-bit, so paired singles or doubles might still be 32-bit aligned! const u32 first_half_size = em_address_end_page - em_address; const u32 second_half_size = size - first_half_size; - WriteToHardware( - memory, em_address, Common::RotateRight(data, second_half_size * 8), first_half_size); + WriteToHardware(memory, em_address, + std::rotr(data, second_half_size * 8), first_half_size); WriteToHardware(memory, em_address_end_page, data, second_half_size); return; } @@ -353,7 +354,7 @@ static void WriteToHardware(Memory::MemoryManager& memory, u32 em_address, const } } - const u32 swapped_data = Common::swap32(Common::RotateRight(data, size * 8)); + const u32 swapped_data = Common::swap32(std::rotr(data, size * 8)); // Locked L1 technically doesn't have a fixed address, but games all use 0xE0000000. if (memory.GetL1Cache() && (em_address >> 28 == 0xE) && @@ -376,7 +377,7 @@ static void WriteToHardware(Memory::MemoryManager& memory, u32 em_address, const // (https://github.com/dolphin-emu/hwtests/pull/42) ProcessorInterface::SetInterrupt(ProcessorInterface::INT_CAUSE_PI); - const u32 rotated_data = Common::RotateRight(data, ((em_address & 0x3) + size) * 8); + const u32 rotated_data = std::rotr(data, ((em_address & 0x3) + size) * 8); for (u32 addr = em_address & ~0x7; addr < em_address + size; addr += 8) { diff --git a/Source/UnitTests/Common/BitUtilsTest.cpp b/Source/UnitTests/Common/BitUtilsTest.cpp index 1428c7c3a6..7558cbc65c 100644 --- a/Source/UnitTests/Common/BitUtilsTest.cpp +++ b/Source/UnitTests/Common/BitUtilsTest.cpp @@ -57,44 +57,6 @@ TEST(BitUtils, ExtractBits) EXPECT_EQ((Common::ExtractBits<0, 31, s32, s32>(negative_one)), -1); } -TEST(BitUtils, RotateLeft) -{ - EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0, 0), 0xF0F0F0F0U); - EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0, 4), 0x0F0F0F0FU); - EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0, 8), 0xF0F0F0F0U); - EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0F0F0F0F0, 0), 0xF0F0F0F0F0F0F0F0U); - EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0F0F0F0F0, 4), 0x0F0F0F0F0F0F0F0FU); - EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0F0F0F0F0, 8), 0xF0F0F0F0F0F0F0F0U); - - EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1, 1), 0xE3E3E3E3U); - EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1, 2), 0xC7C7C7C7U); - EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1, 3), 0x8F8F8F8FU); - EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1, 4), 0x1F1F1F1FU); - EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1F1F1F1F1, 1), 0xE3E3E3E3E3E3E3E3U); - EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1F1F1F1F1, 2), 0xC7C7C7C7C7C7C7C7U); - EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1F1F1F1F1, 3), 0x8F8F8F8F8F8F8F8FU); - EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1F1F1F1F1, 4), 0x1F1F1F1F1F1F1F1FU); -} - -TEST(BitUtils, RotateRight) -{ - EXPECT_EQ(Common::RotateRight(0xF0F0F0F0, 0), 0xF0F0F0F0U); - EXPECT_EQ(Common::RotateRight(0xF0F0F0F0, 4), 0x0F0F0F0FU); - EXPECT_EQ(Common::RotateRight(0xF0F0F0F0, 8), 0xF0F0F0F0U); - EXPECT_EQ(Common::RotateRight(0xF0F0F0F0F0F0F0F0, 0), 0xF0F0F0F0F0F0F0F0U); - EXPECT_EQ(Common::RotateRight(0xF0F0F0F0F0F0F0F0, 4), 0x0F0F0F0F0F0F0F0FU); - EXPECT_EQ(Common::RotateRight(0xF0F0F0F0F0F0F0F0, 8), 0xF0F0F0F0F0F0F0F0U); - - EXPECT_EQ(Common::RotateRight(0xF1F1F1F1, 1), 0xF8F8F8F8U); - EXPECT_EQ(Common::RotateRight(0xF1F1F1F1, 2), 0x7C7C7C7CU); - EXPECT_EQ(Common::RotateRight(0xF1F1F1F1, 3), 0x3E3E3E3EU); - EXPECT_EQ(Common::RotateRight(0xF1F1F1F1, 4), 0x1F1F1F1FU); - EXPECT_EQ(Common::RotateRight(0xF1F1F1F1F1F1F1F1, 1), 0xF8F8F8F8F8F8F8F8U); - EXPECT_EQ(Common::RotateRight(0xF1F1F1F1F1F1F1F1, 2), 0x7C7C7C7C7C7C7C7CU); - EXPECT_EQ(Common::RotateRight(0xF1F1F1F1F1F1F1F1, 3), 0x3E3E3E3E3E3E3E3EU); - EXPECT_EQ(Common::RotateRight(0xF1F1F1F1F1F1F1F1, 4), 0x1F1F1F1F1F1F1F1FU); -} - TEST(BitUtils, IsValidLowMask) { EXPECT_TRUE(Common::IsValidLowMask(0b0u));