Xref: utzoo comp.lang.c:32461 comp.arch:18366 Path: utzoo!attcan!uunet!cs.utexas.edu!sun-barr!newstop!male!mutchler From: mutchler@zule.EBay.Sun.COM (Dan Mutchler) Newsgroups: comp.lang.c,comp.arch Subject: Re: a style question Message-ID: Date: 2 Oct 90 17:34:24 GMT References: <7341@darkstar.ucsc.edu> <1990Sep30.050655.13212@zoo.toronto.edu> <1990Sep30.172917.2951@Neon.Stanford.EDU> <1990Oct2.151644.1581@phri.nyu.edu> Sender: news@male.EBay.Sun.COM Followup-To: comp.lang.c Lines: 39 In-reply-to: roy@phri.nyu.edu's message of 2 Oct 90 15:16:44 GMT In article <1990Oct2.151644.1581@phri.nyu.edu> roy@phri.nyu.edu (Roy Smith) writes: davis@pacific.mps.ohio-state.edu (John E. Davis) writes: > Which ['x != 100' or 'x < 100' RHS] generates faster code? It seems to > me that it is easier to tell if two values are unequal than to tell if > one is greater than the other. I'd rather save the machine a few > micro-seconds than myself since I only do the comparison once whereas the > machine must do it many times. Are there actually any machines in which a compare-and-branch for inequality is any faster or slower than a compare-and-branch for less-than? It seems to me that either should take one pass through the ALU to do the comparison and set some flags, so they should both take the same amount of time. I'm basing my assumption on experience with pdp-11 type machines, but I find it hard to imagine any other machine being significantly different. Maybe if you had an asynchronous ALU? The only scenario I could think of would be a RISC machine which has only two branches; branch-on-equal, and branch-on-less-than. The compiler could generate an appropriate stream of instructions to simulate any possible branch condition from just those two, and some streams might end up being longer than others, but that sounds pretty strange, and very un-orthogonal. My experiece has been that compares are essentially a subtract (some early machines didn't actually have a compare) that sets the appropriate condition flags. So X!=100 is subtract 100 from X and branch not zero and X < 100 is subtract 100 from X and branch negative. If I remember correctly the cmp and sub instructions use the same number of clock cycles on the 8086. -- Dan Mutchler | ARPA/Internet: mutchler@zule.EBay.Sun.COM Sun Federal System Engineer | UUCP: ...!sun!mutchler -------------------------------------------------------------------------- Flying back from Lubbock, I saw Jesus on the plane Or maybe it was Elvis, You know they kind of look the same. -- Don Henley