Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Floating point boxing again
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Quetzalcoatl Bradley <qbradley@b...>
Subject: Re: [Caml-list] Floating point boxing again
Very interesting!  On PowerPC, the code is also very different, and the 
one with the spurious addition is MUCH faster. (factor of about 4.5 
times faster)

version A keeps the reference up to date in memory for every iteration 
of the loop.  version B just accumulates the value in a register, 
updating the reference at the end of the loop.  Obviously, all the 
updating of the reference is a lot of memory accessing.

I'm not familiar with the compiler internals but I can imagine how the 
logic might look here.  Perhaps the code generator looks at the 
reference, and sees that in case A, the next use after the loop is 
boxed (to return it), while in version B, it is unboxed (to add to it), 
and concludes that in case A it will keep it boxed the whole time, 
unboxed in case B.

Can anyone describe why the compiler will decide to keep the value 
boxed/unboxed in the loop?

Thanks,

Quetzalcoatl Bradley
qbradley@blackfen.com

On Thursday, October 24, 2002, at 01:37  AM, malc wrote:

> let a n =
>   let x = ref 1.0 in
>   for i = 1 to n do
>     x := !x +. 1.0;
>   done;
>   !x
>
> let b n =
>   let x = ref 1.0 in
>   for i = 1 to n do
>     x := !x +. 1.0;
>   done;
>   !x +. 0.0
>
> The code produced for a and b respectively differ greatly, even the 
> inner
> loops. Can someone from Caml team clarify the issue?
>
> P.S. Native code obviously.
>
> -- 
> mailto:malc@pulsesoft.com
>
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: 
> http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: 
> http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners