linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* PowerPC function returning long long
@ 1999-10-13  4:54 Bob Doyle
  1999-10-13  8:06 ` Gabriel Paubert
  0 siblings, 1 reply; 10+ messages in thread
From: Bob Doyle @ 1999-10-13  4:54 UTC (permalink / raw)
  To: linuxppc-dev


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

unsigned long long get_timebase(void) {
        unsigned long tbu;
        unsigned long tbl;
        unsigned long junk;
        __asm__ __volatile__ ("
1:      mftbu   %2
        mftb    %1
        mftbu   %0
        cmpw    %0,%2
        bne     1b"
        : "=r" (tbu), "=r" (tbl), "=r" (junk));
        return ((unsigned long long)tbu << 32) | tbl;
}

This function compiles to (gcc 2.95.1) :

get_timebase:
1:      mftbu   5 
        mftb    6
        mftbu   0   
        cmpw    0,5 
        bne     1b
        mr 10,0
        li 9,0   
        mr 7,10
        mr 12,6
        li 8,0
        li 11,0
        or 3,7,11 
        or 4,8,12
        blr

As one can see, most of this is a bunch of register thrashing.
I expected it to generate something along this:

1:      mftbu   5 
        mftb    4
        mftbu   3   
        cmpw    3,4
        bne     1b
	blr 

I assume it is because gcc is struggling with the code
in the return statement.

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)?

Any ideas?

Yes I know that there is a similar function in
arch/ppc/kernel/apus_setup.c which isn't quite
what I want.

Bob

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

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: PowerPC function returning long long
@ 1999-10-13  6:14 Christophe Lizzi
  0 siblings, 0 replies; 10+ messages in thread
From: Christophe Lizzi @ 1999-10-13  6:14 UTC (permalink / raw)
  To: linuxppc-dev, doyle



> 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/

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~1999-10-14 13:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-10-13  4:54 PowerPC function returning long long Bob Doyle
1999-10-13  8:06 ` Gabriel Paubert
1999-10-13 12:27   ` Michael Meissner
1999-10-14  4:12     ` Bob Doyle
1999-10-14  4:35       ` Michael Meissner
1999-10-14  7:28       ` [TANGENT] GNU as [was: Re: PowerPC function returning long long] Bill Brooks
1999-10-14 12:45         ` Daniel Jacobowitz
1999-10-14 13:21         ` Michael Meissner
1999-10-14 12:44       ` PowerPC function returning long long Daniel Jacobowitz
  -- strict thread matches above, loose matches on Subject: below --
1999-10-13  6:14 Christophe Lizzi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).