From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA16281; Wed, 23 Jan 2002 16:07:12 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA16265 for ; Wed, 23 Jan 2002 16:07:12 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g0NF7AT26756; Wed, 23 Jan 2002 16:07:10 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA10320; Wed, 23 Jan 2002 16:07:09 +0100 (MET) Date: Wed, 23 Jan 2002 16:07:09 +0100 From: Xavier Leroy To: Christophe Raffalli Cc: caml-list@inria.fr Subject: [Caml-list] Re: Float and OCaml C interface Message-ID: <20020123160709.A15740@pauillac.inria.fr> References: <20020104144617.G941@pauillac.inria.fr> <20020110185619.A20606@pauillac.inria.fr> <3C3DDC97.D5C26779@univ-savoie.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <3C3DDC97.D5C26779@univ-savoie.fr>; from raffalli@univ-savoie.fr on Thu, Jan 10, 2002 at 07:25:27PM +0100 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > 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