Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!zodiac!joyce!sri-unix!garth!smryan From: smryan@garth.UUCP (Steven Ryan) Newsgroups: comp.lang.misc Subject: Re: Many people's opinions on compu Message-ID: <1452@garth.UUCP> Date: 21 Sep 88 21:52:08 GMT References: <1433@garth.UUCP> <208100001@s.cs.uiuc.edu> Reply-To: smryan@garth.UUCP (Steven Ryan) Organization: INTERGRAPH (APD) -- Palo Alto, CA Lines: 46 >But if the compiler has any brains at all, p && q should be compiled to >the same thing as p?q:false. I don't see what the latter gains you >except to irritate the programmer. Using an example from my alma mater, suppose we have (m=n and o<0), where m, n, o are integer variables. Then if and<->if-then-else, on Cy170, + SX6 B1 * assume true. IX0 X.m-X.n * X0 := m-n ZR X0,TRUE * stall cpu; true if (m=n); maybe fill i-cache. + ZR X.o,FALSE * -0 gotcha; stall cpu; maybe fill i-cache. NG X.o,TRUE * stall cpu; true if (o<0); maybe fill i-cache. +FALSE SX6 0 NO NO +TRUE So that it takes 3 words and 3 jumps; each jump stalls the cpu until the jump condition is verified. If the target label is out of stack, the i-cache has to be filled. Now when the and is semantically distinct from if-then-else, + SX7 B0 * +0. IX0 X.m-X.n * X0 := m-n. IX.o X.o+X7 * insure o is not a -0. BX1 -X0 * X1 := n-m. + IX0 X0+X7 * insure m-n is not a -0. IX1 X1+X7 * insure n-m is not a -0 SX7 B1 BX0 -X0-X1 * set sign bit if sign(m-n)=sign(n-m), if m=n. + BX0 X0*X.o * set sign bit if m=n and o<0. LX0 1 BX6 X0*X7 * X6=X0 sign bit, 1 if true, 0 if false. So that it takes 1 parcel less than three words, no alignment constraints (only 15-bit instructions used), no jumps, no cpu stalls, no no-ops, i-cache can be prefetched, and the code does not create additional basic blocks so that all the usual basic block optimisations can be applied. All the world is not a Vax. On some machines, jumps are killers. By providing a separate conditional expression to handle, say, if x>0 then sqrt(x)>2 else false, it is reasonable to let and/or be the fastest possible operator the machine can provide. In other words, say what you mean and don't depend on tricks.