Re: PowerPC function returning long long

From: Christophe Lizzi <hidden>
Date: 1999-10-13 06:14:56

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/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help