digitalmars.D.learn - D WebAssembly working differently than C++, Zig
- Allen Garvey (18/18) May 16 2022 I'm working on a comparison of WebAssembly performance for error
- Adam D Ruppe (3/3) May 16 2022 I would suspect it is something to do with your memset... even if
- Allen Garvey (4/8) May 16 2022 I was thinking memset might be the case, but I tried changing it
- kinke (4/4) May 16 2022 The problem is the memset signature. You assume the length is the
- Allen Garvey (3/7) May 16 2022 Thanks so much, that fixed the problem! You have no idea have
- Adam D Ruppe (8/10) May 17 2022 Oh I should have checked my impl, where I did all this already!
- Siarhei Siamashka (4/6) May 17 2022 Looks like you forgot to increment the pointer and need "*d++ =
- Adam D Ruppe (3/6) May 17 2022 prolly but meh, that's where the intrinsics are nice.
- Sergey (2/6) May 17 2022 Hm D version is the slowest one?!
- Tejas (3/9) May 17 2022 It's faster than the JS version atleast. But yeah, C++ and Zig
I'm working on a comparison of WebAssembly performance for error propagation dithering using D, C++ and Zig. So far C++ and Zig work as expected, but for D, despite using the same algorithm and similar code the output is different. You can see the differences here https://wasm-error-propagation-dither-comparison.netlify.app/ by opening an image. Code * D https://github.com/allen-garvey/wasm-error-propagation-dither-comparison/blob/master/wasm/d/main.d * C++ https://github.com/allen-garvey/wasm-error-propagation-dither-comparison/blob/master/wasm/cpp/main.cpp * Zig https://github.com/allen-garvey/wasm-error-propagation-dither-comparison/blob/master/wasm/zig/main.zig Any help would be appreciated. From my extensive debugging it seems that calculating the pixel lightness is working correctly, it has something to do with either saving or retrieving the stored error in the float arrays.
May 16 2022
I would suspect it is something to do with your memset... even if it needs to take the int (wtf but ldc is weird) you might want to reinterpret cast it to float to avoid any extra conversions.
May 16 2022
On Monday, 16 May 2022 at 18:05:00 UTC, Adam D Ruppe wrote:I would suspect it is something to do with your memset... even if it needs to take the int (wtf but ldc is weird) you might want to reinterpret cast it to float to avoid any extra conversions.I was thinking memset might be the case, but I tried changing it to ignore the int value and just hard-coding 0 and the result was the same.
May 16 2022
The problem is the memset signature. You assume the length is the number of floats, while it's the number of *bytes* to be set to the specified value. https://en.cppreference.com/w/c/string/byte/memset
May 16 2022
On Monday, 16 May 2022 at 18:14:13 UTC, kinke wrote:The problem is the memset signature. You assume the length is the number of floats, while it's the number of *bytes* to be set to the specified value. https://en.cppreference.com/w/c/string/byte/memsetThanks so much, that fixed the problem! You have no idea have long I have spent trying to debug this!
May 16 2022
On Monday, 16 May 2022 at 18:17:03 UTC, Allen Garvey wrote:Thanks so much, that fixed the problem! You have no idea have long I have spent trying to debug this!Oh I should have checked my impl, where I did all this already! https://github.com/adamdruppe/webassembly/blob/master/arsd-webassembly/object.d#L263 And also might be able to just have the function forward to the ldc intrinsic: https://github.com/ldc-developers/druntime/blob/ldc/src/ldc/intrinsics.di#L160 might help speed up a lil too, i don't know though (I didn't do it here for me)
May 17 2022
On Tuesday, 17 May 2022 at 11:36:21 UTC, Adam D Ruppe wrote:Oh I should have checked my impl, where I did all this already! https://github.com/adamdruppe/webassembly/blob/master/arsd-webassembly/object.d#L263Looks like you forgot to increment the pointer and need "*d++ = cast(ubyte) c;" there. And filling the buffer one byte at a time is likely slow.
May 17 2022
On Tuesday, 17 May 2022 at 11:43:45 UTC, Siarhei Siamashka wrote:Looks like you forgot to increment the pointer and need "*d++ = cast(ubyte) c;" there.hahaha yup.And filling the buffer one byte at a time is likely slow.prolly but meh, that's where the intrinsics are nice.
May 17 2022
On Monday, 16 May 2022 at 17:32:20 UTC, Allen Garvey wrote:I'm working on a comparison of WebAssembly performance for error propagation dithering using D, C++ and Zig. So far C++ and Zig work as expected, but for D, despite using the same algorithm and similar code the output is different.Hm D version is the slowest one?!
May 17 2022
On Tuesday, 17 May 2022 at 09:38:31 UTC, Sergey wrote:On Monday, 16 May 2022 at 17:32:20 UTC, Allen Garvey wrote:It's faster than the JS version atleast. But yeah, C++ and Zig being 30+% faster than the D solution doesn't look good on us :(I'm working on a comparison of WebAssembly performance for error propagation dithering using D, C++ and Zig. So far C++ and Zig work as expected, but for D, despite using the same algorithm and similar code the output is different.Hm D version is the slowest one?!
May 17 2022