Skip to content

Promote float32 to stable #2709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/amd64/arch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ let assert_simd_enabled () =
(extension_universe stable) in your library configuration file."

let assert_float32_enabled () =
if not (Language_extension.is_enabled Small_numbers) then
if not (Language_extension.(is_at_least Small_numbers Stable)) then
Misc.fatal_error "float32 is not enabled. This error might happen \
if you are using float32 yourself or are linking code that uses it. \
Pass [-extension-universe beta] to the compiler, or set \
Expand Down
21 changes: 12 additions & 9 deletions backend/amd64/proc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ let hard_float32_reg =
for i = 0 to 15 do v.(i) <- Reg.at_location Float32 (Reg (100 + i)) done;
fun () -> assert_float32_enabled (); v

let extension_regs (type a) ?prefix (ext : a Language_extension.t) () =
if not (Language_extension.is_enabled ext) then [||]
let extension_regs (type a) ?prefix (ext : a Language_extension.t) (maturity : a) () =
if not (Language_extension.is_at_least ext maturity) then [||]
else let regs =
match ext with
| SIMD -> hard_vec128_reg ()
Expand All @@ -180,9 +180,10 @@ let extension_regs (type a) ?prefix (ext : a Language_extension.t) () =
| Some p -> Array.sub regs 0 (Int.min p (Array.length regs))

let all_phys_regs =
let open Language_extension in
let basic_regs = Array.append hard_int_reg hard_float_reg in
let simd_regs = extension_regs SIMD in
let f32_regs = extension_regs Small_numbers in
let simd_regs = extension_regs SIMD () in
let f32_regs = extension_regs Small_numbers Stable in
fun () -> Array.append basic_regs
(Array.append (simd_regs ()) (f32_regs ()))

Expand All @@ -204,7 +205,7 @@ let rbp = phys_reg Int 12
let destroy_xmm n =
let f64 = [| phys_reg Float (100 + n) |] in
let f32 =
if Language_extension.is_enabled Small_numbers
if Language_extension.(is_at_least Small_numbers Stable)
then [| phys_reg Float32 (100 + n) |]
else [||]
in
Expand Down Expand Up @@ -410,23 +411,25 @@ let int_regs_destroyed_at_c_call =

let destroyed_at_c_call_win64 =
(* Win64: rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15 preserved *)
let open Language_extension in
let basic_regs = Array.append
(Array.map (phys_reg Int) int_regs_destroyed_at_c_call_win64)
(Array.sub hard_float_reg 0 6)
in
let v128_regs = extension_regs ~prefix:6 SIMD in
let f32_regs = extension_regs ~prefix:6 Small_numbers in
let v128_regs = extension_regs ~prefix:6 SIMD () in
let f32_regs = extension_regs ~prefix:6 Small_numbers Stable in
fun () -> Array.append basic_regs
(Array.append (v128_regs ()) (f32_regs ()))

let destroyed_at_c_call_unix =
let open Language_extension in
(* Unix: rbx, rbp, r12-r15 preserved *)
let basic_regs = Array.append
(Array.map (phys_reg Int) int_regs_destroyed_at_c_call)
hard_float_reg
in
let v128_regs = extension_regs SIMD in
let f32_regs = extension_regs Small_numbers in
let v128_regs = extension_regs SIMD () in
let f32_regs = extension_regs Small_numbers Stable in
fun () -> Array.append basic_regs
(Array.append (v128_regs ()) (f32_regs ()))

Expand Down
7 changes: 3 additions & 4 deletions ocaml/otherlibs/stdlib_beta/.ocamlformat-enable
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
beta.mli
beta.ml
float32.mli
float32.ml
stdlib_beta.mli
stdlib_beta.ml

2 changes: 0 additions & 2 deletions ocaml/otherlibs/stdlib_beta/stdlib_beta.ml
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
module Float32 = Float32
module Float32_u = Float32_u
2 changes: 0 additions & 2 deletions ocaml/otherlibs/stdlib_beta/stdlib_beta.mli
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
module Float32 = Float32
module Float32_u = Float32_u
6 changes: 4 additions & 2 deletions ocaml/otherlibs/stdlib_stable/.ocamlformat-enable
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
stable.mli
stable.ml
stdlib_stable.mli
stdlib_stable.ml
float32.mli
float32.ml
2 changes: 2 additions & 0 deletions ocaml/otherlibs/stdlib_stable/stdlib_stable.ml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module Iarray = Iarray
module IarrayLabels = IarrayLabels
module Float32 = Float32
module Float32_u = Float32_u
2 changes: 2 additions & 0 deletions ocaml/otherlibs/stdlib_stable/stdlib_stable.mli
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module Iarray = Iarray
module IarrayLabels = IarrayLabels
module Float32 = Float32
module Float32_u = Float32_u
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
upstream_compatible.mli
upstream_compatible.ml
stdlib_upstream_compatible.mli
stdlib_upstream_compatible.ml
4 changes: 2 additions & 2 deletions ocaml/testsuite/tests/mixed-blocks/closure_padding_float32.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* TEST
runtime5;
include stdlib_beta;
include stdlib_stable;
ocamlopt_flags="-extension layouts_alpha -extension small_numbers";
native;
*)
Expand All @@ -10,7 +10,7 @@
https://github.com/ocaml-flambda/flambda-backend/pull/2763
*)

