Commit Graph

85 Commits

Author SHA1 Message Date
Andrew Brown
18c31403e8 Translate Wasm's I8x16Shl to Cranelift's ishl.i8x16 2020-04-23 10:55:54 -07:00
Andrew Brown
a148de08f8 Translate Wasm's I8x16ShrU to Cranelift's ushr.i8x16 2020-04-17 11:59:47 -07:00
Andrew Brown
39c0a28d77 Zero-extend the result of extractlane
Previously, `extractlane` results did not have the expected `uextend` because this work was completed by PEXTRB in x86. Since other architectures may eventually need this and since leaving the `uextend` out leaves the extracted values with the wrong type (`i16` instead of `i32`), the `uextend` is re-added. The duplicated zero-extension work (from PEXTRB and MOVZX) could be fixed by a later optimization.
2020-04-17 11:59:47 -07:00
Andrew Brown
3699e7d925 Translate Wasm SIMD load_extend operations to Cranelift IR 2020-03-31 11:35:26 -07:00
Andrew Brown
a2d388b593 Fix types of SIMD or, xor, and
The operands of these bitwise instructions could have different types and still be valid Wasm (i.e. `v128`). Because of this, we must tell Cranelift to cast both operands to the same type--the default type, in this case. This undoes the work merged in https://github.com/bytecodealliance/cranelift/pull/1233.
2020-03-17 11:44:25 -07:00
Andrew Brown
ebaf95e507 Fix types of i8x16 and i16x8 replace_lane
Because the smallest Wasm scalar type is i32, users of the `i8x16.replace_lane` and `i16x8.replace_lane` instructions will only be able to pass `i32` values as operands. These values must be reduced by dropping the upper bits (see https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#replace-lane-value) using Cranelift's `ireduce` instruction.
2020-03-17 11:44:25 -07:00
Andrew Brown
27532410d2 Fix local.set and local.tee types for SIMD
Because Wasm SIMD vectors store their type as `v128`, there is a mismatch between the more specific types Cranelift uses and Wasm SIMD. Because of this mismatch, Wasm SIMD translates to the default Cranelift type `I8X16`, causing issues when more specific type information is available (e.g. `I32x4`). To fix this, all incoming values to SIMD instructions are checked during translation (not runtime) and if necessary cast from `I8X16` to the appropriate type by functions like `optionally_bitcast_vector`, `pop1_with_bitcast` and `pop2_with_bitcast`. However, there are times when we must also cast to `I8X16` for outgoing values, as with `local.set` and `local.tee`.

There are other ways of resolving this (e.g., see adding a new vector type, https://github.com/bytecodealliance/cranelift/pull/1251) but we discussed staying with this casting approach in https://github.com/bytecodealliance/wasmtime/issues/1147.
2020-03-17 11:44:25 -07:00
Andrew Brown
ffa467a0d0 Translate Wasm's f32x4.convert_i32x4s to Cranelift's fcvt_from_sint 2020-03-17 10:52:03 -07:00
Till Schneidereit
8f824a9fc1 Update outdated references to the Cranelift repository
This patch updates or removes all references to the Cranelift repository. It affects links in README documents, issues that were transferred to the Wasmtime repository, CI badges, and a small bunch of sundry items.
2020-03-09 14:06:24 +01:00
Andrew Brown
4284491339 Translate Wasm swizzle to Cranelift swizzle 2020-03-06 15:49:53 -08:00
Ryan Hunt
07f335dca6 Rename 'an block' to 'a block'
Missed this in the automatic rename of 'Ebb' to 'Block'.
2020-03-03 13:21:13 -06:00
Andrew Brown
78bf63c76d Translate Wasm SIMD's avgr_u to Cranelift's new avg_round instruction 2020-02-24 09:48:38 -08:00
Andrew Brown
91727d99c0 Clean up unnecessary return 2020-02-21 09:33:43 -08:00
Andrew Brown
f9ef4948fc Translate Wasm integer min/max to Cranelift's integer min/max 2020-02-21 09:33:43 -08:00
Gabor Greif
950dadac94 Catch a few typos (#1381) 2020-02-07 12:51:28 -08:00
Ryan Hunt
832666c45e Mass rename Ebb and relatives to Block (#1365)
* Manually rename BasicBlock to BlockPredecessor

BasicBlock is a pair of (Ebb, Inst) that is used to represent the
basic block subcomponent of an Ebb that is a predecessor to an Ebb.

Eventually we will be able to remove this struct, but for now it
makes sense to give it a non-conflicting name so that we can start
to transition Ebb to represent a basic block.

I have not updated any comments that refer to BasicBlock, as
eventually we will remove BlockPredecessor and replace with Block,
which is a basic block, so the comments will become correct.

* Manually rename SSABuilder block types to avoid conflict

SSABuilder has its own Block and BlockData types. These along with
associated identifier will cause conflicts in a later commit, so
they are renamed to be more verbose here.

* Automatically rename 'Ebb' to 'Block' in *.rs

* Automatically rename 'EBB' to 'block' in *.rs

* Automatically rename 'ebb' to 'block' in *.rs

* Automatically rename 'extended basic block' to 'basic block' in *.rs

* Automatically rename 'an basic block' to 'a basic block' in *.rs

* Manually update comment for `Block`

`Block`'s wikipedia article required an update.

* Automatically rename 'an `Block`' to 'a `Block`' in *.rs

* Automatically rename 'extended_basic_block' to 'basic_block' in *.rs

* Automatically rename 'ebb' to 'block' in *.clif

* Manually rename clif constant that contains 'ebb' as substring to avoid conflict

* Automatically rename filecheck uses of 'EBB' to 'BB'

'regex: EBB' -> 'regex: BB'
'$EBB' -> '$BB'

* Automatically rename 'EBB' 'Ebb' to 'block' in *.clif

* Automatically rename 'an block' to 'a block' in *.clif

* Fix broken testcase when function name length increases

Test function names are limited to 16 characters. This causes
the new longer name to be truncated and fail a filecheck test. An
outdated comment was also fixed.
2020-02-07 10:46:47 -06:00
Ryan Hunt
c360007b19 Drop 'basic-blocks' feature (#1363)
* All: Drop 'basic-blocks' feature

This makes it so that 'basic-blocks' cannot be disabled and we can
start assuming it everywhere.

* Tests: Replace non-bb filetests with bb version

* Tests: Adapt solver-fixedconflict filetests to use basic blocks
2020-01-23 22:36:06 -07:00
Ryan Hunt
32a95a89eb Wasm: Add support for typed select instruction
Reference types introduces a typed select operation. It has identical execution
semantics so no codegen change is needed.
2020-01-23 16:31:34 -06:00
Ryan Hunt
946251e655 Codegen: Align representation of stackmap with SpiderMonkey
This commit aligns the representation of stackmaps to be the same
as Spidermonkey's by:
 * Reversing the order of the bitmap from low addresses to high addresses
 * Including incoming stack arguments
 * Excluding outgoing stack arguments

Additionally, some accessor functions were added to allow Spidermonkey
to access the internals of the bitmap.
2020-01-23 13:37:11 -06:00
Ryan Hunt
3b1dda8e92 Wasm: Ensure result of ref.is_null is I32
The (r32|r64).is_null instruction yields a boolean type, so we must
convert a Wasm `ref.is_null` to an integer so we don't get verifier
errors.
2020-01-23 13:37:11 -06:00
Ryan Hunt
41f225804b Wasm: Allow environment to translate some global.set/get operations
Spidermonkey will need to emit pre/post barriers for global.set/get to a
reference type. #1176 and #1299 plan to add a template concept that could
be used to implement this. Once that has been stabilized, we should be able
to remove this code in favor of templates easily.
2020-01-23 13:37:11 -06:00
Ryan Hunt
f41bf5ecca Wasm: Use environment to translate reference types instructions and add support for multiple tables
This commit introduces environment functions to handle the translation of
reference type instructions, analogous to how bulk-memory was implemented.

Additionally, the bulk-memory instructions that operate on tables are extended
to support multiple table indices.
2020-01-23 13:37:11 -06:00
Andrew Brown
dfc9e195ee Add temporary translation of Wasm's load_splat using Cranelift's load and splat instructions (#1347)
If/when Cranelift gains a `load_splat` instruction, the `load + splat` could be replaced with a single Cranelift `load_splat`. This change allows the `simd_load_splat.wast` spec test to pass.
2020-01-21 08:18:52 -08:00
Alex Crichton
1266b68f9a Use is_wasm_parameter in translating wasm calls (#1352)
* Use `is_wasm_parameter` in translating wasm calls

Added in #1329 it's now possible for multiple parameters to be non-wasm
parameters, so the previous `param_types` method is no longer suitable
for acquiring all wasm-related parameters, rather then `FuncEnvironment`
must be consulted. This removes usage of `param_types()` as a method
from the wasm translation and instead adds a custom method inline for
filtering the parameters based on `is_wasm_parameter`.

* Apply feedback

* Run rustfmt

* Don't require `mut`

* Run rustfmt
2020-01-17 12:11:54 -08:00
Dan Gohman
8bec6fe869 Update to wasmparser 0.47. (#1331)
Co-authored-by: Yury Delendik <ydelendik@mozilla.com>
2020-01-10 15:31:37 -08:00
Andrew Brown
c7b0d49550 Fix V128AndNot type mapping (#1319)
Prior to this fix, `type_of` could not determine the Cranelift type for the parameters to `V128AndNot`.
2020-01-10 08:41:11 -08:00
Andrew Brown
46e58fbaaa Bitcasting at control flow exits (#1272)
* Bitcast vectors immediately before a return

* Bitcast vectors immediately before a block end

* Use helper function for bitcasting arguments

* Add FuncTranslationState::peekn_mut; allows mutating of peeked values

* Bitcast values in place, avoiding an allocation

Also, retrieves the correct EBB header types for bitcasting on Operator::End.

* Bitcast values of a function with no explicit Wasm return instruction

* Add Signature::return_types method

This eliminates some duplicate code and avoids extra `use`s of `Vec`.

* Add Signature::param_types method; only collect normal parameters in both this and Signature::return_types

* Move normal_args to Signature::num_normal_params method

This matches the organization of the other Signature::num_*_params methods.

* Bitcast values of Operator::Call and Operator::CallIndirect

* Add DataFlowGraph::ebb_param_types

* Bitcast values of Operator::Br and Operator::BrIf

* Bitcast values of Operator::BrTable
2020-01-06 15:33:22 -08:00
Andrew Brown
b486289ab8 Translate Wasm's V128AndNot to CLIF's band_not (#1297)
The CLIF is already implemented for x86 SIMD.
2019-12-18 13:50:12 -07:00
Andrew Brown
887f897c9a Update wasmparser to 0.45.0 (#1295)
Adds many new operators and a few API changes.
2019-12-17 14:07:11 -06:00
Andrew Brown
af64187ec7 Truncate over-large parameters to splat (#1276)
See https://github.com/WebAssembly/simd/issues/149 for associated discussion on this.
2019-12-12 13:52:26 -08:00
Andrew Brown
396eba5235 Bitcast values incoming to vall_true and vany_true before use in Wasm translation (#1275) 2019-12-09 10:05:47 -08:00
Yury Delendik
2c51341888 Add wasm reference/pointers translation. (#1073) 2019-12-06 17:46:03 -06:00
Ryan Hunt
aabf6559a0 Add hooks for implementing bulk-memory-operations (#1258) 2019-12-06 16:13:53 +01:00
Andrew Brown
f72a5d9caa Translate WASM floating-point abs and neg to CLIF 2019-11-15 13:45:25 -08:00
Projjal Chanda
cd4d7ca0a1 Merged scalar and simd logical operator 2019-11-15 08:56:51 -08:00
Andrew Brown
a2b28f9472 Ensure vectors are bitcast to the correct type
Due to SIMD's v128 operations, vectors that may have had an explicit type (e.g. f32x4) before a v128 operation will subsequently have CLIF's v128 stand-in type: i8x16. In order for follow-on operations (that may be more stricly typed, e.g. f32x4.add) to avoid CLIF errors, we must bitcast them back to the operation type. The raw_bitcast operation used to do this emits no machine code but does incur some small compile-time cost; it would be nice to avoid this in the future.
2019-11-12 17:05:39 -08:00
Andrew Brown
b425ddc52d Translate WASM floating-point arithmetic to CLIF 2019-11-12 17:05:39 -08:00
Andrew Brown
81df93e6a0 Translate WASM float comparisons to CLIF 2019-11-08 14:06:53 -08:00
Andrew Brown
1417215532 Translate WASM integer less-than to CLIF 2019-11-05 16:42:34 -08:00
Andrew Brown
ce67ea5d58 Factor out common translations for SIMD comparisons 2019-11-05 16:42:34 -08:00
Andrew Brown
7715c5e07a Translate WASM integer greater-than to CLIF 2019-11-05 16:42:34 -08:00
Andrew Brown
f053595748 Translate WASM iTxN.gt_s to CLIF 2019-11-05 16:42:34 -08:00
Andrew Brown
3a94e8d46a Translate WASM iTxN.ne to CLIF 2019-11-05 16:42:34 -08:00
Andrew Brown
f8c3dfeb17 Translate WASM iTxN.eq to CLIF 2019-11-05 16:42:34 -08:00
Peter Huene
9f506692c2 Fix clippy warnings.
This commit fixes the current set of (stable) clippy warnings in the repo.
2019-10-24 17:20:12 -07:00
Andrew Brown
77035b44a6 Translate WASM all_true to CLIF 2019-10-22 11:01:05 -07:00
Andrew Brown
65e18df12f Translate WASM any_true to CLIF 2019-10-22 11:01:05 -07:00
Andrew Brown
135f9eb4a6 Translate WASM bitselect to CLIF 2019-10-17 15:49:29 -07:00
Andrew Brown
19a980363e Translate WASM shr to CLIF sshr and ushr
As with shift left, the spec requires that the shift count is computed modulo the lane width (see https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#left-shift-by-scalar).
2019-10-15 15:51:50 -07:00
Andrew Brown
808885ce56 Translate WASM shl to CLIF ishl
Note how, according to the spec (see https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#left-shift-by-scalar), the shift count is computed modulo the lane width. E.g., a shift count of 17 on an i16x8 should not result in all zeroes as it does with Cranelift's `ishl` and x86's `PSSLW`--it should shift once to the left.
2019-10-15 15:51:50 -07:00