Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single-pass native code generation for x86-64 using dynasm. #276

Merged
merged 112 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from 111 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
9649219
Initial work on WebAssembly parser for Dynasm backend.
losfair Feb 8, 2019
f735471
Merge remote-tracking branch 'private/master' into feature/dynasm-bac…
losfair Feb 11, 2019
af19f5c
Update dependencies.
losfair Feb 11, 2019
bbb27be
Code generation framework.
losfair Feb 11, 2019
ffc1bde
Cleanup & add imports.
losfair Feb 11, 2019
2fbb5e3
Codegen backend for x64.
losfair Feb 11, 2019
4ebb22f
Calling conventions, value stack, and runtime stack layout.
losfair Feb 12, 2019
a69c5b4
stack: Helper functions and unified return types
losfair Feb 13, 2019
43df3dd
Use System V calling convention and implement a few opcodes.
losfair Feb 13, 2019
7df7204
codegen: More opcodes
losfair Feb 13, 2019
8d8db4a
Starting integration.
losfair Feb 13, 2019
1526d35
Emit a Return opcode if the last one is not return.
losfair Feb 14, 2019
bb52a4e
Now we can run `add`!
losfair Feb 14, 2019
5583e96
Mitigate a bug that causes incorrect code generation.
losfair Feb 19, 2019
93d2713
Operators.
losfair Feb 19, 2019
61c8350
Control frames, jumps & stack unwinding.
losfair Feb 20, 2019
aaabbf1
Operator::Br and control stack fixes
losfair Feb 20, 2019
6f97ebd
Remove a hack in parser.
losfair Feb 21, 2019
63b3f41
Handle unreachable and fix return.
losfair Feb 21, 2019
7c43993
Block and conditional branch.
losfair Feb 21, 2019
08a2ec8
Unary operators, comparison opcodes, loops, etc.
losfair Feb 22, 2019
693c9fd
Single-pass backend tests.
losfair Feb 22, 2019
e9c0325
Update dependencies
losfair Feb 23, 2019
09cbd4a
Changed to using custom calling conventions; Implemented direct calls.
losfair Feb 23, 2019
b2f5f77
Add direct call test
losfair Feb 23, 2019
dbebdf9
Code generation for br_table.
losfair Feb 24, 2019
2432a6c
Fix function calls.
losfair Feb 25, 2019
da1a3fa
Add test for br_table.
losfair Feb 25, 2019
80812e3
Implement native call & fix stack alignment.
losfair Feb 25, 2019
78fd995
Fix argument passing at entry.
losfair Feb 25, 2019
b18595f
Pass command-line arguments to wasm as i32.
losfair Feb 25, 2019
5302949
Allow more registers to be used.
losfair Feb 25, 2019
9d8c5a5
Add a note on incorrect code generation.
losfair Feb 25, 2019
3c3c5db
Native trampolines.
losfair Feb 26, 2019
d50f1cc
If/Else.
losfair Feb 27, 2019
ec9a8f0
Add test for if/else.
losfair Feb 27, 2019
b7ca5e4
Add Select opcode.
losfair Feb 28, 2019
adb309f
Add select test.
losfair Feb 28, 2019
64142c4
Reserve R15.
losfair Feb 28, 2019
e026adf
Initial work on linear memory.
losfair Feb 28, 2019
aa75994
Add memory opcodes and test.
losfair Mar 1, 2019
2962fe2
Add unwinding test.
losfair Mar 1, 2019
fa61b66
Strongly type scratch registers and fixed an unwinding issue.
losfair Mar 4, 2019
bd7698e
64-bit operators.
losfair Mar 4, 2019
5a97a25
Add basic test for i64.
losfair Mar 4, 2019
27b2061
Implemented missing integer operators and fixed division.
losfair Mar 5, 2019
8d2e877
tee_local and div tests
losfair Mar 5, 2019
12c2137
Hack around calling imports. Not yet working.
losfair Mar 7, 2019
258dea6
Fix calling imports.
losfair Mar 8, 2019
4c4743e
Globals.
losfair Mar 8, 2019
3efccbe
Support imported globals.
losfair Mar 8, 2019
25034ec
Almost finished indirect calls.
losfair Mar 8, 2019
c6dfbcd
Add tests.
losfair Mar 8, 2019
c5ef0a9
Update vm::Ctx.
losfair Mar 8, 2019
683cb20
Fix call_indirect.
losfair Mar 12, 2019
c3b0bd7
Validate return values in indirect call test.
losfair Mar 12, 2019
1fc7b31
Add missing trait items to DynasmCompiler so that cargo build --all w…
bjfish Mar 13, 2019
557be77
Merge branch 'master' into feature/dynasm-backend
bjfish Mar 13, 2019
a5bab8c
Updates to compile dynasm after merge from master
bjfish Mar 13, 2019
68181ac
Add dynasm to spectests
bjfish Mar 13, 2019
d4ded2c
Fix bugs found when running spectests.
losfair Mar 13, 2019
179bbf9
Fix integer division.
losfair Mar 14, 2019
e5d67c9
Add dynasm feature to emscripten tests
bjfish Mar 14, 2019
d80ea47
FIx bugs found with spectests.
losfair Mar 14, 2019
c76887d
Merge remote-tracking branch 'private/feature/dynasm-backend' into fe…
losfair Mar 14, 2019
592c3fb
Fixes and some floating point operations.
losfair Mar 14, 2019
4d2b6a0
Add Copy + Clone for IfElseState
losfair Mar 14, 2019
1104073
Implemented more floating point operations.
losfair Mar 14, 2019
1b5ea9b
Passes all `assert_return(_*)` tests.
losfair Mar 14, 2019
53a8fca
Make wasmer executable work with dynasm
syrusakbary Mar 16, 2019
81af8cf
Fixed several bugs in the single-pass backend and implemented a runti…
losfair Mar 16, 2019
1f8c644
Merge remote-tracking branch 'private/feature/dynasm-backend' into fe…
losfair Mar 16, 2019
f8fe999
Implemented protected call and floating point traps; passing all spec…
losfair Mar 17, 2019
d8d39c3
Fix warnings.
losfair Mar 17, 2019
7394df2
FIx floating point trunc's.
losfair Mar 17, 2019
08f4526
Merge remote-tracking branch 'origin/master' into feature/dynasm-backend
losfair Mar 17, 2019
fcfde73
Use R15 as temporary register.
losfair Mar 17, 2019
337b2eb
Add dynasm tests to the Makefile
bjfish Mar 17, 2019
99faa79
Run cargo fmt.
losfair Mar 17, 2019
6c40ea1
Cargo fmt more files.
losfair Mar 17, 2019
e2a3887
Merge remote-tracking branch 'private/feature/dynasm-backend' into fe…
losfair Mar 17, 2019
4ca27b6
Manually fix lint errors.
losfair Mar 17, 2019
e48ff02
Remove commented out code.
losfair Mar 17, 2019
c5694ec
Fix lint errors.
losfair Mar 17, 2019
662a649
Only run dynasm tests on nightly.
losfair Mar 17, 2019
e1cb4fc
Removed submodule cranlift
bjfish Mar 17, 2019
caa239a
Make wasmer-dynasm-backend optional.
losfair Mar 18, 2019
75678b5
Merge remote-tracking branch 'origin/feature/dynasm-backend' into fea…
losfair Mar 18, 2019
b94c046
Remove println.
losfair Mar 18, 2019
af8f307
Fix dependencies.
losfair Mar 18, 2019
cd5c145
Fix default compiler.
losfair Mar 18, 2019
b06a49e
Move wasmer-dynasm-backend out of default-compiler.
losfair Mar 18, 2019
eb606a6
Disable clippy temporarily.
losfair Mar 18, 2019
af24cfc
Exclude dynasm backend in cargo test.
losfair Mar 18, 2019
2ab2205
Allow cross-module indirect calls.
losfair Mar 19, 2019
ebaf2dc
Make DynFunc::func_index private.
losfair Mar 19, 2019
61abe70
cargo fmt
losfair Mar 19, 2019
a006a36
Cleanup.
losfair Mar 19, 2019
14da8ab
Run-time memory bound checking.
losfair Mar 19, 2019
4256ccb
Cleanup & fix need_check condition.
losfair Mar 19, 2019
7ee364a
Cargo fmt.
losfair Mar 19, 2019
fd60631
Remove '+nightly' in Makefile.
losfair Mar 19, 2019
f0e8f22
Merge remote-tracking branch 'origin/master' into feature/dynasm-backend
losfair Mar 19, 2019
82b2034
Run clippy on nightly rust.
losfair Mar 19, 2019
8b85099
Unset global git redirection.
losfair Mar 19, 2019
295efbf
Fix clippy errors.
losfair Mar 19, 2019
01f18b2
Merge remote-tracking branch 'origin/master' into feature/dynasm-backend
losfair Mar 19, 2019
395161a
Merge remote-tracking branch 'origin/master' into feature/dynasm-backend
losfair Mar 20, 2019
cb3846f
Add `InternalCtx`.
losfair Mar 21, 2019
a4ee873
Merge remote-tracking branch 'origin/master' into feature/dynasm-backend
losfair Mar 21, 2019
26e4278
Make the `internal` field private from outside.
losfair Mar 21, 2019
08ba696
Fix vmctx offset tests.
losfair Mar 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ jobs:
- run:
name: Install lint deps
command: |
git config --global --unset url."ssh://git@github.com".insteadOf || true
rustup toolchain install nightly
rustup component add rustfmt
rustup component add clippy
rustup component add clippy --toolchain=nightly || cargo +nightly install --git https://github.com/rust-lang/rust-clippy/ --force clippy
- run:
name: Execute lints
command: |
Expand Down Expand Up @@ -274,6 +276,9 @@ jobs:
- run: |
export LLVM_SYS_70_PREFIX="`pwd`/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/"
make test
make test-nightly
make test-emscripten
make test-emscripten-nightly
- save_cache:
paths:
- /usr/local/cargo/registry
Expand Down
68 changes: 68 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ wasmer-clif-backend = { path = "lib/clif-backend" }
wasmer-runtime = { path = "lib/runtime" }
wasmer-runtime-core = { path = "lib/runtime-core" }
wasmer-emscripten = { path = "lib/emscripten" }

