caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xavier.leroy@inria.fr>
To: Christophe Raffalli <raffalli@univ-savoie.fr>
Cc: caml-list@inria.fr
Subject: [Caml-list] Re: Float and OCaml C interface
Date: Wed, 23 Jan 2002 16:07:09 +0100	[thread overview]
Message-ID: <20020123160709.A15740@pauillac.inria.fr> (raw)
In-Reply-To: <3C3DDC97.D5C26779@univ-savoie.fr>; from raffalli@univ-savoie.fr on Thu, Jan 10, 2002 at 07:25:27PM +0100

> Is it possible to call from OCaml a C function of type double
> f(double,double,double) 
> without packing and unpacking the double when using the native code
> compiler ?

Yes.  Declare it as follows:

external f : float -> float -> float -> float = "f_wrapper" "f" "float"

"f_wrapper" should be the standard C wrapper function that takes three
values, unpacks the doubles, call f, packs the result.  This wrapper
will be called by the bytecode interpreter.

"f" is just the base C function taking unboxed doubles and returning a
double.  It will be called directly by the code generated by ocamlopt.

The "float" declaration at the end instructs ocamlopt to perform (and
optimize!) the unboxing of the arguments and the boxing of the result
itself, rather than relying on "f" to do it.

> In other word, is the unboxing optimization of floats available to
> external C function ?

Yes.  The standard library uses it for most of the floating-point
functions defined in Pervasives.

- Xavier Leroy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  parent reply	other threads:[~2002-01-23 15:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-04  2:55 [Caml-list] Stop at exception Magesh Kannan
2002-01-04 13:46 ` Xavier Leroy
2002-01-05 11:19   ` [Caml-list] Non-mutable strings Mattias Waldau
2002-01-05 22:01     ` YAMAGATA yoriyuki
2002-01-10 17:56     ` Xavier Leroy
2002-01-10 18:25       ` [Caml-list] Float and OCaml C interface Christophe Raffalli
2002-01-12 21:12         ` David Mentre
2002-01-12 21:32           ` David Mentre
2002-01-23 15:07         ` Xavier Leroy [this message]
2002-01-23 16:02           ` [Caml-list] " David Monniaux
2002-01-10 18:41       ` [Caml-list] Non-mutable strings Patrick M Doane
2002-01-10 18:50         ` Brian Rogoff
2002-01-13 20:05           ` Nicolas George
2002-01-16 19:22       ` Mattias Waldau
2002-01-17  9:56         ` YAMAGATA yoriyuki
2002-01-17 10:19         ` Jerome Vouillon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020123160709.A15740@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=raffalli@univ-savoie.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).