[vm] Fix a bug in Utils::NBitMask.

The function was broken on arm64 due to incorrect
mask calculation (based on the target ISA).

Change-Id: Ib5c26bf4c7b901ae27f2a0580c4f88b2b7952212
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121709
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Aart Bik <ajcbik@google.com>
This commit is contained in:
Artem Serov 2019-10-17 17:19:32 +00:00 committed by commit-bot@chromium.org
parent ba728b1368
commit 9ae7b10cea
2 changed files with 30 additions and 5 deletions

View file

@ -340,11 +340,9 @@ class Utils {
static uword NBitMask(uint32_t n) {
ASSERT(n <= kBitsPerWord);
if (n == kBitsPerWord) {
#if defined(TARGET_ARCH_X64)
return 0xffffffffffffffffll;
#else
return 0xffffffff;
#endif
static_assert((sizeof(uword) * kBitsPerByte) == kBitsPerWord,
"Unexpected uword size");
return std::numeric_limits<uword>::max();
}
return (1ll << n) - 1;
}

View file

@ -323,4 +323,31 @@ VM_UNIT_TEST_CASE(DoublesBitEqual) {
EXPECT(Utils::DoublesBitEqual(NAN, NAN));
}
VM_UNIT_TEST_CASE(NBitMask) {
#if defined(ARCH_IS_64_BIT)
EXPECT_EQ(0ull, Utils::NBitMask(0));
EXPECT_EQ(0x1ull, Utils::NBitMask(1));
EXPECT_EQ(0x3ull, Utils::NBitMask(2));
EXPECT_EQ(0xfull, Utils::NBitMask(4));
EXPECT_EQ(0xffull, Utils::NBitMask(8));
EXPECT_EQ(0xffffull, Utils::NBitMask(16));
EXPECT_EQ(0x1ffffull, Utils::NBitMask(17));
EXPECT_EQ(0x7fffffffull, Utils::NBitMask(31));
EXPECT_EQ(0xffffffffull, Utils::NBitMask(32));
EXPECT_EQ(0x1ffffffffull, Utils::NBitMask(33));
EXPECT_EQ(0x7fffffffffffffffull, Utils::NBitMask(kBitsPerWord - 1));
EXPECT_EQ(0xffffffffffffffffull, Utils::NBitMask(kBitsPerWord));
#else
EXPECT_EQ(0u, Utils::NBitMask(0));
EXPECT_EQ(0x1u, Utils::NBitMask(1));
EXPECT_EQ(0x3u, Utils::NBitMask(2));
EXPECT_EQ(0xfu, Utils::NBitMask(4));
EXPECT_EQ(0xffu, Utils::NBitMask(8));
EXPECT_EQ(0xffffu, Utils::NBitMask(16));
EXPECT_EQ(0x1ffffu, Utils::NBitMask(17));
EXPECT_EQ(0x7fffffffu, Utils::NBitMask(kBitsPerWord - 1));
EXPECT_EQ(0xffffffffu, Utils::NBitMask(kBitsPerWord));
#endif
}
} // namespace dart