@@ -317,6 +317,12 @@ module Generate (Target : Target_sig.S) = struct
317317 | [ x ] -> f (transl_prim_arg ctx ?typ x)
318318 | l -> invalid_arity name l ~expected: 1 )
319319
320+ let register_un_prim_ctx name ?typ ?ret_typ f =
321+ register_prim name `Mutator ~unbox: (is_unboxed typ) ?ret_typ (fun ctx context l ->
322+ match l with
323+ | [ x ] -> f context (transl_prim_arg ctx ?typ x)
324+ | l -> invalid_arity name l ~expected: 1 )
325+
320326 let register_bin_prim name k ?tx ?ty ?ret_typ f =
321327 let unbox = is_unboxed tx || is_unboxed ty in
322328 register_prim name k ~unbox ?ret_typ (fun ctx _ l ->
@@ -415,12 +421,44 @@ module Generate (Target : Target_sig.S) = struct
415421 ~ty: int_n
416422 ~ret_typ: float_u
417423 Memory. float_array_get;
424+ register_bin_prim
425+ " caml_array_unsafe_get_indexed_by_int32"
426+ `Mutable
427+ ~ty: int32_u
428+ (fun x y -> Memory. gen_array_get x y);
429+ register_bin_prim
430+ " caml_array_unsafe_get_indexed_by_int64"
431+ `Mutable
432+ ~ty: int64_u
433+ (fun x y ->
434+ let y =
435+ let * y = y in
436+ return (W. I32WrapI64 y)
437+ in
438+ Memory. gen_array_get x y);
439+ register_bin_prim
440+ " caml_array_unsafe_get_indexed_by_nativeint"
441+ `Mutable
442+ ~ty: nativeint_u
443+ (fun x y -> Memory. gen_array_get x y);
418444 register_tern_prim " caml_array_unsafe_set" ~ty: int_n (fun x y z ->
419445 seq (Memory. gen_array_set x y z) Value. unit );
420446 register_tern_prim " caml_array_unsafe_set_addr" ~ty: int_n (fun x y z ->
421447 seq (Memory. array_set x y z) Value. unit );
422448 register_tern_prim " caml_floatarray_unsafe_set" ~ty: int_n ~tz: float_u (fun x y z ->
423449 seq (Memory. float_array_set x y z) Value. unit );
450+ register_tern_prim " caml_array_unsafe_set_indexed_by_int32" ~ty: int32_u (fun x y z ->
451+ seq (Memory. gen_array_set x y z) Value. unit );
452+ register_tern_prim " caml_array_unsafe_set_indexed_by_int64" ~ty: int64_u (fun x y z ->
453+ let y =
454+ let * y = y in
455+ return (W. I32WrapI64 y)
456+ in
457+ seq (Memory. gen_array_set x y z) Value. unit );
458+ register_tern_prim
459+ " caml_array_unsafe_set_indexed_by_nativeint"
460+ ~ty: nativeint_u
461+ (fun x y z -> seq (Memory. gen_array_set x y z) Value. unit );
424462 register_bin_prim
425463 " caml_string_unsafe_get"
426464 `Pure
@@ -514,6 +552,50 @@ module Generate (Target : Target_sig.S) = struct
514552 let * cond = Arith. uge y (Memory. float_array_length (load a)) in
515553 instr (W. Br_if (label, cond)))
516554 x);
555+ register_un_prim_ctx
556+ " caml_checked_int32_to_int"
557+ ~typ: int32_u
558+ ~ret_typ: int_n
559+ (fun context x ->
560+ let y = Code.Var. fresh () in
561+ seq
562+ (let * () = store y x in
563+ let label = label_index context bound_error_pc in
564+ let * cond = Arith. ((load y lsl const 1l ) asr const 1l <> load y) in
565+ instr (W. Br_if (label, cond)))
566+ (load y));
567+ register_un_prim_ctx
568+ " caml_checked_nativeint_to_int"
569+ ~typ: nativeint_u
570+ ~ret_typ: int_n
571+ (fun context x ->
572+ let y = Code.Var. fresh () in
573+ seq
574+ (let * () = store y x in
575+ let label = label_index context bound_error_pc in
576+ let * cond = Arith. ((load y lsl const 1l ) asr const 1l <> load y) in
577+ instr (W. Br_if (label, cond)))
578+ (load y));
579+ register_un_prim_ctx
580+ " caml_checked_int64_to_int"
581+ ~typ: int64_u
582+ ~ret_typ: int_n
583+ (fun context x ->
584+ let y = Code.Var. fresh () in
585+ seq
586+ (let * () = store y x in
587+ let * y = load y in
588+ let label = label_index context bound_error_pc in
589+ let cond =
590+ W. BinOp
591+ ( I64 Ne
592+ , y
593+ , BinOp (I64 (Shr U ), BinOp (I64 Shl , y, Const (I64 33L )), Const (I64 33L ))
594+ )
595+ in
596+ instr (W. Br_if (label, cond)))
597+ (let * y = load y in
598+ return (W. I32WrapI64 y)));
517599 register_arith_bin_prim " caml_add_float" `Pure ~typ: float_u (fun f g ->
518600 float_bin_op Add f g);
519601 register_arith_bin_prim " caml_sub_float" ~typ: float_u `Pure (fun f g ->
@@ -1883,6 +1965,9 @@ module Generate (Target : Target_sig.S) = struct
18831965 | " caml_check_bound"
18841966 | " caml_check_bound_gen"
18851967 | " caml_check_bound_float"
1968+ | " caml_checked_int32_to_int"
1969+ | " caml_checked_nativeint_to_int"
1970+ | " caml_checked_int64_to_int"
18861971 | " caml_ba_get_1"
18871972 | " caml_ba_get_2"
18881973 | " caml_ba_get_3"
0 commit comments