Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing the compiler to use a certain register for a certain variable

Is it possible to force a compiler (gcc or clang in my case) to use a certain register, lets say R15 on x86_64 for a certain variable and also prohibit it from using R15 for any other purpose besides that variable.

like image 879
MetallicPriest Avatar asked Jul 23 '13 12:07

MetallicPriest


1 Answers

gcc can do it.

The already cited gcc docs answers your question of how to force a variable into a certain register.

To stop the compiler from generating code using this register for other purposes, use the gcc switch -ffixed-reg (see gcc doc for details).

like image 104
flolo Avatar answered Sep 28 '22 04:09

flolo