Compiler optimization of division and remainder

hbaker@netcom.com (Henry G. Baker)
27 Jan 1996 01:12:48 -0500

          From comp.compilers

Related articles
Compiler optimization of division and remainder hbaker@netcom.com (1996-01-27)
Re: Compiler optimization of division and remainder d.sand@ix.netcom.com (1996-01-27)
Re: Compiler optimization of division and remainder augustss@cs.chalmers.se (1996-01-27)
Re: Compiler optimization of division and remainder richard@atheist.tamu.edu (1996-01-28)
Re: Compiler optimization of division and remainder prener@watson.ibm.com (1996-01-29)
Re: Compiler optimization of division and remainder hbaker@netcom.com (1996-01-29)
Re: Compiler optimization of division and remainder Peter-Lawrence.Montgomery@cwi.nl (1996-01-29)
[5 later articles]
| List of all articles for this month |

From: hbaker@netcom.com (Henry G. Baker)
Newsgroups: comp.compilers
Date: 27 Jan 1996 01:12:48 -0500
Organization: nil
Keywords: arithmetic, optimize, question

On another newsgroup, a poster claimed that some compilers could
optimize a program which used both a/b and a%b (both quotient and
remainder with the _same_ arguments) in such a way that the compiler
would perform only a single hardware division operation and arrange to
use both the quotient and remainder from this single operation.


I've looked at a lot of highly optimized code from a lot of compilers,
and I can't recall ever seeing such an optimization.


I can imagine how such an optimization would be done, but I can't
imagine many other places -- except for possibly keeping track of a
shifted out carry bit in a shift operation, or gathering both the high
order and low order bits of a double-precision integer multiplication
-- where such an optimization would be used. Due to the relatively
low frequency (statically) of occurrence of such a situation, I can
imagine that such an optimization never 'makes the cut'. (I would
also imagine that the general case would easily be NP-complete, as are
most code generation optimizations.)


I have seen references to some pretty garish shifting hacks in the GNU
C compiler, but I'm not sure how many other compilers dabble in this
sort of thing.


I would be interested in a) references to real, existing compilers
which are capable of doing such a thing; and b)
papers/tech-reports/theses, etc. which say how to do this.


Thx in advance.
--


Post a followup to this message

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