Path: utzoo!attcan!uunet!pdn!alan From: alan@pdn.UUCP (Alan Lovejoy) Newsgroups: comp.arch Subject: Re: negative addresses (really unsigned arithmetic) Message-ID: <3221@pdn.UUCP> Date: 23 May 88 14:21:08 GMT References: <2393@uvacs.CS.VIRGINIA.EDU> <9485@apple.Apple.Com> <1988May22.020336.17472@utzoo.uucp> Reply-To: alan@pdn.UUCP (0000-Alan Lovejoy) Organization: Paradyne Corporation, Largo, Florida Lines: 36 In article <1988May22.020336.17472@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: /> ... what are the "nasty surprises" /> hiding in unsigned arithmetic that do not also exist for signed /> arithmetic AS IT IS COMMONLY IMPLEMENTED IN HARDWARE? >Well, for example, consider that a+b>c does not imply a>c-b in unsigned >arithmetic. (To make this more obvious, consider that b>c does not imply >c-b<0, since no unsigned number is less than zero.) Remember too that one >unsigned number in a calculation tends to make the whole calculation be >done unsigned, by C rules, sometimes unexpectedly. But "a + b > c" does not imply that "a > c - b" using signed arithmetic either, because undeflow is still possible! For example: "2 + 1 > -32768" does not imply that "2 > -32768 - 1", because for 16 bit integers, "-32768 - 1" is 32767. /> Why should signed arithmetic be more efficient than unsigned? >Because the hardware sometimes supports it rather better. On the machine >I'm typing this on, for example, unsigned multiplication or division is >significantly slower than the signed forms, because the hardware multiply >and divide instructions are signed-only. This argument might be valid if we were discussing what sort of arithmetic to use on your machine. But the subject is what sort of arithmetic to design into new machines. This is comp.arch, not comp.sys.yourmachine. Unsigned arithmetic is just an efficient range checking mechanism. Ranges with a lower bound of zero are quite common, and it makes sense to support them in the hardware. -- Alan Lovejoy; alan@pdn; 813-530-8241; Paradyne Corporation: Largo, Florida. Disclaimer: Do not confuse my views with the official views of Paradyne Corporation (regardless of how confusing those views may be). Motto: Never put off to run-time what you can do at compile-time!