Re: compiler smarts: register variables and catching exceptions
andrew_nuss@yahoo.com wrote:
I have a long running loop that uses 4 stacks whose pointers are
declared as register variables and which catches a SpecialException.
The question is whether the introduction of the catch block will
destroy register optimizations, and force the compiler to ignore
using registers to hold the stack pointers.
Just like 'inline' the 'register' keyword is mostly advisory, i.e. a
compiler is free to ignore it, which is what most modern compilers do. The
point is that their optimiser can usually figure out much better what data
is accessed so often that it's worth putting it into a register.
FYI, the only guaranteed effect of 'register' is that you can't take the
address of a variable anymore. The only guaranteed effect of 'inline' is
that multiple definitions don't lead to linker errors.
switch (op) {
// all of the cases do brief manipulations of the various sp1,...,sp4
// some of the cases call functions which throw SpecialException
Ahem, this is far from low-level code that would benefit being called with
most data held in registers, function calls and exceptions with
constructors and destructors (which, again, are function calls) mess up any
local register allocation. Please, please, pretty please, profile such code
before you throw 'register' at it in order to optimise it.
Uli
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]