WebAssembly image dithering example

kinke noone at nowhere.com
Fri Aug 3 23:36:18 UTC 2018


On Friday, 3 August 2018 at 21:55:56 UTC, Allen Garvey wrote:
> My knowledge of pointers is a bit sketchy, so I had assumed 
> they were pretty much interchangeable with ints.

They apparently are (numbers on the JS side, pointers on wasm), 
so you can simply declare the params as appropriately typed 
pointers. That wasn't the problem though, see below.

> I'm seeing a speed increase of over 2x compared to the 
> non-optimized version.

And further doubling of that performance [at least for me] with 
https://github.com/allen-garvey/wasm-dither-example/pull/1. :)

> It's also a bit strange how llvm was able to output valid code 
> with no optimizations, but not do it with optimizations turned 
> on.

The optimizer apparently figured you were going to dereference a 
seemingly invalid address (probably `3`, the alpha channel of the 
1st pixel, which is read unconditionally in each iteration) and 
so optimized the whole loop body to a trap (and branched directly 
to the first unreachable in the 1st iteration).
These low addresses are perfectly valid and to be expected in 
wasm though (well, I don't encourage using null though :]). 
Passing the pointer as argument prevents LLVM from such 
aggressive optimizations.

> Also, on an unrelated note, do you by any chance know if 
> version(WebAssembly) is supported yet (or maybe it is in master 
> but not the beta)? I was trying to use it to conditionally 
> include the assert stub, but it doesn't seem to be working for 
> me.

Ah yeah, that made it into master shortly after beta2. [In beta2, 
it's `WebAssembly32`.]


More information about the digitalmars-d-ldc mailing list