Commit Graph

101 Commits

Author SHA1 Message Date
dheaton-arm
cb30ecc7bc Implement Iabs for the interpreter
Implemented `Iabs` to return the absolute integer value with wrapping.

Copyright (c) 2021, Arm Limited
2021-09-22 12:59:30 +01:00
Chris Fallin
38728c5746 Merge pull request #3362 from dheaton-arm/implement-unarrow
Implement `Unarrow`, `Uunarrow`, and `Snarrow` for the interpreter
2021-09-21 10:06:46 -07:00
Chris Fallin
e0bd4bd007 Merge pull request #3363 from dheaton-arm/implement-widening-pairwise-dotprod
Implement `WideningPairwiseDotProductS` for interpreter
2021-09-21 10:05:07 -07:00
dheaton-arm
8abb19cbd8 Generate new_vec using an iterator chain
Copyright (c) 2021, Arm Limited
2021-09-20 10:31:34 +01:00
dheaton-arm
3fc29f5f6c Return u128 from bounds; form new_vec from iter chain
Copyright (c) 2021, Arm Limited
2021-09-20 09:57:19 +01:00
Chris Fallin
6a98fe2104 Merge pull request #3332 from afonso360/interp-icmp
cranelift: Add SIMD `icmp` to interpreter
2021-09-17 15:13:44 -07:00
Afonso Bordado
e17d9cfbab cranelift: Rename icmp type variable 2021-09-17 22:17:54 +01:00
Chris Fallin
1f2d1c097d Merge pull request #3364 from dheaton-arm/implement-smulhi
Implement `Smulhi` for interpreter
2021-09-17 12:56:37 -07:00
Nick Fitzgerald
a1f4b46f64 Bump Wasmtime to version 0.30.0; cranelift to 0.77.0 2021-09-17 10:33:50 -07:00
dheaton-arm
2f0ce4c86c Implement Smulhi for interpreter
Implemented `Smulhi` for the Cranelift interpreter, performing signed
integer multiplication and producing the high half of a double-length
result.

Copyright (c) 2021, Arm Limited
2021-09-17 16:49:38 +01:00
dheaton-arm
3b9bfc8187 Implement WideningPairwiseDotProductS for interpreter
Implemented `WideningPairwiseDotProductS` to perform sign-extending
length-doubling multiplication on corresponding elements from two
`i16x8` SIMD vectors, performing a pairwise add on the results (thus
returning `i32x4`).

Copyright (c) 2021, Arm Limited
2021-09-17 13:31:16 +01:00
dheaton-arm
83c3bc5b9d Implement Unarrow, Uunarrow, and Snarrow for the interpreter
Implemented the following Opcodes for the Cranelift interpreter:
- `Unarrow` to combine two SIMD vectors into a new vector with twice
the lanes but half the width, with signed inputs which are clamped to
`0x00`.
- `Uunarrow` to perform the same operation as `Unarrow` but treating
inputs as unsigned.
- `Snarrow` to perform the same operation as `Unarrow` but treating
both inputs and outputs as signed, and saturating accordingly.

Note that all 3 instructions saturate at the type boundaries.

Copyright (c) 2021, Arm Limited
2021-09-17 13:26:10 +01:00
Chris Fallin
2412e8d784 Merge pull request #3317 from dheaton-arm/implement-swiden
Implement `SwidenLow` and `SwidenHigh` for the interpreter
2021-09-14 08:57:57 -07:00
dheaton-arm
99cc95d630 Factor out shared logic for widening ops.
Copyright (c) 2021, Arm Limited
2021-09-14 13:08:35 +01:00
dheaton-arm
a595bd22e3 Replace loops with iterator methods.
Copyright (c) 2021, Arm Limited
2021-09-14 12:37:36 +01:00
dheaton-arm
75ef00f1fd Implement SwidenLow and SwidenHigh for the interpreter
Implemented `SwidenLow` and `SwidenHigh` for the Cranelift interpreter,
doubling the width and halving the number of lanes preserving the low
and high halves respectively.

Conversions are performed using signed extension.

