Re: Compiler optimization of division and remainder

michael.williams@armltd.co.uk (Michael Williams)
29 Jan 1996 17:43:53 -0500

          From comp.compilers

Related articles
[2 earlier articles]
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)
Re: Compiler optimization of division and remainder johnmce@world.std.com (1996-01-29)
Re: Compiler optimization of division and remainder michael.williams@armltd.co.uk (1996-01-29)
Re: Compiler optimization of division and remainder jgj@ssd.hcsc.com (1996-01-29)
Re: Compiler optimization of division and remainder dave@occl-cam.demon.co.uk (Dave Lloyd) (1996-01-29)
Re: Compiler optimization of division and remainder dave@occl-cam.demon.co.uk (Dave Lloyd) (1996-02-02)
| List of all articles for this month |

From: michael.williams@armltd.co.uk (Michael Williams)
Newsgroups: comp.compilers
Date: 29 Jan 1996 17:43:53 -0500
Organization: Advanced RISC Machines Ltd
References: 96-01-088
Keywords: arithmetic, optimize

Henry G. Baker <hbaker@netcom.com> wrote:
>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 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.


The Norcroft/ARM C compiler performs this optimisation, since division
is done by a run-time routine which also delivers the remainder. I
cannot say for sure, but I suspect that this is done using CSE.


For example:


int f(int y,int x)
{
return x/y + x%y;
}


is compiled to:


                 f
e92d4000 STMDB sp!,{lr}
ebfffffd BL __rt_sdiv
e0800001 ADD a1,a1,a2
e8bd8000 LDMIA sp!,{pc}


Mike.
              _____________________________________________________________________
\ x / Michael Williams Advanced RISC Machines Limited
|\/|\/\ michael.williams@armltd.co.uk Fulbourn Road, Cambridge, CB1 4JN, UK
--


Post a followup to this message

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