SIMD.ts

https://github.com/CrimsonCodes0/SIMD.ts
Not run yet
3 runs
This repl has no cover image
Details
Created on Jan 3, 2021
1 Reaction
58comments
to comment
xxpertHacker3 months ago

@Baconman321 How tho?

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.

Pseudocode:

import true, false

Table = [ false, true ]

func equal(f64 x, f64 y) -> boolean {
    Table[x == y]
}

If x == y returns 0, then the table is accessed at 0, yielding false, 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.

Forks
SIMD.ts