Summary: Optimizing operations of the Sun SPARC assembler

tthorn@daimi.aau.dk (Tommy Thorn)
Sun, 3 Nov 91 22:59:36 GMT

          From comp.compilers

Related articles
Summary: Optimizing operations of the Sun SPARC assembler tthorn@daimi.aau.dk (1991-11-03)
| List of all articles for this month |

Newsgroups: comp.compilers
From: tthorn@daimi.aau.dk (Tommy Thorn)
Keywords: assembler, SPARC, optimize, summary
Organization: DAIMI: Computer Science Department, Aarhus University, Denmark
Date: Sun, 3 Nov 91 22:59:36 GMT

Thanx to all that replied.


Perhaps I should have stated my assumption, that the assembler was run
with the -O flag, as I got five replies stating that the assembler didn't
perform any kind of optimizations at all.


Well, at least at our sparc-stations running SunOS 4.1.1, it's fairly easy
to verify that the assembler does indeed perform some kind of
optimizations. See my example at the end.


As thc@cs.brown.edu (Thomas Colthurst) writes:


The description I have of the SUN compiling system states that the
postpass optimizer is integrated into the assembler, and presumably
activated by the -O[n] option. Specifically, the postpass assembler


"does a series of quite standard machine-dependent optimizations,
eliminating jumps to jumps, deleting redundant loads, stores and
unreachable code, inverting loops and so on, as indicated in Section 21.4.
In additon, the postpass optimizer does instruction scheduling and leaf
routine optimization."


The instruction scheduling not only fills delay-slots, but also arranges
integer and floating-point instructions so they can execute in parallel.
My description (taken from the upcoming _Optimization in Compilers_ ACM
book in a chapter written by Steven S. Muchnick) claims that this can
reduce execution time by 8 to 20%.


Of course, the as man page warns that optimization can be used safely only
when assembling code produced by a Sun compiler.


David Lively <dfl@Think.COM> says:


    I asked the Sun compiler folks a while back (July '90) about using the
optimizer on their assembler, and they replied that the assembler
optimizer was only intended to be used on assembly code produced by their
compilers, not on user (or other compiler) code. We tried it anyway on
the serial portion of the code produced by one of our compilers, and found
that while it worked well in most cases, it didn't work for nearly all of
the cases since we were presumably violating some assumptions they make.
So it seems you have to do it yourself :-<


As promised, here comes an example:


extern char b[];


blob(b)
          char b[];
{
        int i;
        for (i = 0; i < 10; i++)
            b[i]=0;
}


/* generated by the compiler, that is:cpp,ccom,iropt,cg
      (condensed a lot, but haven't touched instructions)
.seg "text"
.proc 020
.global _blob
_blob:
sethi %hi(LF13),%g1
add %g1,%lo(LF13),%g1
save %sp,%g1,%sp
L77007:
L77001:
b L77008
nop
b L77006
nop
L77008:
mov 0,%i5
add %i5,%i0,%o0
mov %o0,%i5
mov 0xa,%o1
add %o1,%i0,%o2
mov %o2,%i0
L77003:
stb %g0,[%i5]
add %i5,0x1,%i5
cmp %i5,%i0
blu L77003
nop
L77006:
b LE13
nop
LE13:
ret
restore
              LF13 = -64
*/


/* sending this though as -O2 -S generates
.seg "text" ! [internal]
.proc 16
.global _blob
_blob:
mov 0,%o5
add %o5,%o0,%o5
mov 10,%o1
add %o1,%o0,%o0
stb %g0,[%o5]
LY1: ! [internal]
inc %o5
cmp %o5,%o0
blu,a LY1
stb %g0,[%o5]
retl
nop ! [internal]
.seg "data" ! [internal]
*/
--
Tommy Thorn email: tthorn@daimi.aau.dk
Computer Science Department
Aarhus University
DENMARK
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.