4 ms·
> Instructions, blocks, and functions can now return more than one result value, sometimes supporting faster calling conventions and avoiding indirections. Unf
by adrian17 1y ago
> Instructions, blocks, and functions can now return more than one result value, sometimes supporting faster calling conventions and avoiding indirections.
Unfortunately, despite being "enabled", Rust+LLVM don't take advantage of this because of ABI compatibility mess. I don't know whether the story on Clang's side is similar.
- sapiogram 1y agoInteresting, got any links to more information?
- adrian17 1y agohttps://blog.rust-lang.org/2024/09/24/webassembly-targets-change-in-default-target-features/ https://blog.rust-lang.org/2024/09/24/webassembly-targets-ch... "As a result there is no longer any possible method of writing a function in Rust that returns multiple values at the WebAssembly function type level." And similar queries in Rust's zulip: https://rust-lang.zulipchat.com/#narrow/channel/122651-general/topic/how.20to.20write.20multivalue.20functions.20for.20webassembly/near/507127327 https://rust-lang.zulipchat.com/#narrow/channel/122651-gener...
- burakemir 1y agohttps://blog.rust-lang.org/2025/04/04/c-abi-changes-for-wasm32-unknown-unknown/ https://blog.rust-lang.org/2025/04/04/c-abi-changes-for-wasm...
- Dwedit 1y agoI figured out the way to get multi-value results on GCC for 32-bit ARM. Use a union to pack two 32-bit values into a 64-bit value. Return the 64-bit value. Then use a union to split the 64-bit value into two 32-bit values. I haven't tested it on other 32-bit architectures though.
- _lvbh 1y agoI'm using the same trick in Zig via packed structs
- azakai 1y agoThis is indeed unfortunate, but on the other hand, multivalue's benefits are probably very small. Inside functions, there is perhaps a 1-3% code size opportunity at best (https://github.com/WebAssembly/binaryen?tab=readme-ov-file#binaryen-ir https://github.com/WebAssembly/binaryen?tab=readme-ov-file#b...), and no performance advantage. Between functions there might be a performance advantage, but as wasm VMs do more things like runtime inlining (which becomes more and more important with wasm GC and the languages that compile to it), that benefit goes away.