From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
To: Greg Lindahl <lindahl@pbm.com>
Subject: Re: fast array calculation in C
Date: 1999/10/18 [thread overview]
Message-ID: <380AE3CA.DE154537@ife.ee.ethz.ch> (raw)
In-Reply-To: 7ud6gc$2o94@news2.newsguy.com
[cc mailed and posted]
Greg Lindahl wrote:
>
> Alex Rhomberg <rhomberg@ife.ee.ethz.ch> writes:
>
> > > The memcpy() call at the end, on the other hand, is expensive.
> >
> > Did you check that?
> > It isn't (expensive). The compiler inlines it and then does some more
> > optimizations.
> > I get >400 MFLOPS (40% peak) with the memcpy
>
> Compilers are clever with memcopy, but I've yet to see one that could
> figure out at compile time "hey, the byte count is divisible by 8 and
> the buffers are aligned..." That's why a good compiler will usually do
> a better job of optimizing a copy loop.
>
> As for your "proof" that it isn't expensive, you didn't prove your
> point. Many computational kernels get more than 40% peak. You're
> certainly doing well, but you don't know yet if you're as good as you
> can get.
I didn't say "proof". But I can show you an example (which you can test
yourself):
Seems here is the memcpy you were looking for :-)
The memcopy gets compiled to:
d8: 00 00 b0 9d stt $f13,0(a0) #pretty optimized IMHO
dc: 08 00 10 9e stt $f16,8(a0)
e0: 10 00 30 9c stt $f1,16(a0)
e4: 18 00 d0 9d stt $f14,24(a0)
e8: 20 00 30 9e stt $f17,32(a0)
ec: 28 00 50 9d stt $f10,40(a0)
f0: 30 00 10 9c stt $f0,48(a0)
f4: 38 00 90 9d stt $f12,56(a0)
f8: 40 00 70 9d stt $f11,64(a0)
Compile the following with ccc -O4 -DFAST and check the assembler.
void subroutine(double *res, const double *x,
const double *y)
{
int k;
#ifdef FAST
double res_loc[9];
#else
double *res_loc = res;
#endif
res_loc[0+3*0] = x[0]*y[0];
res_loc[0+3*1] = x[0]*y[1];
res_loc[0+3*2] = x[0]*y[2];
res_loc[1+3*0] = x[1]*y[0];
res_loc[1+3*1] = x[1]*y[1];
res_loc[1+3*2] = x[1]*y[2];
res_loc[2+3*0] = x[2]*y[0];
res_loc[2+3*1] = x[2]*y[1];
res_loc[2+3*2] = x[2]*y[2];
for (k = 1;k < 8;k++) {
res_loc[0+3*0] += x[3*k+0]*y[3*k+0];
res_loc[0+3*1] += x[3*k+0]*y[3*k+1];
res_loc[0+3*2] += x[3*k+0]*y[3*k+2];
res_loc[1+3*0] += x[3*k+1]*y[3*k+0];
res_loc[1+3*1] += x[3*k+1]*y[3*k+1];
res_loc[1+3*2] += x[3*k+1]*y[3*k+2];
res_loc[2+3*0] += x[3*k+2]*y[3*k+0];
res_loc[2+3*1] += x[3*k+2]*y[3*k+1];
res_loc[2+3*2] += x[3*k+2]*y[3*k+2];
}
#ifdef FAST
memcpy(res, res_loc, sizeof(double)*9);
#endif
}
- Alex
next parent reply other threads:[~1999-10-18 4:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <3809E64D.85BDCAFC@ife.ee.ethz.ch>
[not found] ` <7ud6gc$2o94@news2.newsguy.com>
1999-10-18 4:00 ` Alex Rhomberg [this message]
1999-10-18 4:00 ` fast array calculation in C Greg Lindahl
1999-10-18 4:00 ` Alex Rhomberg
1999-10-18 4:00 ` Emil Briggs
1999-10-18 4:00 ` Greg Lindahl
1999-10-07 4:00 Alex Rhomberg
1999-10-09 4:00 ` Greg Lindahl
1999-10-11 4:00 ` Alex Rhomberg
1999-10-11 4:00 ` Greg Lindahl
1999-10-11 4:00 ` memore0
1999-10-11 4:00 ` Greg Lindahl
1999-10-12 4:00 ` Alex Rhomberg
1999-10-12 4:00 ` memore0
1999-10-12 4:00 ` Alex Rhomberg
1999-10-12 4:00 ` Eberhard Burr
1999-10-13 4:00 ` Alex Rhomberg
1999-10-13 4:00 ` Robert Harley
1999-10-12 4:00 ` Alex Rhomberg
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox