caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Inline assembly?
@ 2001-03-21  8:00 Niall Dalton
  2001-03-22 13:28 ` Xavier Leroy
  0 siblings, 1 reply; 4+ messages in thread
From: Niall Dalton @ 2001-03-21  8:00 UTC (permalink / raw)
  To: caml-list

Hi there,

Is it possible to use inline assembly in ocaml?
If not, what is the lowest overhead way to approximate
it? Using a C function which includes the asm?

Best regards,
Niall
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Inline assembly?
  2001-03-21  8:00 [Caml-list] Inline assembly? Niall Dalton
@ 2001-03-22 13:28 ` Xavier Leroy
  2001-03-23 15:59   ` Markus Mottl
  0 siblings, 1 reply; 4+ messages in thread
From: Xavier Leroy @ 2001-03-22 13:28 UTC (permalink / raw)
  To: Niall Dalton; +Cc: caml-list

> Is it possible to use inline assembly in ocaml?

Currently, no.  A gcc-style inline asm facility could be useful to
express some canned instruction sequences that are currently hardcoded
into each native-code generator, but that's also quite a lot of work
to implement properly.

> If not, what is the lowest overhead way to approximate
> it? Using a C function which includes the asm?

Yes.  Since the C function will not heap-allocate nor raise
exceptions, you can tell the compiler about it using the "noalloc"
annotation:

        external myfunction : ... = "myfunction" "noalloc"

and this will select a faster calling convention from Caml to C for
this function.  If the function operates over floats, there are other
performance tricks one can play; write me if this is the case.

Regards,

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Inline assembly?
  2001-03-22 13:28 ` Xavier Leroy
@ 2001-03-23 15:59   ` Markus Mottl
  2001-03-29 13:29     ` Xavier Leroy
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Mottl @ 2001-03-23 15:59 UTC (permalink / raw)
  To: Xavier Leroy; +Cc: caml-list

On Thu, 22 Mar 2001, Xavier Leroy wrote:
> Yes.  Since the C function will not heap-allocate nor raise
> exceptions, you can tell the compiler about it using the "noalloc"
> annotation:
> 
>         external myfunction : ... = "myfunction" "noalloc"
> 
> and this will select a faster calling convention from Caml to C for
> this function.  If the function operates over floats, there are other
> performance tricks one can play; write me if this is the case.

I have some functions that return floats in the LAPACK-interface. They
could (slightly) benefit from more appropriate calling conventions.

If I am not mistaken, it is not ok to use "noalloc" if the C-function uses
"copy_double", because the latter could trigger the GC. If the function
returns a float, it seems that the additional annotation "float" could
be applied, but it is obviously not always used in the Pervasives library
(e.g. float_of_string; ld_exp).

Is this just an oversight or do these functions have other properties that
prevent the use of this annotation? Are there special rules to follow?

Best regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Inline assembly?
  2001-03-23 15:59   ` Markus Mottl
@ 2001-03-29 13:29     ` Xavier Leroy
  0 siblings, 0 replies; 4+ messages in thread
From: Xavier Leroy @ 2001-03-29 13:29 UTC (permalink / raw)
  To: Markus Mottl; +Cc: caml-list

> > If the function operates over floats, there are other
> > performance tricks one can play; write me if this is the case.
> 
> I have some functions that return floats in the LAPACK-interface. They
> could (slightly) benefit from more appropriate calling conventions.
> 
> If I am not mistaken, it is not ok to use "noalloc" if the C-function uses
> "copy_double", because the latter could trigger the GC.

Correct.

> If the function
> returns a float, it seems that the additional annotation "float" could
> be applied, but it is obviously not always used in the Pervasives library
> (e.g. float_of_string; ld_exp).

Currently, the "float" annotation works only for external functions
where the result and all parameters are of type "float".  Typically,
transcendental and trigonometric functions.  In this case, the
arguments and result are passed unboxed, as C "double" floats.  But it
doesn't work for functions that take / return a mixture of floats and
other data types.

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

end of thread, other threads:[~2001-03-29 13:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-21  8:00 [Caml-list] Inline assembly? Niall Dalton
2001-03-22 13:28 ` Xavier Leroy
2001-03-23 15:59   ` Markus Mottl
2001-03-29 13:29     ` Xavier Leroy

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).