caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* OCaml and C math routines
@ 2000-10-13 17:01 David McClain
  2000-10-14 12:19 ` Xavier Leroy
  0 siblings, 1 reply; 4+ messages in thread
From: David McClain @ 2000-10-13 17:01 UTC (permalink / raw)
  To: caml-list

OCaml'ers... I would be very interested to hear your response to this!

|> From: -Zhong Shao
(shao-zhong@cs.yale.edu)

||> From: "Stephen T. Weeks" <sweeks@intertrust.com>
||> ...................
||> Even more impressive for the OCAML compiler is the fact that the
||> PLClub entry was compiled using separate compilation (please
||> correct me if I'm wrong) but the MLton entry was compiled whole
||> program (by necessity) and the SML/NJ entry was compiled whole
||> program (because it improves the speed).
||> 

>From what I know, for the floating-point intensive benchmarks, Ocaml
is faster than SML/NJ mainly because Ocaml directly calls the native,
C-based math library (which in turn is fine-tuned for the actual
processor).  SML/NJ, on the other hand, implements all of the math
library functions (e.g., cos, sin, tan) in ML itself (as part of the
SML basis). There is easily an order-of-magnitude difference between
these two implementations. You could try to measure a few such math
functions to find out.

>Members of the SML basis committee and the Ocaml group probably can
tell us the pros and cons of calling the native math library vs. having
it written in ML itself.


- DM




^ permalink raw reply	[flat|nested] 4+ messages in thread
* Re: OCaml and C math routines
@ 2000-10-13 22:17 John R Harrison
  0 siblings, 0 replies; 4+ messages in thread
From: John R Harrison @ 2000-10-13 22:17 UTC (permalink / raw)
  To: caml-list; +Cc: John Harrison


David McClain writes:

| OCaml'ers... I would be very interested to hear your response to this!

I guess I should comment, since I work closely with the people designing
math functions for various Intel architectures, and have even written a
few myself.

| Members of the SML basis committee and the Ocaml group probably can 
| tell us the pros and cons of calling the native math library vs. having
| it written in ML itself.

There are (at least) three things to consider in writing a good math
library function:

 * accuracy

 * speed

 * proper handling of exceptional cases

Getting good speed and accuracy together (or sometimes just one of them at
at a time) is often non-trivial. And even given a good basic design for the
core function, it's a serious amount of work to make all the peculiar
corner cases work sensibly, e.g. detecting overflow and underflow
correctly, behaving sensibly when unusual exceptions like "inexact" are
enabled, or even providing accurate answers when the rounding mode is not
the default of round-to-nearest or when trigonometric functions are applied
to huge arguments.

Besides, there's room for disagreement over what *should* be done in many
of the obscure cases. There's no IEEE standard for the transcendentals,
though C99 is establishing some sort of norm. In the absence of absolute
standards, there are hard trade-offs to be made between various desirable
characteristics.

So, on the one hand, it's ambitious bordering on hubristic for SML experts
who are not floating point specialists to reimplement all this stuff
themselves. On the other hand, it's certainly true that most available math
libraries have shortcomings in some area or another, so if the SML people
are able and determined enough, it would be possible in principle for them
to do better. For an idea of some of the techniques we've used at Intel in
recent math library work, you might look at the following:

  "The Computation of Transcendental Functions on the IA-64 Architecture"
  http://developer.intel.com/technology/itj/q41999/articles/art_5.htm

  "New Algorithms for Improved Transcendental Functions on IA-64"
  http://euler.ecs.umass.edu/paper/final/paper-118.ps

The original question seemed particularly focused on speed. In my
experience the really critical math functions tend to be coded in
assembler, simply because C compilers don't usually provide adequate
control or provide intrinsics to access special hardware features. For
less popular functions (like the cube root and Bessel functions), it's
common to use some portable C routines such as those in FDLIBM:

         http://www.netlib.org/fdlibm

There's certainly a case for having a similar library in ML, but the case
for using it as the default for important functions is more questionable.

Cheers,

John.



^ permalink raw reply	[flat|nested] 4+ messages in thread
* RE: OCaml and C math routines
@ 2000-10-16 12:55 Dave Berry
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Berry @ 2000-10-16 12:55 UTC (permalink / raw)
  To: Xavier Leroy, David McClain, caml-list

As a member of the SML Basis Library committee, my answer is quite simple.
The SML Basis Library is a specification, and does not specify that
mathematical functions should be implemented in ML.  For the most part, the
specification puts as few constraints as possible on implementations.  I'm
pretty certain that MLWorks implemented these functions in C.
 
Dave.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-10-16 15:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-13 17:01 OCaml and C math routines David McClain
2000-10-14 12:19 ` Xavier Leroy
2000-10-13 22:17 John R Harrison
2000-10-16 12:55 Dave Berry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).