Copyright (c) 2021, Arm Limited
2021-09-14 12:37:36 +01:00
Chris Fallin
7421e1a65b Merge pull request #3324 from dheaton-arm/implement-shuffle
Implement `Shuffle` for the interpreter
2021-09-13 09:49:59 -07:00
Chris Fallin
9323762d71 Merge pull request #3314 from dheaton-arm/implement-bitops
Implement bit operations for Cranelift interpreter
2021-09-13 09:29:10 -07:00
Afonso Bordado
92690b84a0 cranelift: Add SIMD icmp comparisons to interpreter 2021-09-11 17:15:44 +01:00
Afonso Bordado
f48e40f150 cranelift: Implement icmp for scalar types
Add `icmp` tests for all scalar types and condition codes.

AArch64 (no)overflow tests are disabled because they are currently failing.
2021-09-11 17:15:44 +01:00
dheaton-arm
4a4f940fac Move immediate value retrieval to imm
Copyright (c) 2021, Arm Limited
2021-09-10 12:36:33 +01:00
dheaton-arm
e7d570ddd9 Collect into Result rather than unwrap
Copyright (c) 2021, Arm Limited
2021-09-10 12:26:48 +01:00
dheaton-arm
924b0368e9 Rewrite as iterator methods
Copyright (c) 2021, Arm Limited
2021-09-10 09:41:23 +01:00
dheaton-arm
f7a1b3f9bd Implement UwidenLow and UwidenHigh for the interpreter
Implemented `UwidenLow` and `UwidenHigh` for the Cranelift interpreter,
doubling the width and halving the number of lanes preserving the low
and high halves respectively. Conversions are performed using unsigned
zero extension.

Copyright (c) 2021, Arm Limited
2021-09-08 14:17:11 +01:00
dheaton-arm
dfe1c914ea Cast types back to expected in macros
Also neatened `popcnt` a little following feedback.

Copyright (c) 2021, Arm Limited
2021-09-08 12:36:01 +01:00
dheaton-arm
bca3cb32ef Implement Shuffle for the interpreter
Implemented `Shuffle` for the Cranelift interpreter, to shuffle two SIMD
vectors together based on an immediate mask of 16 bytes.

Copyright (c) 2021, Arm Limited
2021-09-08 11:13:57 +01:00
dheaton-arm
9f647301ff Implement bit operations for Cranelift interpreter
Implemented for the Cranelift interpreter:
- `Bitrev` to reverse the order of the bits in an integer.
- `Cls` to count the leading bits which are the same as the sign bit in
an integer, yielding one less than the size of the integer for 0 and -1.
- `Clz` to count the number of leading zeros in the bitwise representation of the
integer.
- `Ctz` to count the number of trailing zeros in the bitwise representation of the
integer.
- `Popcnt` to count the number of ones in the bitwise representation of the
integer.

