Skip to content

Commit

Permalink
Change various tests to use the new module
Browse files Browse the repository at this point in the history
  • Loading branch information
ccasin committed Jul 26, 2023
1 parent 62caaee commit c1aa377
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 113 deletions.
33 changes: 9 additions & 24 deletions ocaml/testsuite/tests/typing-layouts-float64/alloc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,15 @@
(* A test comparing allocations with unboxed floats to allocations with boxed
floats. *)

(* CR layouts v2: Delete this `Float_u` module and use the one we add to the
standard library instead. *)
module type Float_u = sig
external to_float : float# -> (float[@local_opt]) = "%box_float"
external of_float : (float[@local_opt]) -> float# = "%unbox_float"

val ( + ) : float# -> float# -> float#
val ( - ) : float# -> float# -> float#
val ( * ) : float# -> float# -> float#
val ( / ) : float# -> float# -> float#
val ( ** ) : float# -> float# -> float#
val ( > ) : float# -> float# -> bool
end

module Float_u : Float_u = struct
external to_float : float# -> (float[@local_opt]) = "%box_float"
external of_float : (float[@local_opt]) -> float# = "%unbox_float"

let ( + ) x y = of_float ((to_float x) +. (to_float y))
let ( - ) x y = of_float ((to_float x) -. (to_float y))
let ( * ) x y = of_float ((to_float x) *. (to_float y))
let ( / ) x y = of_float ((to_float x) /. (to_float y))
let ( ** ) x y = of_float ((to_float x) ** (to_float y))
let ( > ) x y = (to_float x) > (to_float y)
module Float_u = struct
include Stdlib__Float_u

let ( + ) = add
let ( - ) = sub
let ( * ) = mul
let ( / ) = div
let ( ** ) = pow
let ( > ) x y = (compare x y) > 0
end

