From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111c93,80f21c0575c616e8 X-Google-Attributes: gid111c93,public From: Robert Harley Subject: Re: fast array calculation in C Date: 1999/10/13 Message-ID: #1/1 X-Deja-AN: 536197213 Content-Transfer-Encoding: 8bit References: <3801A6BC.21E8653E@ife.ee.ethz.ch> <7tt2o3$15m0@news1.newsguy.com> <3802454b.1730032204@news.onramp.net> <3802E47C.3CF0CDE9@ife.ee.ethz.ch> <877lksab9h.fsf@gmx.de> <38044C2C.C06F699B@ife.ee.ethz.ch> Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: usenet@inria.fr X-Trace: ites.inria.fr 939812824 15566 128.93.11.84 (13 Oct 1999 11:07:04 GMT) Organization: I.N.R.I.A Rocquencourt Mime-Version: 1.0 NNTP-Posting-Date: 13 Oct 1999 11:07:04 GMT Newsgroups: comp.os.linux.alpha Alex Rhomberg 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.