Skip to content

Commit 8e27699

Browse files
committed
Squashed commit of the following:
Unify boxed and unboxed primitive operations. Also adds an Unboxed_int type.
1 parent 023cffe commit 8e27699

File tree

81 files changed

+4994
-3572
lines changed

Some content is hidden

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

81 files changed

+4994
-3572
lines changed

backend/cmm.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ type integer_comparison = Lambda.integer_comparison =
146146
| Cle
147147
| Cge
148148

149-
let negate_integer_comparison = Lambda.negate_integer_comparison
149+
let negate_integer_comparison = Scalar.Integer_comparison.negate
150150

151-
let swap_integer_comparison = Lambda.swap_integer_comparison
151+
let swap_integer_comparison = Scalar.Integer_comparison.swap
152152

153153
(* With floats [not (x < y)] is not the same as [x >= y] due to NaNs, so we
154154
provide additional comparisons to represent the negations.*)
@@ -164,9 +164,9 @@ type float_comparison = Lambda.float_comparison =
164164
| CFge
165165
| CFnge
166166

167-
let negate_float_comparison = Lambda.negate_float_comparison
167+
let negate_float_comparison = Scalar.Float_comparison.negate
168168

169-
let swap_float_comparison = Lambda.swap_float_comparison
169+
let swap_float_comparison = Scalar.Float_comparison.swap
170170

171171
type label = Label.t
172172

backend/cmm_helpers.ml

+24-37
Original file line numberDiff line numberDiff line change
@@ -3544,44 +3544,31 @@ let addr_array_length arg dbg =
35443544
to Arbitrary_effects and Has_coeffects, resp. Check if this can be improved
35453545
(e.g., bswap). *)
35463546

3547-
let bbswap bi arg dbg =
3548-
match (bi : Primitive.unboxed_integer) with
3549-
| Unboxed_int8 -> arg
3550-
| _ ->
3551-
let bitwidth : Cmm.bswap_bitwidth =
3552-
match (bi : Primitive.unboxed_integer) with
3553-
| Unboxed_nativeint -> if size_int = 4 then Thirtytwo else Sixtyfour
3554-
| Unboxed_int8 -> assert false
3555-
| Unboxed_int16 -> Sixteen
3556-
| Unboxed_int32 -> Thirtytwo
3557-
| Unboxed_int64 -> Sixtyfour
3547+
let bbswap (bitwidth : Cmm.bswap_bitwidth) arg dbg =
3548+
let op = Cbswap { bitwidth } in
3549+
if Proc.operation_supported op
3550+
&& not (bitwidth = Cmm.Sixtyfour && size_int < 8)
3551+
then Cop (op, [arg], dbg)
3552+
else
3553+
let func, tyarg =
3554+
match bitwidth with
3555+
| Sixteen -> "caml_bswap16_direct", XInt16
3556+
| Thirtytwo -> "caml_int32_direct_bswap", XInt32
3557+
| Sixtyfour -> "caml_int64_direct_bswap", XInt64
35583558
in
3559-
let op = Cbswap { bitwidth } in
3560-
if (bi = Primitive.Unboxed_int64 && size_int = 4)
3561-
|| not (Proc.operation_supported op)
3562-
then
3563-
let func, tyarg =
3564-
match (bi : Primitive.unboxed_integer) with
3565-
| Unboxed_int8 -> assert false
3566-
| Unboxed_int16 -> "caml_bswap16_direct", XInt16
3567-
| Unboxed_int32 -> "caml_int32_direct_bswap", XInt32
3568-
| Unboxed_nativeint -> "caml_nativeint_direct_bswap", XInt
3569-
| Unboxed_int64 -> "caml_int64_direct_bswap", XInt64
3570-
in
3571-
Cop
3572-
( Cextcall
3573-
{ func;
3574-
builtin = false;
3575-
returns = true;
3576-
effects = Arbitrary_effects;
3577-
coeffects = Has_coeffects;
3578-
ty = typ_int;
3579-
alloc = false;
3580-
ty_args = [tyarg]
3581-
},
3582-
[arg],
3583-
dbg )
3584-
else Cop (op, [arg], dbg)
3559+
Cop
3560+
( Cextcall
3561+
{ func;
3562+
builtin = false;
3563+
returns = true;
3564+
effects = No_effects;
3565+
coeffects = No_coeffects;
3566+
ty = typ_int;
3567+
alloc = false;
3568+
ty_args = [tyarg]
3569+
},
3570+
[arg],
3571+
dbg )
35853572

35863573
type binary_primitive = expression -> expression -> Debuginfo.t -> expression
35873574

backend/cmm_helpers.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ val negint : unary_primitive
455455
val addr_array_length : unary_primitive
456456

457457
(** Byte swap primitive Operates on Cmm integers (unboxed values) *)
458-
val bbswap : Primitive.unboxed_integer -> unary_primitive
458+
val bbswap : bswap_bitwidth -> unary_primitive
459459

460460
type binary_primitive = expression -> expression -> Debuginfo.t -> expression
461461

0 commit comments

Comments
 (0)