AnsweredAssumed Answered

Preserving L Registers in C Functions

Question asked by RyanJ on Mar 11, 2010
Latest reply on Mar 13, 2010 by SeanM
Is there a way to have a C function clear or store/restore the L registers upon exit?
I have a problem (actually, I've had this happen a few times before too), where a compiled C function with optimizations enabled uses one or more of the L registers, but they are not reset on function exit. I end up getting a crash from some other function due to the modified L registers.
I know the L registers aren't among the scratch register set, and in making assembly functions I always protect them, but occasionally I have a C function which doesn't. A likely cause of the L registers being used is my use of the circindex() functions.
Trying using either #pragma regs_clobbered "ALLscratch" or #pragma regs_clobbered "L0 L1 L2 L3" didn't help.
I tried putting assembly blocks at the beginning/end of the C function to store/restore them, but since my circindex call was near the end of the function, it ended up putting the restoration before where it was modified (I'm guessing because of it's being returned):
function() {
volatile uint32 l0,l1,l2,l3;
asm volatile ("%0 = l0;"
     "%1 = l1;"
     "%2 = l2;"
     "%3 = l3;" : "=r" (l0), "=r" (l1), "=r" (l2), "=r" (l3)
); of function...
index = circindex( index, 1, 205881);
asm volatile ("l0 = %0;"
     "l1 = %1;"
     "l2 = %2;"
     "l3 = %3;" :: "r" (l0), "r" (l1), "r" (l2), "r" (l3)
return( index );

turns into (end of function only):
L0 = R1 ;
L1 = R2 ;
L2 = R3 ;
L3 = R7 ;
I1 = R0 ;
L1.L = 0x2439 ;
L1.H = 0x3 ;
B1 = B0 ;
M0 = 25735 ( X ) ;
I1 += M0 ;
R0 = I1 ;
SP += 20 ;
P0 = [ FP + 0x4 ] ;
( R7:4 , P5:4 ) = [ SP ++ ] ;

We are using a relatively old version of VDSP (4.5, November 2006 update), so maybe this is something which has since been fixed, or maybe I'm mistaken about how the L registers are to be preserved?
Thanks for the help,
-- Ryan