module Float32_u = Stdlib_beta.Float32_u
module Float32_u = Stdlib_stable.Float32_u

type t =
| Mutable_str of { mutable x : string }
Expand Down
8 changes: 4 additions & 4 deletions ocaml/testsuite/tests/mixed-blocks/constructor_args.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(* TEST
flags = "-extension layouts_beta -extension small_numbers";
include stdlib_beta;
flags = "-extension layouts_beta";
flambda2;
include stdlib_stable;
include stdlib_upstream_compatible;
{
native;
Expand All @@ -13,8 +13,8 @@
(*****************************************)
(* Prelude: Functions on unboxed numbers *)

module Float32_u = Stdlib_beta.Float32_u
module Float32 = Stdlib_beta.Float32
module Float32_u = Stdlib_stable.Float32_u
module Float32 = Stdlib_stable.Float32
module Float_u = Stdlib_upstream_compatible.Float_u
module Int32_u = Stdlib_upstream_compatible.Int32_u
module Int64_u = Stdlib_upstream_compatible.Int64_u
Expand Down
12 changes: 6 additions & 6 deletions ocaml/testsuite/tests/mixed-blocks/generate_mixed_blocks_code.ml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ let type_to_field_integrity_check type_ ~access1 ~access2 ~message =
| Imm -> "check_int", None
| Float -> "check_float", None
| Float64 -> "check_float", Some "Stdlib_upstream_compatible.Float_u.to_float"
| Float32 -> "check_float32", Some "Stdlib_beta.Float32_u.to_float32"
| Float32 -> "check_float32", Some "Stdlib_stable.Float32_u.to_float32"
| Bits32 -> "check_int32", Some "Stdlib_upstream_compatible.Int32_u.to_int32"
| Bits64 -> "check_int64", Some "Stdlib_upstream_compatible.Int64_u.to_int64"
| Word -> "check_int", Some "Stdlib_upstream_compatible.Nativeint_u.to_int"
Expand Down Expand Up @@ -612,8 +612,8 @@ let main n ~bytecode =
List.iter2 values (List.tl values @ [ List.hd values]) ~f
in
line {|(* TEST
flags = "-extension layouts_beta -extension small_numbers";
include stdlib_beta;
flags = "-extension layouts_beta";
include stdlib_stable;
include stdlib_upstream_compatible;|};
if bytecode then (
line {| bytecode;|};
Expand All @@ -628,9 +628,9 @@ let main n ~bytecode =
line {|let create_string () = String.make (Random.int 100) 'a'|};
line {|let create_int () = Random.int 0x3FFF_FFFF|};
line {|let create_float () = Random.float Float.max_float|};
line {|let create_float32 () = Stdlib_beta.Float32.of_float (Random.float Float.max_float)|};
line {|let create_float32 () = Stdlib_stable.Float32.of_float (Random.float Float.max_float)|};
line {|let create_float_u () = Stdlib_upstream_compatible.Float_u.of_float (create_float ())|};
line {|let create_float32_u () = Stdlib_beta.Float32_u.of_float32 (create_float32 ())|};
line {|let create_float32_u () = Stdlib_stable.Float32_u.of_float32 (create_float32 ())|};
line {|let create_int32_u () = Stdlib_upstream_compatible.Int32_u.of_int32 (Random.int32 0x7FFF_FFFFl)|};
line {|let create_int64_u () = Stdlib_upstream_compatible.Int64_u.of_int64 (Random.int64 0x7FFF_FFFF_FFFF_FFFFL)|};
line {|let create_nativeint_u () = Stdlib_upstream_compatible.Nativeint_u.of_nativeint (Random.nativeint 0x7FFF_FFFF_FFFF_FFFFn)|};
Expand All @@ -648,7 +648,7 @@ let main n ~bytecode =
check_gen ~equal:Float.equal ~to_string:Float.to_string|};
line
{|let check_float32 =
check_gen ~equal:Stdlib_beta.Float32.equal ~to_string:Stdlib_beta.Float32.to_string|};
check_gen ~equal:Stdlib_stable.Float32.equal ~to_string:Stdlib_stable.Float32.to_string|};
line
{|let check_int32 =
check_gen ~equal:Int32.equal ~to_string:Int32.to_string|};
Expand Down
Loading
Loading