Commit Graph

7815 Commits

Author SHA1 Message Date
Anton Kirilov
043a8434d2 Cranelift AArch64: Improve the Popcnt implementation
Now the backend uses the CNT instruction, which results into a major
simplification.

Copyright (c) 2021, Arm Limited.
2021-01-19 16:49:47 +00:00
Han Zhao
f8268b2139 Bugfix of issue #2575
Bugfix of issue #2575.

Use libc 0.2.82 on aarch64-apple-darwin Apple Silicon, and local test passes.
2021-01-19 17:08:11 +01:00
Chris Fallin
c7de8f5efb Merge pull request #2541 from cfallin/struct-arg-ret
x64 and aarch64: allow StructArgument and StructReturn args.
2021-01-17 23:50:19 -08:00
Chris Fallin
e04e67ec94 Merge pull request #2540 from cfallin/x64-tls
Add ELF TLS support in new x64 backend.
2021-01-17 23:25:59 -08:00
Chris Fallin
456561f431 x64 and aarch64: allow StructArgument and StructReturn args.
The StructReturn ABI is fairly simple at the codegen/isel level: we only
need to take care to return the sret pointer as one of the return values
if that wasn't specified in the initial function signature.

Struct arguments are a little more complex. A struct argument is stored
as a chunk of memory in the stack-args space. However, the CLIF
semantics are slightly special: on the caller side, the parameter passed
in is a pointer to an arbitrary memory block, and we must memcpy this
data to the on-stack struct-argument; and on the callee side, we provide
a pointer to the passed-in struct-argument as the CLIF block param
value.

This is necessary to support various ABIs other than Wasm, such as that
of Rust (with the cg_clif codegen backend).
2021-01-17 23:11:45 -08:00
Chris Fallin
0f563f786a Add ELF TLS support in new x64 backend.
This follows the implementation in the legacy x86 backend, including
hardcoded sequence that is compatible with what the linker expects. We
could potentially do better here, but it is likely not necessary.

Thanks to @bjorn3 for a bugfix to an earlier version of this.
2021-01-17 22:48:51 -08:00
Pat Hickey
7f7a0be938 wasi-c2: implement a synchronous poll_oneoff in terms of yanix
doesnt work on unix yet! also breaks all the rules about using the
cap-std family instead of rawfds! but this is cool and im happy with it
2021-01-14 17:43:53 -08:00
Pat Hickey
b84c4d7488 poll_oneoff test: if you subscribe to a badf, the whole call fails with badf
rather than the results telling you an individual file was a badf.

why? i think the old behavior was too clever, and makes it harder to
write a scheduler.

* what should the call do when you pass it some badf and some not-badf?
i don't think anything besides exiting early is the correct answer.
* the results vector tells you something that the scheduler had to say
about the file, not about your inputs. the errno of the function
always says what the validity of the inputs was
2021-01-14 17:41:27 -08:00
Pat Hickey
f667263d9c TEMPORARY: poll_oneoff test uses CLOCKID_REALTIME instead of MONOTONIC
the scheduler does not support the monotonic clock yet, i will fix this
soon
2021-01-14 17:40:56 -08:00
Pat Hickey
7d7acc4614 poll_oneoff test: outline assertions
this makes the panic message have the line number, which
is handy
2021-01-14 17:40:04 -08:00
Pat Hickey
9a1ce1a272 TEMPORARY: inherit stdio for the wasi ctx
this is unfortunate but the poll_oneoff test insists on polling on stdio
handles. to undo this temporary fix later, lets rewrite the test to open
some regular files from the scratch directory and poll on them instead.
2021-01-14 17:38:43 -08:00
Peter Huene
8640025d8b Merge pull request #2585 from alexcrichton/module-linking-update
Update support for the module linking proposal
2021-01-14 15:48:14 -08:00
Chris Fallin
25088dee9d Merge pull request #2539 from cfallin/x64-i128
Support for I128 operations in x64 backend.
2021-01-14 14:45:03 -08:00
Alex Crichton
d66db16d00 Fix a doc link 2021-01-14 14:38:05 -08:00
Alex Crichton
bc9f10115d Fix a typo 2021-01-14 14:37:44 -08:00
Pat Hickey
4b39a14163 fix tests in pipe 2021-01-14 14:14:41 -08:00
Chris Fallin
71ead6e31d x64 backend: implement 128-bit ops and misc fixes.
This implements all of the ops on I128 that are implemented by the
legacy x86 backend, and includes all that are required by at least one
major use-case (cg_clif rustc backend).

The sequences are open-coded where necessary; for e.g. the bit
operations, this can be somewhat complex, but these sequences have been
tested carefully. This PR also includes a drive-by fix of clz/ctz for 8-
and 16-bit cases where they were incorrect previously.

Also includes ridealong fixes developed while bringing up cg_clif
support, because they are difficult to completely separate due to
other refactors that occurred in this PR:

- fix REX prefix logic for some 8-bit instructions.

  When using an 8-bit register in 64-bit mode on x86-64, the REX prefix
  semantics are somewhat subtle: without the REX prefix, register numbers
  4--7 correspond to the second-to-lowest byte of the first four registers
  (AH, CH, BH, DH), whereas with the REX prefix, these register numbers
  correspond to the usual encoding (SPL, BPL, SIL, DIL). We could always
  emit a REX byte for instructions with 8-bit cases (this is harmless even
  if unneeded), but this would unnecessarily inflate code size; instead,
  the usual approach is to emit it only for these registers.

  This logic was present in some cases but missing for some other
  instructions: divide, not, negate, shifts.

  Fixes #2508.

- avoid unaligned SSE loads on some f64 ops.

  The implementations of several FP ops, such as fabs/fneg, used SSE
  instructions. This is not a problem per-se, except that load-op merging
  did not take *alignment* into account. Specifically, if an op on an f64
  loaded from memory happened to merge that load, and the instruction into
  which it was merged was an SSE instruction, then the SSE instruction
  imposes stricter (128-bit) alignment requirements than the load.f64 did.

  This PR simply forces any instruction lowerings that could use SSE
  instructions to implement non-SIMD operations to take inputs in
  registers only, and avoid load-op merging.

  Fixes #2507.

- two bugfixes exposed by cg_clif: urem/srem.i8, select.b1.

  - urem/srem.i8: the 8-bit form of the DIV instruction on x86-64 places
    the remainder in AH, not RDX, different from all the other width-forms
    of this instruction.

  - select.b1: we were not recognizing selects of boolean values as
    integer-typed operations, so we were generating XMM moves instead (!).
2021-01-14 13:45:50 -08:00
Pat Hickey
5c8efe868e need Any on WasiFile to upcast for AsRawFd 2021-01-14 13:39:01 -08:00
Alex Crichton
703762c49e Update support for the module linking proposal
This commit updates the various tooling used by wasmtime which has new
updates to the module linking proposal. This is done primarily to sync
with WebAssembly/module-linking#26. The main change implemented here is
that wasmtime now supports creating instances from a set of values, nott
just from instantiating a module. Additionally subtyping handling of
modules with respect to imports is now properly handled by desugaring
two-level imports to imports of instances.

A number of small refactorings are included here as well, but most of
them are in accordance with the changes to `wasmparser` and the updated
binary format for module linking.
2021-01-14 10:37:39 -08:00
Nick Fitzgerald
705af0ac41 Merge pull request #2584 from alexcrichton/update-c-api
Adjust `wasmtime_func_callback_*` type signature
2021-01-14 09:48:04 -08:00
Alex Crichton
55c5424e0e Adjust wasmtime_func_callback_* type signature
This aligns the C header with what we have in the crate itself, in
addition to matching what's in `wasm.h`.
2021-01-14 08:57:15 -08:00
Peter Huene
f94db6556c Update WebAssembly C API submodule to latest commit. (#2579)
* Update WebAssembly C API submodule to latest commit.

This commit updates the WebAssembly C API submodule (for `wasm.h`) to the
latest commit out of master.

This fixes the behavior of `wasm_name_new_from_string` such that it no longer
copies the null character into the name, which caused unexpected failures when
using the Wasmtime linker as imports wouldn't resolve when the null was
present.

Along with this change were breaking changes to `wasm_func_call`, the host
callback signatures, and `wasm_instance_new` to take a vector type instead of a
pointer to an unsized array.

As a result, Wasmtime language bindings based on the C API will need to be
updated once this change is pulled in.

Fixes #2211.
Fixes #2131.

* Update Doxygen comments for wasm.h changes.
2021-01-14 09:36:12 -06:00
Johnnie Birch
cde07b9a79 Re-enable spec tests that were disabled for #2432 #2470. Enable new tests
Re-enables spec tests that were turned off for #2432 and #2470 while
also enabling tests that now work due to patch pushes in the interim.
Currently all SIMD spec tests past. Testing to assure this is ok to
enable hasn't been super intense so we should monitor but there
was an attempt of doing 1000 runs 3 different times to try and reproduce
the issue and it did not occur. In the past would have occurred several
times with that many runs.
2021-01-13 19:44:00 -08:00
Johnnie Birch
d17815a239 Zero newly allocated registers whose immediate use depends on content not being NaN
An intermittent failure during SIMD spectests is described in #2432. This patch
corrects code written in a way that assumes comparing fp equality of a register with itself will
always return true. This is not true when the register value is NaN as NaN. In this case, and
with all ordered comparisons involving NaN, the comparisons will always return false.
This patch corrects that assumption for SIMD Fabs and Fneg which seem to be the only
instructions generating the failure with #2432.
2021-01-13 19:44:00 -08:00
Pat Hickey
ea94d6f79d this is indeed a nice way to do refs! 2021-01-13 15:11:11 -08:00
Pat Hickey
7beb52a2bc i guess this is a way to do refs 2021-01-13 14:23:59 -08:00
Pat Hickey
8298ce9e4d clock sub, start with the read sub 2021-01-13 11:57:42 -08:00
Pat Hickey
e0e205f8d2 ctx builder: fix warnings, test harness 2021-01-13 11:07:06 -08:00
Pat Hickey
28c57c0fe3 Merge pull request #2577 from Ekleog/pr-2487
wasi-c2 improvements
2021-01-13 11:03:49 -08:00
Chris Fallin
2b2f369bbb Merge pull request #2576 from cfallin/cmp-load-bug
x64 bugfix: prevent load-op fusion of cmp because it could be emitted multiple times.
2021-01-13 10:33:37 -08:00
Chris Fallin
4638de673c x64 bugfix: prevent load-op fusion of cmp because it could be emitted multiple times.
On x64, the new backend generates `cmp` instructions at their use-sites
when possible (when the icmp that generates a boolean is known) so that
the condition flows directly through flags rather than a materialized
boolean. E.g., both `bint` (boolean to int) and `select` (conditional
select) instruction lowerings invoke `emit_cmp()` to do so.

Load-op fusion in `emit_cmp()` nominally allowed `cmp` to use its `cmp
reg, mem` form.

However, the mergeable-load condition (load has only single use) was not
adequately checked. Consider the sequence:

```
    v2 = load.i64 v1
    v3 = icmp eq v0, v2
    v4 = bint.i64 v3
    v5 = select.i64 v3, v0, v1
```

The load `v2` is only used in the `icmp` at `v3`. However, the cmp will
be separately codegen'd twice, once for the `bint` and once for the
`select`.

Prior to this fix, the above example would result in the load at `v2`
sinking to the `cmp` just above the `select`; we then emit another `cmp`
for the `bint`, but the load has already been used once so we do not
allow merging. We thus (i) expect the register for `v2` to contain the
loaded value, but (ii) skip the codegen for the load because it has been
sunk. This results in a regalloc error (unexpected livein) as the
unfilled register is upward-exposed to the entry point.

Because of this, we need to accept only the reg, reg form in
`emit_cmp()` (and the FP equivalent). We could get marginally better
code by tracking whether the `cmp` we are emitting comes from an
`icmp`/`fcmp` with only one use; but IMHO simplicity is a better rule
here when subtle interactions occur.
2021-01-13 09:48:51 -08:00
Nick Fitzgerald
90b80a2d3c Merge pull request #2574 from fitzgen/randomize-location-of-heap-objects
wasmtime-bench-api: Randomize the locations of heap objects
2021-01-13 09:35:46 -08:00
Léo Gaspard
932378eb7b reexport all the things required to implement WasiDir 2021-01-13 05:18:36 +01:00
Léo Gaspard
20bb4b211e Also reexport Error from wasmtime_wasi 2021-01-13 05:10:28 +01:00
Léo Gaspard
5d85216329 also reexport WasiDir from wasmtime_wasi 2021-01-13 05:05:37 +01:00
Léo Gaspard
2e035be60a make WasiCtxBuilder be an actual builder, allowing to call .build() at the end of a call chain 2021-01-13 04:57:16 +01:00
Léo Gaspard
f3156114c4 reserve keys 0, 1 and 2 for stdio 2021-01-13 04:24:02 +01:00
Léo Gaspard
7303793fa0 also expose WasiCtxBuilder 2021-01-13 04:10:12 +01:00
Pat Hickey
81065eba38 more scheduler 2021-01-12 17:42:59 -08:00
Pat Hickey
b79bdcee84 port subscriptions in from old branch 2021-01-12 15:55:25 -08:00
Nick Fitzgerald
bc6dc083f0 wasmtime-bench-api: Randomize the locations of heap objects
This helps us avoid measurement bias due to accidental locality of unrelated
heap objects. See *Stabilizer: Statistically Sound Performance Evaluation* by
Curtsinger and Berger for details (although Stabilizer deals with much more than
just the location of heap allocations):
https://people.cs.umass.edu/~emery/pubs/stabilizer-asplos13.pdf
2021-01-12 15:43:26 -08:00
Pat Hickey
47ff726c61 Merge pull request #2570 from bytecodealliance/pch/wiggle_flags_bitflags
wiggle: generate flags using `bitflags`
2021-01-12 13:48:35 -08:00
Pat Hickey
0e42c2e1d9 scaffold a scheduler 2021-01-12 12:07:00 -08:00
Pat Hickey
32f162aa78 fix windows flags 2021-01-12 09:51:09 -08:00
Pat Hickey
e7018bf6e0 wiggle flags are now bitflags! 2021-01-11 18:33:52 -08:00
Pat Hickey
b53aecb367 Merge branch 'pch/wiggle_flags_bitflags' into pch/wasi_common_cap_std 2021-01-11 18:31:43 -08:00
Pat Hickey
75a9dc7fe2 wasi-common: wiggle flags are now bitflags!
this mostly mechanical change is just getting rid of passing to
`contains` by reference.
2021-01-11 18:27:55 -08:00
Pat Hickey
ed44a19e5e wiggle: use bitflags to generate flags
more consistient with the rest of the ecosystem.
2021-01-11 18:20:57 -08:00
Pat Hickey
e2fb99af86 wiggle: depend on bitflags, and re-export it. 2021-01-11 18:04:43 -08:00
Pat Hickey
94467bcd9a wiggle: bugfix, generated code should use Names::runtime_mod not wiggle
as the crate from which these deps come.

I worked around this in lucet, but I'll be able to revert that
workaround.
2021-01-11 18:03:48 -08:00