Skip to content

wasm2c: fix SIMD_FORCE_READ constraint for V-incapable RISC-V targets - #2880

Merged
shravanrn merged 1 commit into
WebAssembly:mainfrom
CSharperMantle:fix-riscv-no-rvv-vr
Oct 20, 2026
Merged

shravanrn merged 1 commit into
WebAssembly:mainfrom
CSharperMantle:fix-riscv-no-rvv-vr

Conversation

@CSharperMantle

@CSharperMantle CSharperMantle commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

When building Firefox 158, which uses vendored wasm2c to compile WASM code, on RISC-V RVA20U64, the following error occurs:

111:25.21 E /var/cache/acbs/build/acbs.05foslpj/firefox-158.0/obj-riscv64-unknown-linux-gnu/media/libsoundtouch/src/rlboxsoundtouch.wasm.c:962:1: error: couldn't allocate input reg for constraint 'vr'
111:25.22 E   962 | DEFINE_SIMD_LOAD_FUNC(v128_load64_zero, v128_impl_load64_zero, u64)
111:25.23 E       | ^
111:25.24 E /var/cache/acbs/build/acbs.05foslpj/firefox-158.0/obj-riscv64-unknown-linux-gnu/media/libsoundtouch/src/rlboxsoundtouch.wasm.c:890:5: note: expanded from macro 'DEFINE_SIMD_LOAD_FUNC'
111:25.25 E   890 |     SIMD_FORCE_READ(result);                                              \
111:25.26 E       |     ^
111:25.26 E /var/cache/acbs/build/acbs.05foslpj/firefox-158.0/obj-riscv64-unknown-linux-gnu/media/libsoundtouch/src/rlboxsoundtouch.wasm.c:866:38: note: expanded from macro 'SIMD_FORCE_READ'
111:25.27 E   866 | #define SIMD_FORCE_READ(var) __asm__("" ::"vr"(var));
111:25.27 E       |                                      ^

Thus gating this arm by defined(__riscv_vector).

@CSharperMantle
CSharperMantle marked this pull request as ready for review October 14, 2026 15:36
CSharperMantle added a commit to AOSC-Tracking/firefox-git that referenced this pull request Oct 14, 2026
CSharperMantle added a commit to AOSC-Tracking/thunderbird that referenced this pull request Oct 14, 2026
@sbc100
sbc100 requested a review from shravanrn October 14, 2026 18:26
#elif defined(__aarch64__)
#define SIMD_FORCE_READ(var) __asm__("" ::"w"(var));
#elif defined(__riscv)
#elif defined(__riscv) && defined(__riscv_vector)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine. Could you send a PR with only the RISC-v change that is not stacked on the PowerPC and default case change so we can land this separately?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. See also #2878 (comment).

@shravanrn
shravanrn enabled auto-merge (rebase) October 20, 2026 14:36
@shravanrn
shravanrn force-pushed the fix-riscv-no-rvv-vr branch from 9f4e61e to 40eca66 Compare October 20, 2026 14:36
When compiling wasm2c-generated programs for V-incapable RISC-V targets,
the following error occurs:

        111:25.21 E /var/cache/acbs/build/acbs.05foslpj/firefox-158.0/obj-riscv64-unknown-linux-gnu/media/libsoundtouch/src/rlboxsoundtouch.wasm.c:962:1: error: couldn't allocate input reg for constraint 'vr'
        111:25.22 E   962 | DEFINE_SIMD_LOAD_FUNC(v128_load64_zero, v128_impl_load64_zero, u64)
        111:25.23 E       | ^
        111:25.24 E /var/cache/acbs/build/acbs.05foslpj/firefox-158.0/obj-riscv64-unknown-linux-gnu/media/libsoundtouch/src/rlboxsoundtouch.wasm.c:890:5: note: expanded from macro 'DEFINE_SIMD_LOAD_FUNC'
        111:25.25 E   890 |     SIMD_FORCE_READ(result);                                              \
        111:25.26 E       |     ^
        111:25.26 E /var/cache/acbs/build/acbs.05foslpj/firefox-158.0/obj-riscv64-unknown-linux-gnu/media/libsoundtouch/src/rlboxsoundtouch.wasm.c:866:38: note: expanded from macro 'SIMD_FORCE_READ'
        111:25.27 E   866 | #define SIMD_FORCE_READ(var) __asm__("" ::"vr"(var));
        111:25.27 E       |                                      ^

