Skip to content
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

pulley: Refactor conditional branches and table codegen #9794

Merged

Conversation

alexcrichton
Copy link
Member

This commit first fixed an issue with table access codegen to disable
spectre mitigations on Pulley targets like how spectre is disabled for
memory accesses as well. This unblocked many tests related to tables
which then led to a different error about a trapnz with an 8-bit value
not being supported.

In fixing trapnz with 8-bit values this PR went ahead and did a
general-purpose refactoring for how conditional branches are managed.
Previously conditional traps and conditional branches had some
duplicated logic and the goal was to unify everything. There is now a
single Cond which represents the condition of a conditional jump which
is used uniformly for all locations such as select, brif, and
trap[n]z. This new type represents all the sorts of conditional
branches that can be done in Pulley, for example integer comparisons and
whether or not a register is zero. This Cond type has various helpers
for printing it, inverting it, collecting operands, emission, etc.

The end result is that it's a bit wordy to work with Cond right now
due to the size of the variants but all locations working with
conditional traps are deduplicated and now it's just repetitive logic
rather than duplicated logic.

Putting all of this together gets a large batch of spec tests working.

I'll note that this does remove a feature where trapnz was turned into
nothing or an unconditional trap if the argument was a constant, but
that feels like an optimization perhaps best left for the middle-end
rather than doing it in the backend.

cc #9783

@alexcrichton alexcrichton requested review from a team as code owners December 11, 2024 20:36
@alexcrichton alexcrichton requested review from cfallin and fitzgen and removed request for a team December 11, 2024 20:36
@alexcrichton
Copy link
Member Author

alexcrichton commented Dec 11, 2024

Note this is currently based on #9793

@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language pulley Issues related to the Pulley interpreter wasmtime:api Related to the API of the `wasmtime` crate itself labels Dec 11, 2024
Copy link

Subscribe to Label Action

cc @cfallin, @fitzgen

This issue or pull request has been labeled: "cranelift", "isle", "pulley", "wasmtime:api"

Thus the following users have been cc'd because of the following labels:

  • cfallin: isle
  • fitzgen: isle, pulley

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

This commit first fixed an issue with table access codegen to disable
spectre mitigations on Pulley targets like how spectre is disabled for
memory accesses as well. This unblocked many tests related to tables
which then led to a different error about a `trapnz` with an 8-bit value
not being supported.

In fixing `trapnz` with 8-bit values this PR went ahead and did a
general-purpose refactoring for how conditional branches are managed.
Previously conditional traps and conditional branches had some
duplicated logic and the goal was to unify everything. There is now a
single `Cond` which represents the condition of a conditional jump which
is used uniformly for all locations such as `select`, `brif`, and
`trap[n]z`. This new type represents all the sorts of conditional
branches that can be done in Pulley, for example integer comparisons and
whether or not a register is zero. This `Cond` type has various helpers
for printing it, inverting it, collecting operands, emission, etc.

The end result is that it's a bit wordy to work with `Cond` right now
due to the size of the variants but all locations working with
conditional traps are deduplicated and now it's just repetitive logic
rather than duplicated logic.

Putting all of this together gets a large batch of spec tests working.

I'll note that this does remove a feature where `trapnz` was turned into
nothing or an unconditional trap if the argument was a constant, but
that feels like an optimization perhaps best left for the middle-end
rather than doing it in the backend.

cc bytecodealliance#9783
@fitzgen
Copy link
Member

fitzgen commented Dec 12, 2024

I'll note that this does remove a feature where trapnz was turned into
nothing or an unconditional trap if the argument was a constant, but
that feels like an optimization perhaps best left for the middle-end
rather than doing it in the backend.

Agreed that ideally that would happen in the mid-end, but FWIW the mid-end doesn't have the power to do that currently. I think it is ultimately fine to remove this now tho, and if it is ever an issue in the future we can address it again at that point.

@fitzgen fitzgen added this pull request to the merge queue Dec 12, 2024
Merged via the queue into bytecodealliance:main with commit 04a3736 Dec 12, 2024
43 checks passed
@alexcrichton alexcrichton deleted the pulley-condition-refactor branch December 12, 2024 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language pulley Issues related to the Pulley interpreter wasmtime:api Related to the API of the `wasmtime` crate itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants