From 203c444fd469961a6cfc5ff923859f97e67ba394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Bobot?= Date: Wed, 4 Nov 2015 11:35:52 +0100 Subject: [PATCH] Make `Pervasives.ldexp` unboxed and noalloc --- byterun/floats.c | 7 +++++++ otherlibs/threads/pervasives.ml | 3 ++- stdlib/pervasives.ml | 3 ++- stdlib/pervasives.mli | 4 +++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/byterun/floats.c b/byterun/floats.c index 69af1d876..4fa575ef3 100644 --- a/byterun/floats.c +++ b/byterun/floats.c @@ -225,6 +225,13 @@ CAMLprim value caml_frexp_float(value f) CAMLreturn (res); } +// Seems dumb but intnat could not correspond to int type. +double caml_ldexp_float_unboxed(double f, intnat i) +{ + return ldexp(f, i); +} + + CAMLprim value caml_ldexp_float(value f, value i) { return caml_copy_double(ldexp(Double_val(f), Int_val(i))); diff --git a/otherlibs/threads/pervasives.ml b/otherlibs/threads/pervasives.ml index abea182ff..f5fc1a7f3 100644 --- a/otherlibs/threads/pervasives.ml +++ b/otherlibs/threads/pervasives.ml @@ -154,7 +154,8 @@ external copysign : float -> float -> float external mod_float : float -> float -> float = "caml_fmod_float" "fmod" [@@unboxed] [@@noalloc] external frexp : float -> float * int = "caml_frexp_float" -external ldexp : float -> int -> float = "caml_ldexp_float" +external ldexp : (float [@unboxed]) -> (int [@untagged]) -> (float [@unboxed]) = + "caml_ldexp_float" "caml_ldexp_float_unboxed" [@@noalloc] external modf : float -> float * float = "caml_modf_float" external float : int -> float = "%floatofint" external float_of_int : int -> float = "%floatofint" diff --git a/stdlib/pervasives.ml b/stdlib/pervasives.ml index 15a1af3ff..2916720de 100644 --- a/stdlib/pervasives.ml +++ b/stdlib/pervasives.ml @@ -150,7 +150,8 @@ external copysign : float -> float -> float external mod_float : float -> float -> float = "caml_fmod_float" "fmod" [@@unboxed] [@@noalloc] external frexp : float -> float * int = "caml_frexp_float" -external ldexp : float -> int -> float = "caml_ldexp_float" +external ldexp : (float [@unboxed]) -> (int [@untagged]) -> (float [@unboxed]) = + "caml_ldexp_float" "caml_ldexp_float_unboxed" [@@noalloc] external modf : float -> float * float = "caml_modf_float" external float : int -> float = "%floatofint" external float_of_int : int -> float = "%floatofint" diff --git a/stdlib/pervasives.mli b/stdlib/pervasives.mli index c66a0f190..553253a16 100644 --- a/stdlib/pervasives.mli +++ b/stdlib/pervasives.mli @@ -454,7 +454,9 @@ external frexp : float -> float * int = "caml_frexp_float" zero. When [f] is non-zero, they are defined by [f = x *. 2 ** n] and [0.5 <= x < 1.0]. *) -external ldexp : float -> int -> float = "caml_ldexp_float" + +external ldexp : (float [@unboxed]) -> (int [@untagged]) -> (float [@unboxed]) = + "caml_ldexp_float" "caml_ldexp_float_unboxed" [@@noalloc] (** [ldexp x n] returns [x *. 2 ** n]. *) external modf : float -> float * float = "caml_modf_float"