public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Sparc `long long' incorrect code generation
@ 1997-10-20 19:22 Zack Weinberg
  1997-12-28 22:18 ` Jeffrey A Law
  0 siblings, 1 reply; 2+ messages in thread
From: Zack Weinberg @ 1997-10-20 19:22 UTC (permalink / raw)
  To: egcs

Solaris has a special trap to read the `high resolution timer' which
is useful for timing inner loops.  It's exposed as a library call,
gethrtime(), the disassembly of which is:

gethrvtime:
	ta 0x24
	retl
	nop

The trap returns a 64 bit value in o0:o1 (hi:lo).  You can write a
version of this with gcc's inline asms:

unsigned long long
timer(void)
{
    register unsigned long long val asm("%o0");
    asm("ta 0x24" : "=r" (val));
    return val;
}

gcc 2.7.2 translates this to
timer:
        save %sp,-112,%sp
        ta 0x24
        mov %o0,%i0
        mov %o1,%i1
        ret
        restore

which is correct, although it should be optimized to a leaf.  egcs
971016, on the other hand, generates:

timer:
        save %sp,-112,%sp
        ta 0x24
        ret
        restore

which, if I understand Sparc register windows correctly, is wrong:
the results of the trap will be shifted away and the caller will not
see them.

Interestingly, if you make this an inline function and refer to it
elsewhere, say like so:

extern void foo(unsigned long long);
int
main(void)
{
    foo(timer());
    return 0;
}

both compilers generate the same code:

main:
        save %sp,-112,%sp
        ta 0x24
        call foo,0
        mov 0,%i0
        ret
        restore

which is correct and optimal.

Also, it would be nice if the docs said that you could allocate a
32-bit register pair to a 64-bit integer by putting the high register
in the asm("reg") phrase.  I found that out by trial and error.

zw

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

* Re: Sparc `long long' incorrect code generation
  1997-10-20 19:22 Sparc `long long' incorrect code generation Zack Weinberg
@ 1997-12-28 22:18 ` Jeffrey A Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeffrey A Law @ 1997-12-28 22:18 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: egcs

  In message <199710210221.WAA05773@rabi.phys.columbia.edu>you write:
  > 
  > Solaris has a special trap to read the `high resolution timer' which
  > is useful for timing inner loops.  It's exposed as a library call,
  > gethrtime(), the disassembly of which is:
  > 
  > gethrvtime:
  > 	ta 0x24
  > 	retl
  > 	nop
  > 
  > The trap returns a 64 bit value in o0:o1 (hi:lo).  You can write a
  > version of this with gcc's inline asms:
  > 
  > unsigned long long
  > timer(void)
  > {
  >     register unsigned long long val asm("%o0");
  >     asm("ta 0x24" : "=r" (val));
  >     return val;
  > }
  > 
  > gcc 2.7.2 translates this to
  > timer:
  >         save %sp,-112,%sp
  >         ta 0x24
  >         mov %o0,%i0
  >         mov %o1,%i1
  >         ret
  >         restore
  > 
  > which is correct, although it should be optimized to a leaf.  egcs
  > 971016, on the other hand, generates:
  > 
  > timer:
  >         save %sp,-112,%sp
  >         ta 0x24
  >         ret
  >         restore
  > 
  > which, if I understand Sparc register windows correctly, is wrong:
  > the results of the trap will be shifted away and the caller will not
  > see them.
I believe this was fixed a while ago.  I get this with the latest egcs
snapshot:

        !#PROLOGUE# 0
        save %sp,-112,%sp
        !#PROLOGUE# 1
        ta 0x24
        mov %o0,%i0
        mov %o1,%i1
        ret
        restore

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

end of thread, other threads:[~1997-12-28 22:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-20 19:22 Sparc `long long' incorrect code generation Zack Weinberg
1997-12-28 22:18 ` Jeffrey A Law

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 read-only IMAP folder(s) and NNTP newsgroup(s).