-
-
Notifications
You must be signed in to change notification settings - Fork 677

Description
The WebAssembly multi-value proposal has already been apart of the Wasm finished-proposals for some time, yet I can't find any mention of how to use it in ASC, although Binaryen supports it, and AS is supposed to allow low-level control over the output Wasm, if I'm not mistaken.
I had edited a simple Fibonnaci function implementation, into the following:
const SQRT5 = 2.23606797749979;
const C1 = 0.48121182505960347;
const C2 = -0.48121182505960336;
export function fib(n: f64): f64 {
if (n <= 0) {
return 0;
}
const temp = f64x2.mul(f64x2(C1, C2), f64x2.splat(n));
const a = Math.exp( f64x2.extract_lane(temp, 0) );
const b = Math.exp( f64x2.extract_lane(temp, 1) );
return Math.round(
(i32(n) & 1 ? a + b : a - b) * (1.0 / SQRT5)
);
}
Regarding optimization, I checked the wat and noticed that the compiler was emitting two f64 locals, when it could've left the values on the stack, something more like the following:
local.get temp
f64x2.extract_lane 0
call Math.exp
local.get temp
f64x2.extract_lane 1
call Math.exp
local.get n
i32/f64
i32.const 1
i32.and
if (param f64 f64) (result f64)
f64.add
else
f64.sub
end
f64.const 1.0
global.get SQRT5
f64.div
f64.mul
call Math.round
return
which should provide superior codegen in runtime VMs, while yielding size benefits.
There has been mention of waiting for Multi-value support for multiple things already, such as adding nullable types, among other things.
Is multi-value support is the plans already?