[m-dev.] Re: [mercury-users] accumulator introduction

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Jun 23 20:07:23 AEST 2000


On 23-Jun-2000, Peter Ross <petdr at cs.mu.OZ.AU> wrote:
> On Fri, Jun 23, 2000 at 04:42:28PM +1000, David Overton wrote:
> > On Fri, Jun 23, 2000 at 01:11:05PM +1000, Michael Day wrote:
> > > 
> > > Is there any way for Mercury to automatically convert this predicate to
> > > use an accumulator, or is it condemned to overflow the detstack forever?
> > > 
> > > sum(Input, Output) :-
> > >     ( if Input = 0 then
> > >         Output = Input
> > >     else
> > >         sum(Input-1, Output0),
> > >         Output = Output0 + Input
> > >     ).
> > > 
> > > Adding an accumulator manually to make it tail recursive gives performance
> > > quite close to a C loop:
> > > 
> > > for (i = 0; i <= Input; ++i) sum += i;
> > > 
> > > which is rather nice. But it would be nicer if it added the accumulator
> > > itself. Is this possible?
> > > 
> > 
> Unfortunately when I rewrote the module to support the new update state
> transformation.  I removed the support for if-then-elses, I will add
> that back in the next few days.
> 
> When it is back in all you need to do is add the option
> '--introduce-accumulators' to your command line.

Once that option works, it should be enabled by some `-O' level. e.g. `-O4'.
(See the opt_level predicate in compiler/options.m.)

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list