Commit Graph

128 Commits

Author SHA1 Message Date
Takeshi Yoneda
84e796978b Introduce internal pkg, reorganize directories (#158)
This PR introduces internal directory and put all the following non-user-relevant packages there:

* wazeroir
* leb128
* ieee754
* wasm/example
*spectests

Also this creates interpreter package where we put the wazeroir interpreter taken out of wazeroir pkg
since the fact wazeroir.NewEngine returns interpreter is not intuitive to users and IR is IR so it shouldn’t
be the matter of users.


Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-01-24 09:08:55 +09:00
Crypt Keeper
152ecac8d6 Adds wasm.EncodeModule and wasm.DecodeModule (#142)
This moves encoding logic into the packages binary and text, adding a
new top-level function for encoding and decoding:

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-01-18 12:43:53 +08:00
Takeshi Yoneda
9beec85a76 Delete simple.wasm (#112) 2022-01-03 10:58:16 +09:00
Crypt Keeper
c3b79a4f40 Completes basic implementation of wat.TextToBinary (#108)
The completes the minimal features required to run the following:

```
(module
	(import "" "hello" (func $hello))
	(start $hello)
)
```

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-01-02 09:12:27 +08:00
Takeshi Yoneda
26ee5eb735 Rename Go source dirs for Wasms to testdata. (#106)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-12-31 17:33:03 +09:00
Crypt Keeper
255176479e Simplifies simple example and clarifies the StartSection (#95)
A particularly confusing point is that function indices in Wasm are
preceded by imports. Hopefully, this helps reduce that confusion.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2021-12-29 16:32:38 +08:00
Crypt Keeper
47e0509feb Adds a new example and adjusts some naming (#94)
This adds a simpler example, which helps understand the basic ins and
outs. This will be used later when the %.wat parser is implemented.

Along the way, I noticed naming inconsistency. Most of the time,
function inputs are named params and outputs are named results. Using
the same vocab helps when mapping the spec to our code.

See https://www.w3.org/TR/wasm-core-1/#function-types%E2%91%A6

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-12-28 10:01:23 +08:00
Takeshi Yoneda
2d72d04c77 Remove naivevm. (#80)
resolves #79

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-12-22 09:40:00 +09:00
Takeshi Yoneda
f493238c83 examples: panic on errors in Wasm. (#57)
This commit makes sure that in-Wasm errors are detected as panics in examples.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-11-22 16:34:48 +09:00
Takeshi Yoneda
535a4c22eb Update TinyGo to 0.21.0 for example builds. (#55)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-11-19 09:59:33 +09:00
Takeshi Yoneda
a02b010fa2 Execute _start func before benches. (#53)
Previously, we didn't execute _start function which is in charge of
in-Wasm memory state initialization.

That's why we faced the memory related error with -gc=conservative
which is the default validator.

Also this commit revives the file system example which was temporarily removed.
2021-11-18 17:19:37 +09:00
Takeshi Yoneda
4fda76e203 Emit backtrace in runtime error message. (#54)
This commit adds the parser of the "name" custom section[1],
and starts emitting the backtrace of the program into the runtime error message
by leveraging the function name informations stored in "name" custom section.

Note that this is the minimal implementation -- the trace doesn't contain the
original Wasm instruction address nor the source code info. The former
can be implemented easily but the latter requires us to implement the Wasm
DWARF format parser of .debug_* custom sections[2].

[1] https://webassembly.github.io/spec/core/appendix/custom.html#name-section
[2] https://yurydelendik.github.io/webassembly-dwarf/

The following is the output from examples/trap_test.go:

=== RUN   Test_trap
panic: causing panic!!!!!!!!!!
wasm runtime error: unreachable
wasm backtrace:
	0: runtime._panic
	1: main.three
	2: main.two
	3: main.one
	4: cause_panic
2021-11-18 15:29:43 +09:00
Takeshi Yoneda
6f7d68bcf0 Fix benchmarks and add more cases. (#51)
Some of the benchmarks have been broken as we didn't 
check the errors. This commit fixes it, add more cases
and produces the actual benchmark results.

___

goarch: amd64
cpu: AMD Ryzen 9 3950X 16-Core Processor            
BenchmarkEngines
BenchmarkEngines/naivevm
BenchmarkEngines/naivevm/base64_5_per_exec
BenchmarkEngines/naivevm/base64_5_per_exec-32           1000000000               0.0007209 ns/op               0 B/op          0 allocs/op
BenchmarkEngines/naivevm/base64_100_per_exec
BenchmarkEngines/naivevm/base64_100_per_exec-32         1000000000               0.01021 ns/op         0 B/op          0 allocs/op
BenchmarkEngines/naivevm/base64_10000_per_exec
BenchmarkEngines/naivevm/base64_10000_per_exec-32       1000000000               0.5875 ns/op          0 B/op          0 allocs/op
BenchmarkEngines/naivevm/fibofor_5
BenchmarkEngines/naivevm/fibofor_5-32                      88412             14147 ns/op            9224 B/op        380 allocs/op
BenchmarkEngines/naivevm/fibofor_10
BenchmarkEngines/naivevm/fibofor_10-32                      6082            167432 ns/op          108936 B/op       4511 allocs/op
BenchmarkEngines/naivevm/fibofor_20
BenchmarkEngines/naivevm/fibofor_20-32                        56          20171810 ns/op        13473914 B/op     558218 allocs/op
BenchmarkEngines/naivevm/string_manipulation_size_50
BenchmarkEngines/naivevm/string_manipulation_size_50-32                      214           5451473 ns/op         3536602 B/op     146660 allocs/op
BenchmarkEngines/naivevm/string_manipulation_size_100
BenchmarkEngines/naivevm/string_manipulation_size_100-32                      79          15338381 ns/op         9842499 B/op     406379 allocs/op
BenchmarkEngines/naivevm/string_manipulation_size_1000
BenchmarkEngines/naivevm/string_manipulation_size_1000-32                      2         924341970 ns/op        602264464 B/op  24639795 allocs/op
BenchmarkEngines/naivevm/reverse_array_size_500
BenchmarkEngines/naivevm/reverse_array_size_500-32                          1034           1136004 ns/op          755544 B/op      30876 allocs/op
BenchmarkEngines/naivevm/reverse_array_size_1000
BenchmarkEngines/naivevm/reverse_array_size_1000-32                          501           2158362 ns/op         1508296 B/op      61626 allocs/op
BenchmarkEngines/naivevm/reverse_array_size_10000
BenchmarkEngines/naivevm/reverse_array_size_10000-32                          48          21937936 ns/op        15057797 B/op     615126 allocs/op
BenchmarkEngines/naivevm/random_mat_mul_size_5
BenchmarkEngines/naivevm/random_mat_mul_size_5-32                            746           1614151 ns/op         1059720 B/op      45503 allocs/op
BenchmarkEngines/naivevm/random_mat_mul_size_10
BenchmarkEngines/naivevm/random_mat_mul_size_10-32                           157           7612253 ns/op         5061602 B/op     215029 allocs/op
BenchmarkEngines/naivevm/random_mat_mul_size_100
BenchmarkEngines/naivevm/random_mat_mul_size_100-32                            1        4734519289 ns/op        3246427296 B/op 133368916 allocs/op
BenchmarkEngines/wazeroir
BenchmarkEngines/wazeroir/base64_5_per_exec
BenchmarkEngines/wazeroir/base64_5_per_exec-32                          1000000000               0.0000669 ns/op               0 B/op          0 allocs/op
BenchmarkEngines/wazeroir/base64_100_per_exec
BenchmarkEngines/wazeroir/base64_100_per_exec-32                        1000000000               0.0007913 ns/op               0 B/op          0 allocs/op
BenchmarkEngines/wazeroir/base64_10000_per_exec
BenchmarkEngines/wazeroir/base64_10000_per_exec-32                      1000000000               0.05185 ns/op         0 B/op          0 allocs/op
BenchmarkEngines/wazeroir/fibofor_5
BenchmarkEngines/wazeroir/fibofor_5-32                                    853510              1298 ns/op             144 B/op         10 allocs/op
BenchmarkEngines/wazeroir/fibofor_10
BenchmarkEngines/wazeroir/fibofor_10-32                                    84042             13943 ns/op            1440 B/op         91 allocs/op
BenchmarkEngines/wazeroir/fibofor_20
BenchmarkEngines/wazeroir/fibofor_20-32                                      710           1714837 ns/op          175153 B/op      10948 allocs/op
BenchmarkEngines/wazeroir/string_manipulation_size_50
BenchmarkEngines/wazeroir/string_manipulation_size_50-32                    2751            367486 ns/op           34444 B/op        911 allocs/op
BenchmarkEngines/wazeroir/string_manipulation_size_100
BenchmarkEngines/wazeroir/string_manipulation_size_100-32                   1292            923810 ns/op           83649 B/op       1811 allocs/op
BenchmarkEngines/wazeroir/string_manipulation_size_1000
BenchmarkEngines/wazeroir/string_manipulation_size_1000-32                    25          49036675 ns/op         5807610 B/op      18011 allocs/op
BenchmarkEngines/wazeroir/reverse_array_size_500
BenchmarkEngines/wazeroir/reverse_array_size_500-32                        21375             58553 ns/op           12648 B/op          3 allocs/op
BenchmarkEngines/wazeroir/reverse_array_size_1000
BenchmarkEngines/wazeroir/reverse_array_size_1000-32                       10590            114361 ns/op              40 B/op          3 allocs/op
BenchmarkEngines/wazeroir/reverse_array_size_10000
BenchmarkEngines/wazeroir/reverse_array_size_10000-32                       1020           1227607 ns/op          645119 B/op          3 allocs/op
BenchmarkEngines/wazeroir/random_mat_mul_size_5
BenchmarkEngines/wazeroir/random_mat_mul_size_5-32                         10677            110478 ns/op            2920 B/op        183 allocs/op
BenchmarkEngines/wazeroir/random_mat_mul_size_10
BenchmarkEngines/wazeroir/random_mat_mul_size_10-32                         2278            491795 ns/op            8776 B/op        549 allocs/op
BenchmarkEngines/wazeroir/random_mat_mul_size_100
BenchmarkEngines/wazeroir/random_mat_mul_size_100-32                           4         281132028 ns/op          659944 B/op      41247 allocs/op
2021-11-17 15:17:17 +09:00
Takeshi Yoneda
d0e318b700 Use wazeroir in examples. (#50)
As per #49, this commit uses wazeroir in examples to showcase that it is the default engine we recommend.
2021-11-17 12:54:45 +09:00
Takeshi Yoneda
2a88bf56ca Add basic benchmarks among engines. (#49)
This commit adds the basic benchmark to compare the performance of
different engine implementations (currently naivevm vs wazeroir interpreter).
Notably this proves that wazeroir interpreter drastically outperforms the
naivevm by the order of magnitudes.

___

goos: linux
goarch: amd64
cpu: AMD Ryzen 9 3950X 16-Core Processor            
BenchmarkEngines/naivevm/base64_5_per_exec-32             442126              2504 ns/op
BenchmarkEngines/naivevm/base64_100_per_exec-32           421365              2524 ns/op
BenchmarkEngines/naivevm/base64_10000_per_exec-32         461840              2499 ns/op
BenchmarkEngines/naivevm/fibo_for_5-32                     52987             21711 ns/op
BenchmarkEngines/naivevm/fibo_for_10-32                     4387            273636 ns/op
BenchmarkEngines/naivevm/fibo_for_20-32                       32          34090849 ns/op
BenchmarkEngines/wazeroir/base64_5_per_exec-32           3209636               383.2 ns/op
BenchmarkEngines/wazeroir/base64_100_per_exec-32         3116974               391.3 ns/op
BenchmarkEngines/wazeroir/base64_10000_per_exec-32       2948252               382.7 ns/op
BenchmarkEngines/wazeroir/fibo_for_5-32                  2899800               395.1 ns/op
BenchmarkEngines/wazeroir/fibo_for_10-32                 2981100               397.8 ns/op
BenchmarkEngines/wazeroir/fibo_for_20-32                 2958919               395.1 ns/op
2021-11-16 22:37:24 +09:00
Takeshi Yoneda
abc52fdd36 Fix cursive VM calls with naivevm runtime. (#48)
This commit fixes a bug that exists in naivevm implementation
around stack frames. Notably this fixes the usage of
recursive VM calls (i.e. calling VM functions inside of the
host function implementations). In order to test the behavior,
we enhance the host_func.go example so that we use
the recursive VM calls.
2021-11-16 17:31:04 +09:00
Crypt Keeper
41082efeaf Ensures examples build (#45)
This adds CI for example code TinyGo -> Wasm. Differences are ignored because compilation is not idempotent.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2021-11-15 16:36:09 +09:00
Crypt Keeper
046a7c2107 Renames to tetratelabs/wazero (#43)
This renames the project to wazero, which emphasizes that this runtime
has no platform depedencies (notably CGO). To avoid having users change
their imports twice, this also changes the org to "tetratelabs" ahead of
transfer.

Exciting times ahead, wazeros!

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2021-11-05 16:13:23 +08:00
Takeshi Yoneda
23df8dc412 refactor: introduce the concept of Engine (#34) 2021-10-22 17:16:11 +09:00
Takeshi Yoneda
f3b2f8ce89 Add call stack limits. (#33)
This commit completes the Wasm specification tests -- check the VM is guarded against the callstack exhaustion via assert_exhaustion tests.
2021-10-18 22:30:24 +09:00
Takeshi Yoneda
f9dad5e6df Make function calls direct jmps. (#32) 2021-10-17 14:14:58 +09:00
Takeshi Yoneda
5d555254ac Refactor / Pass Wasm Specification test suites. (#27) 2021-10-07 21:35:04 +09:00
Gaboose
71556e50c4 wasi: add stdio and file system support (#22) 2021-04-03 08:09:38 +09:00
mathetake
07ad79d1e3 tiny fix 2020-05-11 21:53:52 +09:00
mathetake
779f8b5365 unittest: vm.go 2020-05-09 18:06:17 +09:00
mathetake
378c1a4dd7 refactor: hostfunc module builder 2020-05-09 14:04:58 +09:00
mathetake
05c0096c52 ci: setup .circleci/config.yml 2020-05-09 14:01:02 +09:00
mathetake
52edbd17a5 initial commit 2020-05-05 21:04:23 +09:00