WebAssembly image dithering example

Allen Garvey allen.garvey at gmail.com
Fri Aug 3 21:55:56 UTC 2018


On Friday, 3 August 2018 at 21:05:09 UTC, kinke wrote:
>> An LLVM issue, I guess.
>
> Nope, LLVM apparently doesn't like the pixels array starting at 
> null (so just pass a null pointer from JS to WebAssembly). With 
> this diff and your python2 help, I got it to work locally now 
> (849 bytes):

Thank you very much for your help! My knowledge of pointers is a 
bit sketchy, so I had assumed they were pretty much 
interchangeable with ints. With your changes I was able to get it 
to compile and run beta2, with I assume similar output, as the 
binary was also 849 bytes. I'm seeing a speed increase of over 2x 
compared to the non-optimized version. This is surprising to me, 
because since browsers JIT everything I had assumed optimizing 
the wasm binary would not make that much of a difference.

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. After skimming through this link 
https://webassembly.org/docs/semantics/ for wasm semantics, it 
seems as though a function (or possibly block as well?) can end 
with a return statement or an unreachable statement, but not 
both, as in the optimized dither function output (before your 
changes).

"""
unreachable: An instruction which always traps. It is intended to 
be used for example after calls to functions which are known by 
the producer not to return.
"""

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.



More information about the digitalmars-d-ldc mailing list