Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!mintaka!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: a style question Message-ID: <18365@haddock.ima.isc.com> Date: 2 Oct 90 02:35:08 GMT References: <7341@darkstar.ucsc.edu> <1990Sep30.050655.13212@zoo.toronto.edu> <1990Sep30.172917.2951@Neon.Stanford.EDU> Reply-To: karl@kelp.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 16 In article davis@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@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint