From: Robert Harley <harley@corton.inria.fr>
Subject: Re: fast array calculation in C
Date: 1999/10/13 [thread overview]
Message-ID: <rz7yad77c4r.fsf@corton.inria.fr> (raw)
In-Reply-To: 38044C2C.C06F699B@ife.ee.ethz.ch
Alex Rhomberg <rhomberg@ife.ee.ethz.ch> writes:
> Sure
>
> here is the code I posted to the alpha-c mailing list (for compaq ccc):
How does one join that list?
Here's how I would write your code snippet if it was speed-critical.
I would compile with gcc 2.95 and Compaq's cc, with and without
-DUNROLL and compare the run-times.
------------------------------------------------------------------------------
/* Try with and without -DUNROLL - Rob. */
static void subroutine
( double * __restrict fmat
, const double * __restrict x, const double * __restrict d
) {
int k;
double d0,d1,d2, f00,f01,f02,f10,f11,f12,f20,f21,f22, x0,x1,x2;
x0 = x[0]; x1 = x[1]; x2 = x[2];
d0 = d[0]; d1 = d[1]; d2 = d[2];
f00 = x0*d0; f01 = x0*d1; f02 = x0*d2;
f10 = x1*d0; f11 = x1*d1; f12 = x1*d2;
f20 = x2*d0; f21 = x2*d1; f22 = x2*d2;
#ifndef UNROLL
for (k = 1; k < 8; ++k) {
x0 = x[3*k+0]; x1 = x[3*k+1]; x2 = x[3*k+2];
d0 = d[3*k+0]; d1 = d[3*k+1]; d2 = d[3*k+2];
f00 += x0*d0; f01 += x0*d1; f02 += x0*d2;
f10 += x1*d0; f11 += x1*d1; f12 += x1*d2;
f20 += x2*d0; f21 += x2*d1; f22 += x2*d2;
}
#else
#define STEP(k) \
x0 = x[3*k+0]; x1 = x[3*k+1]; x2 = x[3*k+2]; \
d0 = d[3*k+0]; d1 = d[3*k+1]; d2 = d[3*k+2]; \
f00 += x0*d0; f01 += x0*d1; f02 += x0*d2; \
f10 += x1*d0; f11 += x1*d1; f12 += x1*d2; \
f20 += x2*d0; f21 += x2*d1; f22 += x2*d2 /* ; */
STEP(1);
STEP(2);
STEP(3);
STEP(4);
STEP(5);
STEP(6);
STEP(7);
#undef STEP
#endif
fmat[0+3*0] = f00; fmat[0+3*1] = f01; fmat[0+3*2] = f02;
fmat[1+3*0] = f10; fmat[1+3*1] = f11; fmat[1+3*2] = f12;
fmat[2+3*0] = f20; fmat[2+3*1] = f21; fmat[2+3*2] = f22;
} /* end function subroutine */
------------------------------------------------------------------------------
Rob.
PS: Untested. If your computer blows up it's not my fault etc etc.
next prev parent reply other threads:[~1999-10-13 4:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-10-07 4:00 fast array calculation in C 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 [this message]
1999-10-12 4:00 ` Alex Rhomberg
[not found] <3809E64D.85BDCAFC@ife.ee.ethz.ch>
[not found] ` <7ud6gc$2o94@news2.newsguy.com>
1999-10-18 4:00 ` Alex Rhomberg
1999-10-18 4:00 ` Greg Lindahl
1999-10-18 4:00 ` Alex Rhomberg
1999-10-18 4:00 ` Emil Briggs
1999-10-18 4:00 ` Greg Lindahl
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