Skip to content

Commit 84ad475

Browse files
authored
128-bit vector primitive types (#1568)
1 parent d1dedad commit 84ad475

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+850
-463
lines changed

backend/cmm_helpers.ml

+5-13
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,10 @@ let alloc_float_header mode dbg =
149149
| Lambda.Alloc_heap -> Cconst_natint (float_header, dbg)
150150
| Lambda.Alloc_local -> Cconst_natint (float_local_header, dbg)
151151

152-
let alloc_boxedvector_header vi mode dbg =
153-
let header, local_header =
154-
match vi with
155-
| Primitive.Pvec128 -> boxedvec128_header, boxedvec128_local_header
156-
in
152+
let alloc_boxedvec128_header mode dbg =
157153
match mode with
158-
| Lambda.Alloc_heap -> Cconst_natint (header, dbg)
159-
| Lambda.Alloc_local -> Cconst_natint (local_header, dbg)
154+
| Lambda.Alloc_heap -> Cconst_natint (boxedvec128_header, dbg)
155+
| Lambda.Alloc_local -> Cconst_natint (boxedvec128_local_header, dbg)
160156

161157
let alloc_floatarray_header len dbg = Cconst_natint (floatarray_header len, dbg)
162158

@@ -715,8 +711,7 @@ let rec unbox_float dbg =
715711

716712
(* Vectors *)
717713

718-
let box_vector dbg vi m c =
719-
Cop (Calloc m, [alloc_boxedvector_header vi m dbg; c], dbg)
714+
let box_vec128 dbg m c = Cop (Calloc m, [alloc_boxedvec128_header m dbg; c], dbg)
720715

721716
let rec unbox_vec128 dbg =
722717
map_tail ~kind:Any (function
@@ -745,9 +740,6 @@ let rec unbox_vec128 dbg =
745740
| Ctail e -> Ctail (unbox_vec128 dbg e)
746741
| cmm -> Cop (Cload (Onetwentyeight, Immutable), [cmm], dbg))
747742

748-
let unbox_vector dbg vi e =
749-
match vi with Primitive.Pvec128 -> unbox_vec128 dbg e
750-
751743
(* Complex *)
752744

753745
let box_complex dbg c_re c_im =
@@ -1128,7 +1120,7 @@ module Extended_machtype = struct
11281120
| Pbottom ->
11291121
Misc.fatal_error "No unique Extended_machtype for layout [Pbottom]"
11301122
| Punboxed_float -> typ_float
1131-
| Punboxed_vector Pvec128 -> typ_vec128
1123+
| Punboxed_vector (Pvec128 _) -> typ_vec128
11321124
| Punboxed_int _ ->
11331125
(* Only 64-bit architectures, so this is always [typ_int] *)
11341126
typ_any_int

backend/cmm_helpers.mli

+2-8
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,9 @@ val box_float : Debuginfo.t -> Lambda.alloc_mode -> expression -> expression
211211
val unbox_float : Debuginfo.t -> expression -> expression
212212

213213
(** Vector boxing and unboxing *)
214-
val box_vector :
215-
Debuginfo.t ->
216-
Primitive.boxed_vector ->
217-
Lambda.alloc_mode ->
218-
expression ->
219-
expression
214+
val box_vec128 : Debuginfo.t -> Lambda.alloc_mode -> expression -> expression
220215

221-
val unbox_vector :
222-
Debuginfo.t -> Primitive.boxed_vector -> expression -> expression
216+
val unbox_vec128 : Debuginfo.t -> expression -> expression
223217

224218
(** Complex number creation and access *)
225219
val box_complex : Debuginfo.t -> expression -> expression -> expression

backend/cmmgen.ml

+11-15
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ let get_field env layout ptr n dbg =
163163
| Pvalue Pintval | Punboxed_int _ -> Word_int
164164
| Pvalue _ -> Word_val
165165
| Punboxed_float -> Double
166-
| Punboxed_vector Pvec128 -> Onetwentyeight
166+
| Punboxed_vector (Pvec128 _) -> Onetwentyeight
167167
| Ptop ->
168168
Misc.fatal_errorf "get_field with Ptop: %a" Debuginfo.print_compact dbg
169169
| Pbottom ->
@@ -323,7 +323,7 @@ let typ_of_boxed_number = function
323323
| Boxed_float _ -> Cmm.typ_float
324324
| Boxed_integer (Pint64, _,_) when size_int = 4 -> [|Int;Int|]
325325
| Boxed_integer _ -> Cmm.typ_int
326-
| Boxed_vector (Pvec128, _, _) -> Cmm.typ_vec128
326+
| Boxed_vector (Pvec128 _, _, _) -> Cmm.typ_vec128
327327

328328
let equal_unboxed_integer ui1 ui2 =
329329
match ui1, ui2 with
@@ -343,7 +343,7 @@ let box_number bn arg =
343343
match bn with
344344
| Boxed_float (m, dbg) -> box_float dbg m arg
345345
| Boxed_integer (bi, m, dbg) -> box_int dbg bi m arg
346-
| Boxed_vector (vi, m, dbg) -> box_vector dbg vi m arg
346+
| Boxed_vector (Pvec128 _, m, dbg) -> box_vec128 dbg m arg
347347

348348
(* Returns the unboxed representation of a boxed float or integer.
349349
For Pint32 on 64-bit archs, the high 32 bits of the result are undefined. *)
@@ -355,8 +355,8 @@ let unbox_number dbg bn arg =
355355
low_32 dbg (unbox_int dbg Pint32 arg)
356356
| Boxed_integer (bi, _, _) ->
357357
unbox_int dbg bi arg
358-
| Boxed_vector (vi, _, _) ->
359-
unbox_vector dbg vi arg
358+
| Boxed_vector (Pvec128 _, _, _) ->
359+
unbox_vec128 dbg arg
360360

361361
(* Auxiliary functions for optimizing "let" of boxed numbers (floats and
362362
boxed integers *)
@@ -438,7 +438,7 @@ let rec is_unboxed_number_cmm = function
438438
| Some (Uconst_int64 _) ->
439439
Boxed (Boxed_integer (Pint64, alloc_heap, Debuginfo.none), true)
440440
| Some (Uconst_vec128 _) ->
441-
Boxed (Boxed_vector (Pvec128, alloc_heap, Debuginfo.none), true)
441+
Boxed (Boxed_vector (Pvec128 Unknown128, alloc_heap, Debuginfo.none), true)
442442
| _ ->
443443
No_unboxing
444444
end
@@ -932,12 +932,8 @@ and transl_ccall env prim args dbg =
932932
| Pint32 -> XInt32
933933
| Pint64 -> XInt64 in
934934
(xty, transl_unbox_int dbg env bi arg)
935-
| Unboxed_vector bi ->
936-
let xty =
937-
match bi with
938-
| Pvec128 -> XVec128
939-
in
940-
(xty, transl_unbox_vector dbg env bi arg)
935+
| Unboxed_vector (Pvec128 _) ->
936+
(XVec128, transl_unbox_vec128 dbg env arg)
941937
| Untagged_int ->
942938
(XInt, untag_int (transl env arg) dbg)
943939
in
@@ -962,7 +958,7 @@ and transl_ccall env prim args dbg =
962958
| _, Unboxed_integer Pint64 when size_int = 4 ->
963959
([|Int; Int|], box_int dbg Pint64 alloc_heap)
964960
| _, Unboxed_integer bi -> (typ_int, box_int dbg bi alloc_heap)
965-
| _, Unboxed_vector Pvec128 -> (typ_vec128, box_vector dbg Pvec128 alloc_heap)
961+
| _, Unboxed_vector (Pvec128 _) -> (typ_vec128, box_vec128 dbg alloc_heap)
966962
| _, Untagged_int -> (typ_int, (fun i -> tag_int i dbg))
967963
in
968964
let typ_args, args = transl_args prim.prim_native_repr_args args in
@@ -1307,8 +1303,8 @@ and transl_unbox_float dbg env exp =
13071303
and transl_unbox_int dbg env bi exp =
13081304
unbox_int dbg bi (transl env exp)
13091305

1310-
and transl_unbox_vector dbg env bi exp =
1311-
unbox_vector dbg bi (transl env exp)
1306+
and transl_unbox_vec128 dbg env exp =
1307+
unbox_vec128 dbg (transl env exp)
13121308

13131309
(* transl_unbox_int, but may return garbage in upper bits *)
13141310
and transl_unbox_int_low dbg env bi e =

middle_end/clambda.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ let compare_structured_constants c1 c2 =
229229
| Uconst_string s1, Uconst_string s2 -> String.compare s1 s2
230230
| Uconst_closure (_,lbl1,_), Uconst_closure (_,lbl2,_) ->
231231
String.compare lbl1 lbl2
232-
| Uconst_vec128 {high = l0; low = l1}, Uconst_vec128 {high = r0; low = r1} ->
232+
| Uconst_vec128 { high = l0; low = l1},
233+
Uconst_vec128 { high = r0; low = r1} ->
233234
let cmp = Int64.compare l0 r0 in
234235
if cmp = 0 then Int64.compare l1 r1 else cmp
235236
| _, _ ->

middle_end/clambda_primitives.ml

+11-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,17 @@ and block_shape = Lambda.block_shape
172172
and boxed_integer = Primitive.boxed_integer =
173173
Pnativeint | Pint32 | Pint64
174174

175-
and boxed_vector = Primitive.boxed_vector =
176-
| Pvec128
175+
and vec128_type = Lambda.vec128_type =
176+
| Unknown128
177+
| Int8x16
178+
| Int16x8
179+
| Int32x4
180+
| Int64x2
181+
| Float32x4
182+
| Float64x2
183+
184+
and boxed_vector = Lambda.boxed_vector =
185+
| Pvec128 of vec128_type
177186

178187
and bigarray_kind = Lambda.bigarray_kind =
179188
Pbigarray_unknown

middle_end/clambda_primitives.mli

+11-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,17 @@ and block_shape = Lambda.block_shape
176176
and boxed_integer = Primitive.boxed_integer =
177177
Pnativeint | Pint32 | Pint64
178178

179-
and boxed_vector = Primitive.boxed_vector =
180-
| Pvec128
179+
and vec128_type = Lambda.vec128_type =
180+
| Unknown128
181+
| Int8x16
182+
| Int16x8
183+
| Int32x4
184+
| Int64x2
185+
| Float32x4
186+
| Float64x2
187+
188+
and boxed_vector = Lambda.boxed_vector =
189+
| Pvec128 of vec128_type
181190

182191
and bigarray_kind = Lambda.bigarray_kind =
183192
Pbigarray_unknown

middle_end/flambda2/from_lambda/closure_conversion.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ let close_c_call acc env ~loc ~let_bound_ids_with_kinds
448448
Some (P.Box_number (Naked_int32, Alloc_mode.For_allocations.heap))
449449
| _, Unboxed_integer Pint64 ->
450450
Some (P.Box_number (Naked_int64, Alloc_mode.For_allocations.heap))
451-
| _, Unboxed_vector Pvec128 ->
451+
| _, Unboxed_vector (Pvec128 _) ->
452452
Some (P.Box_number (Naked_vec128, Alloc_mode.For_allocations.heap))
453453
| _, Untagged_int -> Some P.Tag_immediate
454454
in
@@ -473,7 +473,7 @@ let close_c_call acc env ~loc ~let_bound_ids_with_kinds
473473
| Unboxed_integer Pint32 -> K.naked_int32
474474
| Unboxed_integer Pint64 -> K.naked_int64
475475
| Untagged_int -> K.naked_immediate
476-
| Unboxed_vector Pvec128 -> K.naked_vec128
476+
| Unboxed_vector (Pvec128 _) -> K.naked_vec128
477477
in
478478
let param_arity =
479479
List.map kind_of_primitive_native_repr prim_native_repr_args
@@ -560,7 +560,7 @@ let close_c_call acc env ~loc ~let_bound_ids_with_kinds
560560
| _, Unboxed_integer Pint32 -> Some (P.Unbox_number Naked_int32)
561561
| _, Unboxed_integer Pint64 -> Some (P.Unbox_number Naked_int64)
562562
| _, Untagged_int -> Some P.Untag_immediate
563-
| _, Unboxed_vector Pvec128 -> Some (P.Unbox_number Naked_vec128)
563+
| _, Unboxed_vector (Pvec128 _) -> Some (P.Unbox_number Naked_vec128)
564564
in
565565
match unbox_arg with
566566
| None -> fun args acc -> call (arg :: args) acc

middle_end/flambda2/identifiers/int_ids.ml

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module Const_data = struct
4848
| Naked_int32 of Int32.t
4949
| Naked_int64 of Int64.t
5050
| Naked_nativeint of Targetint_32_64.t
51-
| Naked_vec128 of Numeric_types.Vec128_by_bit_pattern.t
51+
| Naked_vec128 of Vector_types.Vec128.Bit_pattern.t
5252

5353
let flags = const_flags
5454

@@ -87,10 +87,10 @@ module Const_data = struct
8787
Flambda_colours.naked_number
8888
Targetint_32_64.print n
8989
Flambda_colours.pop
90-
| Naked_vec128 v ->
91-
Format.fprintf ppf "%t#%a%t"
90+
| Naked_vec128 (v) ->
91+
Format.fprintf ppf "%t#vec128[%a]%t"
9292
Flambda_colours.naked_number
93-
Numeric_types.Vec128_by_bit_pattern.print v
93+
Vector_types.Vec128.Bit_pattern.print v
9494
Flambda_colours.pop
9595

9696
let compare t1 t2 =
@@ -104,7 +104,7 @@ module Const_data = struct
104104
| Naked_int64 n1, Naked_int64 n2 -> Int64.compare n1 n2
105105
| Naked_nativeint n1, Naked_nativeint n2 -> Targetint_32_64.compare n1 n2
106106
| Naked_vec128 v1, Naked_vec128 v2 ->
107-
Numeric_types.Vec128_by_bit_pattern.compare v1 v2
107+
Vector_types.Vec128.Bit_pattern.compare v1 v2
108108
| Naked_immediate _, _ -> -1
109109
| _, Naked_immediate _ -> 1
110110
| Tagged_immediate _, _ -> -1
@@ -132,7 +132,7 @@ module Const_data = struct
132132
| Naked_int64 n1, Naked_int64 n2 -> Int64.equal n1 n2
133133
| Naked_nativeint n1, Naked_nativeint n2 -> Targetint_32_64.equal n1 n2
134134
| Naked_vec128 v1, Naked_vec128 v2 ->
135-
Numeric_types.Vec128_by_bit_pattern.equal v1 v2
135+
Vector_types.Vec128.Bit_pattern.equal v1 v2
136136
| ( ( Naked_immediate _ | Tagged_immediate _ | Naked_float _
137137
| Naked_vec128 _ | Naked_int32 _ | Naked_int64 _ | Naked_nativeint _
138138
),
@@ -147,7 +147,7 @@ module Const_data = struct
147147
| Naked_int32 n -> Hashtbl.hash n
148148
| Naked_int64 n -> Hashtbl.hash n
149149
| Naked_nativeint n -> Targetint_32_64.hash n
150-
| Naked_vec128 v -> Numeric_types.Vec128_by_bit_pattern.hash v
150+
| Naked_vec128 v -> Vector_types.Vec128.Bit_pattern.hash v
151151
end)
152152
end
153153

middle_end/flambda2/identifiers/int_ids.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module Const : sig
6060

6161
val naked_nativeint : Targetint_32_64.t -> t
6262

63-
val naked_vec128 : Numeric_types.Vec128_by_bit_pattern.t -> t
63+
val naked_vec128 : Vector_types.Vec128.Bit_pattern.t -> t
6464

6565
module Descr : sig
6666
type t = private
@@ -70,7 +70,7 @@ module Const : sig
7070
| Naked_int32 of Int32.t
7171
| Naked_int64 of Int64.t
7272
| Naked_nativeint of Targetint_32_64.t
73-
| Naked_vec128 of Numeric_types.Vec128_by_bit_pattern.t
73+
| Naked_vec128 of Vector_types.Vec128.Bit_pattern.t
7474

7575
include Container_types.S with type t := t
7676
end

middle_end/flambda2/kinds/flambda_kind.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ let to_lambda (t : t) : Lambda.layout =
7070
| Naked_number Naked_int32 -> Punboxed_int Pint32
7171
| Naked_number Naked_int64 -> Punboxed_int Pint64
7272
| Naked_number Naked_nativeint -> Punboxed_int Pnativeint
73-
| Naked_number Naked_vec128 -> Punboxed_vector Pvec128
73+
| Naked_number Naked_vec128 -> Punboxed_vector (Pvec128 Unknown128)
7474
| Region -> Misc.fatal_error "Can't convert kind [Region] to lambda layout"
7575
| Rec_info ->
7676
Misc.fatal_error "Can't convert kind [Rec_info] to lambda layout"
@@ -278,7 +278,7 @@ module Boxable_number = struct
278278
| Naked_int32 -> Format.pp_print_string ppf "naked_int32"
279279
| Naked_int64 -> Format.pp_print_string ppf "naked_int64"
280280
| Naked_nativeint -> Format.pp_print_string ppf "naked_nativeint"
281-
| Naked_vec128 -> Format.pp_print_string ppf "naked_vec128"
281+
| Naked_vec128 -> Format.fprintf ppf "naked_vec128"
282282

283283
let print_lowercase_short ppf t =
284284
match t with
@@ -528,7 +528,7 @@ module With_subkind = struct
528528
| Pboxedintval Pint32 -> boxed_int32
529529
| Pboxedintval Pint64 -> boxed_int64
530530
| Pboxedintval Pnativeint -> boxed_nativeint
531-
| Pboxedvectorval Pvec128 -> boxed_vec128
531+
| Pboxedvectorval (Pvec128 _) -> boxed_vec128
532532
| Pintval -> tagged_immediate
533533
| Pvariant { consts; non_consts } -> (
534534
match consts, non_consts with
@@ -570,7 +570,7 @@ module With_subkind = struct
570570
| Punboxed_int Pint32 -> naked_int32
571571
| Punboxed_int Pint64 -> naked_int64
572572
| Punboxed_int Pnativeint -> naked_nativeint
573-
| Punboxed_vector Pvec128 -> naked_vec128
573+
| Punboxed_vector (Pvec128 _) -> naked_vec128
574574

575575
include Container_types.Make (struct
576576
type nonrec t = t

middle_end/flambda2/numbers/numeric_types.ml

-62
Original file line numberDiff line numberDiff line change
@@ -250,65 +250,3 @@ module Int64 = struct
250250

251251
let cross_product = Pair.create_from_cross_product
252252
end
253-
254-
module type Vector_width = sig
255-
val size_in_int64s : int
256-
end
257-
258-
module Vector_by_bit_pattern (Width : Vector_width) = struct
259-
module T0 = struct
260-
type t = Int64.t Array.t
261-
262-
let rec compare l r i =
263-
if i = Width.size_in_int64s
264-
then 0
265-
else
266-
let cmp = Int64.compare l.(i) r.(i) in
267-
if cmp = 0 then compare l r (i + 1) else cmp
268-
269-
let compare l r = compare l r 0
270-
271-
let equal = Array.for_all2 Int64.equal
272-
273-
let hash v = Hashtbl.hash v
274-
275-
let print ppf t =
276-
Format.pp_print_list
277-
~pp_sep:(fun ppf () -> Format.pp_print_char ppf ':')
278-
(fun ppf i64 -> Format.fprintf ppf "%016Lx" i64)
279-
ppf (Array.to_list t)
280-
end
281-
282-
include T0
283-
module Self = Container_types.Make (T0)
284-
include Self
285-
286-
let zero = Array.init Width.size_in_int64s (fun _ -> 0L)
287-
288-
let to_int64_array t = t
289-
290-
let of_int64_array t =
291-
if not (Array.length t = Width.size_in_int64s)
292-
then
293-
Misc.fatal_error
294-
"Vector_by_bit_pattern.of_int64_array: wrong length array";
295-
t
296-
end
297-
298-
module Vec128_by_bit_pattern = struct
299-
include Vector_by_bit_pattern (struct
300-
let size_in_int64s = 2
301-
end)
302-
303-
type bits =
304-
{ high : int64;
305-
low : int64
306-
}
307-
308-
let to_bits t =
309-
match to_int64_array t with
310-
| [| high; low |] -> { high; low }
311-
| _ -> Misc.fatal_error "Vec128.to_bits: wrong size vector"
312-
313-
let of_bits { high; low } = of_int64_array [| high; low |]
314-
end

0 commit comments

Comments
 (0)