Skip to content

Commit c8a69a3

Browse files
authored
flambda-backend: Use float32 for float32x4 scalar casts (#2710)
1 parent 11b29ce commit c8a69a3

File tree

7 files changed

+52
-17
lines changed

7 files changed

+52
-17
lines changed

bytecomp/bytegen.ml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,13 @@ let preserve_tailcall_for_prim = function
150150
| Pbigstring_load_64 _ | Pbigstring_load_128 _
151151
| Pbigstring_set_16 _ | Pbigstring_set_32 _ | Pbigstring_set_f32 _
152152
| Pfloatarray_load_128 _ | Pfloat_array_load_128 _ | Pint_array_load_128 _
153-
| Punboxed_float_array_load_128 _ | Punboxed_int32_array_load_128 _
154-
| Punboxed_int64_array_load_128 _ | Punboxed_nativeint_array_load_128 _
153+
| Punboxed_float_array_load_128 _ | Punboxed_float32_array_load_128 _
154+
| Punboxed_int32_array_load_128 _ | Punboxed_int64_array_load_128 _
155+
| Punboxed_nativeint_array_load_128 _
155156
| Pfloatarray_set_128 _ | Pfloat_array_set_128 _ | Pint_array_set_128 _
156-
| Punboxed_float_array_set_128 _ | Punboxed_int32_array_set_128 _
157-
| Punboxed_int64_array_set_128 _ | Punboxed_nativeint_array_set_128 _
157+
| Punboxed_float_array_set_128 _ | Punboxed_float32_array_set_128 _
158+
| Punboxed_int32_array_set_128 _ | Punboxed_int64_array_set_128 _
159+
| Punboxed_nativeint_array_set_128 _
158160
| Pbigstring_set_64 _ | Pbigstring_set_128 _
159161
| Pprobe_is_enabled _ | Pobj_dup
160162
| Pctconst _ | Pbswap16 | Pbbswap _ | Pint_as_pointer _
@@ -573,11 +575,13 @@ let comp_primitive stack_info p sz args =
573575
| Pstring_load_128 _ | Pbytes_load_128 _ | Pbytes_set_128 _
574576
| Pbigstring_load_128 _ | Pbigstring_set_128 _
575577
| Pfloatarray_load_128 _ | Pfloat_array_load_128 _ | Pint_array_load_128 _
576-
| Punboxed_float_array_load_128 _ | Punboxed_int32_array_load_128 _
577-
| Punboxed_int64_array_load_128 _ | Punboxed_nativeint_array_load_128 _
578+
| Punboxed_float_array_load_128 _ | Punboxed_float32_array_load_128 _
579+
| Punboxed_int32_array_load_128 _ | Punboxed_int64_array_load_128 _
580+
| Punboxed_nativeint_array_load_128 _
578581
| Pfloatarray_set_128 _ | Pfloat_array_set_128 _ | Pint_array_set_128 _
579-
| Punboxed_float_array_set_128 _ | Punboxed_int32_array_set_128 _
580-
| Punboxed_int64_array_set_128 _ | Punboxed_nativeint_array_set_128 _ ->
582+
| Punboxed_float_array_set_128 _ | Punboxed_float32_array_set_128 _
583+
| Punboxed_int32_array_set_128 _ | Punboxed_int64_array_set_128 _
584+
| Punboxed_nativeint_array_set_128 _ ->
581585
fatal_error "128-bit load/store is not supported in bytecode mode."
582586
(* The cases below are handled in [comp_expr] before the [comp_primitive] call
583587
(in the order in which they appear below),
@@ -1218,3 +1222,4 @@ let compile_phrase expr =
12181222
let init_code = comp_block empty_env expr 1 [Kreturn 1] in
12191223
let fun_code = comp_remainder [] in
12201224
(init_code, fun_code))
1225+

lambda/lambda.ml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,15 @@ type primitive =
270270
| Pfloat_array_load_128 of { unsafe : bool; mode : alloc_mode }
271271
| Pint_array_load_128 of { unsafe : bool; mode : alloc_mode }
272272
| Punboxed_float_array_load_128 of { unsafe : bool; mode : alloc_mode }
273+
| Punboxed_float32_array_load_128 of { unsafe : bool; mode : alloc_mode }
273274
| Punboxed_int32_array_load_128 of { unsafe : bool; mode : alloc_mode }
274275
| Punboxed_int64_array_load_128 of { unsafe : bool; mode : alloc_mode }
275276
| Punboxed_nativeint_array_load_128 of { unsafe : bool; mode : alloc_mode }
276277
| Pfloatarray_set_128 of { unsafe : bool }
277278
| Pfloat_array_set_128 of { unsafe : bool }
278279
| Pint_array_set_128 of { unsafe : bool }
279280
| Punboxed_float_array_set_128 of { unsafe : bool }
281+
| Punboxed_float32_array_set_128 of { unsafe : bool }
280282
| Punboxed_int32_array_set_128 of { unsafe : bool }
281283
| Punboxed_int64_array_set_128 of { unsafe : bool }
282284
| Punboxed_nativeint_array_set_128 of { unsafe : bool }
@@ -1764,6 +1766,7 @@ let primitive_may_allocate : primitive -> alloc_mode option = function
17641766
| Pfloat_array_load_128 { mode = m; _ }
17651767
| Pint_array_load_128 { mode = m; _ }
17661768
| Punboxed_float_array_load_128 { mode = m; _ }
1769+
| Punboxed_float32_array_load_128 { mode = m; _ }
17671770
| Punboxed_int32_array_load_128 { mode = m; _ }
17681771
| Punboxed_int64_array_load_128 { mode = m; _ }
17691772
| Punboxed_nativeint_array_load_128 { mode = m; _ }
@@ -1782,8 +1785,9 @@ let primitive_may_allocate : primitive -> alloc_mode option = function
17821785
| Pbigstring_set_16 _ | Pbigstring_set_32 _ | Pbigstring_set_f32 _
17831786
| Pbigstring_set_64 _ | Pbigstring_set_128 _
17841787
| Pfloatarray_set_128 _ | Pfloat_array_set_128 _ | Pint_array_set_128 _
1785-
| Punboxed_float_array_set_128 _ | Punboxed_int32_array_set_128 _
1786-
| Punboxed_int64_array_set_128 _ | Punboxed_nativeint_array_set_128 _ -> None
1788+
| Punboxed_float_array_set_128 _ | Punboxed_float32_array_set_128 _
1789+
| Punboxed_int32_array_set_128 _ | Punboxed_int64_array_set_128 _
1790+
| Punboxed_nativeint_array_set_128 _ -> None
17871791
| Pctconst _ -> None
17881792
| Pbswap16 -> None
17891793
| Pbbswap (_, m) -> Some m
@@ -1874,8 +1878,9 @@ let primitive_result_layout (p : primitive) =
18741878
| Pbytes_set_128 _ | Pbigstring_set_16 _ | Pbigstring_set_32 _ | Pbigstring_set_f32 _
18751879
| Pbigstring_set_64 _ | Pbigstring_set_128 _
18761880
| Pfloatarray_set_128 _ | Pfloat_array_set_128 _ | Pint_array_set_128 _
1877-
| Punboxed_float_array_set_128 _ | Punboxed_int32_array_set_128 _
1878-
| Punboxed_int64_array_set_128 _ | Punboxed_nativeint_array_set_128 _
1881+
| Punboxed_float_array_set_128 _ | Punboxed_float32_array_set_128 _
1882+
| Punboxed_int32_array_set_128 _ | Punboxed_int64_array_set_128 _
1883+
| Punboxed_nativeint_array_set_128 _
18791884
-> layout_unit
18801885
| Pgetglobal _ | Psetglobal _ | Pgetpredef _ -> layout_module_field
18811886
| Pmakeblock _ | Pmakefloatblock _ | Pmakearray _ | Pduprecord _
@@ -1941,6 +1946,8 @@ let primitive_result_layout (p : primitive) =
19411946
| Pfloatarray_load_128 _ | Pfloat_array_load_128 _
19421947
| Punboxed_float_array_load_128 _ ->
19431948
layout_boxed_vector (Pvec128 Float64x2)
1949+
| Punboxed_float32_array_load_128 _ ->
1950+
layout_boxed_vector (Pvec128 Float32x4)
19441951
| Pint_array_load_128 _ | Punboxed_int64_array_load_128 _
19451952
| Punboxed_nativeint_array_load_128 _ ->
19461953
(* 128-bit types are only supported in the x86_64 backend, so we may

lambda/lambda.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ type primitive =
167167
| Poffsetint of int
168168
| Poffsetref of int
169169
(* Float operations *)
170-
(* CR mslater: (float32) use a single cast primitive *)
171170
| Pfloatoffloat32 of alloc_mode
172171
| Pfloat32offloat of alloc_mode
173172
| Pintoffloat of boxed_float
@@ -256,13 +255,15 @@ type primitive =
256255
| Pfloat_array_load_128 of { unsafe : bool; mode : alloc_mode }
257256
| Pint_array_load_128 of { unsafe : bool; mode : alloc_mode }
258257
| Punboxed_float_array_load_128 of { unsafe : bool; mode : alloc_mode }
258+
| Punboxed_float32_array_load_128 of { unsafe : bool; mode : alloc_mode }
259259
| Punboxed_int32_array_load_128 of { unsafe : bool; mode : alloc_mode }
260260
| Punboxed_int64_array_load_128 of { unsafe : bool; mode : alloc_mode }
261261
| Punboxed_nativeint_array_load_128 of { unsafe : bool; mode : alloc_mode }
262262
| Pfloatarray_set_128 of { unsafe : bool }
263263
| Pfloat_array_set_128 of { unsafe : bool }
264264
| Pint_array_set_128 of { unsafe : bool }
265265
| Punboxed_float_array_set_128 of { unsafe : bool }
266+
| Punboxed_float32_array_set_128 of { unsafe : bool }
266267
| Punboxed_int32_array_set_128 of { unsafe : bool }
267268
| Punboxed_int64_array_set_128 of { unsafe : bool }
268269
| Punboxed_nativeint_array_set_128 of { unsafe : bool }

lambda/printlambda.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,9 @@ let primitive ppf = function
738738
| Punboxed_float_array_load_128 {unsafe; mode} ->
739739
if unsafe then fprintf ppf "unboxed_float_array.unsafe_get128%s" (alloc_kind mode)
740740
else fprintf ppf "unboxed_float_array.get128%s" (alloc_kind mode)
741+
| Punboxed_float32_array_load_128 {unsafe; mode} ->
742+
if unsafe then fprintf ppf "unboxed_float32_array.unsafe_get128%s" (alloc_kind mode)
743+
else fprintf ppf "unboxed_float32_array.get128%s" (alloc_kind mode)
741744
| Punboxed_int32_array_load_128 {unsafe; mode} ->
742745
if unsafe then fprintf ppf "unboxed_int32_array.unsafe_get128%s" (alloc_kind mode)
743746
else fprintf ppf "unboxed_int32_array.get128%s" (alloc_kind mode)
@@ -759,6 +762,9 @@ let primitive ppf = function
759762
| Punboxed_float_array_set_128 {unsafe} ->
760763
if unsafe then fprintf ppf "unboxed_float_array.unsafe_set128"
761764
else fprintf ppf "unboxed_float_array.set128"
765+
| Punboxed_float32_array_set_128 {unsafe} ->
766+
if unsafe then fprintf ppf "unboxed_float32_array.unsafe_set128"
767+
else fprintf ppf "unboxed_float32_array.set128"
762768
| Punboxed_int32_array_set_128 {unsafe} ->
763769
if unsafe then fprintf ppf "unboxed_int32_array.unsafe_set128"
764770
else fprintf ppf "unboxed_int32_array.set128"
@@ -920,13 +926,15 @@ let name_of_primitive = function
920926
| Pfloat_array_load_128 _ -> "Pfloat_array_load_128"
921927
| Pint_array_load_128 _ -> "Pint_array_load_128"
922928
| Punboxed_float_array_load_128 _ -> "Punboxed_float_array_load_128"
929+
| Punboxed_float32_array_load_128 _ -> "Punboxed_float32_array_load_128"
923930
| Punboxed_int32_array_load_128 _ -> "Punboxed_int32_array_load_128"
924931
| Punboxed_int64_array_load_128 _ -> "Punboxed_int64_array_load_128"
925932
| Punboxed_nativeint_array_load_128 _ -> "Punboxed_nativeint_array_load_128"
926933
| Pfloatarray_set_128 _ -> "Pfloatarray_set_128"
927934
| Pfloat_array_set_128 _ -> "Pfloat_array_set_128"
928935
| Pint_array_set_128 _ -> "Pint_array_set_128"
929936
| Punboxed_float_array_set_128 _ -> "Punboxed_float_array_set_128"
937+
| Punboxed_float32_array_set_128 _ -> "Punboxed_float32_array_set_128"
930938
| Punboxed_int32_array_set_128 _ -> "Punboxed_int32_array_set_128"
931939
| Punboxed_int64_array_set_128 _ -> "Punboxed_int64_array_set_128"
932940
| Punboxed_nativeint_array_set_128 _ -> "Punboxed_nativeint_array_set_128"

lambda/tmc.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,13 +955,15 @@ let rec choice ctx t =
955955
| Pfloat_array_load_128 _
956956
| Pint_array_load_128 _
957957
| Punboxed_float_array_load_128 _
958+
| Punboxed_float32_array_load_128 _
958959
| Punboxed_int32_array_load_128 _
959960
| Punboxed_int64_array_load_128 _
960961
| Punboxed_nativeint_array_load_128 _
961962
| Pfloatarray_set_128 _
962963
| Pfloat_array_set_128 _
963964
| Pint_array_set_128 _
964965
| Punboxed_float_array_set_128 _
966+
| Punboxed_float32_array_set_128 _
965967
| Punboxed_int32_array_set_128 _
966968
| Punboxed_int64_array_set_128 _
967969
| Punboxed_nativeint_array_set_128 _

lambda/translprim.ml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,10 @@ let lookup_primitive loc ~poly_mode ~poly_sort pos p =
711711
Primitive ((Punboxed_float_array_load_128 {unsafe = false; mode}), 2)
712712
| "%caml_unboxed_float_array_get128u" ->
713713
Primitive ((Punboxed_float_array_load_128 {unsafe = true; mode}), 2)
714+
| "%caml_unboxed_float32_array_get128" ->
715+
Primitive ((Punboxed_float32_array_load_128 {unsafe = false; mode}), 2)
716+
| "%caml_unboxed_float32_array_get128u" ->
717+
Primitive ((Punboxed_float32_array_load_128 {unsafe = true; mode}), 2)
714718
| "%caml_int_array_get128" ->
715719
Primitive ((Pint_array_load_128 {unsafe = false; mode}), 2)
716720
| "%caml_int_array_get128u" ->
@@ -739,6 +743,10 @@ let lookup_primitive loc ~poly_mode ~poly_sort pos p =
739743
Primitive ((Punboxed_float_array_set_128 {unsafe = false}), 3)
740744
| "%caml_unboxed_float_array_set128u" ->
741745
Primitive ((Punboxed_float_array_set_128 {unsafe = true}), 3)
746+
| "%caml_unboxed_float32_array_set128" ->
747+
Primitive ((Punboxed_float32_array_set_128 {unsafe = false}), 3)
748+
| "%caml_unboxed_float32_array_set128u" ->
749+
Primitive ((Punboxed_float32_array_set_128 {unsafe = true}), 3)
742750
| "%caml_int_array_set128" ->
743751
Primitive ((Pint_array_set_128 {unsafe = false}), 3)
744752
| "%caml_int_array_set128u" ->
@@ -1542,11 +1550,13 @@ let lambda_primitive_needs_event_after = function
15421550
| Pbigstring_load_128 _ | Pbigstring_set_16 _ | Pbigstring_set_32 _
15431551
| Pbigstring_set_f32 _ | Pbigstring_set_64 _ | Pbigstring_set_128 _
15441552
| Pfloatarray_load_128 _ | Pfloat_array_load_128 _ | Pint_array_load_128 _
1545-
| Punboxed_float_array_load_128 _ | Punboxed_int32_array_load_128 _
1546-
| Punboxed_int64_array_load_128 _ | Punboxed_nativeint_array_load_128 _
1553+
| Punboxed_float_array_load_128 _| Punboxed_float32_array_load_128 _
1554+
| Punboxed_int32_array_load_128 _ | Punboxed_int64_array_load_128 _
1555+
| Punboxed_nativeint_array_load_128 _
15471556
| Pfloatarray_set_128 _ | Pfloat_array_set_128 _ | Pint_array_set_128 _
1548-
| Punboxed_float_array_set_128 _ | Punboxed_int32_array_set_128 _
1549-
| Punboxed_int64_array_set_128 _ | Punboxed_nativeint_array_set_128 _
1557+
| Punboxed_float_array_set_128 _| Punboxed_float32_array_set_128 _
1558+
| Punboxed_int32_array_set_128 _ | Punboxed_int64_array_set_128 _
1559+
| Punboxed_nativeint_array_set_128 _
15501560
| Prunstack | Pperform | Preperform | Presume
15511561
| Pbbswap _ | Pobj_dup | Pget_header _ -> true
15521562

lambda/value_rec_compiler.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ let compute_static_size lam =
358358
| Pfloat_array_set_128 _
359359
| Pint_array_set_128 _
360360
| Punboxed_float_array_set_128 _
361+
| Punboxed_float32_array_set_128 _
361362
| Punboxed_int32_array_set_128 _
362363
| Punboxed_int64_array_set_128 _
363364
| Punboxed_nativeint_array_set_128 _ ->
@@ -382,6 +383,7 @@ let compute_static_size lam =
382383
| Pfloat_array_load_128 _
383384
| Pint_array_load_128 _
384385
| Punboxed_float_array_load_128 _
386+
| Punboxed_float32_array_load_128 _
385387
| Punboxed_int32_array_load_128 _
386388
| Punboxed_int64_array_load_128 _
387389
| Punboxed_nativeint_array_load_128 _

0 commit comments

Comments
 (0)