* Pervasives.{min,max} not specialized to floats by ocamlopt
@ 2006-08-17 18:34 Will M Farr
2006-08-18 15:34 ` [Caml-list] Pervasives.{min, max} " Olivier Andrieu
0 siblings, 1 reply; 4+ messages in thread
From: Will M Farr @ 2006-08-17 18:34 UTC (permalink / raw)
To: caml-list
Hello all,
I was profiling some numerical code compiled with ocamlopt today (for
the record: PPC G4, Mac OS X 10.4.7, ocamlopt 3.09.2), and I noticed
that a lot of time was taken up in the compare_val function, even
though type inference asserted that all values I was comparing were
floats. Turns out the culprits were Pervasives.min and
Pervasives.max---these functions do not specialize to the appropriate
assembly instructions if their arguments are known to be floats.
Including my own min and max functions in the module to shadow these
removed the calls to compare_val. I'm curious if this is well-known
behavior (a google search didn't turn up anything). It's, of course,
not a bug, but it's definitely surprising when all the other
polymorphic comparisons are special-cased for floats!
I don't know how hard it would be to change this in ocamlopt, but it
seems like it would be pretty simple. If it is simple, it would be a
good candidate to change in the next release for those of us who do a
lot of float-comparing.
Thanks!
Will
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Pervasives.{min, max} not specialized to floats by ocamlopt
2006-08-17 18:34 Pervasives.{min,max} not specialized to floats by ocamlopt Will M Farr
@ 2006-08-18 15:34 ` Olivier Andrieu
2006-08-18 15:37 ` Will M Farr
2006-08-18 15:43 ` Shawn
0 siblings, 2 replies; 4+ messages in thread
From: Olivier Andrieu @ 2006-08-18 15:34 UTC (permalink / raw)
To: Will M Farr; +Cc: caml-list
Will M Farr [Thursday 17 August 2006] :
>
> Hello all,
>
> I was profiling some numerical code compiled with ocamlopt today (for
> the record: PPC G4, Mac OS X 10.4.7, ocamlopt 3.09.2), and I noticed
> that a lot of time was taken up in the compare_val function, even
> though type inference asserted that all values I was comparing were
> floats. Turns out the culprits were Pervasives.min and
> Pervasives.max---these functions do not specialize to the appropriate
> assembly instructions if their arguments are known to be floats.
Indeed. That's because min and max are not primitives provided by the
runtime library but regular caml functions from pervasives.ml :
,----
| let min x y = if x <= y then x else y
| let max x y = if x >= y then x else y
`----
> I don't know how hard it would be to change this in ocamlopt, but
> it seems like it would be pretty simple.
I don't know, float comparisons tend not to be 'pretty simple' usually
(because of NaNs).
--
Olivier
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Pervasives.{min, max} not specialized to floats by ocamlopt
2006-08-18 15:34 ` [Caml-list] Pervasives.{min, max} " Olivier Andrieu
@ 2006-08-18 15:37 ` Will M Farr
2006-08-18 15:43 ` Shawn
1 sibling, 0 replies; 4+ messages in thread
From: Will M Farr @ 2006-08-18 15:37 UTC (permalink / raw)
To: Olivier Andrieu; +Cc: caml-list
On Aug 18, 2006, at 11:34 AM, Olivier Andrieu wrote:
> Indeed. That's because min and max are not primitives provided by the
> runtime library but regular caml functions from pervasives.ml :
> ,----
> | let min x y = if x <= y then x else y
> | let max x y = if x >= y then x else y
> `----
In this case, it seems strange that they weren't inlined---when I
defined my own min and max functions, *they* were inlined. Could it
be because I was working inside a functor, or am I mistaken in my
belief that ocaml does cross-module inlining?
Will
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Pervasives.{min, max} not specialized to floats by ocamlopt
2006-08-18 15:34 ` [Caml-list] Pervasives.{min, max} " Olivier Andrieu
2006-08-18 15:37 ` Will M Farr
@ 2006-08-18 15:43 ` Shawn
1 sibling, 0 replies; 4+ messages in thread
From: Shawn @ 2006-08-18 15:43 UTC (permalink / raw)
To: caml-list
Olivier Andrieu wrote:
> Will M Farr [Thursday 17 August 2006] :
>
>
> > I don't know how hard it would be to change this in ocamlopt, but
> > it seems like it would be pretty simple.
>
> I don't know, float comparisons tend not to be 'pretty simple' usually
> (because of NaNs).
>
So only do it with -ffast-math, which already special-cases Pervasives
functions like sin and cos...
It looks like only the x86 port supports that option right now, though.
Hmm. It really should be present on all architectures, even if it
doesn't actually do anything.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-08-18 15:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-17 18:34 Pervasives.{min,max} not specialized to floats by ocamlopt Will M Farr
2006-08-18 15:34 ` [Caml-list] Pervasives.{min, max} " Olivier Andrieu
2006-08-18 15:37 ` Will M Farr
2006-08-18 15:43 ` Shawn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox