[m-dev.] introduce box/unbox float operators in HLDS

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Mar 15 22:31:02 AEDT 2001


On 15-Mar-2001, Peter Ross <peter.ross at miscrit.be> wrote:
> On Thu, Mar 15, 2001 at 03:08:48AM -0800, Ralph Becket wrote:
> > > From: Peter Ross [mailto:peter.ross at miscrit.be]
> > > Sent: 15 March 2001 10:55
> > > >
> > > > > If that's the case, wouldn't it be simpler to just add SR versions
> > > > > of the float operations?
> > > >
> > > > That sounds to me like a much easier way of solving the problem
> > > > that Pete is trying to solve.
> > > >
> > > It doesn't help for the following code
> > > 
> > > swap(p(X, Y), p(Y, X)).
> > > 
> > > There is no floating point operation, yet we will still unbox and then
> > > box the X and Y cells on the MLDS backend, while the LLDS backend
> > > doesn't do the box and unbox and hence introduces aliases between the
> > > two headvars.
> > 
> > I don't understand why the MLDS would unbox either argument.  Either
> > (1) this code is polymorphic, in which case you don't need to unbox or
> > (2) in this case we know that X and Y are floats, and whether they're
> > boxed or not still doesn't make any difference that I can see.
>
> The case is 2) and you are correct, there is no need to unbox and then
> rebox the arguments, but that is what the current code generator does.
> Why, I am sure fjh will let us know.

In the MLDS back-end, fields are always boxed, but local variables
are only boxed if they have a polymorphic type.  The code for the
above source fragment will first extract the fields of p/1 and copy
them into local variables (hence they need to be unboxed)
and then construct a new p/2 struct on the heap and copy the local
variables into fields of this (hence they need to be boxed).

In this case, it would be more efficient to keep the local variable boxed.
But the MLDS back-end doesn't try to do that.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- 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