Re: Constant divisions, remainders

jfc@athena.mit.edu (John F Carr)
Mon, 16 Nov 1992 02:02:53 GMT

          From comp.compilers

Related articles
[6 earlier articles]
Re: Constant divisions, remainders henry@zoo.toronto.edu (1992-11-08)
Re: Constant divisions, remainders jones@pyrite.cs.uiowa.edu (1992-11-11)
Re: Constant divisions, remainders nickh@CS.CMU.EDU (1992-11-11)
Re: Constant divisions, remainders preston@miranda.cs.rice.edu (1992-11-11)
Re: Constant divisions, remainders jlg@cochiti.lanl.gov (1992-11-12)
Re: Constant divisions, remainders corbett@lupa.Eng.Sun.COM (1992-11-12)
Re: Constant divisions, remainders jfc@athena.mit.edu (1992-11-16)
| List of all articles for this month |
Newsgroups: comp.compilers
From: jfc@athena.mit.edu (John F Carr)
Organization: Massachusetts Institute of Technology
Date: Mon, 16 Nov 1992 02:02:53 GMT
References: 92-10-075 92-11-025
Keywords: arithmetic

joe@babel.ho.att.com (Joseph M Orost) writes:


>The problem with this thinking is that you will get inconsistent results
>if you divide by a constant power-of-2 versus dividing by a variable with
>the same value. And you will get LOTS of bug reports from the compiler
>users!


Only if there is a hardware divide instruction. I modified gcc on the IBM
RT to use shift for division by a power of 2. At the same time, I changed
the divide function to round down when dividing a negative number by a
positive number. The divide function uses a series of divide-step
instructions; it takes about the same amount of code to implement either
rounding mode.


The IBM RS/6000 has an equally good solution to the problem: the divide
instructions rounds to zero, but the shift instruction sets the carry bit
if the result is negative so a shift follwed by an add-with-carry
instruction is equivalent to a round-to-zero divide.
--
        John Carr (jfc@athena.mit.edu)
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.