From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,95a7ce6b0163274c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-05-10 08:55:43 PST Path: newsfeed.google.com!newsfeed.stanford.edu!feed.textport.net!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: implementing software unsigned divide Date: 10 May 2001 11:54:22 -0400 Organization: NASA Goddard Space Flight Center Message-ID: References: <3AF80FA7.49816047@averstar.com> <3AF985BD.BC0E1C12@averstar.com> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 989510990 25086 128.183.220.71 (10 May 2001 16:09:50 GMT) X-Complaints-To: dscoggin@cne-odin.gsfc.nasa.gov NNTP-Posting-Date: 10 May 2001 16:09:50 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.6 Xref: newsfeed.google.com comp.lang.ada:7484 Date: 2001-05-10T16:09:50+00:00 List-Id: Tucker Taft writes: > Does your chip happen to have 32-bits/16-bits => 16-bit > quotient and 16-bit remainder? No. > For that case, clearly you just zero out the high order part rather > than sign-extending to handle an unsigned dividend. If it has 32/32 > => 32, of course you can handle 16-bit unsigned trivially. Yes, I got that part :). I also realized (after your message yesterday) that if neither operand has the high bit set, the signed divide will give the correct answer. > A more general solution, I believe, is to (logical) shift both the > dividend and divisor right 1 bit, do the divide, and then adjust the > quotient up or down by 1 to get the remainder to be >= 0 and less > than the divisor. (Obviously you need to first check for the special > case when the divisor is <= 1!) Ah, that sounds promising. Thanks! -- -- Stephe