Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!samsung!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!news.funet.fi!funic!santra!hila.hut.fi!jmunkki From: jmunkki@hila.hut.fi (Juri Munkki) Newsgroups: comp.sys.mac.programmer Subject: Re: Pascal deficiency? Message-ID: <1990Dec19.191939.21773@santra.uucp> Date: 19 Dec 90 19:19:39 GMT References: <13650001@hpspdra.HP.COM> <1990Dec18.042748.6765@d.cs.okstate.edu> Sender: news@santra.uucp (Cnews - USENET news system) Reply-To: jmunkki@hila.hut.fi (Juri Munkki) Organization: Helsinki University of Technology, FINLAND Lines: 70 n67786@lehtori.tut.fi (Nieminen Tero) writes: > OK. What I don't understand is what the heck is going on around what I > marked "ick." Surely such a minute optimisation as not reading back what > you just wrote is not too difficult to code. (Of course, I don't write > compilers, either. :-) However, I think the ideal would be to replace > ALPHA's > > +0004 MOVEQ #$01,D0 | tmp = 1; > +0006 MOVE.W D0,-$0002(A6) | x = tmp; <== ick > +000A MOVE.W -$0002(A6),D0 | tmp = x; <== > +000E ADDQ.W #$1,D0 | tmp = tmp + 1; > +0010 MOVE.W D0,-$0002(A6) | x = tmp; One thing to remember about the Think C compiler is that it doesn't automatically allocate register variables. The Think Pascal examples that we have seen here allocated a register variable and used that. That's why they saved the register in the stack first and then initialized it. If you really want to write something as stupid as the subroutine that has been discussed here, write it like this in Think C: void dotest() { register int i=1; i++; } This produces: move.l D7,-(sp) moveq.l #1,D7 addq.w #1,D7 move.l (sp)+,D7 rts Looks good to me. Of course Think C is not an optimizing compiler in the strict sense of the word. IMHO, C is just a fancy assembler that produces portable code... Also, Think C 4.02 produces the following code, if I omit the register allocation: link A6,-2 moveq.l #1,D0 move.w D0,-2(A6) addq.l #1,-2(A6) unlk A6 rts Changing the initializer to something like 1024 will change the code so that we have: link A6,-2 move.w #1024,-2(A6) addq.l #1,-2(A6) unlk A6 rts To be honest, I don't find this thread useful. The best way to learn about these things is to read a basic text on compilers or take a course on compiler design. The reason why C doesn't produce all that good code with i=i+1 is because it has i++ available, so programmers use that and there is no need to waste time trying to optimize i=i+1, since it doesn't usually occur in normal code. Pascal compilers run into i:=i+1 all the time, so they have to watch for it. ____________________________________________________________________________ / Juri Munkki / Helsinki University of Technology / Wind / Project / / jmunkki@hut.fi / Computing Center Macintosh Support / Surf / STORM / ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~