Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mmintl.UUCP Path: utzoo!linus!philabs!pwa-b!mmintl!franka From: franka@mmintl.UUCP (Frank Adams) Newsgroups: net.arch Subject: Re: Right shift vs. divide Message-ID: <996@mmintl.UUCP> Date: Mon, 6-Jan-86 09:20:33 EST Article-I.D.: mmintl.996 Posted: Mon Jan 6 09:20:33 1986 Date-Received: Sat, 11-Jan-86 05:59:58 EST References: <124000005@ima.UUCP> <4772@alice.UUCP> Reply-To: franka@mmintl.UUCP (Frank Adams) Organization: Multimate International, E. Hartford, CT Lines: 27 In article <4772@alice.UUCP> ark@alice.UucP (Andrew Koenig) writes: >> Now that we know that right shifting is not the same as division, has >> anybody ever come up with a plausible reason for computers to have >> arithmetic shift instructions on twos complement machines (other than that >> they're easy to implement and poorly educated engineers might have thought >> they were the same as division)? For positive numbers, they give the same >> result as unsigned shifts, and for negative numbers they give the wrong >> answer. Followups to net.arch, please. > >I can think of two reasons: (1) sometimes you want to divide with >truncation toward -infinity and an arithmetic right shift gives you >that; (2) on some machines, an arithmetic left shift lets you multiply >by a power of 2 with overflow checking. Also, (3) sometimes you know that the dividend is divisible by the power of two you are dividing it by. And (4), a conditional add followed by a shift is equivalent to a divide, and is often much faster. Finally, (5), if you regard the number as a fraction, with the decimal point at the left, what happens to the low order bit is of no great consequence. It does seem, however, that an arithmetic right shift which *is* equivalent to a division would be more useful, however. There are relatively few cases where one wish to round towards minus infinity, and those cases are not especially likely to be divisions by powers of two. Frank Adams ihpn4!philabs!pwa-b!mmintl!franka Multimate International 52 Oakland Ave North E. Hartford, CT 06108