Skip to content

Commit c0850be

Browse files
authored
flambda-backend: unboxed float32 (#2520)
* squash for review * address comments
1 parent acdd1ae commit c0850be

40 files changed

+2303
-54
lines changed

asmcomp/cmmgen.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,15 @@ let exttype_of_sort (s : Jkind.Sort.const) =
363363
| Bits32 -> XInt32
364364
| Bits64 -> XInt64
365365
| Void -> Misc.fatal_error "Cmmgen.exttype_of_sort: void encountered"
366+
| Float32 -> Misc.fatal_error "Cmmgen.exttype_of_sort: float32 encountered"
366367

367368
let machtype_of_sort (s : Jkind.Sort.const) =
368369
match s with
369370
| Value -> typ_val
370371
| Float64 -> typ_float
371372
| Word | Bits32 | Bits64 -> typ_int
372373
| Void -> Misc.fatal_error "Cmmgen.machtype_of_sort: void encountered"
374+
| Float32 -> Misc.fatal_error "Cmmgen.machtype_of_sort: float32 encountered"
373375

374376
let is_unboxed_number_cmm ~strict cmm =
375377
let r = ref No_result in

bytecomp/symtable.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ let rec transl_const = function
152152
Const_base(Const_int i) -> Obj.repr i
153153
| Const_base(Const_char c) -> Obj.repr c
154154
| Const_base(Const_string (s, _, _)) -> Obj.repr s
155-
| Const_base(Const_float32 f) -> float32_of_string f
155+
| Const_base(Const_float32 f)
156+
| Const_base(Const_unboxed_float32 f) -> float32_of_string f
156157
| Const_base(Const_float f)
157158
| Const_base(Const_unboxed_float f) -> Obj.repr (float_of_string f)
158159
| Const_base(Const_int32 i)

lambda/lambda.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,7 @@ let constant_layout: constant -> layout = function
17481748
| Const_float _ -> Pvalue (Pboxedfloatval Pfloat64)
17491749
| Const_float32 _ -> Pvalue (Pboxedfloatval Pfloat32)
17501750
| Const_unboxed_float _ -> Punboxed_float Pfloat64
1751+
| Const_unboxed_float32 _ -> Punboxed_float Pfloat32
17511752

17521753
let structured_constant_layout = function
17531754
| Const_base const -> constant_layout const
@@ -1763,6 +1764,7 @@ let layout_of_extern_repr : extern_repr -> _ = function
17631764
begin match s with
17641765
| Value -> layout_any_value
17651766
| Float64 -> layout_unboxed_float Pfloat64
1767+
| Float32 -> layout_unboxed_float Pfloat32
17661768
| Word -> layout_unboxed_nativeint
17671769
| Bits32 -> layout_unboxed_int32
17681770
| Bits64 -> layout_unboxed_int64

lambda/matching.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@ let can_group discr pat =
11601160
| Constant (Const_float _), Constant (Const_float _)
11611161
| Constant (Const_float32 _), Constant (Const_float32 _)
11621162
| Constant (Const_unboxed_float _), Constant (Const_unboxed_float _)
1163+
| Constant (Const_unboxed_float32 _), Constant (Const_unboxed_float32 _)
11631164
| Constant (Const_int32 _), Constant (Const_int32 _)
11641165
| Constant (Const_int64 _), Constant (Const_int64 _)
11651166
| Constant (Const_nativeint _), Constant (Const_nativeint _)
@@ -1186,9 +1187,10 @@ let can_group discr pat =
11861187
( Any
11871188
| Constant
11881189
( Const_int _ | Const_char _ | Const_string _ | Const_float _
1189-
| Const_float32 _ | Const_unboxed_float _ | Const_int32 _
1190-
| Const_int64 _ | Const_nativeint _ | Const_unboxed_int32 _
1191-
| Const_unboxed_int64 _ | Const_unboxed_nativeint _ )
1190+
| Const_float32 _ | Const_unboxed_float _ | Const_unboxed_float32 _
1191+
| Const_int32 _ | Const_int64 _ | Const_nativeint _
1192+
| Const_unboxed_int32 _ | Const_unboxed_int64 _
1193+
| Const_unboxed_nativeint _ )
11921194
| Construct _ | Tuple _ | Record _ | Array _ | Variant _ | Lazy ) ) ->
11931195
false
11941196