Gate "vr" to V-capable RISC-V targets only and fall back to the default
path when V is not supported.
@shravanrn
shravanrn force-pushed the fix-riscv-no-rvv-vr branch from 40eca66 to 4842835 Compare October 20, 2026 16:20
@shravanrn
shravanrn merged commit fa3338c into WebAssembly:main Oct 20, 2026
17 checks passed
felixonmars added a commit to felixonmars/archriscv-packages that referenced this pull request Oct 24, 2026
Use wasm2c's explicit bounds checks on RISC-V without vector registers.
The instrumented build fails in rlboxsoundtouch.wasm.c with "could not
allocate input reg for constraint 'vr'". The upstream RVV guard fix leaves
an unsuitable floating-point fallback; upstream rejected a memory-operand
fallback because it does not guarantee the reads needed by guard pages.
No complete upstream fix was found. Retain RLBox sandboxing with bounds
checks instead.

Drop the XPTC tail-jump patch, included in Firefox 158.0.1 by upstream
commit da6b7fa59644be65b8082c770d915c635377aa80 (bug 2077820).

https://archriscv.felixc.at/.status/logs/firefox/firefox-158.0.1-1.log
WebAssembly/wabt#2880
WebAssembly/wabt#2888 (review)
https://github.com/mozilla-firefox/firefox/blob/FIREFOX_158_0_1_RELEASE/xpcom/reflect/xptcall/md/unix/xptcstubs_riscv64.cpp
felixonmars added a commit to felixonmars/archriscv-packages that referenced this pull request Oct 25, 2026
Bundled wasm2c selects vector registers on baseline RISC-V, failing in
rlboxsoundtouch.wasm.c with "could not allocate input reg for constraint
'vr'". Reuse the Firefox Developer Edition patch to require __riscv_vector
for the vector constraint and use a memory operand otherwise, preserving
forced SIMD reads and RLBox guard-page sandboxing.

WABT PR #2880 gates RVV but retains the floating-point fallback. Apply the
memory-operand approach from unmerged PR #2888 only to RISC-V in the
prebuilt template consumed by the build.

WebAssembly/wabt#2880
WebAssembly/wabt#2888
https://archriscv.felixc.at/.status/logs/thunderbird/thunderbird-158.0-1.log
CSharperMantle added a commit to AOSC-Tracking/firefox-git that referenced this pull request Oct 29, 2026
CSharperMantle added a commit to AOSC-Tracking/thunderbird that referenced this pull request Oct 29, 2026
felixonmars added a commit to felixonmars/archriscv-packages that referenced this pull request Oct 30, 2026
Drop the XPCOM tail-call patch already included by Mozilla bug 2077820;
prepare() rejects it as previously applied in the 159.0 source.

Use the Firefox overlay's wasm2c bounds checks on RISC-V without RVV
for "could not allocate input reg for constraint 'vr'". Upstream's RVV
guard leaves an unsuitable floating-point fallback, and its rejected
memory-operand fallback cannot guarantee the reads needed by guard pages.
No complete upstream fix was found. Keep RLBox sandboxing and the
llama.cpp RVV feature-detection fix.

https://github.com/mozilla-firefox/firefox/blob/FIREFOX_159_0_RELEASE/xpcom/reflect/xptcall/md/unix/xptcstubs_riscv64.cpp#L142
WebAssembly/wabt#2880
WebAssembly/wabt#2888 (review)
https://archriscv.felixc.at/.status/logs/librewolf/librewolf-159.0.0_1-1.log
https://archriscv.felixc.at/.status/logs/librewolf/librewolf-158.0.1_1-1.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants