I have looked at this question already, but neither of the two solutions work for me, for the following reasons.
Is it possible to wrap a set of c++ statements in some way to tell the compiler to not use certain registers?
Not in a portable way of course. C++ semantic level knows nothing about this register thing (despite having a register
keyword).
g++
for example however can allocate a register globally or locally to a variable and in this case the compiler will never touch that register. This can sometimes be useful (I've used this with serious performance gains in a VM for a Lisp implementation without having to write everything in assembly by hand).
I suspect of course that unless you recompile also all the standard library changing the standard headers to include the declaration that code in the library can touch the register (and depending on the ABI it's possible that the registers you want to use are declared "scratch" and therefore not saved and restored).
May be other compilers have this option too (clang
however for example despite being almost g++-compatible does not support register allocation).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With