4 ms·
> it would be nice if there was some way to specify how memory in certain address ranges need to be addressed. If making the respective loads and stores volati
by AndyKelley 2y ago
> it would be nice if there was some way to specify how memory in certain address ranges need to be addressed.
If making the respective loads and stores volatile doesn't solve this problem please feel free to file a bug against the compiler.
https://ziglang.org/documentation/0.13.0/#volatile https://ziglang.org/documentation/0.13.0/#volatile
- ant6n 2y agoOh look, small world!
- AndyKelley 2y agoHowdy!
- underdeserver 2y ago> Did you know that you can’t write to video memory on the Game Boy Advance in units of 8 bits, and if you do, it’ll still work but all your graphics will be messed up with no obvious way to figure it out unless you read one specific paragraph of the documentation? Hey did you know that when you compile a binary optimized for size, memory copies will be by units of 8 bits, but not if you use debug mode? Andrew (or any Zig mavens) - What would be the idiomatic way of solving this issue? Can you define your own memcpy with @std.mem.doNotOptimizeAway or something?
- MatthiasPortzel 2y agoAndrew’s point is that marking the memory as volatile should prevent this optimization. (i.e. the compiler isn’t allowed to split a 16-bit volatile write into two 8-but writes.) This is idiomatic because volatile is intended for MMIO. There’s a proposal for a way to disable LLVM generating builtin calls like memcpy. But I’d argue volatile would still be more appropriate in this case. https://github.com/ziglang/zig/issues/22110 https://github.com/ziglang/zig/issues/22110 Edit: this comment from later in the thread is also relevant: https://news.ycombinator.com/item?id=42556624 https://news.ycombinator.com/item?id=42556624