Skip to content

Commit a3ca2af

Browse files
chore: refactor compiler macros
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
1 parent 15ab54b commit a3ca2af

File tree

8 files changed

+176
-251
lines changed

8 files changed

+176
-251
lines changed

.github/workflows/test.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,3 @@ jobs:
9999
target: ${{ matrix.target }}
100100
toolchain: ${{ matrix.rust }}
101101
if: matrix.target != ''
102-
103-
- name: Run clippy (${{ matrix.target }})
104-
uses: houseabsolute/actions-rust-cross@v0.0.13
105-
with:
106-
command: clippy
107-
target: ${{ matrix.target }}
108-
toolchain: ${{ matrix.rust }}
109-
if: matrix.target != ''

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/parser/src/visit.rs

Lines changed: 35 additions & 218 deletions
Large diffs are not rendered by default.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// WIP
2+
3+
struct V128([u8; 16]);
4+
5+
impl V128 {
6+
fn f32x4(&self) -> [f32; 4] {
7+
let mut res = [0.0; 4];
8+
for i in 0..4 {
9+
let mut f = [0; 4];
10+
for j in 0..4 {
11+
f[j] = self.0[i * 4 + j];
12+
}
13+
res[i] = f32::from_le_bytes(f);
14+
}
15+
res
16+
}
17+
18+
fn i32x4(&self) -> [i32; 4] {
19+
let mut res = [0; 4];
20+
for i in 0..4 {
21+
let mut f = [0; 4];
22+
for j in 0..4 {
23+
f[j] = self.0[i * 4 + j];
24+
}
25+
res[i] = i32::from_le_bytes(f);
26+
}
27+
res
28+
}
29+
30+
fn i64x2(&self) -> [i64; 2] {
31+
let mut res = [0; 2];
32+
for i in 0..2 {
33+
let mut f = [0; 8];
34+
for j in 0..8 {
35+
f[j] = self.0[i * 8 + j];
36+
}
37+
res[i] = i64::from_le_bytes(f);
38+
}
39+
res
40+
}
41+
42+
fn f64x2(&self) -> [f64; 2] {
43+
let mut res = [0.0; 2];
44+
for i in 0..2 {
45+
let mut f = [0; 8];
46+
for j in 0..8 {
47+
f[j] = self.0[i * 8 + j];
48+
}
49+
res[i] = f64::from_le_bytes(f);
50+
}
51+
res
52+
}
53+
54+
fn i16x8(&self) -> [i16; 8] {
55+
let mut res = [0; 8];
56+
for i in 0..8 {
57+
let mut f = [0; 2];
58+
for j in 0..2 {
59+
f[j] = self.0[i * 2 + j];
60+
}
61+
res[i] = i16::from_le_bytes(f);
62+
}
63+
res
64+
}
65+
66+
fn i8x16(&self) -> [i8; 16] {
67+
let mut res = [0; 16];
68+
for i in 0..16 {
69+
res[i] = i8::from_le_bytes([self.0[i]]);
70+
}
71+
res
72+
}
73+
}
74+
75+
fn vvunop(c1: V128) -> V128 {
76+
let mut res = [0; 16];
77+
for i in 0..16 {
78+
res[i] = !c1.0[i];
79+
}
80+
V128(res)
81+
}
82+
83+
fn vvbinop(c1: V128, c2: V128) -> V128 {
84+
let mut res = [0; 16];
85+
for i in 0..16 {
86+
res[i] = c1.0[i] & c2.0[i];
87+
}
88+
V128(res)
89+
}
90+
91+
fn vvternop(c1: V128, c2: V128, c3: V128) -> V128 {
92+
let mut res = [0; 16];
93+
for i in 0..16 {
94+
res[i] = c1.0[i] & c2.0[i] | !c1.0[i] & c3.0[i];
95+
}
96+
V128(res)
97+
}
98+
99+
fn any_true(val: V128) -> bool {
100+
val.0.iter().any(|&x| x != 0)
101+
}
102+
103+
fn i8x16_swizzle(c1: V128, c2: V128) -> V128 {
104+
let mut res = [0; 16];
105+
for i in 0..16 {
106+
res[i] = c1.0[c2.0[i] as usize];
107+
}
108+
V128(res)
109+
}
110+
111+
fn i18x16_shuffle(c1: V128, c2: V128) -> V128 {
112+
let mut res = [0; 16];
113+
for i in 0..16 {
114+
res[i] = c1.0[(c2.0[i] & 0xf) as usize];
115+
}
116+
V128(res)
117+
}
118+
119+
fn f32x4_abs(val: V128) -> V128 {
120+
let mut res = [0; 16];
121+
for i in 0..4 {
122+
let f = val.f32x4();
123+
let f = f32::abs(f[i]);
124+
let f = f.to_le_bytes();
125+
for j in 0..4 {
126+
res[i * 4 + j] = f[j];
127+
}
128+
}
129+
V128(res)
130+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() -> Result<()> {
77
let mut test_suite = TestSuite::new();
88

99
TestSuite::set_log_level(log::LevelFilter::Off);
10-
test_suite.run_spec_group(wasm_testsuite::V2_DRAFT_1_TESTS)?;
10+
test_suite.run_spec_group(wasm_testsuite::V2_TESTS)?;
1111
test_suite.save_csv("./tests/generated/wasm-2.csv", env!("CARGO_PKG_VERSION"))?;
1212

1313
if test_suite.failed() {

crates/types/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ rust-version.workspace=true
1010

1111
[dependencies]
1212
log={workspace=true, optional=true}
13-
rkyv={version="0.8.0-rc.2", optional=true, default-features=false, features=["alloc", "bytecheck"]}
13+
rkyv={version="0.8.1", optional=true, default-features=false, features=["alloc", "bytecheck"]}
1414

1515
[features]
1616
default=["std", "logging", "archive"]

crates/types/src/instructions.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,6 @@ pub enum ConstInstruction {
4242
// should be kept as small as possible (16 bytes max)
4343
#[rustfmt::skip]
4444
pub enum Instruction {
45-
// > Custom Instructions
46-
// // LocalGet + I32Const + I32Add
47-
// I32LocalGetConstAdd(LocalAddr, i32),
48-
// // LocalGet + I32Const + I32Store
49-
// I32ConstStoreLocal { local: LocalAddr, const_i32: i32, offset: u32, mem_addr: u8 },
50-
// // LocalGet + LocalGet + I32Store
51-
// I32StoreLocal { local_a: LocalAddr, local_b: LocalAddr, offset: u32, mem_addr: u8 },
52-
// // I64Xor + I64Const + I64RotL
53-
// // Commonly used by a few crypto libraries
54-
// I64XorConstRotl(i64),
55-
// // LocalTee + LocalGet
56-
// LocalTeeGet(LocalAddr, LocalAddr),
57-
// LocalGet2(LocalAddr, LocalAddr),
58-
// LocalGet3(LocalAddr, LocalAddr, LocalAddr),
59-
// LocalGetSet(LocalAddr, LocalAddr),
60-
61-
// LocalGetGet32(LocalAddr, LocalAddr), LocalGetGet64(LocalAddr, LocalAddr), LocalGetGet128(LocalAddr, LocalAddr),
62-
// LocalTeeGet32(LocalAddr, LocalAddr), LocalTeeGet64(LocalAddr, LocalAddr), LocalTeeGet128(LocalAddr, LocalAddr),
6345
LocalCopy32(LocalAddr, LocalAddr), LocalCopy64(LocalAddr, LocalAddr), LocalCopy128(LocalAddr, LocalAddr), LocalCopy128Ref(LocalAddr, LocalAddr), LocalCopyRef(LocalAddr, LocalAddr),
6446
LocalsStore32(LocalAddr, LocalAddr, u32, MemAddr), LocalsStore64(LocalAddr, LocalAddr, u32, MemAddr), LocalsStore128(LocalAddr, LocalAddr, u32, MemAddr), LocalsStoreRef(LocalAddr, LocalAddr, u32, MemAddr),
6547

@@ -205,4 +187,8 @@ pub enum Instruction {
205187
MemoryFill(MemAddr),
206188
DataDrop(DataAddr),
207189
ElemDrop(ElemAddr),
190+
191+
// // > SIMD Instructions
192+
// V128Load(MemoryArg), V128Load8x8S { offset: u64, mem_addr: MemAddr }, V128Load8x8U { offset: u64, mem_addr: MemAddr }, V128Load16x4S { offset: u64, mem_addr: MemAddr }, V128Load16x4U { offset: u64, mem_addr: MemAddr }, V128Load32x2S { offset: u64, mem_addr: MemAddr }, V128Load32x2U { offset: u64, mem_addr: MemAddr }, V128Load8Splat { offset: u64, mem_addr: MemAddr }, V128Load16Splat { offset: u64, mem_addr: MemAddr }, V128Load32Splat { offset: u64, mem_addr: MemAddr }, V128Load64Splat { offset: u64, mem_addr: MemAddr }, V128Load32Zero { offset: u64, mem_addr: MemAddr }, V128Load64Zero { offset: u64, mem_addr: MemAddr },
193+
// V128Store { offset: u64, mem_addr: MemAddr }, V128Store8x8 { offset: u64, mem_addr: MemAddr }, V128Store16x4 { offset: u64, mem_addr: MemAddr }, V128Store32x2 { offset: u64, mem_addr: MemAddr },
208194
}

crates/wasm-testsuite/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub const MVP_TESTS: &[&str] = &["address.wast", "align.wast", "binary-leb128.wa
3232

3333
/// List of all tests that apply to the V2 draft 1 spec.
3434
#[rustfmt::skip]
35-
pub const V2_DRAFT_1_TESTS: &[&str] = &["address.wast", "align.wast", "binary-leb128.wast", "binary.wast", "block.wast", "br.wast", "br_if.wast", "br_table.wast", "bulk.wast", "call.wast", "call_indirect.wast", "comments.wast", "const.wast", "conversions.wast", "custom.wast", "data.wast", "elem.wast", "endianness.wast", "exports.wast", "f32.wast", "f32_bitwise.wast", "f32_cmp.wast", "f64.wast", "f64_bitwise.wast", "f64_cmp.wast", "fac.wast", "float_exprs.wast", "float_literals.wast", "float_memory.wast", "float_misc.wast", "forward.wast", "func.wast", "func_ptrs.wast", "global.wast", "i32.wast", "i64.wast", "if.wast", "imports.wast", "inline-module.wast", "int_exprs.wast", "int_literals.wast", "labels.wast", "left-to-right.wast", "linking.wast", "load.wast", "local_get.wast", "local_set.wast", "local_tee.wast", "loop.wast", "memory.wast", "memory_copy.wast", "memory_fill.wast", "memory_grow.wast", "memory_init.wast", "memory_redundancy.wast", "memory_size.wast", "memory_trap.wast", "names.wast", "nop.wast", "obsolete-keywords.wast", "ref_func.wast", "ref_is_null.wast", "ref_null.wast", "return.wast", "select.wast", "skip-stack-guard-page.wast", "stack.wast", "start.wast", "store.wast", "switch.wast", "table-sub.wast", "table.wast", "table_copy.wast", "table_fill.wast", "table_get.wast", "table_grow.wast", "table_init.wast", "table_set.wast", "table_size.wast", "token.wast", "traps.wast", "type.wast", "unreachable.wast", "unreached-invalid.wast", "unreached-valid.wast", "unwind.wast", "utf8-custom-section-id.wast", "utf8-import-field.wast", "utf8-import-module.wast", "utf8-invalid-encoding.wast"];
35+
pub const V2_TESTS: &[&str] = &["address.wast", "align.wast", "binary-leb128.wast", "binary.wast", "block.wast", "br.wast", "br_if.wast", "br_table.wast", "bulk.wast", "call.wast", "call_indirect.wast", "comments.wast", "const.wast", "conversions.wast", "custom.wast", "data.wast", "elem.wast", "endianness.wast", "exports.wast", "f32.wast", "f32_bitwise.wast", "f32_cmp.wast", "f64.wast", "f64_bitwise.wast", "f64_cmp.wast", "fac.wast", "float_exprs.wast", "float_literals.wast", "float_memory.wast", "float_misc.wast", "forward.wast", "func.wast", "func_ptrs.wast", "global.wast", "i32.wast", "i64.wast", "if.wast", "imports.wast", "inline-module.wast", "int_exprs.wast", "int_literals.wast", "labels.wast", "left-to-right.wast", "linking.wast", "load.wast", "local_get.wast", "local_set.wast", "local_tee.wast", "loop.wast", "memory.wast", "memory_copy.wast", "memory_fill.wast", "memory_grow.wast", "memory_init.wast", "memory_redundancy.wast", "memory_size.wast", "memory_trap.wast", "names.wast", "nop.wast", "obsolete-keywords.wast", "ref_func.wast", "ref_is_null.wast", "ref_null.wast", "return.wast", "select.wast", "skip-stack-guard-page.wast", "stack.wast", "start.wast", "store.wast", "switch.wast", "table-sub.wast", "table.wast", "table_copy.wast", "table_fill.wast", "table_get.wast", "table_grow.wast", "table_init.wast", "table_set.wast", "table_size.wast", "token.wast", "traps.wast", "type.wast", "unreachable.wast", "unreached-invalid.wast", "unreached-valid.wast", "unwind.wast", "utf8-custom-section-id.wast", "utf8-import-field.wast", "utf8-import-module.wast", "utf8-invalid-encoding.wast"];
3636

3737
/// List of all tests that apply to the simd proposal
3838
#[rustfmt::skip]

0 commit comments

Comments
 (0)