Skip to contentSkip to conversation

PowerPC function returning long long

DISCUSSION Christophe Lizzi 1 participant 1 message Oct 13, 1999

lore
Share & tools
lore
#0 lore raw
Quoted 10 lines

I was playing with the inline assembler and the ppc timebase facility and created the following function -

Is there a better way to write the return statement?

Is there a register constraint for a long long register (like the "A" constraint for the x86 which returns the 64 bit data in edx:eax)?

64 bit values are returned in r3:r4.

I'm definitively not an asm guru, but the following code works:

/*
from PowerPC Microprocessor Family: The Programming Environments,
section 2.2: PowerPC VEA Register Set - Time Base, IBM Microelectronics - Motorola.
*/

unsigned long long timebase(void)
{
asm( "isync" ); /* discard prefetched instructions */
/* the loop ensures that a consistent pair of values is obtained */
asm("loop:" );
asm("mftbu 3" ); /* load r3 from TBU */
asm("mftb 4" ); /* load r4 from TBL */
asm("mftbu 5" ); /* load r5 from TBU */
asm("cmpw 5, 3"); /* compare r5 and r3 */
asm("bne loop"); /* loop if carry occured */
}

--Christophe

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/