Path: utzoo!attcan!uunet!husc6!mailrus!purdue!i.cc.purdue.edu!k.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.lang.c Subject: Re: Does your compiler get this program right? Summary: If the hardware instructions are there, it is ONE instruction Keywords: float, increment Message-ID: <1025@l.cc.purdue.edu> Date: 24 Nov 88 12:13:35 GMT References: <2298@cbnews.ATT.COM> <4082@cs.utexas.edu> Organization: Purdue University Statistics Department Lines: 35 In article <4082@cs.utexas.edu>, meyering@cs.utexas.edu (Jim Meyering) writes: > In article <2298@cbnews.ATT.COM> lvc@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@l.cc.purdue.edu (Internet, bitnet, UUCP)