Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site turtlevax.UUCP Path: utzoo!linus!decvax!decwrl!turtlevax!ken From: ken@turtlevax.UUCP (Ken Turkowski) Newsgroups: net.arch Subject: Re: Right shift vs. divide Message-ID: <1016@turtlevax.UUCP> Date: Mon, 6-Jan-86 03:39:43 EST Article-I.D.: turtleva.1016 Posted: Mon Jan 6 03:39:43 1986 Date-Received: Tue, 7-Jan-86 06:50:42 EST References: <124000005@ima.UUCP> <4772@alice.UUCP> Reply-To: ken@turtlevax.UUCP (Ken Turkowski) Organization: CIMLINC, Inc. @ Menlo Park, CA Lines: 28 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. Several more reasons are: (3) arithmetic right shift is an approximation to division by a power of two that is only one LSB off. Sometimes you may want to divide a signed number by a power of two, but can tolerate a small error, but not excessive computation time; thus the popularity of the arithmetic right shift. (4) Arithmetic right shift is necessary to implement multiplication without a multiplier array. (5) Arithmetic left shift is necessary to implement division and square root. -- Ken Turkowski @ CIMLINC, Menlo Park, CA UUCP: {amd,decwrl,hplabs,seismo,spar}!turtlevax!ken ARPA: turtlevax!ken@DECWRL.DEC.COM