find number of floating point register programmaticaly in c++ [closed]-Collection of common programming errors
In general, compilers do know this sort of stuff (and how to best use it), so I’m slightly surprised that you think that you can outsmart the compiler – unless I have very high domain knowledge, and start writing assembler code, I very rarely outsmart the compiler.
Since writing assembler code is highly unportable, I don’t think that counts as a solution for optimising the code using knowledge as to how many registers, etc. It is very difficult to know how the compiler uses registers. If you have int x = y + z; as a simple example, how many registers does it take? Depends on the compiler – it could use none, one, two, three, four, five or six, without being below optimal register usage – it all depends on how the compiler decides to deal with things, machine architecture, where/how variables are being stored, etc. The same principle applies to number of floating point registers if we change int to double. There is no obvious way to tell how many registers are being used in this statement (although I suspect no more than three – however, it could be zero or one, depending on what the compiler decides to do).
It’s probably possible to do some clever tricks if you know the processor architecture and how the compiler deals with certain types of code – but that also assumes that the compiler doesn’t change its behaviour in the next release. But if you know what processor architecture it is, then you also know the number of registers of various kinds…