Repository navigation
[Bits] Use abs(rhs) in getMaxBits for rem_s #9364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
731402a
b1ce7b8
5edcd93
891b615
1559efa
36d7778
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,6 +199,21 @@ void test_bits() { | |
| assert_equal(getMaxBits(&b), 32); | ||
| c0.value = Literal(int32_t(3)); | ||
| c1.value = Literal(int32_t(-1)); | ||
| assert_equal(getMaxBits(&b), 0); | ||
| c0.value = Literal(int32_t(0xFF)); | ||
| c1.value = Literal(int32_t(-4)); | ||
| assert_equal(getMaxBits(&b), 2); | ||
| c0.value = Literal(int32_t(0xFF)); | ||
| c1.value = Literal(int32_t(-5)); | ||
| assert_equal(getMaxBits(&b), 3); | ||
| c0.value = Literal(int32_t(-1)); | ||
| c1.value = Literal(int32_t(-4)); | ||
| assert_equal(getMaxBits(&b), 32); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rhs is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 same question. LGTM otherwise
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That comes from here: https://github.com/WebAssembly/binaryen/pull/9364/changes#diff-6ff45ddead31428b20efeba2b73d4e2c4764eb01d31eec2ab168a656e9de78e0R213-R216. It reasons that if the left hand side can be negative, so can the result.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, can we remove that pre-existing bit, then? Can leave it to later, maybe with a TODO in the tests that give odd results atm.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, that is important for correctness in general. For example, in this test: https://github.com/WebAssembly/binaryen/pull/9364/changes#diff-a94a68e8de6450424e23594987df4a57904920644e71a2f3fb5c481a41ebe1d2R9666-R9676 The only reason that you, the reader, know there is a more precise answer here is because you're looking at a concrete value on the LHS, and not just a judgment of its maximum bits. We could get the more precise result by specifically handling the case where the LHS and RHS are both constants, but that's better left to Precompute.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, IIUC,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, a signed value being divided... I forgot that. |
||
| c0.value = Literal(int32_t(0x7FFFFFFF)); | ||
| c1.value = Literal(int32_t(0x80000000)); | ||
| assert_equal(getMaxBits(&b), 31); | ||
| c0.value = Literal(int32_t(3)); | ||
| c1.value = Literal(int32_t(0x80000000)); | ||
| assert_equal(getMaxBits(&b), 2); | ||
| c0.value = Literal(int32_t(0x7FFFFFFF)); | ||
| c1.value = Literal(int32_t(0x7FFFFFFF)); | ||
|
|
@@ -412,6 +427,21 @@ void test_bits() { | |
| assert_equal(getMaxBits(&b), 64); | ||
| c0.value = Literal(int64_t(3)); | ||
| c1.value = Literal(int64_t(-1)); | ||
| assert_equal(getMaxBits(&b), 0); | ||
| c0.value = Literal(int64_t(0xFF)); | ||
| c1.value = Literal(int64_t(-4)); | ||
| assert_equal(getMaxBits(&b), 2); | ||
| c0.value = Literal(int64_t(0xFF)); | ||
| c1.value = Literal(int64_t(-5)); | ||
| assert_equal(getMaxBits(&b), 3); | ||
| c0.value = Literal(int64_t(-1)); | ||
| c1.value = Literal(int64_t(-4)); | ||
| assert_equal(getMaxBits(&b), 64); | ||
| c0.value = Literal(int64_t(0x7FFFFFFFFFFFFFFF)); | ||
| c1.value = Literal(int64_t(0x8000000000000000)); | ||
| assert_equal(getMaxBits(&b), 63); | ||
| c0.value = Literal(int64_t(3)); | ||
| c1.value = Literal(int64_t(0x8000000000000000)); | ||
| assert_equal(getMaxBits(&b), 2); | ||
| c0.value = Literal(int64_t(0x7FFFFFFFFFFFFFFF)); | ||
| c1.value = Literal(int64_t(0x7FFFFFFFFFFFFFFF)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.