Article View: comp.lang.misc
Article #1966Re: C's sins of commission
From: Greg Lindahl
Date: Thu, 08 Nov 1990 02:40
Date: Thu, 08 Nov 1990 02:40
38 lines
2182 bytes
2182 bytes
In article <2440:Nov607:32:5890@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes:
>> [ I write: ]
>> a[i] = b[i] / c[i];
>> d[i] = b[i] * c[i];
> [ Fortran sees separate arrays and loads b[i] and c[i] only once ]
> [ C sees possible aliasing and loads them twice ]
>
>Hmmm. I would almost automatically optimize the above into
>
> {
> register double bi = b[i];
> register double ci = c[i];
>
> a[i] = bi / ci;
> d[i] = bi * ci;
> }
Great, you've just doubled the # of lines of code. This is known as
"creating a maintenance nightmare".
Now take one of my real loops, with 3 lines of code referencing a
dozen or so array elements, including things like a[i], a[i-2], etc.
How do you pick the names? How do you keep the programmer from making
a mistake when they modify one of the lines?
I don't see why Dan thinks I should use a hard-to-optimize language
for numerical programming, which requires the programmer to do common
sub-expression elimination, when I can use a simple and fast language
instead. Having the compiler do a simple optimization seems much more
reliable than having the programmer optimize and maintain the code
segment, or have a compiler for an unnecessarily compliated language
compile the code segment.
By the way, this code has loops which can be unrolled 3 or 5 times and
keep loaded array values from previous iterations for future
iterations. Writing this out by hand is a nightmare when you have to
permute the temporary register variables. But it's not that difficult
to add such a feature to most Fortran compilers.
Technical Details
Message-ID:
<1990Nov8.024049.9731@murdoch.acc.Virginia.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!mcnc!uvaarpa!murdoch!astsun.astro.Virginia.EDU!gl8fReferences:
<3673@stl.stc.co.uk> <1990Nov2.052815.22188@murdoch.acc.Virginia.EDU> <2440:Nov607:32:5890@kramden.acf.nyu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!mcnc!uvaarpa!murdoch!astsun.astro.Virginia.EDU!gl8f From: gl8f@astsun.astro.Virginia.EDU (Greg Lindahl) Newsgroups: comp.lang.misc Subject: Re: C's sins of commission Message-ID: <1990Nov8.024049.9731@murdoch.acc.Virginia.EDU> Date: 8 Nov 90 02:40:49 GMT References: <3673@stl.stc.co.uk> <1990Nov2.052815.22188@murdoch.acc.Virginia.EDU> <2440:Nov607:32:5890@kramden.acf.nyu.edu> Sender: news@murdoch.acc.Virginia.EDU Organization: Department of Astronomy, University of Virginia Lines: 38