a style question

Dan Mutchler mutchler at zule.EBay.Sun.COM
Wed Oct 3 03:34:24 AEST 1990


In article <1990Oct2.151644.1581 at phri.nyu.edu> roy at phri.nyu.edu (Roy Smith) writes:

   davis at 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 at 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



More information about the Comp.lang.c mailing list