* [Caml-list] Floating point boxing again
@ 2002-10-24 8:37 malc
2002-10-25 3:13 ` Quetzalcoatl Bradley
0 siblings, 1 reply; 2+ messages in thread
From: malc @ 2002-10-24 8:37 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Floating point boxing again
2002-10-24 8:37 [Caml-list] Floating point boxing again malc
@ 2002-10-25 3:13 ` Quetzalcoatl Bradley
0 siblings, 0 replies; 2+ messages in thread
From: Quetzalcoatl Bradley @ 2002-10-25 3:13 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-10-25 7:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-24 8:37 [Caml-list] Floating point boxing again malc
2002-10-25 3:13 ` Quetzalcoatl Bradley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox