@@ -110,12 +110,12 @@ let convert_block_shape (shape : L.block_shape) ~num_fields =
110
110
num_fields shape_length;
111
111
List. map K.With_subkind. from_lambda_value_kind shape
112
112
113
- let check_float_array_optimisation_enabled () =
113
+ let check_float_array_optimisation_enabled name =
114
114
if not (Flambda_features. flat_float_array () )
115
115
then
116
- Misc. fatal_error
117
- " [Pgenarray ] is not expected when the float array optimisation is \
118
- disabled "
116
+ Misc. fatal_errorf
117
+ " [%s ] is not expected when the float array optimisation is disabled " name
118
+ ()
119
119
120
120
type converted_array_kind =
121
121
| Array_kind of P.Array_kind .t
@@ -124,7 +124,7 @@ type converted_array_kind =
124
124
let convert_array_kind (kind : L.array_kind ) : converted_array_kind =
125
125
match kind with
126
126
| Pgenarray ->
127
- check_float_array_optimisation_enabled () ;
127
+ check_float_array_optimisation_enabled " Pgenarray " ;
128
128
Float_array_opt_dynamic
129
129
| Paddrarray -> Array_kind Values
130
130
| Pintarray -> Array_kind Immediates
@@ -257,7 +257,7 @@ let convert_array_kind_to_duplicate_array_kind (kind : L.array_kind) :
257
257
converted_duplicate_array_kind =
258
258
match kind with
259
259
| Pgenarray ->
260
- check_float_array_optimisation_enabled () ;
260
+ check_float_array_optimisation_enabled " Pgenarray " ;
261
261
Float_array_opt_dynamic
262
262
| Paddrarray -> Duplicate_array_kind Values
263
263
| Pintarray -> Duplicate_array_kind Immediates
@@ -565,6 +565,78 @@ let bytes_like_set_safe ~dbg ~size_int ~access_size kind ~boxed bytes index
565
565
new_value)
566
566
bytes index
567
567
568
+ (* Array vector load/store *)
569
+
570
+ let array_vector_access_validity_condition array ~size_int
571
+ (array_kind : P.Array_kind.t ) index =
572
+ let width_in_scalars =
573
+ match array_kind with
574
+ | Naked_floats | Immediates | Naked_int64s | Naked_nativeints -> 2
575
+ | Naked_int32s -> 4
576
+ | Values ->
577
+ Misc. fatal_error
578
+ " Attempted to load/store a SIMD vector from/to a value array."
579
+ in
580
+ let length_untagged =
581
+ untag_int (H. Prim (Unary (Array_length (Array_kind array_kind), array )))
582
+ in
583
+ let reduced_length_untagged =
584
+ H. Prim
585
+ (Binary
586
+ ( Int_arith (Naked_immediate , Sub ),
587
+ length_untagged,
588
+ Simple
589
+ (Simple. untagged_const_int
590
+ (Targetint_31_63. of_int (width_in_scalars - 1 ))) ))
591
+ in
592
+ (* We need to convert the length into a naked_nativeint because the optimised
593
+ version of the max_with_zero function needs to be on machine-width integers
594
+ to work (or at least on an integer number of bytes to work). *)
595
+ let reduced_length_nativeint =
596
+ H. Prim
597
+ (Unary
598
+ ( Num_conv { src = Naked_immediate ; dst = Naked_nativeint },
599
+ reduced_length_untagged ))
600
+ in
601
+ let check_nativeint = max_with_zero ~size_int reduced_length_nativeint in
602
+ let check_untagged =
603
+ H. Prim
604
+ (Unary
605
+ ( Num_conv { src = Naked_nativeint ; dst = Naked_immediate },
606
+ check_nativeint ))
607
+ in
608
+ check_bound_tagged index check_untagged
609
+
610
+ let check_array_vector_access ~dbg ~size_int ~array array_kind ~index primitive
611
+ : H.expr_primitive =
612
+ checked_access ~primitive
613
+ ~conditions:
614
+ [array_vector_access_validity_condition ~size_int array array_kind index]
615
+ ~dbg
616
+
617
+ let array_like_load_128 ~dbg ~size_int ~unsafe ~mode ~current_region array_kind
618
+ array index =
619
+ let primitive =
620
+ box_vec128 mode ~current_region
621
+ (H. Binary (Array_load (array_kind, Vec128 , Mutable ), array , index))
622
+ in
623
+ if unsafe
624
+ then primitive
625
+ else
626
+ check_array_vector_access ~dbg ~size_int ~array array_kind ~index primitive
627
+
628
+ let array_like_set_128 ~dbg ~size_int ~unsafe array_kind array index new_value =
629
+ let primitive =
630
+ H. Ternary
631
+ (Array_set (array_kind, Vec128 ), array , index, unbox_vec128 new_value)
632
+ in
633
+ if unsafe
634
+ then primitive
635
+ else
636
+ check_array_vector_access ~dbg ~size_int ~array
637
+ (P.Array_set_kind. array_kind array_kind)
638
+ ~index primitive
639
+
568
640
(* Bigarray accesses *)
569
641
let bigarray_box_or_tag_raw_value_to_read kind alloc_mode =
570
642
let error what =
@@ -688,17 +760,20 @@ let check_array_access ~dbg ~array array_kind ~index primitive :
688
760
let array_load_unsafe ~array ~index (array_ref_kind : Array_ref_kind.t )
689
761
~current_region : H. expr_primitive =
690
762
match array_ref_kind with
691
- | Immediates -> Binary (Array_load (Immediates , Mutable ), array , index)
692
- | Values -> Binary (Array_load (Values , Mutable ), array , index)
763
+ | Immediates -> Binary (Array_load (Immediates , Scalar , Mutable ), array , index)
764
+ | Values -> Binary (Array_load (Values , Scalar , Mutable ), array , index)
693
765
| Naked_floats_to_be_boxed mode ->
694
766
box_float mode
695
- (Binary (Array_load (Naked_floats , Mutable ), array , index))
767
+ (Binary (Array_load (Naked_floats , Scalar , Mutable ), array , index))
696
768
~current_region
697
- | Naked_floats -> Binary (Array_load (Naked_floats , Mutable ), array , index)
698
- | Naked_int32s -> Binary (Array_load (Naked_int32s , Mutable ), array , index)
699
- | Naked_int64s -> Binary (Array_load (Naked_int64s , Mutable ), array , index)
769
+ | Naked_floats ->
770
+ Binary (Array_load (Naked_floats , Scalar , Mutable ), array , index)
771
+ | Naked_int32s ->
772
+ Binary (Array_load (Naked_int32s , Scalar , Mutable ), array , index)
773
+ | Naked_int64s ->
774
+ Binary (Array_load (Naked_int64s , Scalar , Mutable ), array , index)
700
775
| Naked_nativeints ->
701
- Binary (Array_load (Naked_nativeints , Mutable ), array , index)
776
+ Binary (Array_load (Naked_nativeints , Scalar , Mutable ), array , index)
702
777
703
778
let array_set_unsafe ~array ~index ~new_value
704
779
(array_set_kind : Array_set_kind.t ) : H.expr_primitive =
@@ -710,7 +785,7 @@ let array_set_unsafe ~array ~index ~new_value
710
785
| Naked_floats_to_be_unboxed -> unbox_float new_value
711
786
in
712
787
let array_set_kind = convert_intermediate_array_set_kind array_set_kind in
713
- Ternary (Array_set array_set_kind, array , index, new_value)
788
+ Ternary (Array_set ( array_set_kind, Scalar ) , array , index, new_value)
714
789
715
790
let [@ inline always] match_on_array_ref_kind ~array array_ref_kind f :
716
791
H. expr_primitive =
@@ -1526,6 +1601,58 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
1526
1601
[ bytes_like_set_safe ~dbg ~size_int
1527
1602
~access_size: (One_twenty_eight { aligned })
1528
1603
Bigstring ~boxed bigstring index new_value ]
1604
+ | Pfloat_array_load_128 { unsafe; mode } , [[array ]; [index]] ->
1605
+ check_float_array_optimisation_enabled " Pfloat_array_load_128" ;
1606
+ [ array_like_load_128 ~dbg ~size_int ~current_region ~unsafe ~mode
1607
+ Naked_floats array index ]
1608
+ | Pfloatarray_load_128 { unsafe; mode }, [[array ]; [index]]
1609
+ | Punboxed_float_array_load_128 { unsafe; mode } , [[array ]; [index]] ->
1610
+ [ array_like_load_128 ~dbg ~size_int ~current_region ~unsafe ~mode
1611
+ Naked_floats array index ]
1612
+ | Pint_array_load_128 { unsafe; mode } , [[array ]; [index]] ->
1613
+ if Targetint. size <> 64
1614
+ then Misc. fatal_error " [Pint_array_load_128]: immediates must be 64 bits." ;
1615
+ [ array_like_load_128 ~dbg ~size_int ~current_region ~unsafe ~mode
1616
+ Immediates array index ]
1617
+ | Punboxed_int64_array_load_128 { unsafe; mode } , [[array ]; [index]] ->
1618
+ [ array_like_load_128 ~dbg ~size_int ~current_region ~unsafe ~mode
1619
+ Naked_int64s array index ]
1620
+ | Punboxed_nativeint_array_load_128 { unsafe; mode } , [[array ]; [index]] ->
1621
+ if Targetint. size <> 64
1622
+ then
1623
+ Misc. fatal_error
1624
+ " [Punboxed_nativeint_array_load_128]: nativeint must be 64 bits." ;
1625
+ [ array_like_load_128 ~dbg ~size_int ~current_region ~unsafe ~mode
1626
+ Naked_nativeints array index ]
1627
+ | Punboxed_int32_array_load_128 { unsafe; mode } , [[array ]; [index]] ->
1628
+ [ array_like_load_128 ~dbg ~size_int ~current_region ~unsafe ~mode
1629
+ Naked_int32s array index ]
1630
+ | Pfloat_array_set_128 { unsafe } , [[array ]; [index]; [new_value]] ->
1631
+ check_float_array_optimisation_enabled " Pfloat_array_set_128" ;
1632
+ [ array_like_set_128 ~dbg ~size_int ~unsafe Naked_floats array index
1633
+ new_value ]
1634
+ | Pfloatarray_set_128 { unsafe }, [[array ]; [index]; [new_value]]
1635
+ | Punboxed_float_array_set_128 { unsafe } , [[array ]; [index]; [new_value]] ->
1636
+ [ array_like_set_128 ~dbg ~size_int ~unsafe Naked_floats array index
1637
+ new_value ]
1638
+ | Pint_array_set_128 { unsafe } , [[array ]; [index]; [new_value]] ->
1639
+ if Targetint. size <> 64
1640
+ then Misc. fatal_error " [Pint_array_set_128]: immediates must be 64 bits." ;
1641
+ [array_like_set_128 ~dbg ~size_int ~unsafe Immediates array index new_value]
1642
+ | Punboxed_int64_array_set_128 { unsafe } , [[array ]; [index]; [new_value]] ->
1643
+ [ array_like_set_128 ~dbg ~size_int ~unsafe Naked_int64s array index
1644
+ new_value ]
1645
+ | Punboxed_nativeint_array_set_128 { unsafe }, [[array ]; [index]; [new_value]]
1646
+ ->
1647
+ if Targetint. size <> 64
1648
+ then
1649
+ Misc. fatal_error
1650
+ " [Punboxed_nativeint_array_load_128]: nativeint must be 64 bits." ;
1651
+ [ array_like_set_128 ~dbg ~size_int ~unsafe Naked_nativeints array index
1652
+ new_value ]
1653
+ | Punboxed_int32_array_set_128 { unsafe } , [[array ]; [index]; [new_value]] ->
1654
+ [ array_like_set_128 ~dbg ~size_int ~unsafe Naked_int32s array index
1655
+ new_value ]
1529
1656
| Pcompare_ints , [[i1]; [i2]] ->
1530
1657
[ tag_int
1531
1658
(Binary
@@ -1612,7 +1739,10 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
1612
1739
| Pasrbint _ | Pfield_computed _ | Pdivbint _ | Pmodbint _
1613
1740
| Psetfloatfield _ | Psetufloatfield _ | Pbintcomp _ | Punboxed_int_comp _
1614
1741
| Pbigstring_load_16 _ | Pbigstring_load_32 _ | Pbigstring_load_64 _
1615
- | Pbigstring_load_128 _
1742
+ | Pbigstring_load_128 _ | Pfloatarray_load_128 _ | Pfloat_array_load_128 _
1743
+ | Pint_array_load_128 _ | Punboxed_float_array_load_128 _
1744
+ | Punboxed_int32_array_load_128 _ | Punboxed_int64_array_load_128 _
1745
+ | Punboxed_nativeint_array_load_128 _
1616
1746
| Parrayrefu
1617
1747
( Pgenarray_ref _ | Paddrarray_ref | Pintarray_ref | Pfloatarray_ref _
1618
1748
| Punboxedfloatarray_ref _ | Punboxedintarray_ref _ )
@@ -1639,7 +1769,10 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
1639
1769
| Punboxedfloatarray_set _ | Punboxedintarray_set _ )
1640
1770
| Pbytes_set_16 _ | Pbytes_set_32 _ | Pbytes_set_64 _ | Pbytes_set_128 _
1641
1771
| Pbigstring_set_16 _ | Pbigstring_set_32 _ | Pbigstring_set_64 _
1642
- | Pbigstring_set_128 _ | Patomic_cas ),
1772
+ | Pbigstring_set_128 _ | Pfloatarray_set_128 _ | Pfloat_array_set_128 _
1773
+ | Pint_array_set_128 _ | Punboxed_float_array_set_128 _
1774
+ | Punboxed_int32_array_set_128 _ | Punboxed_int64_array_set_128 _
1775
+ | Punboxed_nativeint_array_set_128 _ | Patomic_cas ),
1643
1776
( []
1644
1777
| [_]
1645
1778
| [_; _]
0 commit comments