home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.compilers
- Path: sparky!uunet!think.com!spdcc!iecc!compilers-sender
- From: jfc@athena.mit.edu (John F Carr)
- Subject: Re: Constant divisions, remainders
- Reply-To: jfc@athena.mit.edu (John F Carr)
- Organization: Massachusetts Institute of Technology
- Date: Mon, 16 Nov 1992 02:02:53 GMT
- Approved: compilers@iecc.cambridge.ma.us
- Message-ID: <92-11-081@comp.compilers>
- References: <92-10-075@comp.compilers> <92-11-025@comp.compilers>
- Keywords: arithmetic
- Sender: compilers-sender@iecc.cambridge.ma.us
- Lines: 23
-
- 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)
- --
- Send compilers articles to compilers@iecc.cambridge.ma.us or
- {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.
-