Merge pull request #277 from diml/more-unboxed-on-externals
Switch a few externals to [@@unboxed]master
commit
8fee9d45e1
4
Changes
4
Changes
|
@ -144,6 +144,10 @@ Standard library:
|
|||
(report and fix by Jeremy Yallop)
|
||||
- GPR#265: new implementation of Queue avoiding Obj.magic
|
||||
(Jérémie Dimino)
|
||||
- GPR#277: Switch the following externals to [@@unboxed]:
|
||||
* {Nativeint,Int32,Int64}.{of,to}_float
|
||||
* Int{32,64}.float_of_bits
|
||||
* Int{32,64}.bits_of_float
|
||||
|
||||
Type system:
|
||||
- PR#5545: Type annotations on methods cannot control the choice of abbreviation
|
||||
|
|
|
@ -293,9 +293,15 @@ CAMLprim value caml_int32_of_int(value v)
|
|||
CAMLprim value caml_int32_to_int(value v)
|
||||
{ return Val_long(Int32_val(v)); }
|
||||
|
||||
int32_t caml_int32_of_float_unboxed(double x)
|
||||
{ return x; }
|
||||
|
||||
CAMLprim value caml_int32_of_float(value v)
|
||||
{ return caml_copy_int32((int32_t)(Double_val(v))); }
|
||||
|
||||
double caml_int32_to_float_unboxed(int32_t x)
|
||||
{ return x; }
|
||||
|
||||
CAMLprim value caml_int32_to_float(value v)
|
||||
{ return caml_copy_double((double)(Int32_val(v))); }
|
||||
|
||||
|
@ -320,18 +326,28 @@ CAMLprim value caml_int32_of_string(value s)
|
|||
return caml_copy_int32(parse_intnat(s, 32, INT32_ERRMSG));
|
||||
}
|
||||
|
||||
CAMLprim value caml_int32_bits_of_float(value vd)
|
||||
int32_t caml_int32_bits_of_float_unboxed(double d)
|
||||
{
|
||||
union { float d; int32_t i; } u;
|
||||
u.d = Double_val(vd);
|
||||
return caml_copy_int32(u.i);
|
||||
u.d = d;
|
||||
return u.i;
|
||||
}
|
||||
|
||||
double caml_int32_float_of_bits_unboxed(int32_t i)
|
||||
{
|
||||
union { float d; int32_t i; } u;
|
||||
u.i = i;
|
||||
return u.d;
|
||||
}
|
||||
|
||||
CAMLprim value caml_int32_bits_of_float(value vd)
|
||||
{
|
||||
return caml_copy_int32(caml_int32_bits_of_float_unboxed(Double_val(vd)));
|
||||
}
|
||||
|
||||
CAMLprim value caml_int32_float_of_bits(value vi)
|
||||
{
|
||||
union { float d; int32_t i; } u;
|
||||
u.i = Int32_val(vi);
|
||||
return caml_copy_double(u.d);
|
||||
return caml_copy_double(caml_int32_float_of_bits_unboxed(Int32_val(vi)));
|
||||
}
|
||||
|
||||
/* 64-bit integers */
|
||||
|
@ -499,9 +515,15 @@ CAMLprim value caml_int64_of_int(value v)
|
|||
CAMLprim value caml_int64_to_int(value v)
|
||||
{ return Val_long((intnat) (Int64_val(v))); }
|
||||
|
||||
int64_t caml_int64_of_float_unboxed(double x)
|
||||
{ return x; }
|
||||
|
||||
CAMLprim value caml_int64_of_float(value v)
|
||||
{ return caml_copy_int64((int64_t) (Double_val(v))); }
|
||||
|
||||
double caml_int64_to_float_unboxed(int64_t x)
|
||||
{ return x; }
|
||||
|
||||
CAMLprim value caml_int64_to_float(value v)
|
||||
{ return caml_copy_double((double) (Int64_val(v))); }
|
||||
|
||||
|
@ -569,24 +591,34 @@ CAMLprim value caml_int64_of_string(value s)
|
|||
return caml_copy_int64(res);
|
||||
}
|
||||
|
||||
CAMLprim value caml_int64_bits_of_float(value vd)
|
||||
int64_t caml_int64_bits_of_float_unboxed(double d)
|
||||
{
|
||||
union { double d; int64_t i; int32_t h[2]; } u;
|
||||
u.d = Double_val(vd);
|
||||
u.d = d;
|
||||
#if defined(__arm__) && !defined(__ARM_EABI__)
|
||||
{ int32_t t = u.h[0]; u.h[0] = u.h[1]; u.h[1] = t; }
|
||||
#endif
|
||||
return caml_copy_int64(u.i);
|
||||
return u.i;
|
||||
}
|
||||
|
||||
double caml_int64_float_of_bits_unboxed(int64_t i)
|
||||
{
|
||||
union { double d; int64_t i; int32_t h[2]; } u;
|
||||
u.i = i;
|
||||
#if defined(__arm__) && !defined(__ARM_EABI__)
|
||||
{ int32_t t = u.h[0]; u.h[0] = u.h[1]; u.h[1] = t; }
|
||||
#endif
|
||||
return u.d;
|
||||
}
|
||||
|
||||
CAMLprim value caml_int64_bits_of_float(value vd)
|
||||
{
|
||||
return caml_copy_int64(caml_int64_bits_of_float_unboxed(Double_val(vd)));
|
||||
}
|
||||
|
||||
CAMLprim value caml_int64_float_of_bits(value vi)
|
||||
{
|
||||
union { double d; int64_t i; int32_t h[2]; } u;
|
||||
u.i = Int64_val(vi);
|
||||
#if defined(__arm__) && !defined(__ARM_EABI__)
|
||||
{ int32_t t = u.h[0]; u.h[0] = u.h[1]; u.h[1] = t; }
|
||||
#endif
|
||||
return caml_copy_double(u.d);
|
||||
return caml_copy_double(caml_int64_float_of_bits_unboxed(Int64_val(vi)));
|
||||
}
|
||||
|
||||
/* Native integers */
|
||||
|
@ -746,9 +778,15 @@ CAMLprim value caml_nativeint_of_int(value v)
|
|||
CAMLprim value caml_nativeint_to_int(value v)
|
||||
{ return Val_long(Nativeint_val(v)); }
|
||||
|
||||
intnat caml_nativeint_of_float_unboxed(double x)
|
||||
{ return x; }
|
||||
|
||||
CAMLprim value caml_nativeint_of_float(value v)
|
||||
{ return caml_copy_nativeint((intnat)(Double_val(v))); }
|
||||
|
||||
double caml_nativeint_to_float_unboxed(intnat x)
|
||||
{ return x; }
|
||||
|
||||
CAMLprim value caml_nativeint_to_float(value v)
|
||||
{ return caml_copy_double((double)(Nativeint_val(v))); }
|
||||
|
||||
|
|
|
@ -27,10 +27,18 @@ external shift_right : int32 -> int -> int32 = "%int32_asr"
|
|||
external shift_right_logical : int32 -> int -> int32 = "%int32_lsr"
|
||||
external of_int : int -> int32 = "%int32_of_int"
|
||||
external to_int : int32 -> int = "%int32_to_int"
|
||||
external of_float : float -> int32 = "caml_int32_of_float"
|
||||
external to_float : int32 -> float = "caml_int32_to_float"
|
||||
external bits_of_float : float -> int32 = "caml_int32_bits_of_float"
|
||||
external float_of_bits : int32 -> float = "caml_int32_float_of_bits"
|
||||
external of_float : float -> int32
|
||||
= "caml_int32_of_float" "caml_int32_of_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
external to_float : int32 -> float
|
||||
= "caml_int32_to_float" "caml_int32_to_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
external bits_of_float : float -> int32
|
||||
= "caml_int32_bits_of_float" "caml_int32_bits_of_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
external float_of_bits : int32 -> float
|
||||
= "caml_int32_float_of_bits" "caml_int32_float_of_bits_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
|
||||
let zero = 0l
|
||||
let one = 1l
|
||||
|
|
|
@ -111,13 +111,17 @@ external to_int : int32 -> int = "%int32_to_int"
|
|||
during the conversion. On 64-bit platforms, the conversion
|
||||
is exact. *)
|
||||
|
||||
external of_float : float -> int32 = "caml_int32_of_float"
|
||||
external of_float : float -> int32
|
||||
= "caml_int32_of_float" "caml_int32_of_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
(** Convert the given floating-point number to a 32-bit integer,
|
||||
discarding the fractional part (truncate towards 0).
|
||||
The result of the conversion is undefined if, after truncation,
|
||||
the number is outside the range \[{!Int32.min_int}, {!Int32.max_int}\]. *)
|
||||
|
||||
external to_float : int32 -> float = "caml_int32_to_float"
|
||||
external to_float : int32 -> float
|
||||
= "caml_int32_to_float" "caml_int32_to_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
(** Convert the given 32-bit integer to a floating-point number. *)
|
||||
|
||||
external of_string : string -> int32 = "caml_int32_of_string"
|
||||
|
@ -132,14 +136,18 @@ external of_string : string -> int32 = "caml_int32_of_string"
|
|||
val to_string : int32 -> string
|
||||
(** Return the string representation of its argument, in signed decimal. *)
|
||||
|
||||
external bits_of_float : float -> int32 = "caml_int32_bits_of_float"
|
||||
external bits_of_float : float -> int32
|
||||
= "caml_int32_bits_of_float" "caml_int32_bits_of_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
(** Return the internal representation of the given float according
|
||||
to the IEEE 754 floating-point 'single format' bit layout.
|
||||
Bit 31 of the result represents the sign of the float;
|
||||
bits 30 to 23 represent the (biased) exponent; bits 22 to 0
|
||||
represent the mantissa. *)
|
||||
|
||||
external float_of_bits : int32 -> float = "caml_int32_float_of_bits"
|
||||
external float_of_bits : int32 -> float
|
||||
= "caml_int32_float_of_bits" "caml_int32_float_of_bits_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
(** Return the floating-point number whose internal representation,
|
||||
according to the IEEE 754 floating-point 'single format' bit layout,
|
||||
is the given [int32]. *)
|
||||
|
|
|
@ -27,8 +27,12 @@ external shift_right : int64 -> int -> int64 = "%int64_asr"
|
|||
external shift_right_logical : int64 -> int -> int64 = "%int64_lsr"
|
||||
external of_int : int -> int64 = "%int64_of_int"
|
||||
external to_int : int64 -> int = "%int64_to_int"
|
||||
external of_float : float -> int64 = "caml_int64_of_float"
|
||||
external to_float : int64 -> float = "caml_int64_to_float"
|
||||
external of_float : float -> int64
|
||||
= "caml_int64_of_float" "caml_int64_of_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
external to_float : int64 -> float
|
||||
= "caml_int64_to_float" "caml_int64_to_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
external of_int32 : int32 -> int64 = "%int64_of_int32"
|
||||
external to_int32 : int64 -> int32 = "%int64_to_int32"
|
||||
external of_nativeint : nativeint -> int64 = "%int64_of_nativeint"
|
||||
|
@ -49,8 +53,12 @@ let to_string n = format "%d" n
|
|||
|
||||
external of_string : string -> int64 = "caml_int64_of_string"
|
||||
|
||||
external bits_of_float : float -> int64 = "caml_int64_bits_of_float"
|
||||
external float_of_bits : int64 -> float = "caml_int64_float_of_bits"
|
||||
external bits_of_float : float -> int64
|
||||
= "caml_int64_bits_of_float" "caml_int64_bits_of_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
external float_of_bits : int64 -> float
|
||||
= "caml_int64_float_of_bits" "caml_int64_float_of_bits_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
|
||||
type t = int64
|
||||
|
||||
|
|
|
@ -112,13 +112,17 @@ external to_int : int64 -> int = "%int64_to_int"
|
|||
is taken modulo 2{^31}, i.e. the top 33 bits are lost
|
||||
during the conversion. *)
|
||||
|
||||
external of_float : float -> int64 = "caml_int64_of_float"
|
||||
external of_float : float -> int64
|
||||
= "caml_int64_of_float" "caml_int64_of_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
(** Convert the given floating-point number to a 64-bit integer,
|
||||
discarding the fractional part (truncate towards 0).
|
||||
The result of the conversion is undefined if, after truncation,
|
||||
the number is outside the range \[{!Int64.min_int}, {!Int64.max_int}\]. *)
|
||||
|
||||
external to_float : int64 -> float = "caml_int64_to_float"
|
||||
external to_float : int64 -> float
|
||||
= "caml_int64_to_float" "caml_int64_to_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
(** Convert the given 64-bit integer to a floating-point number. *)
|
||||
|
||||
|
||||
|
@ -154,14 +158,18 @@ external of_string : string -> int64 = "caml_int64_of_string"
|
|||
val to_string : int64 -> string
|
||||
(** Return the string representation of its argument, in decimal. *)
|
||||
|
||||
external bits_of_float : float -> int64 = "caml_int64_bits_of_float"
|
||||
external bits_of_float : float -> int64
|
||||
= "caml_int64_bits_of_float" "caml_int64_bits_of_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
(** Return the internal representation of the given float according
|
||||
to the IEEE 754 floating-point 'double format' bit layout.
|
||||
Bit 63 of the result represents the sign of the float;
|
||||
bits 62 to 52 represent the (biased) exponent; bits 51 to 0
|
||||
represent the mantissa. *)
|
||||
|
||||
external float_of_bits : int64 -> float = "caml_int64_float_of_bits"
|
||||
external float_of_bits : int64 -> float
|
||||
= "caml_int64_float_of_bits" "caml_int64_float_of_bits_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
(** Return the floating-point number whose internal representation,
|
||||
according to the IEEE 754 floating-point 'double format' bit layout,
|
||||
is the given [int64]. *)
|
||||
|
|
|
@ -27,8 +27,12 @@ external shift_right: nativeint -> int -> nativeint = "%nativeint_asr"
|
|||
external shift_right_logical: nativeint -> int -> nativeint = "%nativeint_lsr"
|
||||
external of_int: int -> nativeint = "%nativeint_of_int"
|
||||
external to_int: nativeint -> int = "%nativeint_to_int"
|
||||
external of_float : float -> nativeint = "caml_nativeint_of_float"
|
||||
external to_float : nativeint -> float = "caml_nativeint_to_float"
|
||||
external of_float : float -> nativeint
|
||||
= "caml_nativeint_of_float" "caml_nativeint_of_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
external to_float : nativeint -> float
|
||||
= "caml_nativeint_to_float" "caml_nativeint_to_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
external of_int32: int32 -> nativeint = "%nativeint_of_int32"
|
||||
external to_int32: nativeint -> int32 = "%nativeint_to_int32"
|
||||
|
||||
|
|
|
@ -129,14 +129,18 @@ external to_int : nativeint -> int = "%nativeint_to_int"
|
|||
integer (type [int]). The high-order bit is lost during
|
||||
the conversion. *)
|
||||
|
||||
external of_float : float -> nativeint = "caml_nativeint_of_float"
|
||||
external of_float : float -> nativeint
|
||||
= "caml_nativeint_of_float" "caml_nativeint_of_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
(** Convert the given floating-point number to a native integer,
|
||||
discarding the fractional part (truncate towards 0).
|
||||
The result of the conversion is undefined if, after truncation,
|
||||
the number is outside the range
|
||||
\[{!Nativeint.min_int}, {!Nativeint.max_int}\]. *)
|
||||
|
||||
external to_float : nativeint -> float = "caml_nativeint_to_float"
|
||||
external to_float : nativeint -> float
|
||||
= "caml_nativeint_to_float" "caml_nativeint_to_float_unboxed"
|
||||
[@@unboxed] [@@noalloc]
|
||||
(** Convert the given native integer to a floating-point number. *)
|
||||
|
||||
external of_int32 : int32 -> nativeint = "%nativeint_of_int32"
|
||||
|
|
Loading…
Reference in New Issue