Skip to content

Commit 2883aac

Browse files
committed
Unboxed numbers
Avoid boxing numbers if the boxed value is never actually used.
1 parent 96519eb commit 2883aac

File tree

5 files changed

+868
-343
lines changed

5 files changed

+868
-343
lines changed

compiler/lib-wasm/gc_target.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,7 @@ module Memory = struct
676676
let* l =
677677
expression_list
678678
(fun y ->
679-
if Code.Var.equal y deadcode_sentinal
680-
then return (W.Const (F64 0.))
681-
else unbox_float (load y))
679+
if Code.Var.equal y deadcode_sentinal then return (W.Const (F64 0.)) else load y)
682680
l
683681
in
684682
let* ty = Type.float_array_type in
@@ -731,10 +729,9 @@ module Memory = struct
731729

732730
let array_set e e' e'' = wasm_array_set e Arith.(e' + const 1l) e''
733731

734-
let float_array_get e e' = box_float (wasm_array_get ~ty:Type.float_array_type e e')
732+
let float_array_get e e' = wasm_array_get ~ty:Type.float_array_type e e'
735733

736-
let float_array_set e e' e'' =
737-
wasm_array_set ~ty:Type.float_array_type e e' (unbox_float e'')
734+
let float_array_set e e' e'' = wasm_array_set ~ty:Type.float_array_type e e' e''
738735

739736
let gen_array_get e e' =
740737
let a = Code.Var.fresh_n "a" in
@@ -1037,9 +1034,12 @@ module Constant = struct
10371034
let* e = Memory.make_int32 ~kind:`Nativeint (return (W.Const (I32 i))) in
10381035
return (Const, e)
10391036

1040-
let translate c =
1037+
let translate ~unboxed c =
10411038
match c with
10421039
| Code.Int i -> return (W.Const (I32 (Targetint.to_int32 i)))
1040+
| Float f when unboxed -> return (W.Const (F64 (Int64.float_of_bits f)))
1041+
| Int64 i when unboxed -> return (W.Const (I64 i))
1042+
| (Int32 i | NativeInt i) when unboxed -> return (W.Const (I32 i))
10431043
| _ -> (
10441044
let* const, c = translate_rec c in
10451045
match const with

0 commit comments

Comments
 (0)