Skip to content

Commit 4d24228

Browse files
committed
WIP
1 parent 8bd8126 commit 4d24228

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

compiler/lib-wasm/code_generation.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ module Arith = struct
368368
(match e, e' with
369369
| W.Const (I32 n), W.Const (I32 n') when Int32.(n' < 31l) ->
370370
W.Const (I32 (Int32.shift_left n (Int32.to_int n')))
371+
| _, W.Const (I32 0l) -> e
371372
| _ -> W.BinOp (I32 Shl, e, e'))
372373

373374
let ( lsr ) = binary (Shr U)

compiler/lib-wasm/gc_target.ml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,10 +1406,10 @@ module Bigarray = struct
14061406
let* x = x in
14071407
Memory.box_float (return (W.F64PromoteF32 x)) )
14081408
| Float64 -> "dv_get_f64", F64, 3, Memory.box_float
1409-
| Int8_signed -> "dv_get_i8", I32, 2, Fun.id
1410-
| Int8_unsigned | Char -> "dv_get_ui8", I32, 2, Fun.id
1411-
| Int16_signed -> "dv_get_i16", I32, 2, Fun.id
1412-
| Int16_unsigned -> "dv_get_ui16", I32, 2, Fun.id
1409+
| Int8_signed -> "dv_get_i8", I32, 0, Fun.id
1410+
| Int8_unsigned | Char -> "dv_get_ui8", I32, 0, Fun.id
1411+
| Int16_signed -> "dv_get_i16", I32, 1, Fun.id
1412+
| Int16_unsigned -> "dv_get_ui16", I32, 1, Fun.id
14131413
| Int32 -> "dv_get_i32", I32, 2, Memory.box_int32
14141414
| Nativeint -> "dv_get_i32", I32, 2, Memory.box_nativeint
14151415
| Int64 -> "dv_get_i64", I64, 3, Memory.box_int64
@@ -1427,8 +1427,8 @@ module Bigarray = struct
14271427
in
14281428
let* ty = Type.bigarray_type in
14291429
let* ta = Memory.wasm_struct_get ty (Memory.wasm_cast ty a) 2 in
1430-
let* i = if size = 1 then i else Arith.(i lsl const (Int32.of_int size)) in
1431-
box (return (W.Call (f, [ ta; i ])))
1430+
let* ofs = Arith.(i lsl const (Int32.of_int size)) in
1431+
box (return (W.Call (f, [ ta; ofs ])))
14321432

14331433
let set ~kind a i v =
14341434
let name, (typ : Wasm_ast.value_type), size, unbox =
@@ -1442,10 +1442,10 @@ module Bigarray = struct
14421442
let* e = Memory.unbox_float x in
14431443
return (W.F32DemoteF64 e) )
14441444
| Float64 -> "dv_set_f64", F64, 3, Memory.unbox_float
1445-
| Int8_signed -> "dv_set_i8", I32, 2, Fun.id
1446-
| Int8_unsigned | Char -> "dv_set_ui8", I32, 2, Fun.id
1447-
| Int16_signed -> "dv_set_i16", I32, 2, Fun.id
1448-
| Int16_unsigned -> "dv_set_ui16", I32, 2, Fun.id
1445+
| Int8_signed -> "dv_set_i8", I32, 0, Fun.id
1446+
| Int8_unsigned | Char -> "dv_set_ui8", I32, 0, Fun.id
1447+
| Int16_signed -> "dv_set_i16", I32, 1, Fun.id
1448+
| Int16_unsigned -> "dv_set_ui16", I32, 1, Fun.id
14491449
| Int32 -> "dv_set_i32", I32, 2, Memory.unbox_int32
14501450
| Nativeint -> "dv_set_i32", I32, 2, Memory.unbox_nativeint
14511451
| Int64 -> "dv_set_i64", I64, 3, Memory.unbox_int64
@@ -1454,7 +1454,7 @@ module Bigarray = struct
14541454
in
14551455
let* ty = Type.bigarray_type in
14561456
let* ta = Memory.wasm_struct_get ty (Memory.wasm_cast ty a) 2 in
1457-
let* i = if size = 1 then i else Arith.(i lsl const (Int32.of_int size)) in
1457+
let* ofs = Arith.(i lsl const (Int32.of_int size)) in
14581458
let* v = unbox v in
14591459
let* f =
14601460
register_import
@@ -1465,7 +1465,7 @@ module Bigarray = struct
14651465
; result = []
14661466
})
14671467
in
1468-
instr (W.CallInstr (f, [ ta; i; v ]))
1468+
instr (W.CallInstr (f, [ ta; ofs; v ]))
14691469
end
14701470

14711471
module JavaScript = struct

0 commit comments

Comments
 (0)