WebAssembly image dithering example

kinke noone at nowhere.com
Sun Aug 5 14:06:25 UTC 2018


On Sunday, 5 August 2018 at 03:01:46 UTC, Allen Garvey wrote:
> The thing that's counter-intuitive to me is that if you write 
> the pointer address as 0 right in the code it gets interpreted 
> as null, but if you pass in the same value as 0, everything 
> works as expected.

If you provide the start address as null literal directly in the 
D code, the optimizer infers that you're going to read from 
address 0x3 in the first iteration. If you provide the start 
address as argument from outside code not available during 
optimization, LLVM cannot make any assumptions in this regard.

> The only thing is that I've noticed a weird visual glitch that 
> I've narrowed down to the use of the enum array for some reason

I wasn't sure about the enum array; it'd probably make more sense 
to define it as static immutable directly in the function. I'd 
then expect this global to live in the module's memory 
(`exports.memory`) and be initialized properly during 
instantiation; this means that the start address/offset of the 
pixel data probably shouldn't be 0 and that you shouldn't 
overwrite any existing data after instantiation, just appending 
to it, in order not to overwrite any D globals.


More information about the digitalmars-d-ldc mailing list