-
Notifications
You must be signed in to change notification settings - Fork 1.5k
winch: Simplify constant handling, part 2/N #10989
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
Merged
saulecabrera
merged 5 commits into
bytecodealliance:main
from
saulecabrera:winch-isa-dependent-imm
Jun 9, 2025
Merged
winch: Simplify constant handling, part 2/N #10989
saulecabrera
merged 5 commits into
bytecodealliance:main
from
saulecabrera:winch-isa-dependent-imm
Jun 9, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit introduces a register allocator for scratch registers. The objective of this change is to make it generally safer to work with scratch registers and prevent accidental clobbering of said registers. This approach also has the advantage that allows for a more natural abstraction over ISA-dependent scratch register definitions, e.g., we can easily encode that fact that in aarch64 x16 and x17 are considered scratch registers, while in x64 Winch's ABI defines a single global scratch register.
This commit makes use of the scratch register allocator in both the x64 and aarch64 backends for immediate value loading. Given that the MacroAssembler is the boundary between ISA-agnostic code and ISA-dependent code, it seems to be the natural location for this allocator to live. The allocator gives exclusive access to a scratch register of a particular class, through the `Masm::with_scratch` method. Note that the semantics of this allocator don't involve spilling or any other form of register availability resolution. If a register is requested and it's not available, this method will panic.
Even though the entire change doens't contain major funcitonal changes, a side effect of improving the constant handling in aarch64 is that we perform better instruction selection for instructions that deal with immediattes, improving the generated code in some cases.
alexcrichton
approved these changes
Jun 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all look sound and good to me, definitely makes handling scratch registers less brittle!
Subscribe to Label Action
This issue or pull request has been labeled: "winch"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
saulecabrera
added a commit
to saulecabrera/wasmtime
that referenced
this pull request
Jun 10, 2025
This commit is a follow-up to bytecodealliance#10989; it migrates all the uses of the scratch register to use `Masm::with_scratch`. This commit also updates the tests that can fail / are ignored, since many of the bugs were introduced by accidental clobbers to scratch registers. Even though this change doesn't introduce any functional changes, the disassembly changes in aarch64 are due to the usage of x17 as an extra scratch registers. The updates in x64 dissembly are related to offset changes.
saulecabrera
added a commit
to saulecabrera/wasmtime
that referenced
this pull request
Jun 10, 2025
This commit is a follow-up to bytecodealliance#10989; it migrates all the uses of the scratch register to use `Masm::with_scratch`. This commit also updates the tests that can fail / are ignored, since many of the bugs were introduced by accidental clobbers to scratch registers. Even though this change doesn't introduce any functional changes, the disassembly changes in aarch64 are due to the usage of x17 as an extra scratch registers. The updates in x64 dissembly are related to offset changes.
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jun 10, 2025
* winch: Use `Masm::with_scratch` in ISA-agnostic code This commit is a follow-up to #10989; it migrates all the uses of the scratch register to use `Masm::with_scratch`. This commit also updates the tests that can fail / are ignored, since many of the bugs were introduced by accidental clobbers to scratch registers. Even though this change doesn't introduce any functional changes, the disassembly changes in aarch64 are due to the usage of x17 as an extra scratch registers. The updates in x64 dissembly are related to offset changes. * Use `with_scratch!` in `pop_to_addr` * Remove dead code * Apply cargo fmt * Remove `imports.wast` from ignore list * Use the new version of `Masm::with_scratch` * Introduce `Masm::with_scratch_for` Helper to derive the register class needed for a particular Wasm value type * Format
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch is best reviewed commit by commit.
This is a follow-up to #10888
Scratch registers are used throughout Winch's codebase to handle constant values that cannot be directly encoded in specific instructions. Since the encoding rules are ISA-specific, selecting instructions for these operations often requires scratch registers. Ideally, these temporary registers should be acquired without adding any register pressure to prevent value spilling.
The objective of this change is to make it generally safer to work with scratch registers and prevent accidental clobbering of such registers.