My question is very similar to: GCC: Prohibit use of some registers
However, I would like to limit the number of registers used in a C function. In other words, I would like to be able to use a directive just like clobber registers but applied at the C function level rather than within inline assembly. Also, each function may have a different set of registers to use, so it can't be a one-fits-all solution.
The only 2 possible solutions that I have thought of were:
- Do everything in assembler. Not really a solution to my problem...
- Compile each function separately using some kind of directive for conditional usage of registers in GCC. I would lose a lot of potential optimization by compiling each function separately and it would make the code virtually unreadable.
Since I am trying to do all this in C, is there any way that the pre-compiler could help here in any way? Are there any possible ways for achieving my intended goal?