Re: RISC again
> Date: Mon, 25 Mar 1996 10:24:12 -0500 (EST)
> From: Penio Penev <penev@pisa.rockefeller.edu>
>
> On Mon, 25 Mar 1996, Andrew Haley wrote:
>
> > Compiler writing for RISC architectures is to a large extent a problem
> > which has already been solved. I use such a compiler every day: the
> > code it generates isn't perfectly optimum, but it is correct. (In
> > fact that's not quite true; I have experienced one optimizer bug which
> > generated incorrect code in the course of three years' programming.)
>
> Actually, to the things that matter most -- loop unrolling for floating
> point routines -- they are very bad (well, the SGI MIPS compiler for IRIX
> 5.3) The compiler, given the following C code, produces either far from
> optimal machine code, or _incorrect_ code, depending on the switches you
> feed it:
>
> /*
> * Calculate the dot product of two samples
> */
>
> double ddot(double *v1, double *v2, int n){
> int i;
> double acc;
>
> for(acc=0,i=0; i<n; i++) acc+=v1[i]*v2[i];
> return(acc);
> }
>
> This is not a staement about RISC per se, it only says, that the problem
> of RISC C compiler writing is far from being solved.
When I said that "compiler writing for RISC architectures is to a
large extent a problem which has already been solved" I didn't mean
that every RISC compiler is execllent! Of course not.
The fact remains, however, that the problem of generating fairly good
code for RISC has been solved. However, good code generation
technology hasn't yet migrated to every such compiler. My MIPS
compiler generates the following unrolled code for the innner loop of
your example:
$L5:
l.d $f4,0($4)
l.d $f2,0($5)
#nop
mul.d $f2,$f4,$f2
add.d $f0,$f0,$f2
l.d $f4,8($4)
l.d $f2,8($5)
#nop
mul.d $f2,$f4,$f2
add.d $f0,$f0,$f2
l.d $f4,16($4)
l.d $f2,16($5)
#nop
mul.d $f2,$f4,$f2
add.d $f0,$f0,$f2
l.d $f4,24($4)
l.d $f2,24($5)
#nop
mul.d $f2,$f4,$f2
addu $7,$7,4
add.d $f0,$f0,$f2
slt $2,$7,$6
addu $4,$4,32
.set noreorder
.set nomacro
bne $2,$0,$L5
addu $5,$5,32
.set macro
.set reorder
which looks pretty good to me. What's wrong with it?
Andrew.