Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!agate!shelby!neon!pescadero.Stanford.EDU!philip From: philip@pescadero.Stanford.EDU (Philip Machanick) Newsgroups: comp.sys.mac.programmer Subject: Re: Increment (Was Re: Pascal deficiency)? Message-ID: <1990Dec18.004838.5623@Neon.Stanford.EDU> Date: 18 Dec 90 00:48:38 GMT References: <1990Dec17.160242.5095@phri.nyu.edu> <1990Dec17.172613.7941@cs.umn.edu> <1990Dec18.001753.3756@Neon.Stanford.EDU> Sender: news@Neon.Stanford.EDU (USENET News System) Reply-To: philip@pescadero.stanford.edu Organization: Computer Science Department, Stanford University Lines: 31 In article <1990Dec18.001753.3756@Neon.Stanford.EDU>, kaufman@Neon.Stanford.EDU (Marc T. Kaufman) writes: |> Well, since we ARE in a Mac group, lets just look at the code MPW C generates |> for just such constructs: |> |> i = i+1; |> MOVE.L i,D2 |> ADDQ.L #$1,D2 |> MOVE.L D2,i |> |> i++; |> MOVE.L i,D2 |> ADDQ.L #$1,i |> |> ++i; |> ADDQ.L #$1,i |> |> Behold. The 68K does, indeed, have an instruction to increment variables in |> memory. Interesting - but remember looking at "toy" examples doesn't tell you much. In "real" code, where performance really matters, I would hope the compiler would have loaded the variable into a register for as long as possbile. Still, it's bad that the compiler doesn't pick up i=i+small constant as a special case - it would be even worse if the Pascal compiler also did this since (the original point) you have no option of asking for i++. Many of the programmer-directed "optimizations" in C, like register variables, ought to be unnecessary with a modern optimizing compiler. -- Philip Machanick philip@pescadero.stanford.edu