Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!linus!decvax!yale-com!leichter
From: leichter@yale-com.UUCP (Jerry Leichter)
Newsgroups: net.lang.c,net.arch
Subject: Re: One"s complement machines and C logic
Message-ID: <2825@yale-com.UUCP>
Date: Tue, 31-Jan-84 18:30:49 EST
Article-I.D.: yale-com.2825
Posted: Tue Jan 31 18:30:49 1984
Date-Received: Thu, 2-Feb-84 01:41:55 EST
References: mit-eddi.1233
Lines: 35

The PDP-1 is, of course, not the only machine that did one's-complement
"right".  The CDC 6000 series of machines were one's-complement.  Their
arithmetic operations were so defined that the result of an operation,
neither of whose operands was -0, was guaranteed never to be -0.  It
turns out, when you sit down and do it, that this is no harder, and requires
no more gates, than having it come out the other way; you just have to
design your logic with a little care.

Even on a properly designed one's-complement machine, you have to be a bit
careful.  Booleans - typically, -0 is true and 0 is false - are different
from integers.  It is not useful to test the sign of a Boolean.  In fact,
on a 6000, if a -0 is in an X register, you can't use the "test for 0"
instruction, since it knows that -0 is zero.  (In a B register, you compare
to B0, which is always +0, and different.)  So actually you end up with
three classes:  Booleans, used as truth values; masks, which come out of
logical operations but may get applied to numbers; and numbers.  It's
quite important to test things in the way appropriate to their class!

A nice feature of one's-complement is that negate and complement are
identical.  This leads to the standard 6000-series code for absolute
value:  Give a value in an X register, copy it to another X register,
arithmetically right shift 59 places, and XOR back to the original
register.  This requires no branches - slow on a 6000 (and on modern
pipelined machines, for about the same reasons) - and can be interleaved
with other operations to take advantage of the 6600's multiple functional
units.  (You can do the same thing in 2's-complement, but it takes an
additional instruction:  After the XOR of the mask you built, you sub-
tract the mask from the original register.)

BTW, for properly designed one's-complement adders, the identity for
addition is often -0, rather than 0.  When added to values other than
-0, the two work equally well; but typically -0+0=0 and -0+(-0)=-0.
This is the case for the 6000, anyway...
							-- Jerry
					decvax!yale-comix!leichter leichter@yale