Skip to content

Commit fc0d538

Browse files
authored
wasmi_core: add support for the Wasm simd proposal (#1395)
* add simd crate feature to wasmi_core crate * implement V128 skeleton This is the skeleton with which is it going to be possible to implement most of the V128 API in an efficient way. * rename IntoLane and Lane (appending 's') * add docs to most (or all) simd.rs definitions * add note comments to unsafe transmutes * implement SIMD splat instructions * add extract_lane SIMD APIs * expect dead_code warnings This will help later to remove the lint again. * remove empty line * remove non-existing extract_lane APIs * add replace_lane SIMD APIs * add V128 From impls for bytes and i128 * add SIMD binary integer math ops * add unary integer math SIMD ops * add SIMD integer abs ops * add unsigned SIMD lanes types * use unsigned SIMD types where applicable for now * improve docs for IntoLanes and IntoLaneIdx * add helper IntoLanewiseWidening trait * clean-up API design * add SIMD ext_mul_{low,high} ops * generate docs for new SIMD extmul ops * add extadd_pairwise SIMD ops * implement add_sat and sub_sat SIMD ops * add i16x8_q15mulr_sat_s SIMD operation * add SIMD integer min and max operations * add SIMD avgr_u ops * implement Wasm shift SIMD ops * add bitwise SIMD ops * add v128.bitselect SIMD operation * add SIMD i8x16.popcnt instruction * add i32x4.dot_i16x8_s SIMD operation * implement SIMD reduce ops * add SIMD comparison instructions * add unary float SIMD instructions * move op! macro to top of file * add float binary SIMD instructions * add lanewise unary cast SIMD ops * rewrite i32x4.dot_i16x8_s in terms of other fns * add FromNarrow trait and impls * add V128 convenience methods for FromNarrow * rewrite extmul ops in terms of FromNarrow APIs * rewrite extadd ops in terms of FromNarrow APIs * add new extend SIMD ops * remove old widening and narrowing APIs * no longer silence dead_code warnings * add missing docs for convenience method * refactor unary widen SIMD ops generation * add more widen-low SIMD ops * fix signedness of some SIMD extend-{low,high} ops * rename macro * add narrowing-low-high SIMD ops * rename FromNarrow method * fix i32x4_dot_i16x8_s SIMD impl * re-format code * re-write from_low_high impl * add narrowing low-or SIMD ops * convert all V128 methods to functions in the simd module This better aligns the V128 API with the wasmi_core::wasm API. Furthermore it makes more sense to have those methods as functions for the load and store APIs that still have to be implemented. * align docs with others * align more docs * replace register128 feature with simd feature * move load/store stuff into memory.rs module * redesign WrapInto and ExtendInto macros * remove ImmByte since it is unused * rename OutOfBoundsLaneId * merge macro invocations * re-design extmul macros * refactor macros * refactor memory submodule This now exposes `load`, `load_at`, `store` and `store_at` functions additionally to the load_extend and store_wrap ones. This way we no longer require the weird `WrapInto` and `ExtendInto` impls for `T -> T`. * add v128 store instructions * add v128.load evaluators * add LaneIndex trait * add more IntoLaneIdx trait impls This allows to infer the LaneIdx type from more types such as i8, u32, f64, etc.. * add impls for v128.load{32,64}_zero * update docs * add v128.loadN_splat instruction impls * add v128.loadN_lane SIMD instruction impls * update docs error sections * implement V128 load_mxn_{s,u} ops * configure Cargo to generate simd docs * remove value128 crate feature The new `simd` crate feature is a full replacement for it. * fix avgr SIMD instructions and clippy warnings - Fixes an overflow issue in the avgr_u SIMD instructions. - Now uses div_ceil as suggested by clippy. - Deduplicated logic via macro. * rename some FromNarrow methods to please clippy * add SIMD shuffle and swizzle ops
1 parent cedb0f8 commit fc0d538

File tree

6 files changed

+1741
-18
lines changed

6 files changed

+1741
-18
lines changed

crates/core/Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ downcast-rs = { version = "2.0.1", default-features = false, features = ["sync"]
2121
default = ["std"]
2222
# Use `no-default-features` for a `no_std` build.
2323
std = ["downcast-rs/std"]
24-
25-
# Enable this to use 128-bit untyped values.
24+
# Enables the Wasm `simd` proposal.
2625
#
27-
# This mainly affects the `UntypedVal` type since it acts as Wasmi's register cell type.
28-
value128 = []
26+
# This also changes the size of `UntypedVal` from 64-bit to 128-bit
27+
# which may have significant impact on performance and memory usage.
28+
simd = []
2929

3030
[package.metadata.cargo-udeps.ignore]
3131
# cargo-udeps cannot detect that libm is used for no_std targets only.
3232
normal = ["libm"]
33+
34+
[package.metadata.docs.rs]
35+
all-features = true

crates/core/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ mod untyped;
2121
mod value;
2222
pub mod wasm;
2323

24+
#[cfg(feature = "simd")]
25+
pub mod simd;
26+
2427
extern crate alloc;
2528
#[cfg(feature = "std")]
2629
extern crate std;

crates/core/src/memory.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,25 @@ macro_rules! impl_extend_into {
5050
};
5151
}
5252
impl_extend_into! {
53+
// unsigned -> unsigned
54+
impl ExtendInto<u16> for u8;
55+
impl ExtendInto<u32> for u16;
56+
impl ExtendInto<u64> for u32;
57+
58+
// signed -> signed
59+
impl ExtendInto<i16> for i8;
5360
impl ExtendInto<i32> for i8;
54-
impl ExtendInto<i32> for u8;
55-
impl ExtendInto<i32> for i16;
56-
impl ExtendInto<i32> for u16;
5761
impl ExtendInto<i64> for i8;
58-
impl ExtendInto<i64> for u8;
62+
impl ExtendInto<i32> for i16;
5963
impl ExtendInto<i64> for i16;
60-
impl ExtendInto<i64> for u16;
6164
impl ExtendInto<i64> for i32;
65+
66+
// unsigned -> signed
67+
impl ExtendInto<i32> for u8;
68+
impl ExtendInto<i64> for u8;
69+
impl ExtendInto<i32> for u16;
70+
impl ExtendInto<i64> for u16;
6271
impl ExtendInto<i64> for u32;
63-
impl ExtendInto<u64> for u32;
6472
}
6573

6674
/// Allows to efficiently load bytes from `memory` into a buffer.
@@ -140,7 +148,7 @@ macro_rules! impl_little_endian_convert_primitive {
140148
)*
141149
};
142150
}
143-
impl_little_endian_convert_primitive!(u8, u16, u32, u64, i8, i16, i32, i64, f32, f64);
151+
impl_little_endian_convert_primitive!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, f32, f64);
144152

145153
/// Calculates the effective address of a linear memory access.
146154
///

0 commit comments

Comments
 (0)