4 ms·
> I want variable X to be loaded into a registerer in thos function and only written to memory at the end of the function. > That is complex in C/C++ but you c
by andrepd 10mo ago
> I want variable X to be loaded into a registerer in thos function and only written to memory at the end of the function.
> That is complex in C/C++ but you can look at decompilation and attempt to coerce the compiler into that.
> In rust everything is so abstracted I wouldn't know where to begin looking
I don't know if I fully understand what you want to do, but (1) controlling register allocation is the realm of inline asm, be it in C, C++, or Rust. And (2) if "nudging" the compiler is what you want, then it's literally the same thing in Rust as in C++, it's a matter of inspecting the asm yourself or plonking your function onto godbolt.
- 1718627440 10mo agoI think the issue is that naive translation of C into ASM, which is somewhat simulated by -O0, is usable in C, while it isn't in Rust.
- jpc0 10mo agoThis. I agree that you will probably just end up writing ASM but it was a trivial example, there are non-trivial examples involving jump tables and unrolling loops etc. Effectively weird optimisations that rely on the virtual machine the compiler is building for vs reality, there's just more abstractions with rust than with C++ by the virtue of the safety mechanism, it's just plain not possible to have the one without the other. The hardware can do legal things that rust cannot allow or can allow but you need to write extremely convoluted code, C/C++ is closer to the metal in that regard. Don't get me wrong I am all for the right abstractions, it allows insane optimisations that humans couldn't dream of, but there is a flip side.