a style question

Roy Smith roy at phri.nyu.edu
Wed Oct 3 01:16:44 AEST 1990


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.
--
Roy Smith, Public Health Research Institute
455 First Avenue, New York, NY 10016
roy at alanine.phri.nyu.edu -OR- {att,cmcl2,rutgers,hombre}!phri!roy
"Arcane?  Did you say arcane?  It wouldn't be Unix if it wasn't arcane!"



More information about the Comp.lang.c mailing list