Does your compiler get this program right?
Herman Rubin
cik at l.cc.purdue.edu
Thu Nov 24 22:13:35 AEST 1988
In article <4082 at cs.utexas.edu>, meyering at cs.utexas.edu (Jim Meyering) writes:
> In article <2298 at cbnews.ATT.COM> lvc at cbnews.ATT.COM (Lawrence V. Cipriani) writes:
> >A friend of mine found a bug in his C compiler. He found
>
> It's not a bug.
[Much deleted]
> You might be interested to know that while the Sun3/os3.2
> (or an HP, don't remember which) C compiler produced code
> that gave the "correct" results for your code, when I replaced
> that statement by the two:
>
> *f += *g++; or *f = *f + *g++;
> f++; f++;
>
> I found that the size of the object code was actually reduced.
> Chalk one up for readability *and* efficiency.
On a machine for which the ++ notation is hardware and on which there
is memory-memory addition, this should be done by ONE operation, not
even two, such as
ADDF2 (rG)+,(rF)+
where rF is the register holding the address f, and rG g. For different
architectures, different numbers of instructions. Is there a compiler for
the VAX which could make the optimization above? I would expect any
competent human programmer to do it.
--
Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907
Phone: (317)494-6054
hrubin at l.cc.purdue.edu (Internet, bitnet, UUCP)
More information about the Comp.lang.c
mailing list