Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!rochester!cornell!uw-beaver!tektronix!tekcrl!tekfdi!videovax!stever From: stever@videovax.Tek.COM (Steven E. Rice, P.E.) Newsgroups: comp.sys.amiga Subject: Re: Manx C Message-ID: <4529@videovax.Tek.COM> Date: Mon, 10-Aug-87 15:30:05 EDT Article-I.D.: videovax.4529 Posted: Mon Aug 10 15:30:05 1987 Date-Received: Wed, 12-Aug-87 01:43:39 EDT References: <4540@jade.BERKELEY.EDU> <1836@vax135.UUCP> Reply-To: stever@videovax.Tek.COM (Steven E. Rice, P.E.) Organization: Tektronix Television Systems, Beaverton, Oregon Lines: 53 Keywords: read the manual carefully Summary: Oooops! In article <4524@videovax.Tek.COM>, I wrote: [ a bunch deleted ] > There is no reason (other than incomplete optimization) that (ptr == 0) > should be any larger than (!ptr) -- at least on the 68000 family! If we > ignore the limited arithmetic allowable on pointers, the general strategy > for an equality test would be (using long words, because of the pointer > arithmetic): > > movea.l ,Ax > cmpa.l #,Ax > bne not_equal > > [ code to be executed if the two are equal ] > > bra around > > not_equal [ code to be executed if the two are not equal ] > > around [ next statement ] So far, so good. However, I then stick my foot into my mouth: > But, when the optimizer (or for that matter, the compiler) sees it is > generating a "movea.l ,Ax" / "cmp.l #0,Ax" sequence, it can > immediately delete the "cmp" instruction, because the 68000 sets the > condition codes when the register is loaded. Thomas M. Breuel () wrote to point out that it is true the condition codes are set -- but only when loading the data registers! Thus, while the full sequence would work, the shortened one would not. A reasonable alternative is to load the pointer value into a data register (where the condition codes *are* set), and then branch: move.l ,Dx bne not_equal etc. Then, code in the leg executed when the pointer is non-zero can transfer the pointer value to an address register, or use it directly as an index value. Thanks to Tom for pointing out my error. Steve Rice ----------------------------------------------------------------------------- new: stever@videovax.tv.Tek.com old: {decvax | hplabs | ihnp4 | uw-beaver | cae780}!tektronix!videovax!stever