@@ -2891,7 +2893,7 @@ let combine_constant value_kind loc arg cst partial ctx def
28912893
make_test_sequence value_kind loc fail (Pfloatcomp (Pfloat64, CFneq))
28922894
(Pfloatcomp (Pfloat64, CFlt)) arg
28932895
const_lambda_list
2894-
| Const_float32 _ ->
2896+
| Const_float32 _ | Const_unboxed_float32 _ ->
28952897
(* Should be caught in do_compile_matching. *)
28962898
Misc.fatal_error "Found unexpected float32 literal pattern."
28972899
| Const_unboxed_float _ ->
@@ -3567,7 +3569,8 @@ and do_compile_matching ~scopes value_kind repr partial ctx pmh =
35673569
compile_no_test ~scopes value_kind
35683570
(divide_record ~scopes lbl.lbl_all ph)
35693571
Context.combine repr partial ctx pm
3570-
| Constant (Const_float32 _) -> Parmatch.raise_matched_float32 ()
3572+
| Constant (Const_float32 _ | Const_unboxed_float32 _) ->
3573+
Parmatch.raise_matched_float32 ()
35713574
| Constant cst ->
35723575
compile_test
35733576
(compile_match ~scopes value_kind repr partial)

lambda/printlambda.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ let rec struct_const ppf = function
2525
| Const_base(Const_string (s, _, _)) -> fprintf ppf "%S" s
2626
| Const_immstring s -> fprintf ppf "#%S" s
2727
| Const_base(Const_float f) -> fprintf ppf "%s" f
28-
| Const_base(Const_float32 f) -> fprintf ppf "%s" f
28+
| Const_base(Const_float32 f) -> fprintf ppf "%ss" f
2929
| Const_base(Const_unboxed_float f) ->
3030
fprintf ppf "%s" (Misc.format_as_unboxed_literal f)
31+
| Const_base(Const_unboxed_float32 f) ->
32+
fprintf ppf "%ss" (Misc.format_as_unboxed_literal f)
3133
| Const_base(Const_int32 n) -> fprintf ppf "%lil" n
3234
| Const_base(Const_int64 n) -> fprintf ppf "%LiL" n
3335
| Const_base(Const_nativeint n) -> fprintf ppf "%nin" n

lambda/translcore.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ let layout_pat sort p = layout p.pat_env p.pat_loc sort p.pat_type
5656
let check_record_field_sort loc sort =
5757
match Jkind.Sort.get_default_value sort with
5858
| Value | Float64 | Bits32 | Bits64 | Word -> ()
59+
| Float32 ->
60+
(* CR mslater: (float32) float32# records *)
61+
Misc.fatal_error "Found unboxed float32 record field."
5962
| Void -> raise (Error (loc, Illegal_void_record_field))
6063

6164
(* Forward declaration -- to be filled in by Translmod.transl_module *)

lambda/translprim.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,10 @@ let lookup_primitive loc ~poly_mode ~poly_sort pos p =
700700
| "%obj_magic" -> Primitive(Pobj_magic layout, 1)
701701
| "%array_to_iarray" -> Primitive (Parray_to_iarray, 1)
702702
| "%array_of_iarray" -> Primitive (Parray_of_iarray, 1)
703-
(* CR mslater: (float32) unboxed *)
704703
| "%unbox_float" -> Primitive(Punbox_float Pfloat64, 1)
705704
| "%box_float" -> Primitive(Pbox_float (Pfloat64, mode), 1)
705+
| "%unbox_float32" -> Primitive(Punbox_float Pfloat32, 1)
706+
| "%box_float32" -> Primitive(Pbox_float (Pfloat32, mode), 1)
706707
| "%get_header" -> Primitive (Pget_header mode, 1)
707708
| "%atomic_load" ->
708709
Primitive ((Patomic_load {immediate_or_pointer=Pointer}), 1)

middle_end/closure/closure.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ let rec close ({ backend; fenv; cenv ; mutable_vars; kinds; catch_env } as env)
10271027
| Const_base (Const_string (s, _, _)) ->
10281028
str (Uconst_string s)
10291029
| Const_base(Const_float x) -> str (Uconst_float (float_of_string x))
1030-
| Const_base(Const_float32 _) ->
1030+
| Const_base(Const_float32 _ | Const_unboxed_float32 _) ->
10311031
Misc.fatal_error "float32 is not supported in closure. Consider using flambda2."
10321032
| Const_base (Const_unboxed_float _ | Const_unboxed_int32 _
10331033
| Const_unboxed_int64 _ | Const_unboxed_nativeint _) ->

middle_end/flambda/closure_conversion.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ let rec declare_const t (const : Lambda.structured_constant)
137137
register_const t
138138
(Allocated_const (Float (float_of_string c)))
139139
Names.const_float
140-
| Const_base (Const_float32 _) ->
141-
Misc.fatal_error "float32 is not supported in closure. Consider using flambda2."
140+
| Const_base (Const_float32 _ | Const_unboxed_float32 _) ->
141+
Misc.fatal_error "float32 is not supported in flambda. Consider using flambda2."
142142
| Const_base (Const_int32 c) ->
143143
register_const t (Allocated_const (Int32 c))
144144
Names.const_int32

otherlibs/alpha/alpha.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
module Float32 = Float32
2+
module Float32_u = Float32_u

0 commit comments

Comments
 (0)