@@ -891,11 +891,16 @@ module Generate (Target : Target_sig.S) = struct
891
891
let ta' = transl_prim_arg ctx ta in
892
892
match get_type ctx ta with
893
893
| Bigarray { kind; layout = C } ->
894
- let i' = transl_prim_arg ctx ~typ: (Int Normalized ) i in
894
+ let i' = Var. fresh () in
895
+ let dim0 = Var. fresh () in
895
896
seq
896
- (let * cond = Arith. uge i' (Bigarray. dim 0 ta') in
897
+ (let * () =
898
+ store ~typ: I32 i' (transl_prim_arg ctx ~typ: (Int Normalized ) i)
899
+ in
900
+ let * () = store dim0 ~typ: I32 (Bigarray. dim 0 ta') in
901
+ let * cond = Arith. uge (load i') (load dim0) in
897
902
instr (W. Br_if (label_index context bound_error_pc, cond)))
898
- (Bigarray. get ~kind ta' i' )
903
+ (Bigarray. get ~kind ta' (load i') )
899
904
| _ ->
900
905
let * f =
901
906
register_import ~name: " caml_ba_get_1" (Fun (Type. primitive_type 2 ))
@@ -910,15 +915,25 @@ module Generate (Target : Target_sig.S) = struct
910
915
let ta' = transl_prim_arg ctx ta in
911
916
match get_type ctx ta with
912
917
| 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
918
+ let i' = Var. fresh () in
919
+ let j' = Var. fresh () in
920
+ let dim0 = Var. fresh () in
921
+ let dim1 = Var. fresh () in
915
922
seq
916
- (let * cond = Arith. uge i' (Bigarray. dim 0 ta') in
923
+ (let * () =
924
+ store ~typ: I32 i' (transl_prim_arg ctx ~typ: (Int Normalized ) i)
925
+ in
926
+ let * () =
927
+ store ~typ: I32 j' (transl_prim_arg ctx ~typ: (Int Normalized ) j)
928
+ in
929
+ let * () = store dim0 ~typ: I32 (Bigarray. dim 0 ta') in
930
+ let * () = store dim1 ~typ: I32 (Bigarray. dim 1 ta') in
931
+ let * cond = Arith. uge (load i') (load dim0) in
917
932
let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
918
- let * cond = Arith. uge j' ( Bigarray. dim 1 ta' ) in
933
+ let * cond = Arith. uge (load j') (load dim1 ) in
919
934
let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
920
935
return () )
921
- (Bigarray. get ~kind ta' Arith. ((i' * Bigarray. dim 1 ta' ) + j'))
936
+ (Bigarray. get ~kind ta' Arith. ((load i' * load dim1 ) + load j'))
922
937
| _ ->
923
938
let * f =
924
939
register_import ~name: " caml_ba_get_2" (Fun (Type. primitive_type 3 ))
@@ -934,7 +949,8 @@ module Generate (Target : Target_sig.S) = struct
934
949
let ta' = transl_prim_arg ctx ta in
935
950
match get_type ctx ta with
936
951
| Bigarray { kind; layout = C } ->
937
- let i' = transl_prim_arg ctx ~typ: (Int Normalized ) i in
952
+ let i' = Var. fresh () in
953
+ let dim0 = Var. fresh () in
938
954
let v' =
939
955
transl_prim_arg
940
956
ctx
@@ -947,9 +963,13 @@ module Generate (Target : Target_sig.S) = struct
947
963
v
948
964
in
949
965
seq
950
- (let * cond = Arith. uge i' (Bigarray. dim 0 ta') in
966
+ (let * () =
967
+ store ~typ: I32 i' (transl_prim_arg ctx ~typ: (Int Normalized ) i)
968
+ in
969
+ let * () = store dim0 ~typ: I32 (Bigarray. dim 0 ta') in
970
+ let * cond = Arith. uge (load i') (load dim0) in
951
971
let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
952
- Bigarray. set ~kind ta' i' v')
972
+ Bigarray. set ~kind ta' (load i') v')
953
973
Value. unit
954
974
| _ ->
955
975
let * f =
@@ -966,8 +986,10 @@ module Generate (Target : Target_sig.S) = struct
966
986
let ta' = transl_prim_arg ctx ta in
967
987
match get_type ctx ta with
968
988
| 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
989
+ let i' = Var. fresh () in
990
+ let j' = Var. fresh () in
991
+ let dim0 = Var. fresh () in
992
+ let dim1 = Var. fresh () in
971
993
let v' =
972
994
transl_prim_arg
973
995
ctx
@@ -980,11 +1002,19 @@ module Generate (Target : Target_sig.S) = struct
980
1002
v
981
1003
in
982
1004
seq
983
- (let * cond = Arith. uge i' (Bigarray. dim 0 ta') in
1005
+ (let * () =
1006
+ store ~typ: I32 i' (transl_prim_arg ctx ~typ: (Int Normalized ) i)
1007
+ in
1008
+ let * () =
1009
+ store ~typ: I32 j' (transl_prim_arg ctx ~typ: (Int Normalized ) j)
1010
+ in
1011
+ let * () = store dim0 ~typ: I32 (Bigarray. dim 0 ta') in
1012
+ let * () = store dim1 ~typ: I32 (Bigarray. dim 1 ta') in
1013
+ let * cond = Arith. uge (load i') (load dim0) in
984
1014
let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
985
- let * cond = Arith. uge j' ( Bigarray. dim 1 ta' ) in
1015
+ let * cond = Arith. uge (load j') (load dim1 ) in
986
1016
let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
987
- Bigarray. set ~kind ta' Arith. ((i' * Bigarray. dim 1 ta' ) + j') v')
1017
+ Bigarray. set ~kind ta' Arith. ((load i' * load dim1 ) + load j') v')
988
1018
Value. unit
989
1019
| _ ->
990
1020
let * f =
@@ -1002,9 +1032,12 @@ module Generate (Target : Target_sig.S) = struct
1002
1032
let ta' = transl_prim_arg ctx ta in
1003
1033
match get_type ctx ta with
1004
1034
| 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
1035
+ let i' = Var. fresh () in
1036
+ let j' = Var. fresh () in
1037
+ let k' = Var. fresh () in
1038
+ let dim0 = Var. fresh () in
1039
+ let dim1 = Var. fresh () in
1040
+ let dim2 = Var. fresh () in
1008
1041
let v' =
1009
1042
transl_prim_arg
1010
1043
ctx
@@ -1017,16 +1050,28 @@ module Generate (Target : Target_sig.S) = struct
1017
1050
v
1018
1051
in
1019
1052
seq
1020
- (let * cond = Arith. uge i' (Bigarray. dim 0 ta') in
1053
+ (let * () =
1054
+ store ~typ: I32 i' (transl_prim_arg ctx ~typ: (Int Normalized ) i)
1055
+ in
1056
+ let * () =
1057
+ store ~typ: I32 j' (transl_prim_arg ctx ~typ: (Int Normalized ) j)
1058
+ in
1059
+ let * () =
1060
+ store ~typ: I32 k' (transl_prim_arg ctx ~typ: (Int Normalized ) k)
1061
+ in
1062
+ let * () = store dim0 ~typ: I32 (Bigarray. dim 0 ta') in
1063
+ let * () = store dim1 ~typ: I32 (Bigarray. dim 1 ta') in
1064
+ let * () = store dim2 ~typ: I32 (Bigarray. dim 2 ta') in
1065
+ let * cond = Arith. uge (load i') (load dim0) in
1021
1066
let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
1022
- let * cond = Arith. uge j' ( Bigarray. dim 1 ta' ) in
1067
+ let * cond = Arith. uge (load j') (load dim1 ) in
1023
1068
let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
1024
- let * cond = Arith. uge k' ( Bigarray. dim 2 ta' ) in
1069
+ let * cond = Arith. uge (load k') (load dim2 ) in
1025
1070
let * () = instr (W. Br_if (label_index context bound_error_pc, cond)) in
1026
1071
Bigarray. set
1027
1072
~kind
1028
1073
ta'
1029
- Arith. ((((i' * Bigarray. dim 1 ta' ) + j') * Bigarray. dim 2 ta' ) + k')
1074
+ Arith. ((((load i' * load dim1 ) + load j') * load dim2 ) + load k')
1030
1075
v')
1031
1076
Value. unit
1032
1077
| _ ->
0 commit comments