a style question

Karl Heuer karl at haddock.ima.isc.com
Tue Oct 2 12:35:08 AEST 1990


In article <DAVIS.90Oct1025438 at pacific.mps.ohio-state.edu> davis at pacific.mps.ohio-state.edu (John E. Davis) writes:
>Which 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.

On vaxlike machines, both forms of comparison will generate a compare
instruction (which sets condition codes) followed by a conditional branch,
the only difference being whether the "can't happen" case is included or
excluded from the conditions that cause a branch.  I wouldn't expect any
timing difference.

On a segmented machine where pointers are being compared, relational compares
are *faster*, since the compiler is allowed to assume that they are members of
the same array, and hence the same segment.  Equality compares have to check
the segment part as well.

Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint



More information about the Comp.lang.c mailing list