Do the compare registers persist through stack frames?

Started by biolizard89, October 26, 2012, 06:30:26 AM

Previous topic - Next topic

biolizard89

Let's say I save a stack frame, do some stuff with registers, do a cmp opcode, restore the stack frame, and then use beq.  Will the beq outside of the stack frame be able to see the compare registers from inside the stack frame, or does restoring the stack frame wipe that?

Thanks.

megazig

yes, the condition reg isn't stack dependant. it will last until another instruction sets something there

biolizard89

Quote from: megazig on October 26, 2012, 06:33:29 AM
yes, the condition reg isn't stack dependant. it will last until another instruction sets something there
Awesome, thanks megazig.  This greatly simplifies the thing I'm coding at the moment....  :)

dcx2

This may come in handy.  http://wiird.l0nk.org/forum/index.php/topic,8768.msg75642.html#msg75642

Condition Register fields 2, 3, and 4 are non-volatile.  So if you use cr2, cr3, or cr4, you do actually have to push and pop the CR.

CR 0, 1, 5, 6, 7 are volatile, so feel free to use them without saving them.  I would prefer cr5, 6, or 7 because game code is less likely to use those ones.

However, assuming that you didn't push CR onto the stack when you created your stack frame, then you won't be popping it either, so the contents will be unchanged.  Popping a stack frame always involves directly lwz'ing the register in question so there is never ambiguity about what registers were changed, except for lmw.