Skip to content
This repository was archived by the owner on Oct 3, 2025. It is now read-only.

Commit 86bcc87

Browse files
wip: simd support
Signed-off-by: Henry Gressmann <[email protected]>
1 parent 07804aa commit 86bcc87

File tree

8 files changed

+104
-4
lines changed

8 files changed

+104
-4
lines changed

crates/parser/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ impl Parser {
6161
function_references: true,
6262
tail_call: true,
6363
multi_memory: true,
64+
memory64: false,
65+
simd: true,
6466

6567
gc_types: true,
6668
component_model: false,
@@ -70,10 +72,8 @@ impl Parser {
7072
exceptions: false,
7173
extended_const: false,
7274
gc: false,
73-
memory64: false,
7475
memory_control: false,
7576
relaxed_simd: false,
76-
simd: false,
7777
threads: false,
7878
custom_page_sizes: false,
7979
shared_everything_threads: false,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.8.0,331,286,[{"name":"annotations.wast","passed":74,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"simd_lane.wast","passed":189,"failed":286},{"name":"token.wast","passed":61,"failed":0}]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.8.0,15074,3213,[{"name":"address.wast","passed":260,"failed":0},{"name":"address0.wast","passed":92,"failed":0},{"name":"address1.wast","passed":127,"failed":0},{"name":"address64.wast","passed":0,"failed":242},{"name":"align.wast","passed":162,"failed":0},{"name":"align0.wast","passed":5,"failed":0},{"name":"align64.wast","passed":83,"failed":73},{"name":"annotations.wast","passed":74,"failed":0},{"name":"array_copy.wast","passed":4,"failed":31},{"name":"array_fill.wast","passed":3,"failed":14},{"name":"array_init_data.wast","passed":2,"failed":31},{"name":"array_init_elem.wast","passed":3,"failed":20},{"name":"binary-gc.wast","passed":1,"failed":0},{"name":"binary-leb128.wast","passed":92,"failed":1},{"name":"binary.wast","passed":124,"failed":0},{"name":"binary0.wast","passed":7,"failed":0},{"name":"br_if.wast","passed":119,"failed":0},{"name":"br_on_cast.wast","passed":6,"failed":31},{"name":"br_on_cast_fail.wast","passed":6,"failed":31},{"name":"br_on_non_null.wast","passed":1,"failed":9},{"name":"br_on_null.wast","passed":1,"failed":9},{"name":"br_table.wast","passed":24,"failed":162},{"name":"call_indirect.wast","passed":47,"failed":124},{"name":"call_ref.wast","passed":4,"failed":31},{"name":"data.wast","passed":59,"failed":6},{"name":"data0.wast","passed":7,"failed":0},{"name":"data1.wast","passed":14,"failed":0},{"name":"data_drop0.wast","passed":11,"failed":0},{"name":"elem.wast","passed":137,"failed":14},{"name":"endianness64.wast","passed":0,"failed":69},{"name":"exports.wast","passed":97,"failed":0},{"name":"exports0.wast","passed":8,"failed":0},{"name":"float_exprs0.wast","passed":14,"failed":0},{"name":"float_exprs1.wast","passed":3,"failed":0},{"name":"float_memory0.wast","passed":30,"failed":0},{"name":"float_memory64.wast","passed":0,"failed":90},{"name":"func.wast","passed":175,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":107,"failed":82},{"name":"imports0.wast","passed":8,"failed":0},{"name":"imports1.wast","passed":5,"failed":0},{"name":"imports2.wast","passed":20,"failed":0},{"name":"imports3.wast","passed":10,"failed":0},{"name":"imports4.wast","passed":16,"failed":0},{"name":"linking.wast","passed":122,"failed":41},{"name":"linking0.wast","passed":6,"failed":0},{"name":"linking1.wast","passed":14,"failed":0},{"name":"linking2.wast","passed":11,"failed":0},{"name":"linking3.wast","passed":14,"failed":0},{"name":"load.wast","passed":118,"failed":0},{"name":"load0.wast","passed":3,"failed":0},{"name":"load1.wast","passed":18,"failed":0},{"name":"load2.wast","passed":38,"failed":0},{"name":"load64.wast","passed":59,"failed":38},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_init.wast","passed":10,"failed":0},{"name":"local_tee.wast","passed":98,"failed":0},{"name":"memory-multi.wast","passed":6,"failed":0},{"name":"memory.wast","passed":86,"failed":0},{"name":"memory64.wast","passed":10,"failed":53},{"name":"memory64/array.wast (skipped)","passed":0,"failed":0},{"name":"memory64/extern.wast (skipped)","passed":0,"failed":0},{"name":"memory64/global.wast (skipped)","passed":0,"failed":0},{"name":"memory64/i31.wast (skipped)","passed":0,"failed":0},{"name":"memory64/ref_null.wast (skipped)","passed":0,"failed":0},{"name":"memory64/select.wast (skipped)","passed":0,"failed":0},{"name":"memory64/simd_address.wast (skipped)","passed":0,"failed":0},{"name":"memory64/simd_lane.wast (skipped)","passed":0,"failed":0},{"name":"memory64/struct.wast (skipped)","passed":0,"failed":0},{"name":"memory64/table.wast (skipped)","passed":0,"failed":0},{"name":"memory_copy.wast","passed":8385,"failed":515},{"name":"memory_copy0.wast","passed":29,"failed":0},{"name":"memory_copy1.wast","passed":14,"failed":0},{"name":"memory_fill.wast","passed":164,"failed":36},{"name":"memory_fill0.wast","passed":16,"failed":0},{"name":"memory_grow.wast","passed":149,"failed":0},{"name":"memory_grow64.wast","passed":0,"failed":49},{"name":"memory_init.wast","passed":307,"failed":173},{"name":"memory_init0.wast","passed":13,"failed":0},{"name":"memory_redundancy64.wast","passed":0,"failed":8},{"name":"memory_size.wast","passed":49,"failed":0},{"name":"memory_size0.wast","passed":8,"failed":0},{"name":"memory_size1.wast","passed":15,"failed":0},{"name":"memory_size2.wast","passed":21,"failed":0},{"name":"memory_size3.wast","passed":2,"failed":0},{"name":"memory_trap0.wast","passed":14,"failed":0},{"name":"memory_trap1.wast","passed":168,"failed":0},{"name":"memory_trap64.wast","passed":0,"failed":172},{"name":"ref.wast","passed":12,"failed":1},{"name":"ref_as_non_null.wast","passed":1,"failed":6},{"name":"ref_cast.wast","passed":0,"failed":45},{"name":"ref_eq.wast","passed":6,"failed":83},{"name":"ref_is_null.wast","passed":2,"failed":20},{"name":"ref_test.wast","passed":0,"failed":71},{"name":"return_call.wast","passed":18,"failed":27},{"name":"return_call_indirect.wast","passed":31,"failed":45},{"name":"return_call_ref.wast","passed":11,"failed":40},{"name":"simd_memory-multi.wast","passed":0,"failed":1},{"name":"start0.wast","passed":9,"failed":0},{"name":"store.wast","passed":111,"failed":0},{"name":"store0.wast","passed":5,"failed":0},{"name":"store1.wast","passed":13,"failed":0},{"name":"table-sub.wast","passed":2,"failed":1},{"name":"table_copy.wast","passed":1742,"failed":30},{"name":"table_copy_mixed.wast","passed":3,"failed":1},{"name":"table_fill.wast","passed":9,"failed":71},{"name":"table_get.wast","passed":5,"failed":12},{"name":"table_grow.wast","passed":28,"failed":43},{"name":"table_init.wast","passed":588,"failed":288},{"name":"table_set.wast","passed":7,"failed":21},{"name":"table_size.wast","passed":2,"failed":38},{"name":"tag.wast","passed":1,"failed":8},{"name":"throw.wast","passed":3,"failed":10},{"name":"throw_ref.wast","passed":2,"failed":13},{"name":"token.wast","passed":61,"failed":0},{"name":"traps0.wast","passed":15,"failed":0},{"name":"try_table.wast","passed":11,"failed":50},{"name":"type-canon.wast","passed":0,"failed":2},{"name":"type-equivalence.wast","passed":12,"failed":20},{"name":"type-rec.wast","passed":6,"failed":14},{"name":"type-subtyping.wast","passed":16,"failed":86},{"name":"unreached-invalid.wast","passed":121,"failed":0},{"name":"unreached-valid.wast","passed":2,"failed":11}]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.8.0,1300,24679,[{"name":"simd_address.wast","passed":4,"failed":45},{"name":"simd_align.wast","passed":46,"failed":54},{"name":"simd_bit_shift.wast","passed":39,"failed":213},{"name":"simd_bitwise.wast","passed":28,"failed":141},{"name":"simd_boolean.wast","passed":16,"failed":261},{"name":"simd_const.wast","passed":301,"failed":456},{"name":"simd_conversions.wast","passed":48,"failed":234},{"name":"simd_f32x4.wast","passed":16,"failed":774},{"name":"simd_f32x4_arith.wast","passed":16,"failed":1806},{"name":"simd_f32x4_cmp.wast","passed":24,"failed":2583},{"name":"simd_f32x4_pmin_pmax.wast","passed":14,"failed":3873},{"name":"simd_f32x4_rounding.wast","passed":24,"failed":177},{"name":"simd_f64x2.wast","passed":8,"failed":795},{"name":"simd_f64x2_arith.wast","passed":16,"failed":1809},{"name":"simd_f64x2_cmp.wast","passed":24,"failed":2661},{"name":"simd_f64x2_pmin_pmax.wast","passed":14,"failed":3873},{"name":"simd_f64x2_rounding.wast","passed":24,"failed":177},{"name":"simd_i16x8_arith.wast","passed":11,"failed":183},{"name":"simd_i16x8_arith2.wast","passed":19,"failed":153},{"name":"simd_i16x8_cmp.wast","passed":30,"failed":435},{"name":"simd_i16x8_extadd_pairwise_i8x16.wast","passed":4,"failed":17},{"name":"simd_i16x8_extmul_i8x16.wast","passed":12,"failed":105},{"name":"simd_i16x8_q15mulr_sat_s.wast","passed":3,"failed":27},{"name":"simd_i16x8_sat_arith.wast","passed":16,"failed":206},{"name":"simd_i32x4_arith.wast","passed":11,"failed":183},{"name":"simd_i32x4_arith2.wast","passed":26,"failed":123},{"name":"simd_i32x4_cmp.wast","passed":40,"failed":435},{"name":"simd_i32x4_dot_i16x8.wast","passed":3,"failed":27},{"name":"simd_i32x4_extadd_pairwise_i16x8.wast","passed":4,"failed":17},{"name":"simd_i32x4_extmul_i16x8.wast","passed":12,"failed":105},{"name":"simd_i32x4_trunc_sat_f32x4.wast","passed":4,"failed":103},{"name":"simd_i32x4_trunc_sat_f64x2.wast","passed":4,"failed":103},{"name":"simd_i64x2_arith.wast","passed":11,"failed":189},{"name":"simd_i64x2_arith2.wast","passed":2,"failed":23},{"name":"simd_i64x2_cmp.wast","passed":10,"failed":103},{"name":"simd_i64x2_extmul_i32x4.wast","passed":12,"failed":105},{"name":"simd_i8x16_arith.wast","passed":8,"failed":123},{"name":"simd_i8x16_arith2.wast","passed":25,"failed":186},{"name":"simd_i8x16_cmp.wast","passed":30,"failed":415},{"name":"simd_i8x16_sat_arith.wast","passed":24,"failed":190},{"name":"simd_int_to_int_extend.wast","passed":24,"failed":229},{"name":"simd_lane.wast","passed":189,"failed":286},{"name":"simd_linking.wast","passed":0,"failed":3},{"name":"simd_load.wast","passed":8,"failed":31},{"name":"simd_load16_lane.wast","passed":3,"failed":33},{"name":"simd_load32_lane.wast","passed":3,"failed":21},{"name":"simd_load64_lane.wast","passed":3,"failed":13},{"name":"simd_load8_lane.wast","passed":3,"failed":49},{"name":"simd_load_extend.wast","passed":18,"failed":86},{"name":"simd_load_splat.wast","passed":12,"failed":114},{"name":"simd_load_zero.wast","passed":10,"failed":29},{"name":"simd_splat.wast","passed":23,"failed":162},{"name":"simd_store.wast","passed":9,"failed":19},{"name":"simd_store16_lane.wast","passed":3,"failed":33},{"name":"simd_store32_lane.wast","passed":3,"failed":21},{"name":"simd_store64_lane.wast","passed":3,"failed":13},{"name":"simd_store8_lane.wast","passed":3,"failed":49}]

crates/tinywasm/tests/test-wasm-memory64.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ use testsuite::TestSuite;
55

66
fn main() -> Result<()> {
77
let mut test_suite = TestSuite::new();
8+
test_suite.skip("memory64/array.wast");
9+
test_suite.skip("memory64/extern.wast");
10+
test_suite.skip("memory64/global.wast");
11+
test_suite.skip("memory64/i31.wast");
12+
test_suite.skip("memory64/ref_null.wast");
13+
test_suite.skip("memory64/select.wast");
14+
test_suite.skip("memory64/simd_address.wast");
15+
test_suite.skip("memory64/simd_lane.wast");
16+
test_suite.skip("memory64/struct.wast");
17+
test_suite.skip("memory64/table.wast");
818

919
TestSuite::set_log_level(log::LevelFilter::Off);
1020
test_suite.run_spec_group(wasm_testsuite::get_proposal_tests("memory64"))?;

crates/tinywasm/tests/testsuite/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ impl TestSuite {
5050
Self(BTreeMap::new(), Vec::new())
5151
}
5252

53+
pub fn skip(&mut self, name: &str) {
54+
self.1.push(name.to_string());
55+
}
56+
5357
pub fn failed(&self) -> bool {
5458
self.0.values().any(|group| group.stats().1 > 0)
5559
}

crates/tinywasm/tests/testsuite/util.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ fn wastarg2tinywasmvalue(arg: wast::WastArg) -> Result<tinywasm_types::WasmValue
9797
return Err(eyre!("unsupported arg type: Component"));
9898
};
9999

100-
use wast::core::WastArgCore::{RefExtern, RefNull, F32, F64, I32, I64};
100+
use wast::core::WastArgCore::{RefExtern, RefNull, F32, F64, I32, I64, V128};
101101
Ok(match arg {
102102
F32(f) => WasmValue::F32(f32::from_bits(f.bits)),
103103
F64(f) => WasmValue::F64(f64::from_bits(f.bits)),
104104
I32(i) => WasmValue::I32(i),
105105
I64(i) => WasmValue::I64(i),
106+
V128(i) => WasmValue::V128(i128::from_le_bytes(i.to_le_bytes()).try_into().unwrap()),
106107
RefExtern(v) => WasmValue::RefExtern(v),
107108
RefNull(t) => match t {
108109
wast::core::HeapType::Abstract { shared: false, ty: AbstractHeapType::Func } => {
@@ -117,17 +118,33 @@ fn wastarg2tinywasmvalue(arg: wast::WastArg) -> Result<tinywasm_types::WasmValue
117118
})
118119
}
119120

121+
fn wast_i128_to_i128(i: wast::core::V128Pattern) -> u128 {
122+
match i {
123+
wast::core::V128Pattern::F32x4(f) => {
124+
f.iter().fold(0, |acc, &f| acc << 32 | nanpattern2tinywasmvalue(f).unwrap().as_f32().unwrap() as u128)
125+
}
126+
wast::core::V128Pattern::F64x2(f) => {
127+
f.iter().fold(0, |acc, &f| acc << 64 | nanpattern2tinywasmvalue(f).unwrap().as_f64().unwrap() as u128)
128+
}
129+
wast::core::V128Pattern::I16x8(f) => f.iter().fold(0, |acc, &f| acc << 16 | f as u128),
130+
wast::core::V128Pattern::I32x4(f) => f.iter().fold(0, |acc, &f| acc << 32 | f as u128),
131+
wast::core::V128Pattern::I64x2(f) => f.iter().fold(0, |acc, &f| acc << 64 | f as u128),
132+
wast::core::V128Pattern::I8x16(f) => f.iter().fold(0, |acc, &f| acc << 8 | f as u128),
133+
}
134+
}
135+
120136
fn wastret2tinywasmvalue(ret: wast::WastRet) -> Result<tinywasm_types::WasmValue> {
121137
let wast::WastRet::Core(ret) = ret else {
122138
return Err(eyre!("unsupported arg type"));
123139
};
124140

125-
use wast::core::WastRetCore::{RefExtern, RefFunc, RefNull, F32, F64, I32, I64};
141+
use wast::core::WastRetCore::{RefExtern, RefFunc, RefNull, F32, F64, I32, I64, V128};
126142
Ok(match ret {
127143
F32(f) => nanpattern2tinywasmvalue(f)?,
128144
F64(f) => nanpattern2tinywasmvalue(f)?,
129145
I32(i) => WasmValue::I32(i),
130146
I64(i) => WasmValue::I64(i),
147+
V128(i) => WasmValue::V128(wast_i128_to_i128(i)),
131148
RefNull(t) => match t {
132149
Some(wast::core::HeapType::Abstract { shared: false, ty: AbstractHeapType::Func }) => {
133150
WasmValue::RefNull(ValType::RefFunc)
@@ -139,10 +156,12 @@ fn wastret2tinywasmvalue(ret: wast::WastRet) -> Result<tinywasm_types::WasmValue
139156
},
140157
RefExtern(v) => match v {
141158
Some(v) => WasmValue::RefExtern(v),
159+
None => WasmValue::RefNull(ValType::RefExtern),
142160
_ => return Err(eyre!("unsupported arg type: refextern: {:?}", v)),
143161
},
144162
RefFunc(v) => match v {
145163
Some(wast::token::Index::Num(n, _)) => WasmValue::RefFunc(n),
164+
None => WasmValue::RefNull(ValType::RefFunc),
146165
_ => return Err(eyre!("unsupported arg type: reffunc: {:?}", v)),
147166
},
148167
a => return Err(eyre!("unsupported arg type {:?}", a)),

crates/types/src/value.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,70 @@ impl WasmValue {
7979
_ => false,
8080
}
8181
}
82+
83+
#[doc(hidden)]
84+
pub fn as_i32(&self) -> Option<i32> {
85+
match self {
86+
Self::I32(i) => Some(*i),
87+
_ => None,
88+
}
89+
}
90+
91+
#[doc(hidden)]
92+
pub fn as_i64(&self) -> Option<i64> {
93+
match self {
94+
Self::I64(i) => Some(*i),
95+
_ => None,
96+
}
97+
}
98+
99+
#[doc(hidden)]
100+
pub fn as_f32(&self) -> Option<f32> {
101+
match self {
102+
Self::F32(i) => Some(*i),
103+
_ => None,
104+
}
105+
}
106+
107+
#[doc(hidden)]
108+
pub fn as_f64(&self) -> Option<f64> {
109+
match self {
110+
Self::F64(i) => Some(*i),
111+
_ => None,
112+
}
113+
}
114+
115+
#[doc(hidden)]
116+
pub fn as_v128(&self) -> Option<u128> {
117+
match self {
118+
Self::V128(i) => Some(*i),
119+
_ => None,
120+
}
121+
}
122+
123+
#[doc(hidden)]
124+
pub fn as_ref_extern(&self) -> Option<ExternAddr> {
125+
match self {
126+
Self::RefExtern(addr) => Some(*addr),
127+
_ => None,
128+
}
129+
}
130+
131+
#[doc(hidden)]
132+
pub fn as_ref_func(&self) -> Option<FuncAddr> {
133+
match self {
134+
Self::RefFunc(addr) => Some(*addr),
135+
_ => None,
136+
}
137+
}
138+
139+
#[doc(hidden)]
140+
pub fn as_ref_null(&self) -> Option<ValType> {
141+
match self {
142+
Self::RefNull(ty) => Some(*ty),
143+
_ => None,
144+
}
145+
}
82146
}
83147

84148
#[cold]

0 commit comments

Comments
 (0)