[target.'cfg(not(windows))'.dependencies]
losfair marked this conversation as resolved.
Show resolved Hide resolved
wasmer-llvm-backend = { path = "lib/llvm-backend", optional = true }
wasmer-dynasm-backend = { path = "lib/dynasm-backend", optional = true }

[workspace]
members = ["lib/clif-backend", "lib/runtime", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend"]
members = ["lib/clif-backend", "lib/dynasm-backend", "lib/runtime", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend"]
losfair marked this conversation as resolved.
Show resolved Hide resolved

[build-dependencies]
wabt = "0.7.2"
Expand All @@ -42,3 +41,4 @@ default = ["fast-tests"]
# This feature will allow cargo test to run much faster
fast-tests = []
llvm = ["wasmer-llvm-backend"]
dynasm = ["wasmer-dynasm-backend"]
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,29 @@ integration-tests: release

lint:
cargo fmt --all -- --check
cargo clippy --all
cargo +nightly clippy --all

precommit: lint test

test:
# We use one thread so the emscripten stdouts doesn't collide
cargo test --all --exclude wasmer-runtime-c-api --exclude wasmer-emscripten --exclude wasmer-spectests -- $(runargs)
cargo test --all --exclude wasmer-runtime-c-api --exclude wasmer-emscripten --exclude wasmer-spectests --exclude wasmer-dynasm-backend -- $(runargs)
# cargo test --all --exclude wasmer-emscripten -- --test-threads=1 $(runargs)
cargo test --manifest-path lib/spectests/Cargo.toml --features clif
cargo test --manifest-path lib/spectests/Cargo.toml --features llvm
cargo build -p wasmer-runtime-c-api
cargo test -p wasmer-runtime-c-api -- --nocapture

test-nightly:
cargo test --manifest-path lib/spectests/Cargo.toml --features dynasm

test-emscripten:
cargo test --manifest-path lib/emscripten/Cargo.toml --features clif -- --test-threads=1 $(runargs)
cargo test --manifest-path lib/emscripten/Cargo.toml --features llvm -- --test-threads=1 $(runargs)

test-emscripten-nightly:
cargo test --manifest-path lib/emscripten/Cargo.toml --features dynasm -- --test-threads=1 $(runargs)

release:
# If you are in OS-X, you will need mingw-w64 for cross compiling to windows
# brew install mingw-w64
Expand Down
37 changes: 37 additions & 0 deletions examples/single_pass_tests/br_table.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(module
(func $main (export "main")
(i32.eq (call $test (i32.const 0)) (i32.const 2))
(i32.eq (call $test (i32.const 1)) (i32.const 0))
(i32.eq (call $test (i32.const 2)) (i32.const 1))
(i32.eq (call $test (i32.const 3)) (i32.const 3))
(i32.eq (call $test (i32.const 4)) (i32.const 3))
(i32.and)
(i32.and)
(i32.and)
(i32.and)
(i32.const 1)
(i32.eq)
(br_if 0)
(unreachable)
)

(func $test (param $p i32) (result i32)
(block
(block
(block
(block
(block
(get_local $p)
(br_table 2 0 1 3)
)
(return (i32.const 0))
)
(return (i32.const 1))
)
(return (i32.const 2))
)
(return (i32.const 3))
)
(unreachable)
)
)
23 changes: 23 additions & 0 deletions examples/single_pass_tests/call.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(module
(func $main (export "main")
(local $a i32)
(block
(set_local $a (i32.const 33))
(i32.const 11)
(call $foo (get_local $a))
(i32.add)
(i32.const 86)
(i32.eq)
(br_if 0)
(unreachable)
)
)

(func $foo (param $input i32) (result i32)
(local $a i32)
(set_local $a (i32.const 42))
(get_local $a)
(get_local $input)
(i32.add)
)
)
25 changes: 25 additions & 0 deletions examples/single_pass_tests/call_indirect.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(module
(type $binop (func (param i32 i32) (result i32)))
(table 1 100 anyfunc)
(elem (i32.const 5) $sub)
(elem (i32.const 10) $add)

(func $main (export "main")
(if (i32.eq (call_indirect (type $binop) (i32.const 42) (i32.const 1) (i32.const 10)) (i32.const 43))
(then)
(else unreachable)
)
(if (i32.eq (call_indirect (type $binop) (i32.const 42) (i32.const 1) (i32.const 5)) (i32.const 41))
(then)
(else unreachable)
)
)

(func $add (param i32) (param i32) (result i32)
(i32.add (get_local 0) (get_local 1))
)

(func $sub (param i32) (param i32) (result i32)
(i32.sub (get_local 0) (get_local 1))
)
)
36 changes: 36 additions & 0 deletions examples/single_pass_tests/div.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(module
(func $main (export "main")
(i32.const 1)
(if (i32.ne (i32.div_s (i32.const 2) (i32.const -1)) (i32.const -2))
(then unreachable)
)
(i32.const 2)
(if (i32.ne (i32.div_u (i32.const 2) (i32.const -1)) (i32.const 0))
(then unreachable)
)
(i32.const 3)
(if (i32.ne (i32.div_u (i32.const 10) (i32.const 5)) (i32.const 2))
(then unreachable)
)
(i32.const 4)
(if (i64.ne (i64.div_s (i64.const 300000000000) (i64.const -1)) (i64.const -300000000000))
(then unreachable)
)
(i32.const 5)
(if (i64.ne (i64.div_u (i64.const 300000000000) (i64.const -1)) (i64.const 0))
(then unreachable)
)
(i32.const 6)
(if (i64.ne (i64.div_u (i64.const 300000000000) (i64.const 2)) (i64.const 150000000000))
(then unreachable)
)
(i32.add)
(i32.add)
(i32.add)
(i32.add)
(i32.add)
(if (i32.ne (i32.const 21))
(then unreachable)
)
)
)
26 changes: 26 additions & 0 deletions examples/single_pass_tests/global.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(module
(global $g1 (mut i32) (i32.const 0))
(global $g2 (mut i32) (i32.const 99))
(func $main (export "main")
(if (i32.eq (get_global $g1) (i32.const 0))
(then)
(else unreachable)
)
(if (i32.eq (get_global $g2) (i32.const 99))
(then)
(else unreachable)
)

(set_global $g1 (i32.add (get_global $g1) (i32.const 1)))
(set_global $g2 (i32.sub (get_global $g2) (i32.const 1)))

(if (i32.eq (get_global $g1) (i32.const 1))
(then)
(else unreachable)
)
(if (i32.eq (get_global $g2) (i32.const 98))
(then)
(else unreachable)
)
)
)
Loading