let alloc = ref 0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
File "unboxed_floats.ml", line 21, characters 22-28:
21 | external to_float : float# -> (float[@local_opt]) = "%box_float"
^^^^^^
Error: This construct requires the alpha version of the extension "layouts", which is disabled and cannot be used
File "unboxed_floats.ml", line 74, characters 11-18:
74 | type ('a : float64) t_float64 = 'a
^^^^^^^
Error: Layout float64 is used here, but the appropriate layouts extension is not enabled
36 changes: 9 additions & 27 deletions ocaml/testsuite/tests/typing-layouts-float64/unboxed_floats.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,17 @@
(*****************************************)
(* Prelude: Functions on unboxed floats. *)

module type Float_u = sig
external to_float : float# -> (float[@local_opt]) = "%box_float"
external of_float : (float[@local_opt]) -> float# = "%unbox_float"

val ( + ) : float# -> float# -> float#
val ( - ) : float# -> float# -> float#
val ( * ) : float# -> float# -> float#
val ( / ) : float# -> float# -> float#
val ( ** ) : float# -> float# -> float#
val ( > ) : float# -> float# -> bool
module Float_u = struct
include Stdlib__Float_u

let ( + ) = add
let ( - ) = sub
let ( * ) = mul
let ( / ) = div
let ( ** ) = pow
let ( > ) x y = (compare x y) > 0
end

module Float_u : Float_u = struct
external to_float : float# -> (float[@local_opt]) = "%box_float"
external of_float : (float[@local_opt]) -> float# = "%unbox_float"

(* We may in the future add primitives for these, but for now this has proven
to be good enough - the boxing/unboxing is eliminated on all
middle-ends. *)
let[@inline always] ( + ) x y = of_float ((to_float x) +. (to_float y))
let[@inline always] ( - ) x y = of_float ((to_float x) -. (to_float y))
let[@inline always] ( * ) x y = of_float ((to_float x) *. (to_float y))
let[@inline always] ( / ) x y = of_float ((to_float x) /. (to_float y))
let[@inline always] ( ** ) x y = of_float ((to_float x) ** (to_float y))
let[@inline always] ( > ) x y = (to_float x) > (to_float y)
end

(* CR layouts v2: move this into a stand-alone [Float_u] module *)

(*********************************)
(* Test 1: some basic arithmetic *)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,17 @@
(*****************************************)
(* Prelude: Functions on unboxed floats. *)

module type Float_u = sig
external to_float : float# -> (float[@local_opt]) = "%box_float"
external of_float : (float[@local_opt]) -> float# = "%unbox_float"

val ( + ) : float# -> float# -> float#
val ( - ) : float# -> float# -> float#
val ( * ) : float# -> float# -> float#
val ( / ) : float# -> float# -> float#
val ( ** ) : float# -> float# -> float#
val ( > ) : float# -> float# -> bool
module Float_u = struct
include Stdlib__Float_u

let ( + ) = add
let ( - ) = sub
let ( * ) = mul
let ( / ) = div
let ( ** ) = pow
let ( > ) x y = (compare x y) > 0
end

module Float_u : Float_u = struct
external to_float : float# -> (float[@local_opt]) = "%box_float"
external of_float : (float[@local_opt]) -> float# = "%unbox_float"

(* We may in the future add primitives for these, but for now this has proven
to be good enough - the boxing/unboxing is eliminated on all
middle-ends. *)
let[@inline always] ( + ) x y = of_float ((to_float x) +. (to_float y))
let[@inline always] ( - ) x y = of_float ((to_float x) -. (to_float y))
let[@inline always] ( * ) x y = of_float ((to_float x) *. (to_float y))
let[@inline always] ( / ) x y = of_float ((to_float x) /. (to_float y))
let[@inline always] ( ** ) x y = of_float ((to_float x) ** (to_float y))
let[@inline always] ( > ) x y = (to_float x) > (to_float y)
end

(* CR layouts v2: move this into a stand-alone [Float_u] module *)

(*********************************)
(* Test 1: some basic arithmetic *)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
File "unboxed_floats_beta.ml", line 21, characters 22-28:
21 | external to_float : float# -> (float[@local_opt]) = "%box_float"
^^^^^^
Error: This construct requires the alpha version of the extension "layouts", which is disabled and cannot be used
File "unboxed_floats_beta.ml", line 74, characters 11-18:
74 | type ('a : float64) t_float64 = 'a
^^^^^^^
Error: Layout float64 is used here, but the appropriate layouts extension is not enabled
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,17 @@
(*****************************************)
(* Prelude: Functions on unboxed floats. *)

module type Float_u = sig
external to_float : float# -> (float[@local_opt]) = "%box_float"
external of_float : (float[@local_opt]) -> float# = "%unbox_float"

val ( + ) : float# -> float# -> float#
val ( - ) : float# -> float# -> float#
val ( * ) : float# -> float# -> float#
val ( / ) : float# -> float# -> float#
val ( ** ) : float# -> float# -> float#
val ( > ) : float# -> float# -> bool
module Float_u = struct
include Stdlib__Float_u

let ( + ) = add
let ( - ) = sub
let ( * ) = mul
let ( / ) = div
let ( ** ) = pow
let ( > ) x y = (compare x y) > 0
end

module Float_u : Float_u = struct
external to_float : float# -> (float[@local_opt]) = "%box_float"
external of_float : (float[@local_opt]) -> float# = "%unbox_float"

(* We may in the future add primitives for these, but for now this has proven
to be good enough - the boxing/unboxing is eliminated on all
middle-ends. *)
let[@inline always] ( + ) x y = of_float ((to_float x) +. (to_float y))
let[@inline always] ( - ) x y = of_float ((to_float x) -. (to_float y))
let[@inline always] ( * ) x y = of_float ((to_float x) *. (to_float y))
let[@inline always] ( / ) x y = of_float ((to_float x) /. (to_float y))
let[@inline always] ( ** ) x y = of_float ((to_float x) ** (to_float y))
let[@inline always] ( > ) x y = (to_float x) > (to_float y)
end

(* CR layouts v2: move this into a stand-alone [Float_u] module *)

(*********************************)
(* Test 1: some basic arithmetic *)

Expand Down

0 comments on commit c1aa377

Please sign in to comment.