Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!rutgers!gatech!bloom-beacon!husc6!yale!leichter
From: leichter@yale.UUCP (Jerry Leichter)
Newsgroups: comp.arch
Subject: Re: no-branch 68000 signum, min, max
Message-ID: <32854@yale-celray.yale.UUCP>
Date: 4 Jul 88 19:37:18 GMT
References: <1941@pt.cs.cmu.edu> <3208@ubc-cs.UUCP> <1986@pt.cs.cmu.edu> <7570@boring.cwi.nl> <12212@mimsy.UUCP>
Reply-To: leichter@yale-celray.UUCP (Jerry Leichter)
Organization: Yale University Computer Science Dept, New Haven CT
Lines: 22

It really should be pointed out that these techniques are by no means
new.  I saw them used back around 1971 on a CDC 6600.  On a 6600, branches
were VERY expensive relative to almost anything else.  (The basic unit was
the minor cycle, 100ns.  A Boolean operation was 3 minor cycles; an FP add
was, I think, 8.  A branch was 12 or 14, depending on whether it was taken
or not, plus possible memory latency.)  So techniques like this were very
well developed.  I don't recall ever seeing signum written out this way,
though it's obvious enough, but everyone who knew about good coding practices
knew how to do ABS or MAX with no branches.  (Note that a 6600 is a ones-com-
plement machine, so the code is simpler.)  In fact, the FORTRAN compiler
used these techniques for generating code!

There was also the "take two 60-bit words thought of as 10 6-bit BCD numbers
and add them without a loop" hack which will teach you why there are 26
letters in the English alphabet.  (There have to be.  You reserve 00, then
lay out all the letters, then the digits.  That puts 0 at the only place it
can be to make this trick go through without pre- and post-processing.)
(No, I won't reconstruct the whole thing here.  The trick is to set things
up so that all carries beyond 9 end up setting or clearing a fixed bit in
the 6-bit representation.  A mask extracts those bits, controlling where
the carries have to be "added back in".)
							-- Jerry