a style question

Don_A_Corbitt at cup.portal.com Don_A_Corbitt at cup.portal.com
Wed Oct 3 09:45:55 AEST 1990


roy at phri.nyu.edu 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?

[goes on to theorize about RISC machine with limited branch types]

Actually, the i860 is faster when comparing for equality than greater-than.
For example:
	xor	r16, r17, r0
	bc	somewhere
takes two clocks, plus one annulled after the branch if taken.
The sequence
	subu	r16, r17, r0
	bc	somewhere
takes three clocks, since there is a freeze before the conditional 
branch while the condition code is updated.  On this chip, adds/addu and
subs/subu followed by a conditional branch costs an extra cycle.

I haven't seen this in print, but I assume it is because there is extra 
delay waiting for carry propagation to set the condition code.  XOR can
test all the bits in parallel.
---
Don_A_Corbitt at cup.portal.com      Not a spokesperson for CrystalGraphics, Inc.
Mail flames, post apologies.       Support short .signatures, three lines max.
(Soon leaving this account - flame me now, while you have the chance!)



More information about the Comp.lang.c mailing list