Skip to content

Commit

Permalink
LogicalImm: Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
merryhime committed Jul 10, 2022
1 parent cf99ade commit 581498b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
14 changes: 6 additions & 8 deletions Source/Core/Common/Arm64Emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,12 @@ struct LogicalImm
const size_t rotation = Common::CountTrailingZeros(value & (value + 1));
const u64 normalized = Common::RotateRight(value, rotation);

const size_t esize = Common::CountTrailingZeros(normalized & (normalized + 1));
const size_t element_size = Common::CountTrailingZeros(normalized & (normalized + 1));
const size_t ones = Common::CountTrailingZeros(~normalized);

// Check the value is repeating; also ensures esize is a power of two.
// Check the value is repeating; also ensures element size is a power of two.

if (Common::RotateRight(value, esize) != value)
if (Common::RotateRight(value, element_size) != value)
{
valid = false;
return;
Expand All @@ -567,11 +567,9 @@ struct LogicalImm
// it gives both the number of set bits and the length of the repeated
// segment.

const size_t tmp = ((~esize + 1) << 1) | (ones - 1);

r = static_cast<u8>((esize - rotation) & (esize - 1));
s = tmp & 0x3f;
n = (~tmp >> 6) & 1;
r = static_cast<u8>((element_size - rotation) & (element_size - 1));
s = (((~element_size + 1) << 1) | (ones - 1)) & 0x3f;
n = (element_size >> 6) & 1;

valid = true;
}
Expand Down
7 changes: 3 additions & 4 deletions Source/UnitTests/Core/PowerPC/JitArm64/MovI2R.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,24 @@ TEST(JitArm64, MovI2R_LogImm)
{
TestMovI2R test;

u64 imm;
for (unsigned size = 2; size <= 64; size *= 2)
{
for (unsigned length = 1; length < size; ++length)
{
imm = ~u64{0} >> (64 - length);
u64 imm = ~u64{0} >> (64 - length);
for (unsigned e = size; e < 64; e *= 2)
{
imm |= imm << e;
}
for (unsigned rotation = 0; rotation < size; ++rotation)
{
test.Check64(imm);
EXPECT_EQ((bool)LogicalImm(imm, 64), true);
EXPECT_EQ(static_cast<bool>(LogicalImm(imm, 64)), true);

if (size < 64)
{
test.Check32(imm);
EXPECT_EQ((bool)LogicalImm((u32)imm, 32), true);
EXPECT_EQ(static_cast<bool>(LogicalImm(static_cast<u32>(imm), 32)), true);
}

imm = (imm >> 63) | (imm << 1);
Expand Down

0 comments on commit 581498b

Please sign in to comment.