Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site watdaisy.UUCP Path: utzoo!watmath!watdaisy!ndiamond From: ndiamond@watdaisy.UUCP (Norman Diamond) Newsgroups: net.unix-wizards,net.lang Subject: Re: smart compilers Message-ID: <6833@watdaisy.UUCP> Date: Sun, 30-Dec-84 17:27:15 EST Article-I.D.: watdaisy.6833 Posted: Sun Dec 30 17:27:15 1984 Date-Received: Mon, 31-Dec-84 02:02:16 EST References: <6599@brl-tgr.ARPA> <979@opus.UUCP> <1146@ut-ngp.UUCP> <18397@lanl.ARPA> <2061@umcp-cs.UUCP> <230@lsuc.UUCP> Organization: U of Waterloo, Ontario Lines: 34 Xref: watmath net.unix-wizards:11287 net.lang:1180 > Ho hum... The CORRECT [sic] optimization for: > > DO 100 I = 1 TO 10 > IF (Y .GT. 0) X(I) = SQRT(Y) > 100 CONTINUE > > Is, in Ratfor syntax: > > IF (Y > 0) { > TEMP = SQRT(Y) > DO I = 1,10 > X(I) = TEMP > } > ELSE > I = 11 > > (In some implementations the number 11 will be something else, most > likely 10, but leaving I unchanged is clearly wrong!) The else case can leave anything at all in I and still be correct. The value of I is undefined after completion of the DO loop, and when optimized it remains undefined after the IF statement (whether the then-branch or ELSE-branch is taken). The most optimal setting of I is to leave it alone, requiring 0 machine instructions. Otherwise, this suggestion was correct, as were several others. -- Norman Diamond UUCP: {decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdaisy!ndiamond CSNET: ndiamond%watdaisy@waterloo.csnet ARPA: ndiamond%watdaisy%waterloo.csnet@csnet-relay.arpa "Opinions are those of the keyboard, and do not reflect on me or higher-ups."