@@ -887,45 +887,159 @@ module Generate (Target : Target_sig.S) = struct
887887 | _ -> invalid_arity " caml_compare" l ~expected: 2 );
888888 register_prim " caml_ba_get_1" `Mutator (fun ctx context l ->
889889 match l with
890- | [ x; y ] -> (
891- let x ' = transl_prim_arg ctx x in
892- match get_type ctx x with
893- | Bigarray { kind = ( Int8_unsigned | Char ) as kind ; layout = C } ->
894- let y ' = transl_prim_arg ctx ~typ: (Int Unnormalized ) y in
890+ | [ ta; i ] -> (
891+ let ta ' = transl_prim_arg ctx ta in
892+ match get_type ctx ta with
893+ | Bigarray { kind; layout = C } ->
894+ let i ' = transl_prim_arg ctx ~typ: (Int Normalized ) i in
895895 seq
896- (let * cond = Arith. uge y ' (Bigarray. dim1 x ') in
896+ (let * cond = Arith. uge i ' (Bigarray. dim 0 ta ') in
897897 instr (W. Br_if (label_index context bound_error_pc, cond)))
898- (Bigarray. get ~kind x' y ')
898+ (Bigarray. get ~kind ta' i ')
899899 | _ ->
900900 let * f =
901901 register_import ~name: " caml_ba_get_1" (Fun (Type. primitive_type 2 ))
902902 in
903- let * x ' = x ' in
904- let * y ' = transl_prim_arg ctx y in
905- return (W. Call (f, [ x '; y ' ])))
903+ let * ta ' = ta ' in
904+ let * i ' = transl_prim_arg ctx i in
905+ return (W. Call (f, [ ta '; i ' ])))
906906 | _ -> invalid_arity " caml_ba_get_1" l ~expected: 2 );
907+ register_prim " caml_ba_get_2" `Mutator (fun ctx context l ->
908+ match l with
909+ | [ ta; i; j ] -> (
910+ let ta' = transl_prim_arg ctx ta in
911+ match get_type ctx ta with
912+ | Bigarray { kind; layout = C } ->
913+ let i' = transl_prim_arg ctx ~typ: (Int Normalized ) i in
914+ let j' = transl_prim_arg ctx ~typ: (Int Normalized ) j in
915+ seq
916+ (let * cond = Arith. uge i' (Bigarray. dim 0 ta') in
917+ let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
918+ let * cond = Arith. uge j' (Bigarray. dim 1 ta') in
919+ let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
920+ return () )
921+ (Bigarray. get ~kind ta' Arith. ((i' * Bigarray. dim 0 ta') + j'))
922+ | _ ->
923+ let * f =
924+ register_import ~name: " caml_ba_get_2" (Fun (Type. primitive_type 3 ))
925+ in
926+ let * ta' = ta' in
927+ let * i' = transl_prim_arg ctx i in
928+ let * j' = transl_prim_arg ctx j in
929+ return (W. Call (f, [ ta'; i'; j' ])))
930+ | _ -> invalid_arity " caml_ba_get_1" l ~expected: 3 );
907931 register_prim " caml_ba_set_1" `Mutator (fun ctx context l ->
908932 match l with
909- | [ x; y; z ] -> (
910- let x' = transl_prim_arg ctx x in
911- match get_type ctx x with
912- | Bigarray { kind = (Int8_unsigned | Char ) as kind ; layout = C } ->
913- let y' = transl_prim_arg ctx ~typ: (Int Normalized ) y in
914- let z' = transl_prim_arg ctx ~typ: (Int Unnormalized ) z in
933+ | [ ta; i; v ] -> (
934+ let ta' = transl_prim_arg ctx ta in
935+ match get_type ctx ta with
936+ | Bigarray { kind; layout = C } ->
937+ let i' = transl_prim_arg ctx ~typ: (Int Normalized ) i in
938+ let v' =
939+ transl_prim_arg
940+ ctx
941+ ?typ:
942+ (match kind with
943+ | Int8_signed | Int8_unsigned | Int16_signed | Int16_unsigned | Char
944+ -> Some (Int Unnormalized )
945+ | Int -> Some (Int Normalized )
946+ | _ -> None )
947+ v
948+ in
915949 seq
916- (let * cond = Arith. uge y ' (Bigarray. dim1 x ') in
950+ (let * cond = Arith. uge i ' (Bigarray. dim 0 ta ') in
917951 let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
918- Bigarray. set ~kind x' y' z ')
952+ Bigarray. set ~kind ta' i' v ')
919953 Value. unit
920954 | _ ->
921955 let * f =
922956 register_import ~name: " caml_ba_set_1" (Fun (Type. primitive_type 3 ))
923957 in
924- let * x' = x' in
925- let * y' = transl_prim_arg ctx y in
926- let * z' = transl_prim_arg ctx z in
927- return (W. Call (f, [ x'; y'; z' ])))
928- | _ -> invalid_arity " caml_ba_set_1" l ~expected: 3 )
958+ let * ta' = ta' in
959+ let * i' = transl_prim_arg ctx i in
960+ let * v' = transl_prim_arg ctx v in
961+ return (W. Call (f, [ ta'; i'; v' ])))
962+ | _ -> invalid_arity " caml_ba_set_1" l ~expected: 3 );
963+ register_prim " caml_ba_set_2" `Mutator (fun ctx context l ->
964+ match l with
965+ | [ ta; i; j; v ] -> (
966+ let ta' = transl_prim_arg ctx ta in
967+ match get_type ctx ta with
968+ | Bigarray { kind; layout = C } ->
969+ let i' = transl_prim_arg ctx ~typ: (Int Normalized ) i in
970+ let j' = transl_prim_arg ctx ~typ: (Int Normalized ) j in
971+ let v' =
972+ transl_prim_arg
973+ ctx
974+ ?typ:
975+ (match kind with
976+ | Int8_signed | Int8_unsigned | Int16_signed | Int16_unsigned | Char
977+ -> Some (Int Unnormalized )
978+ | Int -> Some (Int Normalized )
979+ | _ -> None )
980+ v
981+ in
982+ seq
983+ (let * cond = Arith. uge i' (Bigarray. dim 0 ta') in
984+ let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
985+ let * cond = Arith. uge j' (Bigarray. dim 1 ta') in
986+ let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
987+ Bigarray. set ~kind ta' Arith. ((i' * Bigarray. dim 0 ta') + j') v')
988+ Value. unit
989+ | _ ->
990+ let * f =
991+ register_import ~name: " caml_ba_set_2" (Fun (Type. primitive_type 4 ))
992+ in
993+ let * ta' = ta' in
994+ let * i' = transl_prim_arg ctx i in
995+ let * j' = transl_prim_arg ctx j in
996+ let * v' = transl_prim_arg ctx v in
997+ return (W. Call (f, [ ta'; i'; j'; v' ])))
998+ | _ -> invalid_arity " caml_ba_set_2" l ~expected: 4 );
999+ register_prim " caml_ba_set_3" `Mutator (fun ctx context l ->
1000+ match l with
1001+ | [ ta; i; j; k; v ] -> (
1002+ let ta' = transl_prim_arg ctx ta in
1003+ match get_type ctx ta with
1004+ | Bigarray { kind; layout = C } ->
1005+ let i' = transl_prim_arg ctx ~typ: (Int Normalized ) i in
1006+ let j' = transl_prim_arg ctx ~typ: (Int Normalized ) j in
1007+ let k' = transl_prim_arg ctx ~typ: (Int Normalized ) k in
1008+ let v' =
1009+ transl_prim_arg
1010+ ctx
1011+ ?typ:
1012+ (match kind with
1013+ | Int8_signed | Int8_unsigned | Int16_signed | Int16_unsigned | Char
1014+ -> Some (Int Unnormalized )
1015+ | Int -> Some (Int Normalized )
1016+ | _ -> None )
1017+ v
1018+ in
1019+ seq
1020+ (let * cond = Arith. uge i' (Bigarray. dim 0 ta') in
1021+ let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
1022+ let * cond = Arith. uge j' (Bigarray. dim 1 ta') in
1023+ let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
1024+ let * cond = Arith. uge k' (Bigarray. dim 2 ta') in
1025+ let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
1026+ Bigarray. set
1027+ ~kind
1028+ ta'
1029+ Arith. ((((i' * Bigarray. dim 0 ta') + j') * Bigarray. dim 1 ta') + k')
1030+ v')
1031+ Value. unit
1032+ | _ ->
1033+ let * f =
1034+ register_import ~name: " caml_ba_set_3" (Fun (Type. primitive_type 5 ))
1035+ in
1036+ let * ta' = ta' in
1037+ let * i' = transl_prim_arg ctx i in
1038+ let * j' = transl_prim_arg ctx j in
1039+ let * k' = transl_prim_arg ctx k in
1040+ let * v' = transl_prim_arg ctx v in
1041+ return (W. Call (f, [ ta'; i'; j'; k'; v' ])))
1042+ | _ -> invalid_arity " caml_ba_set_3" l ~expected: 5 )
9291043
9301044 let rec translate_expr ctx context x e =
9311045 match e with
@@ -1201,7 +1315,11 @@ module Generate (Target : Target_sig.S) = struct
12011315 | " caml_check_bound_gen"
12021316 | " caml_check_bound_float"
12031317 | " caml_ba_get_1"
1204- | " caml_ba_set_1" )
1318+ | " caml_ba_get_2"
1319+ | " caml_ba_get_3"
1320+ | " caml_ba_set_1"
1321+ | " caml_ba_set_2"
1322+ | " caml_ba_set_3" )
12051323 , _ ) ) -> fst n, true
12061324 | Let
12071325 ( _
0 commit comments