Skip to content

pulley: Allow disabling SIMD in the interpreter at compile-time #10727

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

Conversation

alexcrichton
Copy link
Member

This commit adds a new feature to Pulley which is used to reduce the compiled code size of the interpreter itself by disabling SIMD opcode interpretation at compile-time. The goal here is to be low-impact on Pulley itself to avoid needing #[cfg] all over the place and to additionally avoid the need to redesign Pulley's opcode macro for use in various parts of Wasmtime.

Methods are annotated with a custom macro in the interpreter which registers a #[cfg] that either does the listed implementation or switches to an implementation that emits a trap if executed. This means that it's safe to execute mismatched code where SIMD was enabled at compile time but disabled at runtime, it just means the semantics may be a bit surprising to debug.

Note that this SIMD is still enabled by default, and an explicit --cfg via RUSTFLAGS is required to compile-out the SIMD support. Cargo features aren't a great fit for this sort of feature so an explicit flag is used.

@alexcrichton alexcrichton requested review from a team as code owners May 5, 2025 14:32
@alexcrichton alexcrichton requested review from pchickey and removed request for a team May 5, 2025 14:33
@github-actions github-actions bot added pulley Issues related to the Pulley interpreter wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:docs Issues related to Wasmtime's documentation labels May 5, 2025
Copy link

github-actions bot commented May 5, 2025

Subscribe to Label Action

cc @fitzgen

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

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

  • fitzgen: pulley

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

Learn more.

@alexcrichton
Copy link
Member Author

alexcrichton commented May 5, 2025

I gathered some numbers in google/wasefire#458 (comment) and for that particular embedding this is a 10% reduction in text size (44k) when compiled with --release and a 5% reduction in text size (14k) when compiled with opt-level=z

@alexcrichton alexcrichton added this pull request to the merge queue May 5, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 5, 2025
@alexcrichton alexcrichton force-pushed the compile-away-pulley-simd branch from 40cf44b to b3203bb Compare May 5, 2025 17:56
@alexcrichton alexcrichton enabled auto-merge May 5, 2025 17:56
@alexcrichton alexcrichton force-pushed the compile-away-pulley-simd branch from b3203bb to 2805f3b Compare May 5, 2025 19:40
@alexcrichton alexcrichton added this pull request to the merge queue May 5, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 5, 2025
This commit adds a new feature to Pulley which is used to reduce the
compiled code size of the interpreter itself by disabling SIMD opcode
interpretation at compile-time. The goal here is to be low-impact on
Pulley itself to avoid needing `#[cfg]` all over the place and to
additionally avoid the need to redesign Pulley's opcode macro for use in
various parts of Wasmtime.

Methods are annotated with a custom macro in the interpreter which
registers a `#[cfg]` that either does the listed implementation or
switches to an implementation that emits a trap if executed. This means
that it's safe to execute mismatched code where SIMD was enabled at
compile time but disabled at runtime, it just means the semantics may be
a bit surprising to debug.

Note that this SIMD is still enabled by default, and an explicit `--cfg`
via `RUSTFLAGS` is required to compile-out the SIMD support. Cargo
features aren't a great fit for this sort of feature so an explicit flag
is used.
@alexcrichton alexcrichton force-pushed the compile-away-pulley-simd branch from 2805f3b to d0dc1fd Compare May 5, 2025 20:20
@alexcrichton alexcrichton enabled auto-merge May 5, 2025 20:22
@alexcrichton alexcrichton added this pull request to the merge queue May 5, 2025
Merged via the queue into bytecodealliance:main with commit eed7c10 May 5, 2025
41 checks passed
@alexcrichton alexcrichton deleted the compile-away-pulley-simd branch May 5, 2025 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pulley Issues related to the Pulley interpreter wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:docs Issues related to Wasmtime's documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants