Commit Graph

254 Commits

Author SHA1 Message Date
Takeshi Yoneda
1a46d471f8 bench: compare host call costs on Wasm-impl vs Go-impl (#758)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-23 11:56:42 +09:00
Takeshi Yoneda
50cef32ae0 vs: adds the benchmark to see the cost of host function calls (#756)
This adds the new vs target to measure the cost of host function calls.
Notably, I can see that wazero is roughly 2x to 4x times faster than CGO-based
runtimes in terms of host call boundary crossing. One implication here is that
we can just focus on the native code generation rather than how to organize the
Go function calls. For example, it's not prioritized to call Go functions directly
from the native code.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-22 16:53:58 +09:00
Crypt Keeper
57a705e594 Disallows nil context and fixes linters (#754)
staticcheck linters broke until recent golangci-lint. Now, normal
behaviour of enforcing no nil context works again. Ex.
```
assemblyscript/assemblyscript_example_test.go:16:25: SA1012: do not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use (staticcheck)
	r := wazero.NewRuntime(nil)
```

Since default lint already checks for nil context, this removes our
permission of nil context args. The original reason we permitted nil is
no longer valid: we once allowed context to be stashed in config, and
removed that as it caused bugs. We forgot to undo allowing nil
explicitly.

Note: this doesn't particularly check in our code for nil context,
similar as we don't particularly check in our code for nil anything
else. End users should use linters as none of our parameters should be
nil anyway.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-08-19 14:52:50 +08:00
Takeshi Yoneda
5b2c25cfed Adds test to verify cross-process file system cache works (#753)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-19 14:17:47 +09:00
Takeshi Yoneda
3b32c2028b Externalize compilation cache by compilers (#747)
This adds the experimental support of the file system compilation cache.
Notably, experimental.WithCompilationCacheDirName allows users to configure
where the compiler writes the cache into.

Versioning/validation of binary compatibility has been done via the release tag
(which will be created from the end of this month). More specifically, the cache
file starts with a header with the hardcoded wazero version.


Fixes #618

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2022-08-18 19:37:11 +09:00
Takeshi Yoneda
076d3245e3 Pass context into NewRuntime (#748)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-18 14:47:49 +09:00
Matt Turner
7d071a45d7 Enable comparative benchmark builds on darwin/aarch64 (ie Apple Silicon) (#746)
Enable for Wasmer, as confirmed that the version we use has arm64 support.
Enable for Wasmtime after bumping to a version which supports arm64.
Don't enable for wasm-edge as they don't support arm64/darwin.
2022-08-17 07:33:40 +08:00
Takeshi Yoneda
9be4f2979f amd64: fixes huge memory offset consts handling (#733)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-04 13:17:42 +09:00
Takeshi Yoneda
9dfdab2548 amd64: correctly select sign of zeros on f32x4/f64x2 min/max (#730) 2022-08-02 19:47:49 +09:00
Takeshi Yoneda
76c5d98786 Updates v2 spectest version (#729)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-30 18:33:34 +09:00
Takeshi Yoneda
02c23d55db Disallow direct call of host functions (#723)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-30 09:33:20 +08:00
Takeshi Yoneda
c5daf5a218 interpreter,compiler(arm64): clears higher bits in i32.load_8/16_s (#725)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-28 15:45:07 +09:00
Takeshi Yoneda
d1336806d6 compiler: save conditional values at data.drop (#724)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-27 17:18:42 +09:00
Takeshi Yoneda
a064f68532 compiler: allow memory access after table.grow (#721)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-27 09:56:48 +09:00
Takeshi Yoneda
d15cc069c6 compiler: save conditional value on elem.drop (#722)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-27 09:53:19 +09:00
Takeshi Yoneda
41df6d9556 arm64: fix bounds check on v128.load{32,64}_zero. (#720)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-26 16:23:54 +09:00
Takeshi Yoneda
97e3216eb2 asm(arm64): fixes the source register of CMEQ(vector,zero) (#719)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-26 15:59:45 +09:00
Takeshi Yoneda
37d2c6d803 asm(arm64): fixes unaligned vector stores (#718)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-26 12:10:26 +09:00
Takeshi Yoneda
143b2be398 compiler: save conditional values at ref.func (#717)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-25 13:58:15 +09:00
Takeshi Yoneda
8d75403c49 compiler: save conditional values at table.size (#715)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-25 13:32:32 +09:00
Takeshi Yoneda
ed068597cd ci: adds Go 1.19.0-rc.2 into matrix (#714)
This adds the 1.19.0-rc2. in the testing matrix.

This also formats the Godocs across the codebase, as
Go 1.19 has started auto-formatting Godoc. https://github.com/tetratelabs/wazero/issues/426

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-25 11:14:00 +09:00
Takeshi Yoneda
6a62b794f5 Fixes compileDropRange when all registers are used up by live values (#711)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-25 09:18:04 +09:00
Crypt Keeper
866fac2e96 Makes CacheNumInUint64 lazy and stops crashing in assemblyscript (#712)
* Makes CacheNumInUint64 lazy and stops crashing in assemblyscript

This makes CacheNumInUint64 lazy so that all tests for function types
don't need to handle it. This also changes the assemblyscript special
functions so they don't crash when attempting to log. Finally, this
refactors `wasm.Func` so that it can enclose the parameter names as it
is more sensible than defining them elsewhere.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-22 16:01:20 +08:00
Takeshi Yoneda
4c71c1f33b interpreter: fixes V128FloatPromote to use lower 64-bits. (#709)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-21 17:25:06 +09:00
Takeshi Yoneda
e44fa5f44a interpreter: clear higher bits for 32-bit signed shr (#708)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-21 17:13:09 +09:00
Crypt Keeper
0da1af2d51 Supports mix of wasm and go funcs in the same module (#707)
This removes the constraint of a module being exclusively wasm or host
functions. Later pull requests can optimize special imports to be
implemented in wasm, particularly useful for disabled logging callbacks.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-19 11:55:37 +08:00
Takeshi Yoneda
ff4a7ff4f9 interpreter: fixes i32x4/i16x8 bit mask (#704)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-15 16:07:49 +09:00
Takeshi Yoneda
2d0ed54931 interpreter: signed-extend to 32-bit in SignExtend32 (#701)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-15 10:56:38 +09:00
Takeshi Yoneda
9e3dda2429 ir: rename NeedsAccess* -> Has*, and make them module-scoped (#699)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-15 08:54:00 +09:00
Takeshi Yoneda
0ae4254f21 Support for select instructions on vector values (#696)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-14 14:45:17 +09:00
Takeshi Yoneda
48d6e6f2e1 compiler(amd64),interpreter: signed-extend to 32-bit in V128ExtractLane. (#695)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-14 12:47:44 +09:00
Crypt Keeper
49e5bcb8c7 Top-levels FunctionDefinition to allow access to all function metadata (#686)
This top-levels `api.FunctionDefinition` which was formerly
experimental, and also adds import metadata to it. Now, it holds all
metadata known at compile time.

Here are the public API visible changes:
* api.ExportedFunction - replaced with api.FunctionDefinition as it is
  usable for all types of functions.
* api.Function - `.ParamTypes/ResultTypes()` are replaced with
  `.Definition().
* api.FunctionDefinition - extracted from experimental and adds
  `.Import()` to get the any imported module and function name.
* experimental.FunctionDefinition - replaced with
  api.FunctionDefinition.
* experimental.FunctionListenerFactory - adds first arg of the
  instantiated module name, as it can be different than compiled.
* wazero.CompiledModule - Adds `.ImportedFunctions()` and changes result
  type of `.ExportedFunctions()` to api.FunctionDefinition.

Internally, logic to create function definition are consolidated between
host and wasm-defined functions, notably wasm.Module now includes
`.BuildFunctionDefinitions()` which reduces duplication in
wasm.ModuleInstance `.BuildFunctions()`,

This obviates #681 by deleting the `ExportedFunction` type which
overlaps with this information.

This fixes #637 as it includes more metadata including imports.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 14:16:18 +08:00
Crypt Keeper
fe1cde140d Removes redundant error handling (#668)
This consolidates to use EBADF in places go uses it in syscalls to
reduce where we formally returned both bool and err. This also removes
the redundant panic type handling as go will already panic with a
similar message.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-06-30 07:33:24 +08:00
Takeshi Yoneda
29e1dead13 spectest: precise assertion on (canonical,arithmetic) NaNs (#664)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-28 20:47:02 +09:00
Takeshi Yoneda
2fa67b83bf asm(amd64): resolve NOP padding TODO after golang-asm removal (#663)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-28 09:39:19 +09:00
Takeshi Yoneda
b8c94fd0b9 asm: remove integration tests with golang-asm (#659)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-28 09:19:21 +09:00
Crypt Keeper
798ff20f81 Removes WithWorkDirFS and "." resolution (#660)
This removes WithWorkDirFS and any other attempts to resolve the current directory (".") in host functions. This is a reaction to reality of compilers who track this inside wasm (not via host functions). One nice side effect is substantially simpler internal implementation of file-systems.

This also allows experimental.WithFS to block file access via passing nil.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-06-27 13:29:35 +08:00
Takeshi Yoneda
fb911b811c amd64: fix unsigned extension of i32 globals (#658)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-27 10:30:45 +09:00
Takeshi Yoneda
fd318d4be9 asm: unexport arm64 pkg implementations (#657)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-26 20:26:22 +09:00
Takeshi Yoneda
1489a9f19f arm64: remove golang-asm integeration test (#655)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-24 14:49:50 +09:00
Takeshi Yoneda
70a69c24d0 arm64: remove CompileJumpToMemory (#654)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-24 12:14:56 +09:00
Takeshi Yoneda
c983e2c972 Delete debug assembler (#652)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-23 16:22:58 +09:00
Takeshi Yoneda
3b4544ee48 compiler: remove embedding of pointers of jump tables (#650)
This removes the embedding of pointers of jump tables (uintptr of []byte)
used by BrTable operations. That is the last usage of unsafe.Pointer in
compiler implementations.
Alternatively, we treat jump tables as asm.StaticConst and emit them
into the constPool already implemented and used by various places.

Notably, now the native code compiled by compilers can be reusable
across multiple processes, meaning that they are independent of
any runtime pointers.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-23 13:42:46 +09:00
Takeshi Yoneda
4136a360ac amd64: removes embeddings of pointers of bit masks for FP arithmetic (#648)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-22 13:31:26 +09:00
Takeshi Yoneda
b0588a98c9 Completes arm64 backend for SIMD instructions (#644)
This completes the implementation of arm64 backend for SIMD instructions.
Notably, now the arm64 compiler passes 100% of WebAssemby 2.0 draft
specification tests.

Combined with the completion of the interpreter and amd64 backend (#624),
this finally resolves #484. Therefore, this also documents that wazero is
100% compatible with WebAssembly 1.0 and 2.0.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-21 10:51:02 +09:00
Takeshi Yoneda
3219832e5a arm64: dot and pseudo min/max instructions (#643)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-20 20:03:53 +09:00
Takeshi Yoneda
fdfcd47224 arm64: SIMD extadd, extmul, int-to-int/float-to-int conversions (#642)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-20 17:28:23 +09:00
Takeshi Yoneda
8a2776c2b4 arm64: implement SIMD Integer arithmetics (#641)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-20 15:04:20 +09:00
Takeshi Yoneda
2301afd94b arm64: FP SIMD arithmetic/rounding instructions (#634)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-20 09:08:08 +09:00
Takeshi Yoneda
691a1eddab interpreter: fix integer Eq instruction (#638)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-20 09:02:40 +09:00