Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!orion.oac.uci.edu!ucivax!ucla-cs!math.ucla.edu!euphemia!pmontgom From: pmontgom@euphemia.math.ucla.edu (Peter Montgomery) Newsgroups: comp.arch Subject: Re: inequality vs. less-than Message-ID: <469@kaos.MATH.UCLA.EDU> Date: 2 Oct 90 19:35:42 GMT References: <7341@darkstar.ucsc.edu> <1990Sep30.050655.13212@zoo.toronto.edu> <1990Sep30.172917.2951@Neon.Stanford.EDU> <1990Oct2.151644.1581@phri.nyu.edu> Sender: news@MATH.UCLA.EDU Organization: UCLA Mathematics Dept. Lines: 55 In article <1990Oct2.151644.1581@phri.nyu.edu> roy@phri.nyu.edu (Roy Smith) writes: > 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? On the now obsolete CDC Cyber systems (ones complement) the compare and branch were combined into one instruction. Let Xi denote a 60-bit register. The major branch instructions were ZR Xi,address Branch if Xi == 0 (+0 or -0) NZ Xi,address Branch if Xi != 0 (neither +0 nor -0) PL Xi,address Branch if Xi >= 0 (look at sign bit) MI Xi,address Branch if Xi < 0 (look at sign bit) (four others tested out of range floating point values) The FORTRAN compiler often emitted shorter code for EQ and NE than for GT, GE, LT, LE. For example, if I and J are integer variables in registers X1 and X2, the object codes for IF(I.EQ.J) go to 10 and IF(I.GT.J) go to 10 might be IF (I.EQ.J) GO TO 10 IF (I.GT.J) GO TO 10 IX7 X1-X2 I-J IX7 X2-X1 J-I ZR X7,lab10 MX0 0 X0 = 0 IX7 X7+X0 J-I+0 MI X7,lab10 Because of the obscure case where I might be +0 and J be -0 (in which case the second IF should NOT branch), the compiler had to compute J-I+0 rather than J-I before the branch test. Sometimes compiler was smart enough to optimize this away, such as if I or J was known to be nonzero. Strangely, however, it was better to use GE, GT, LE, LT in relationals connected by .AND. or .OR., because ALL parts of the logical expression got evaluated (no short circuiting) and the ZR, NZ branches were not used on big expressions. For example IF (I1.EQ.0 .AND. I2.EQ.1) ... tested the sign of AND(NXOR(0-I,0+I), NXOR(1-I, I-1)) (NXOR = complemented exclusive OR) whereas IF (I1.GE.0 .AND. I2.GE.1) could test that of AND(I1+0, I2-1). I published an article in SIGPLAN Notices (December, 1978) about better code generation for these conditionals, but I never saw my suggestions adopted. -- Peter L. Montgomery pmontgom@MATH.UCLA.EDU Department of Mathematics, UCLA, Los Angeles, CA 90024-1555 If I spent as much time on my dissertation as I do reading news, I'd graduate.