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: Alex Rhomberg Subject: Re: fast array calculation in C Date: 1999/10/13 Message-ID: <38044C2C.C06F699B@ife.ee.ethz.ch>#1/1 X-Deja-AN: 536166527 Content-Transfer-Encoding: 7bit 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> Content-Type: text/plain; charset=us-ascii X-Trace: 13 Oct 1999 11:08:59 +0100, beethoven.ee.ethz.ch Organization: Electronics Lab, ETH Zurich, Switzerland MIME-Version: 1.0 Newsgroups: comp.os.linux.alpha Eberhard Burr wrote: > > Alex Rhomberg writes: > > Would you care posting an example? I am not a computer scientist but > I'm always interested in speedy calculations ;-) I guess from looking > at an example of what you did, I can learn much more than from > following the discussion about aliasing (honestly, I don't even know > what that is). Sure here is the code I posted to the alpha-c mailing list (for compaq ccc): #define FAST or not and look at the speed differences. I used the perl script at the bottom to find bad lines in the assembler code - Alex ===========snip example code follows void subroutine(double *fmat_lin, const double __restrict x, const double __restrict dhdX0_loc) { #ifdef FAST double fmat_li[9]; #else double *fmat_li = fmat_lin; #endif fmat_li[0+3*0] = x[0]*dhdX0_loc[0]; fmat_li[0+3*1] = x[0]*dhdX0_loc[1]; fmat_li[0+3*2] = x[0]*dhdX0_loc[2]; fmat_li[1+3*0] = x[1]*dhdX0_loc[0]; fmat_li[1+3*1] = x[1]*dhdX0_loc[1]; fmat_li[1+3*2] = x[1]*dhdX0_loc[2]; fmat_li[2+3*0] = x[2]*dhdX0_loc[0]; fmat_li[2+3*1] = x[2]*dhdX0_loc[1]; fmat_li[2+3*2] = x[2]*dhdX0_loc[2]; for (k = 1;k < 8;k++) { fmat_li[0+3*0] += x[3*k+0]*dhdX0_loc[3*k+0]; fmat_li[0+3*1] += x[3*k+0]*dhdX0_loc[3*k+1]; fmat_li[0+3*2] += x[3*k+0]*dhdX0_loc[3*k+2]; fmat_li[1+3*0] += x[3*k+1]*dhdX0_loc[3*k+0]; fmat_li[1+3*1] += x[3*k+1]*dhdX0_loc[3*k+1]; fmat_li[1+3*2] += x[3*k+1]*dhdX0_loc[3*k+2]; fmat_li[2+3*0] += x[3*k+2]*dhdX0_loc[3*k+0]; fmat_li[2+3*1] += x[3*k+2]*dhdX0_loc[3*k+1]; fmat_li[2+3*2] += x[3*k+2]*dhdX0_loc[3*k+2]; } #ifdef FAST memcpy(fmat_lin, fmat_li, sizeof(double)*9); #endif } ============== perl code follows #!/usr/bin/perl -wp # usage if this script is named find_stalls #objdump -d myobject.o | find_stalls | more #then search for UGLY! use strict; use vars qw/$t/; $t && /\Q$t,/ && s/$/\t\t#UGLY!!/; #append UGLY if target is seen $t = (/(?:mult|subt|addt|ldt).*(\$f\d+)/)[0]; #new target is last floating register arg