Skip to content

Commit d3c1413

Browse files
authored
flambda-backend: 128-bit SIMD vector primitive type (#1499)
1 parent bcc0a09 commit d3c1413

24 files changed

+209
-115
lines changed

Makefile.common-jst

+3
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ install_for_test: _install
198198
# replace backend-specific testsuite/tests/asmgen with their new versions
199199
rm _runtest/testsuite/tests/asmgen/*
200200
cp -a testsuite/tests/asmgen/* _runtest/testsuite/tests/asmgen/
201+
# replace backend-specific testsuite/tests/unboxed-primitive-args with their new versions
202+
rm _runtest/testsuite/tests/unboxed-primitive-args/*
203+
cp -a testsuite/tests/unboxed-primitive-args/* _runtest/testsuite/tests/unboxed-primitive-args/
201204

202205
cp $(ocamldir)/Makefile.* _runtest/
203206

asmcomp/amd64/emit.mlp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ let probe_env p =
12101210
env.stack_offset <- p.probe_stack_offset;
12111211
(* Account for the return address that is now pushed on the stack. *)
12121212
env.stack_offset <- env.stack_offset + 8;
1213-
env
1213+
env
12141214

12151215
let emit_probe_handler_wrapper p =
12161216
let wrap_label = probe_handler_wrapper_name p.probe_label in

asmcomp/cmm_helpers.ml

+5
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,8 @@ module Extended_machtype = struct
919919
(* Only 64-bit architectures, so this is always [typ_int] *)
920920
typ_any_int
921921
| Pvalue Pintval -> typ_tagged_int
922+
| Punboxed_vector _ ->
923+
Misc.fatal_error "SIMD vectors are not yet suppored in the upstream compiler build."
922924
| Pvalue _ -> typ_val
923925
end
924926

@@ -3283,5 +3285,8 @@ let kind_of_layout (layout : Lambda.layout) =
32833285
| Pvalue (Pboxedintval bi) -> Boxed_integer bi
32843286
| Pvalue (Pgenval | Pintval | Pvariant _ | Parrayval _)
32853287
| Ptop | Pbottom | Punboxed_float | Punboxed_int _ -> Any
3288+
| Pvalue (Pboxedvectorval _)
3289+
| Punboxed_vector _ ->
3290+
Misc.fatal_error "SIMD vectors are not yet suppored in the upstream compiler build."
32863291

32873292
let make_tuple l = match l with [e] -> e | _ -> Ctuple l

asmcomp/cmmgen.ml

+10
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ let get_field env layout ptr n dbg =
124124
| Pvalue Pintval | Punboxed_int _ -> Word_int
125125
| Pvalue _ -> Word_val
126126
| Punboxed_float -> Double
127+
| Punboxed_vector _ ->
128+
Misc.fatal_error "SIMD vectors are not yet suppored in the upstream compiler build."
127129
| Ptop ->
128130
Misc.fatal_errorf "get_field with Ptop: %a" Debuginfo.print_compact dbg
129131
| Pbottom ->
@@ -842,6 +844,8 @@ and transl_ccall env prim args dbg =
842844
| Pint32 -> XInt32
843845
| Pint64 -> XInt64 in
844846
(xty, transl_unbox_int dbg env bi arg)
847+
| Unboxed_vector _ ->
848+
Misc.fatal_error "SIMD vectors are not yet suppored in the upstream compiler build."
845849
| Untagged_int ->
846850
(XInt, untag_int (transl env arg) dbg)
847851
in
@@ -871,6 +875,8 @@ and transl_ccall env prim args dbg =
871875
([|Int; Int|], box_int dbg Pint64 alloc_heap)
872876
| _, Unboxed_integer bi -> (typ_int, box_int dbg bi alloc_heap)
873877
| _, Untagged_int -> (typ_int, (fun i -> tag_int i dbg))
878+
| _, Unboxed_vector _ ->
879+
Misc.fatal_error "SIMD vectors are not yet suppored in the upstream compiler build."
874880
in
875881
let typ_args, args = transl_args prim.prim_native_repr_args args in
876882
wrap_result
@@ -1244,6 +1250,8 @@ and transl_let_value env str (kind : Lambda.value_kind) id exp transl_body =
12441250
Boxed (Boxed_float (alloc_heap, dbg), false)
12451251
| Mutable, Pboxedintval bi ->
12461252
Boxed (Boxed_integer (bi, alloc_heap, dbg), false)
1253+
| _, Pboxedvectorval _ ->
1254+
Misc.fatal_error "SIMD vectors are not yet suppored in the upstream compiler build."
12471255
| _, (Pfloatval | Pboxedintval _) ->
12481256
(* It would be safe to always unbox in this case, but
12491257
we do it only if this indeed allows us to get rid of
@@ -1290,6 +1298,8 @@ and transl_let env str (layout : Lambda.layout) id exp transl_body =
12901298
there may be constant closures inside that need lifting out. *)
12911299
let _cbody : expression = transl_body env in
12921300
cexp
1301+
| Punboxed_vector _ ->
1302+
Misc.fatal_error "SIMD vectors are not yet suppored in the upstream compiler build."
12931303
| Punboxed_float | Punboxed_int _ -> begin
12941304
let cexp = transl env exp in
12951305
let cbody = transl_body env in

boot/ocamlc

1.51 KB
Binary file not shown.

boot/ocamllex

0 Bytes
Binary file not shown.

lambda/lambda.ml

+15-2
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,14 @@ and value_kind =
260260
non_consts : (int * value_kind list) list;
261261
}
262262
| Parrayval of array_kind
263+
| Pboxedvectorval of boxed_vector
263264

264265
and layout =
265266
| Ptop
266267
| Pvalue of value_kind
267268
| Punboxed_float
268269
| Punboxed_int of boxed_integer
270+
| Punboxed_vector of boxed_vector
269271
| Pbottom
270272

271273
and block_shape =
@@ -289,6 +291,9 @@ and array_set_kind =
289291
and boxed_integer = Primitive.boxed_integer =
290292
Pnativeint | Pint32 | Pint64
291293

294+
and boxed_vector = Primitive.boxed_vector =
295+
| Pvec128
296+
292297
and bigarray_kind =
293298
Pbigarray_unknown
294299
| Pbigarray_float32 | Pbigarray_float64
@@ -310,6 +315,8 @@ and raise_kind =
310315

311316
let equal_boxed_integer = Primitive.equal_boxed_integer
312317

318+
let equal_boxed_vector = Primitive.equal_boxed_vector
319+
313320
let equal_primitive =
314321
(* Should be implemented like [equal_value_kind] of [equal_boxed_integer],
315322
i.e. by matching over the various constructors but the type has more
@@ -321,6 +328,8 @@ let rec equal_value_kind x y =
321328
| Pgenval, Pgenval -> true
322329
| Pfloatval, Pfloatval -> true
323330
| Pboxedintval bi1, Pboxedintval bi2 -> equal_boxed_integer bi1 bi2
331+
| Pboxedvectorval bi1, Pboxedvectorval bi2 ->
332+
equal_boxed_vector bi1 bi2
324333
| Pintval, Pintval -> true
325334
| Parrayval elt_kind1, Parrayval elt_kind2 -> elt_kind1 = elt_kind2
326335
| Pvariant { consts = consts1; non_consts = non_consts1; },
@@ -337,7 +346,7 @@ let rec equal_value_kind x y =
337346
&& List.for_all2 equal_value_kind fields1 fields2)
338347
non_consts1 non_consts2
339348
| (Pgenval | Pfloatval | Pboxedintval _ | Pintval | Pvariant _
340-
| Parrayval _), _ -> false
349+
| Parrayval _ | Pboxedvectorval _), _ -> false
341350

342351
let equal_layout x y =
343352
match x, y with
@@ -354,9 +363,10 @@ let compatible_layout x y =
354363
| Punboxed_float, Punboxed_float -> true
355364
| Punboxed_int bi1, Punboxed_int bi2 ->
356365
equal_boxed_integer bi1 bi2
366+
| Punboxed_vector bi1, Punboxed_vector bi2 -> equal_boxed_vector bi1 bi2
357367
| Ptop, Ptop -> true
358368
| Ptop, _ | _, Ptop -> false
359-
| (Pvalue _ | Punboxed_float | Punboxed_int _), _ -> false
369+
| (Pvalue _ | Punboxed_float | Punboxed_int _ | Punboxed_vector _), _ -> false
360370

361371
let must_be_value layout =
362372
match layout with
@@ -640,6 +650,8 @@ let layout_functor = Pvalue Pgenval
640650
let layout_boxed_float = Pvalue Pfloatval
641651
let layout_string = Pvalue Pgenval
642652
let layout_boxedint bi = Pvalue (Pboxedintval bi)
653+
654+
let layout_boxed_vector vi = Pvalue (Pboxedvectorval vi)
643655
let layout_lazy = Pvalue Pgenval
644656
let layout_lazy_contents = Pvalue Pgenval
645657
let layout_any_value = Pvalue Pgenval
@@ -1442,6 +1454,7 @@ let primitive_result_layout (p : primitive) =
14421454
| Pbox_float _ -> layout_boxed_float
14431455
| Punbox_float -> Punboxed_float
14441456
| Pccall { prim_native_repr_res = _, Untagged_int; _} -> layout_int
1457+
| Pccall { prim_native_repr_res = _, Unboxed_vector v; _} -> layout_boxed_vector v
14451458
| Pccall { prim_native_repr_res = _, Unboxed_float; _} -> layout_boxed_float
14461459
| Pccall { prim_native_repr_res = _, Same_as_ocaml_repr s; _} ->
14471460
begin match s with

lambda/lambda.mli

+7
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ and value_kind =
235235
expected to be significant. *)
236236
}
237237
| Parrayval of array_kind
238+
| Pboxedvectorval of boxed_vector
238239

239240
(* Because we check for and error on void in the translation to lambda, we don't
240241
need a constructor for it here. *)
@@ -243,6 +244,7 @@ and layout =
243244
| Pvalue of value_kind
244245
| Punboxed_float
245246
| Punboxed_int of boxed_integer
247+
| Punboxed_vector of boxed_vector
246248
| Pbottom
247249

248250
and block_shape =
@@ -251,6 +253,9 @@ and block_shape =
251253
and boxed_integer = Primitive.boxed_integer =
252254
Pnativeint | Pint32 | Pint64
253255

256+
and boxed_vector = Primitive.boxed_vector =
257+
| Pvec128
258+
254259
and bigarray_kind =
255260
Pbigarray_unknown
256261
| Pbigarray_float32 | Pbigarray_float64
@@ -280,6 +285,8 @@ val compatible_layout : layout -> layout -> bool
280285

281286
val equal_boxed_integer : boxed_integer -> boxed_integer -> bool
282287

288+
val equal_boxed_vector : boxed_vector -> boxed_vector -> bool
289+
283290
val must_be_value : layout -> value_kind
284291

285292
type structured_constant =

lambda/printlambda.ml

+10
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ let boxed_integer_name = function
8585
| Pint32 -> "int32"
8686
| Pint64 -> "int64"
8787

88+
let boxed_vector_name = function
89+
| Pvec128 -> "vec128"
90+
8891
let variant_kind print_contents ppf ~consts ~non_consts =
8992
fprintf ppf "@[<hov 1>[(consts (%a))@ (non_consts (%a))]@]"
9093
(Format.pp_print_list ~pp_sep:Format.pp_print_space Format.pp_print_int)
@@ -105,6 +108,7 @@ let rec value_kind ppf = function
105108
| Pfloatval -> fprintf ppf "[float]"
106109
| Parrayval elt_kind -> fprintf ppf "[%sarray]" (array_kind elt_kind)
107110
| Pboxedintval bi -> fprintf ppf "[%s]" (boxed_integer_name bi)
111+
| Pboxedvectorval bv -> fprintf ppf "[%s]" (boxed_vector_name bv)
108112
| Pvariant { consts; non_consts; } ->
109113
variant_kind value_kind' ppf ~consts ~non_consts
110114

@@ -114,6 +118,7 @@ and value_kind' ppf = function
114118
| Pfloatval -> fprintf ppf "[float]"
115119
| Parrayval elt_kind -> fprintf ppf "[%sarray]" (array_kind elt_kind)
116120
| Pboxedintval bi -> fprintf ppf "[%s]" (boxed_integer_name bi)
121+
| Pboxedvectorval bv -> fprintf ppf "[%s]" (boxed_vector_name bv)
117122
| Pvariant { consts; non_consts; } ->
118123
variant_kind value_kind' ppf ~consts ~non_consts
119124

@@ -124,6 +129,7 @@ let layout ppf layout =
124129
| Pbottom -> fprintf ppf "[bottom]"
125130
| Punboxed_float -> fprintf ppf "[unboxed_float]"
126131
| Punboxed_int bi -> fprintf ppf "[unboxed_%s]" (boxed_integer_name bi)
132+
| Punboxed_vector bi -> fprintf ppf "[unboxed_%s]" (boxed_vector_name bi)
127133

128134
let return_kind ppf (mode, kind) =
129135
let smode = alloc_mode mode in
@@ -135,10 +141,13 @@ let return_kind ppf (mode, kind) =
135141
| Pvalue (Parrayval elt_kind) ->
136142
fprintf ppf ": %s%sarray@ " smode (array_kind elt_kind)
137143
| Pvalue (Pboxedintval bi) -> fprintf ppf ": %s%s@ " smode (boxed_integer_name bi)
144+
| Pvalue (Pboxedvectorval bv) ->
145+
fprintf ppf ": %s%s@ " smode (boxed_vector_name bv)
138146
| Pvalue (Pvariant { consts; non_consts; }) ->
139147
variant_kind value_kind' ppf ~consts ~non_consts
140148
| Punboxed_float -> fprintf ppf ": unboxed_float@ "
141149
| Punboxed_int bi -> fprintf ppf ": unboxed_%s@ " (boxed_integer_name bi)
150+
| Punboxed_vector bi -> fprintf ppf ": unboxed_%s@ " (boxed_vector_name bi)
142151
| Ptop -> fprintf ppf ": top@ "
143152
| Pbottom -> fprintf ppf ": bottom@ "
144153

@@ -148,6 +157,7 @@ let field_kind ppf = function
148157
| Pfloatval -> pp_print_string ppf "float"
149158
| Parrayval elt_kind -> fprintf ppf "%s-array" (array_kind elt_kind)
150159
| Pboxedintval bi -> pp_print_string ppf (boxed_integer_name bi)
160+
| Pboxedvectorval bv -> pp_print_string ppf (boxed_vector_name bv)
151161
| Pvariant { consts; non_consts; } ->
152162
fprintf ppf "@[<hov 1>[(consts (%a))@ (non_consts (%a))]@]"
153163
(Format.pp_print_list ~pp_sep:Format.pp_print_space Format.pp_print_int)

middle_end/clambda_primitives.ml

+5
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,23 @@ and value_kind = Lambda.value_kind =
158158
non_consts : (int * value_kind list) list;
159159
}
160160
| Parrayval of array_kind
161+
| Pboxedvectorval of boxed_vector
161162

162163
and layout = Lambda.layout =
163164
| Ptop
164165
| Pvalue of value_kind
165166
| Punboxed_float
166167
| Punboxed_int of boxed_integer
168+
| Punboxed_vector of boxed_vector
167169
| Pbottom
168170

169171
and block_shape = Lambda.block_shape
170172
and boxed_integer = Primitive.boxed_integer =
171173
Pnativeint | Pint32 | Pint64
172174

175+
and boxed_vector = Primitive.boxed_vector =
176+
| Pvec128
177+
173178
and bigarray_kind = Lambda.bigarray_kind =
174179
Pbigarray_unknown
175180
| Pbigarray_float32 | Pbigarray_float64

middle_end/clambda_primitives.mli

+5
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,23 @@ and value_kind = Lambda.value_kind =
161161
non_consts : (int * value_kind list) list;
162162
}
163163
| Parrayval of array_kind
164+
| Pboxedvectorval of boxed_vector
164165

165166
and layout = Lambda.layout =
166167
| Ptop
167168
| Pvalue of value_kind
168169
| Punboxed_float
169170
| Punboxed_int of boxed_integer
171+
| Punboxed_vector of boxed_vector
170172
| Pbottom
171173

172174
and block_shape = Lambda.block_shape
173175
and boxed_integer = Primitive.boxed_integer =
174176
Pnativeint | Pint32 | Pint64
175177

178+
and boxed_vector = Primitive.boxed_vector =
179+
| Pvec128
180+
176181
and bigarray_kind = Lambda.bigarray_kind =
177182
Pbigarray_unknown
178183
| Pbigarray_float32 | Pbigarray_float64

middle_end/closure/closure.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ let is_gc_ignorable kind =
6363
| Pbottom -> Misc.fatal_error "[Pbottom] should not be stored in a closure."
6464
| Punboxed_float -> true
6565
| Punboxed_int _ -> true
66+
| Punboxed_vector _ -> true
6667
| Pvalue Pintval -> true
67-
| Pvalue (Pgenval | Pfloatval | Pboxedintval _ | Pvariant _ | Parrayval _) -> false
68+
| Pvalue (Pgenval | Pfloatval | Pboxedintval _ | Pvariant _ | Parrayval _ |
69+
Pboxedvectorval _) -> false
6870

6971
let split_closure_fv kinds fv =
7072
List.fold_right (fun id (not_scanned, scanned) ->

middle_end/flambda/closure_offsets.ml

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ let add_closure_offsets
7979
and not stored in a closure."
8080
| Punboxed_float -> true
8181
| Punboxed_int _ -> true
82+
| Punboxed_vector _ -> true
8283
| Pvalue Pintval -> true
8384
| Pvalue _ -> false)
8485
free_vars

middle_end/flambda/flambda_to_clambda.ml

+1
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ and to_clambda_set_of_closures t env
710710
and not stored in a closure."
711711
| Punboxed_float -> true
712712
| Punboxed_int _ -> true
713+
| Punboxed_vector _ -> true
713714
| Pvalue Pintval -> true
714715
| Pvalue _ -> false)
715716
free_vars

middle_end/printclambda.ml

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ let rec value_kind0 ppf kind =
3737
| Pboxedintval Pnativeint -> Format.pp_print_string ppf ":nativeint"
3838
| Pboxedintval Pint32 -> Format.pp_print_string ppf ":int32"
3939
| Pboxedintval Pint64 -> Format.pp_print_string ppf ":int64"
40+
| Pboxedvectorval Pvec128 -> Format.pp_print_string ppf ":vec128"
4041
| Pvariant { consts; non_consts } ->
4142
Format.fprintf ppf "@[<hov 1>[(consts (%a))@ (non_consts (%a))]@]"
4243
(Format.pp_print_list ~pp_sep:Format.pp_print_space Format.pp_print_int)
@@ -60,6 +61,7 @@ let layout (layout : Lambda.layout) =
6061
| Punboxed_int Pint32 -> ":unboxed_int32"
6162
| Punboxed_int Pint64 -> ":unboxed_int64"
6263
| Punboxed_int Pnativeint -> ":unboxed_nativeint"
64+
| Punboxed_vector Pvec128 -> ":unboxed_vec128"
6365

6466
let rec structured_constant ppf = function
6567
| Uconst_float x -> fprintf ppf "%F" x

0 commit comments

Comments
 (0)