Segher Boessenkool's on August 29, 2019 9:51 pm: > On Thu, Aug 29, 2019 at 07:38:01PM +1000, Nicholas Piggin wrote: >> So... this actually seems to work. Haven't booted it, but the compiler >> seems to do what we want. > > From the GCC manual: > > After defining a global register variable, for the current compilation > unit: > > * If the register is a call-saved register, call ABI is affected: the > register will not be restored in function epilogue sequences after > the variable has been assigned. Therefore, functions cannot safely > return to callers that assume standard ABI. > > and > > * Accesses to the variable may be optimized as usual and the register > remains available for allocation and use in any computations, > provided that observable values of the variable are not affected. > > This doesn't do what you think, or what you want, or what you think you > want ;-)
After reading gcc docs from gcc 4 to 9, I think it does. We want this to apply to all functions in the compilaition unit. It's fine to use the regs temporarily, and so it's fine for called functions in other units to call them (because they will be restored), and we don't want them restored for our caller. > (And if you make all those regs -ffixed-* you are in for a world of hurt). >From the look of it, -ffixed would be a little bit stronger in that it will never allow the register to be used, wheras the global register variable allows it to be allocated and used elsewhere so long as its observable value is not affected. The latter is actually preferred because it's fine for the compiler to use the regs if it wants to. It does not even have to use r15 register when I reference r15 variable, only whatever value it had. Thanks, Nick