Skip to content

Commit

Permalink
first divergence is load
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuoguo committed Oct 5, 2024
1 parent 4c02ce3 commit 779be15
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 55 deletions.
85 changes: 40 additions & 45 deletions benchmarks/wasm/btree/2o1u-tee.wat
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
(module
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32) (result i32)))
(type (;2;) (func (param i32 i32) (result i32)))
(type (;3;) (func (param i32 i32)))
(type (;4;) (func (param i32 i32 i32)))
(type (;5;) (func))
(import "console" "log" (func (;0;) (type 0)))
(func (;1;) (type 1) (param i32) (result i32)
(type (;0;) (func (param i32) (result i32)))
(type (;1;) (func (param i32 i32) (result i32)))
(type (;2;) (func (param i32 i32)))
(type (;3;) (func (param i32 i32 i32)))
(type (;4;) (func))
(func (;0;) (type 0) (param i32) (result i32)
i32.const 0
local.get 0
i32.store
Expand All @@ -29,7 +27,7 @@
i32.store offset=4
end
i32.const 65536)
(func (;2;) (type 2) (param i32 i32) (result i32)
(func (;1;) (type 1) (param i32 i32) (result i32)
(local i32)
i32.const 0
local.set 2
Expand Down Expand Up @@ -109,7 +107,7 @@
i32.add
i32.load offset=8
local.get 1
call 2
call 1
end
end
else
Expand All @@ -134,10 +132,10 @@
i32.add
i32.load offset=8
local.get 1
call 2
call 1
end
end)
(func (;3;) (type 3) (param i32 i32)
(func (;2;) (type 2) (param i32 i32)
(local i32 i32)
i32.const 1
memory.grow
Expand Down Expand Up @@ -480,7 +478,7 @@
i32.add
i32.store offset=4
end)
(func (;4;) (type 3) (param i32 i32)
(func (;3;) (type 2) (param i32 i32)
(local i32 i32)
local.get 0
i32.load offset=4
Expand All @@ -489,10 +487,6 @@
local.set 2
local.get 0
i32.load
local.tee 3
local.get 3
call 0
unreachable
i32.const 1
i32.eq
if ;; label = @1
Expand Down Expand Up @@ -612,7 +606,7 @@
if ;; label = @2
local.get 0
local.get 2
call 3
call 2
local.get 1
local.get 0
i32.const 4
Expand Down Expand Up @@ -642,13 +636,14 @@
i32.add
i32.load offset=8
local.get 1
call 4
call 3
end)
(func (;5;) (type 1) (param i32) (result i32)
(func (;4;) (type 0) (param i32) (result i32)
(local i32 i32)
i32.const 0
i32.load offset=8
local.tee 2
unreachable
i32.load offset=4
i32.const 0
i32.load
Expand Down Expand Up @@ -699,21 +694,21 @@
i32.store offset=8
local.get 1
i32.const 0
call 3
call 2
local.get 1
local.get 0
call 4
call 3
local.get 1
else
i32.const -1
end
else
local.get 2
local.get 0
call 4
call 3
local.get 2
end)
(func (;6;) (type 2) (param i32 i32) (result i32)
(func (;5;) (type 1) (param i32 i32) (result i32)
(local i32 i32 i32 i32)
local.get 0
i32.load
Expand Down Expand Up @@ -894,7 +889,7 @@
i32.mul
i32.add
i32.load offset=8
call 6
call 5
drop
i32.store offset=8
else
Expand Down Expand Up @@ -939,7 +934,7 @@
i32.mul
i32.add
i32.load offset=8
call 6
call 5
drop
i32.store offset=8
else
Expand Down Expand Up @@ -1230,7 +1225,7 @@
i32.store offset=4
local.get 5
local.get 1
call 6
call 5
drop
end
end
Expand Down Expand Up @@ -2531,12 +2526,12 @@
i32.add
i32.load offset=8
local.get 1
call 6
call 5
drop
else
local.get 5
local.get 1
call 6
call 5
drop
end
end
Expand Down Expand Up @@ -2566,7 +2561,7 @@
end
i32.const 0
i32.load offset=8)
(func (;7;) (type 4) (param i32 i32 i32)
(func (;6;) (type 3) (param i32 i32 i32)
(local i32)
local.get 0
local.get 1
Expand All @@ -2584,58 +2579,58 @@
unreachable
end
i32.const 4
call 1
call 0
local.set 3
local.get 0
call 5
call 4
local.set 3
local.get 1
call 5
call 4
local.set 3
local.get 2
call 5
call 4
local.set 3
local.get 3
local.get 0
call 2
call 1
i32.const -1
i32.ne
local.get 3
local.get 1
call 2
call 1
i32.const -1
i32.ne
local.get 3
local.get 2
call 2
call 1
i32.const -1
i32.ne
i32.and
i32.and
local.get 3
local.get 0
call 6
call 5
local.tee 3
local.get 0
call 2
call 1
i32.const -1
i32.eq
local.get 3
local.get 1
call 6
call 5
local.tee 3
local.get 1
call 2
call 1
i32.const -1
i32.eq
i32.and
i32.and
drop)
(func (;8;) (type 5)
(func (;7;) (type 4)
i32.const 3
i32.const 2
i32.const 1
call 7)
call 6)
(memory (;0;) 2)
(start 8)
)
(export "main" (func 7))
(start 7))
11 changes: 5 additions & 6 deletions benchmarks/wasm/btree/2o1u.wat
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,6 @@
(local.set 2) ;; i = x.n -1
(local.get 0) ;; x
(i32.load) ;; get first i32 --> isLeaf
;; (local.tee $tmp)
;; (local.get $tmp)
;; (call $log)
(unreachable)
(i32.const 1)
(i32.eq) ;; is leaf?
(if
Expand Down Expand Up @@ -708,6 +704,10 @@
(i32.const 0)
(i32.load offset=8) ;; root addr
(local.tee 2) ;; set r
;; FIXME: first divergence
;; tos should be 65536, but we got 256
;; (call $log)
(unreachable)
(i32.load offset=4) ;; r.n
(i32.const 0)
(i32.load) ;; t
Expand Down Expand Up @@ -2822,5 +2822,4 @@
call $main
)
(start $real_main)
(export "real_main" (func $real_main))
)
)
4 changes: 2 additions & 2 deletions src/main/scala/wasm/MiniWasm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ object Evaluator {
val inst = insts.head
val rest = insts.tail

//println(f"stack size: ${stack.size}")
//println(s"eval: $inst")
// println(s"inst: ${inst} \t | ${frame.locals} | ${stack.reverse}" )

inst match {
case Drop => eval(rest, stack.tail, frame, kont, trail, ret)
case Select(_) =>
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/genwasym/TestEval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class TestEval extends FunSuite {
test("return") { testFile("./benchmarks/wasm/return.wat", None, None) }

// Parser works, but the memory issue remains
test("btree") { testFile("./benchmarks/wasm/btree/2o1u-tee.wat") }
// test("btree") { testFile("./benchmarks/wasm/btree/2o1u-tee.wat") }

// TODO: add more wasm spec tests?
// test("memory") { test_btree("./benchmarks/wasm/spectest/test.wat", "$real_main") }
// test("memory") { testFile("./benchmarks/wasm/spectest/test.wat") }
}

0 comments on commit 779be15

Please sign in to comment.