Stream: git-wasmtime

Topic: wasmtime / PR #9046 Cranelift: Stop sign-extending `Imm64...


view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 22:25):

fitzgen requested wasmtime-compiler-reviewers for a review on PR #9046.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 22:25):

fitzgen requested abrown for a review on PR #9046.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 22:25):

fitzgen opened PR #9046 from fitzgen:dont-sign-extend-in-iconst to bytecodealliance:main:

Originally, we sign-extended Imm64 immediates from their controlling type var's width to i64 in the builder methods for BinaryImm64 and a couple other instruction formats: https://github.com/bytecodealliance/wasmtime/pull/1687

At some point, we decided that the unused bits in the Imm64 when the controlling type var's width is less than 64 should be zero. And we started asserting that in various places, for example:
https://github.com/bytecodealliance/wasmtime/blob/87817f38a128caa76eaa6a3c3c8ceac81a329a3e/cranelift/codegen/src/machinst/lower.rs#L1237-L1243

However, we never removed or updated the sign-extension code in the builder methods. This commit switches the builder methods over to masking the Imm64 to just the valid bits, effectively doing a zero extend from the controlling type var's width instead of a sign extend.

To avoid too much churn in tests, I made display_inst print the sign-extended-from-the-controlling-type-variable's-width value of Imm64 immediates. I also made the Display implementation for Imm64 always print in decimal form with a - for negative numbers, rather than the hex it would previously print for large negative numbers, so that iconst.i32 0x8000_0000 doesn't display as iconst.i32 0xffff_ffff_8000_0000, which is otherwise pretty confusing.

<!--
Please make sure you include the following information:

Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.html

Please ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 22:49):

cfallin submitted PR review:

Thanks for finding this inconsistency!

A few minor nits below; my only other thought is that the rules around how we print seem a little convoluted, though I understand the goal in trying to preserve existing test expectations. The asymmetry (small positive numbers, or any negative number, are decimal) somehow doesn't sit right with me. I think I'd almost rather take a one-time diff and pick something more consistent -- always hex? Always decimal? Always decimal but with hex in a comment (like we do for constants now e.g. ; v0 = 0)?

Feel free to disregard my bikeshed color preferences; just my thoughts as long as we're here :-)

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 22:49):

cfallin submitted PR review:

Thanks for finding this inconsistency!

A few minor nits below; my only other thought is that the rules around how we print seem a little convoluted, though I understand the goal in trying to preserve existing test expectations. The asymmetry (small positive numbers, or any negative number, are decimal) somehow doesn't sit right with me. I think I'd almost rather take a one-time diff and pick something more consistent -- always hex? Always decimal? Always decimal but with hex in a comment (like we do for constants now e.g. ; v0 = 0)?

Feel free to disregard my bikeshed color preferences; just my thoughts as long as we're here :-)

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 22:49):

cfallin created PR review comment:

To fit with the other operator methods (e.g. wrapping_neg), can we do functional style here (fn mask_to_width(self, bit_width: u32) -> Self)?

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 22:49):

cfallin created PR review comment:

Can we rename the boolean on this if-block (imms_need_sign_extension) as well to something that fits the new scheme?

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 23:15):

fitzgen updated PR #9046.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 23:16):

fitzgen commented on PR #9046:

The asymmetry (small positive numbers, or any negative number, are decimal) somehow doesn't sit right with me. I think I'd almost rather take a one-time diff and pick something more consistent -- always hex? Always decimal? Always decimal but with hex in a comment (like we do for constants now e.g. ; v0 = 0)?

Agreed. I'll look into this as a follow up, rather than doing it in this PR.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 23:16):

fitzgen has enabled auto merge for PR #9046.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 23:56):

fitzgen requested pchickey for a review on PR #9046.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 23:56):

fitzgen updated PR #9046.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2024 at 23:56):

fitzgen requested wasmtime-core-reviewers for a review on PR #9046.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 31 2024 at 00:20):

fitzgen merged PR #9046.


Last updated: Nov 22 2024 at 16:03 UTC