Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ll-xn!adelie!mirror!xanth!kent From: kent@xanth.UUCP (Kent Paul Dolan) Newsgroups: comp.arch Subject: Re: Optimization vs. the programmer Message-ID: <825@xanth.UUCP> Date: Sun, 12-Apr-87 23:40:44 EST Article-I.D.: xanth.825 Posted: Sun Apr 12 23:40:44 1987 Date-Received: Sat, 18-Apr-87 17:45:23 EST References: <479@danews.ATT.COM> <3300003@uiucdcsm> <3135@jade.BERKELEY.EDU> Reply-To: kent@xanth.UUCP (Kent Paul Dolan) Organization: Old Dominion University, Norfolk Va. Lines: 25 In article <3135@jade.BERKELEY.EDU> desj@brahms.Berkeley.EDU (David desJardins) writes: ->In article <3300003@uiucdcsm> grunwald@uiucdcsm.cs.uiuc.edu writes: ->> ->>Strength reduction is replacement of operations such as "i = j * 8" by ->>"i = j << 3", or "i = j % 8" by "i = j & 0x3" (if j is unsigned). -> ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ -> I'm sure you mean "i = j & 0x7". But, more importantly, this is the ->right remainder to compute even if j is signed (assuming two's-complement, ->of course). It's too bad more people (especially hardware designers!) ->don't realize this. -> -> -- David desJardins I 'd like to second the motion. I've lost track of the number of languages and machines in which I have ended up debugging the mod function because the result for signed numbers was either negative values for mods of negative numbers, or a mod function which reflected about zero rather than continuing the same sawtooth pattern through the origin. Apparently this is a very easy function to do wrong, and it is done wrong more often than right. I'd like to encourage compiler and chip designers to review the mod function's output for negative inputs before releasing any product which supports mod. Thanks. Kent.