Copyright (c) 2021, Arm Limited
2021-09-08 11:07:22 +01:00
Afonso Bordado
3f62ef6e58 cranelift: Fix Build error
#3304 and #3268 are slightly incomptible and caused the build to fail
when they were merged together
2021-09-07 18:13:45 +01:00
Damian Heaton
dd23a21b9b Implement Swizzle and Splat for interpreter (#3268)
* Implement `Swizzle` and `Splat` for interpreter

Implemented for the Cranelift interpreter:
- `Swizzle` to shuffle an `i8x16` SIMD vector based
on the indices specified in another vector of the same size.
- `Splat` to create a SIMD vector with all lanes having the same value.

Copyright (c) 2021, Arm Limited

* Fix old x86 backend failing test

Copyright (c) 2021, Arm Limited

* Represent i16x8 and above as hex

Copyright (c) 2021, Arm Limited
2021-09-07 09:53:49 -07:00
Afonso Bordado
63e9a81deb Implement vany_true and vall_true instructions in interpreter (#3304)
* cranelift: Implement ZeroExtend for a bunch of types in interpreter

* cranelift: Implement VConst on interpreter

* cranelift: Implement VallTrue on interpreter

* cranelift: Implement VanyTrue on interpreter

* cranelift: Mark `v{all,any}_true` tests as machinst only

* cranelift: Disable `vany_true` tests on aarch64

The `b64x2` case produces an illegal instruction. See #3305
2021-09-07 09:50:39 -07:00
Chris Fallin
ecd795f736 Merge pull request #3290 from dheaton-arm/implement-ssatarith
Implement `SaddSat` and `SsubSat` for the Cranelift interpreter
2021-09-03 09:48:34 -07:00
Chris Fallin
e3ccff0249 Merge pull request #3283 from dheaton-arm/implement-umulhi
Implement `Umulhi` for the interpreter
2021-09-03 09:29:21 -07:00
dheaton-arm
8f057e0482 Implement SaddSat and SsubSat for the interpreter
Implemented `SaddSat` and `SsubSat` to add and subtract signed vector
values, saturating at the type boundaries rather than overflowing.

Changed the parser to allow signed `i8` immediates in vectors as part of
this work; fixes #3276.

Copyright (c) 2021, Arm Limited.
2021-09-03 11:35:39 +01:00
Chris Fallin
d6a77898ba Merge pull request #3272 from dheaton-arm/implement-iaddpairwise
Implement `IaddPairwise` for the interpreter
2021-09-02 10:52:47 -07:00
Chris Fallin
000a97f4ff Merge pull request #3279 from dheaton-arm/implement-insertlane
Implement `Insertlane` for the Cranelift interpreter
2021-09-02 09:44:59 -07:00
dheaton-arm
16b6a404e4 Implement Umulhi for the interpreter
Implemented `Umulhi` for the Cranelift interpreter, performing unsigned
integer multiplication and producing the high half of a double-length
result.

Fixed `ExtractUpper` conversion behaviour as part of this change, which
was extracting from a 128-bit value regardless of the size of the
original value.

Copyright (c) 2021, Arm Limited.
2021-09-02 13:11:41 +01:00
Chris Fallin
91410aaddf Merge pull request #3234 from dheaton-arm/implement-isubb
Implement `IsubBin`, `IsubBout`, and `IsubBorrow`for Cranelift interpreter
2021-09-01 11:25:43 -07:00
dheaton-arm
d956d349d8 Implement Insertlane for the Cranelift interpreter
Implemented `Insertlane` to insert a value in the lane specified by the
immediate value, overwriting the existing value in that lane.

Added `TernaryImm8` support for the `imm_value` function.

Copyright (c) 2021, Arm Limited.
2021-09-01 16:21:27 +01:00
dheaton-arm
4cdb2d3dac Merge vector iterators into chain
Copyrght (c) 2021, Arm Limited
2021-09-01 15:55:35 +01:00
dheaton-arm
7a5646c5f4 Implement IaddPairwise for the interpreter
Implemented `IaddPairwise` for the Cranelift interpreter, to add pairs
of adjacent values in two SIMD vectors, concatenating them at the end
(preserving both lane size and number of lanes).

Copyright (c) 2021, Arm Limited
2021-09-01 13:53:26 +01:00
Damian Heaton
4378ea8e01 Implement IaddCin, IaddCout, and IaddCarry for Cranelift interpreter (#3233)
* Implement `IaddCin`, `IaddCout`, and `IaddCarry` for Cranelift interpreter

Implemented the following Opcodes for the Cranelift interpreter:
- `IaddCin` to add two scalar integers with an input carry flag.
- `IaddCout` to add two scalar integers and report overflow with the carry flag.
- `IaddCarry` to add two scalar integers with an input carry flag, reporting overflow with the output carry flag.

Copyright (c) 2021, Arm Limited

* Simplify carry check + add i64 `IaddCarry` tests

Copyright (c) 2021, Arm Limited

* Move tests to `runtests`

Copyright (c) 2021, Arm Limited
2021-08-31 09:29:38 -07:00
Damian Heaton
02ef6a02b8 Implement Extractlane, UaddSat, and UsubSat for Cranelift interpreter (#3188)
* Implement `Extractlane`, `UaddSat`, and `UsubSat` for Cranelift interpreter

Implemented the `Extractlane`, `UaddSat`, and `UsubSat` opcodes for the interpreter,
and added helper functions for working with SIMD vectors (`extractlanes`, `vectorizelanes`,
and `binary_arith`).

Copyright (c) 2021, Arm Limited

* Re-use tests + constrict Vector assert

- Re-use interpreter tests as runtests where supported.
- Constrict Vector assertion.
- Code style adjustments following feedback.

Copyright (c) 2021, Arm Limited

* Runtest `i32x4` vectors on AArch64; add `i64x2` tests

Copyright (c) 2021, Arm Limited

* Add `simd-` prefix to test filenames

Copyright (c) 2021, Arm Limited

* Return aliased `SmallVec` from `extractlanes`

Using a `SmallVec<[i128; 4]>` allows larger-width 128-bit vectors
(`i32x4`, `i64x2`, ...) to not cause heap allocations.

Copyright (c) 2021, Arm Limited

* Accept slice to `vectorizelanes` rather than `Vec`

Copyright (c) 2021, Arm Limited
2021-08-25 09:03:19 -07:00
Afonso Bordado
2776074dfc cranelift: Add stack support to the interpreter with virtual addresses (#3187)
* cranelift: Add stack support to the interpreter

We also change the approach for heap loads and stores.

Previously we would use the offset as the address to the heap. However,
this approach does not allow using the load/store instructions to
read/write from both the heap and the stack.

This commit changes the addressing mechanism of the interpreter. We now
return the real addresses from the addressing instructions
(stack_addr/heap_addr), and instead check if the address passed into
the load/store instructions points to an area in the heap or the stack.

* cranelift: Add virtual addresses to cranelift interpreter

Adds a  Virtual Addressing scheme that was discussed as a better
alternative to returning the real addresses.

The virtual addresses are split into 4 regions (stack, heap, tables and
global values), and the address itself is composed of an `entry` field
and an `offset` field. In general the `entry` field corresponds to the
instance of the resource (e.g. table5 is entry 5) and the `offset` field
is a byte offset inside that entry.

There is one exception to this which is the stack, where due to only
having one stack, the whole address is an offset field.

The number of bits in entry vs offset fields is variable with respect to
the `region` and the address size (32bits vs 64bits). This is done
because with 32 bit addresses we would have to compromise on heap size,
or have a small number of global values / tables. With 64 bit addresses
we do not have to compromise on this, but we need to support 32 bit
addresses.

* cranelift: Remove interpreter trap codes

* cranelift: Calculate frame_offset when entering or exiting a frame

* cranelift: Add safe read/write interface to DataValue

* cranelift: DataValue write full 128bit slot for booleans

* cranelift: Use DataValue accessors for trampoline.
2021-08-24 09:29:11 -07:00
Afonso Bordado
3f6b889067 cranelift: Prevent panics when dividing INT_MIN / -1 in interpreter 2021-08-24 09:27:54 -07:00
dheaton-arm
721cfc16b3 Implement IsubBin, IsubBout, and IsubBorrow
Implemented the following Opcodes for the Cranelift interpreter:
- `IsubBin` to subtract two scalar integers with an input borrow flag.
- `IsubBout` to subtract two scalar integers with an output borrow flag.
- `IsubBorrow` to subtract two scalar integers with an input and output borrow flag.

Copyright (c) 2021, Arm Limited
2021-08-24 09:38:17 +01:00
Chris Fallin
a13a777230 Bump to Wasmtime v0.29.0 and Cranelift 0.76.0. 2021-08-02 11:24:09 -07:00
Johnnie Birch
e519fca61c Refactor and turn on lowering for extend-add-pairwise 2021-07-31 10:52:39 -07:00
Johnnie Birch
e373ddfe1b Add extend-add-pairwise instructions x64 2021-07-30 15:06:58 -07:00
Afonso Bordado
a2fb019ba7 cranelift: Add basic i128 support in interpreter 2021-07-23 11:22:07 -07:00
Afonso Bordado
df48798396 cranelift: Emit a trap when dividing by zero in interpreter
Fixes #3058
2021-07-22 10:43:54 -07:00