Stream: git-wasmtime

Topic: wasmtime / PR #11840 cranelift: Add x64 store with immedi...


view this post on Zulip Wasmtime GitHub notifications bot (Oct 12 2025 at 08:54):

jiang1997 opened PR #11840 from jiang1997:x64-store-imm-zero-optimization to bytecodealliance:main:

Add support for generating efficient mov [mem], imm instructions for immediate values, eliminating the need for temporary registers when storing constants.

Changes:

The I64 type is limited to sign-extended i32 values (-2^31 to 2^31-1) due to x86-64 MOV instruction encoding constraints. Values outside this range will panic with a clear error message.

Before: mov r10, 0x42; mov [rsp], r10 (2 instructions, needs register)
After: mov dword ptr [rsp], 0x42 (1 instruction, no register)

This addresses the TODO comment in abi.rs about wanting to store immediate values directly to memory without temporary registers.

<!--
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 (Oct 12 2025 at 08:54):

jiang1997 requested wasmtime-compiler-reviewers for a review on PR #11840.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 12 2025 at 08:54):

jiang1997 requested alexcrichton for a review on PR #11840.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 12 2025 at 09:09):

jiang1997 updated PR #11840.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 12 2025 at 09:19):

jiang1997 updated PR #11840.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 12 2025 at 09:50):

jiang1997 updated PR #11840.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 13 2025 at 14:27):

alexcrichton submitted PR review:

Thanks for the PR! What I might recommend instead though is that we've generally been moving away from Inst-style helpers to construct instructions with the advent of the x64 assembler crate. The one use case for Inst::store_imm, for example, can unconditionally use the movl_mi variant and there's no need for encoding tests or making API design decisions about whether out-of-bounds integers panic or such.

What would you think about replacing the store on the stack here with movl_mi directly, and dropping the new store_imm helper?

view this post on Zulip Wasmtime GitHub notifications bot (Oct 13 2025 at 18:58):

jiang1997 updated PR #11840.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 13 2025 at 19:00):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 13 2025 at 19:00):

alexcrichton has enabled auto merge for PR #11840.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 13 2025 at 19:01):

jiang1997 edited PR #11840:

view this post on Zulip Wasmtime GitHub notifications bot (Oct 13 2025 at 19:21):

jiang1997 commented on PR #11840:

@alexcrichton
Hey, just noticed that changing from mov [rsp], esp to mov [rsp], 0 increases the instruction size from 3 bytes to 7 bytes.
Is this code size increase acceptable? Alternatively, we could keep mov [rsp], rsp and just document it in a comment (resolves the TODO while avoiding the size increase).


Last updated: Dec 06 2025 at 06:05 UTC