Via references.Want to cast a Wasm boolean to a JS boolean?
WebAssembly booleans are numbers, 0 or 1, JS booleans are objects, true or false, quite different things, huh?
Well, by storing a reference to a JS true and false, one can convert Wasm -> JS, from inside of Wasm, with blazingly fast performance, and no JS whatsoever.
https://github.com/00ff0000red/SIMD.ts/issues/1
@Baconman321 How tho?
Via references.Want to cast a Wasm boolean to a JS boolean?
WebAssembly booleans are numbers,
0
or1
, JS booleans are objects,true
orfalse
, quite different things, huh?Well, by storing a reference to a JS true and false, one can convert Wasm -> JS, from inside of Wasm, with blazingly fast performance, and no JS whatsoever.
Pseudocode:
If
x == y
returns0
, then the table is accessed at0
, yieldingfalse
, and vice versa.I did just that ^ in https://repl.it/@xxpertHacker/areSameBits#areSameBits.wat
In this particular case, I'm loading the references at line 1639 of /src/SIMD.js.
Think about it, even VM/browser native code needs to use both, low-level and high-level stuff in order to work well.