Skip to content

Commit bb439da

Browse files
chore: try to make simd ops more likely to autovectorize
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent ca6c66a commit bb439da

File tree

6 files changed

+290
-255
lines changed

6 files changed

+290
-255
lines changed

.github/workflows/test.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@ jobs:
1313
name: Build wasm
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1717
with:
1818
submodules: true
1919
- name: Install Rust toolchain
20-
uses: actions-rust-lang/setup-rust-toolchain@v1
20+
uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4
2121
with:
22-
toolchain: stable
22+
toolchain: nightly
23+
components: rust-src
2324
rustflags: ""
2425
target: wasm32-unknown-unknown
2526
- name: Install Binaryen and WABT
2627
run: sudo apt-get install -y binaryen wabt
2728
- name: Build wasm
2829
run: ./examples/rust/build.sh
2930
- name: Save artifacts
30-
uses: actions/upload-artifact@v4
31+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
3132
with:
3233
name: wasm
3334
path: examples/rust/out
@@ -67,20 +68,20 @@ jobs:
6768
runs-on: ${{ matrix.os }}
6869
steps:
6970
- name: Checkout code
70-
uses: actions/checkout@v4
71+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
7172
with:
7273
submodules: true
7374

7475
- name: Install Rust toolchain
75-
uses: actions-rust-lang/setup-rust-toolchain@v1
76+
uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4
7677
with:
7778
toolchain: ${{ matrix.rust }}
7879
rustflags: ""
7980
components: rustfmt, clippy
8081
if: matrix.target == ''
8182

8283
- name: Load wasm
83-
uses: actions/download-artifact@v4
84+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
8485
with:
8586
name: wasm
8687
path: examples/rust/out
@@ -94,7 +95,7 @@ jobs:
9495
if: matrix.target == ''
9596

9697
- name: Run tests (${{ matrix.target }})
97-
uses: houseabsolute/actions-rust-cross@v0.0.13
98+
uses: houseabsolute/actions-rust-cross@a8cc74d61047fa553b4e908b4b10e70029f00ca6 # v1.0.6
9899
with:
99100
command: test
100101
target: ${{ matrix.target }}

crates/tinywasm/benches/argon2id.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ fn argon2id_run(module: TinyWasmModule) -> Result<()> {
3131

3232
fn criterion_benchmark(c: &mut Criterion) {
3333
let module = argon2id_parse().expect("argon2id_parse");
34-
let _twasm = argon2id_to_twasm(&module).expect("argon2id_to_twasm");
34+
let twasm = argon2id_to_twasm(&module).expect("argon2id_to_twasm");
3535

36-
// c.bench_function("argon2id_parse", |b| b.iter(argon2id_parse));
37-
// c.bench_function("argon2id_to_twasm", |b| b.iter(|| argon2id_to_twasm(&module)));
38-
// c.bench_function("argon2id_from_twasm", |b| b.iter(|| argon2id_from_twasm(&twasm)));
36+
c.bench_function("argon2id_parse", |b| b.iter(argon2id_parse));
37+
c.bench_function("argon2id_to_twasm", |b| b.iter(|| argon2id_to_twasm(&module)));
38+
c.bench_function("argon2id_from_twasm", |b| b.iter(|| argon2id_from_twasm(&twasm)));
3939
c.bench_function("argon2id", |b| b.iter(|| argon2id_run(module.clone())));
4040
}
4141

crates/tinywasm/benches/fibonacci.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ fn fibonacci_run(module: TinyWasmModule, recursive: bool, n: i32) -> Result<()>
3636

3737
fn criterion_benchmark(c: &mut Criterion) {
3838
let module = fibonacci_parse().expect("fibonacci_parse");
39-
let _twasm = fibonacci_to_twasm(&module).expect("fibonacci_to_twasm");
39+
let twasm = fibonacci_to_twasm(&module).expect("fibonacci_to_twasm");
4040

41-
// c.bench_function("fibonacci_parse", |b| b.iter(fibonacci_parse));
42-
// c.bench_function("fibonacci_to_twasm", |b| b.iter(|| fibonacci_to_twasm(&module)));
43-
// c.bench_function("fibonacci_from_twasm", |b| b.iter(|| fibonacci_from_twasm(&twasm)));
41+
c.bench_function("fibonacci_parse", |b| b.iter(fibonacci_parse));
42+
c.bench_function("fibonacci_to_twasm", |b| b.iter(|| fibonacci_to_twasm(&module)));
43+
c.bench_function("fibonacci_from_twasm", |b| b.iter(|| fibonacci_from_twasm(&twasm)));
4444
c.bench_function("fibonacci_iterative_60", |b| b.iter(|| fibonacci_run(module.clone(), false, 60)));
4545
c.bench_function("fibonacci_recursive_26", |b| b.iter(|| fibonacci_run(module.clone(), true, 26)));
4646
}

crates/tinywasm/benches/tinywasm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ fn tinywasm_run(module: TinyWasmModule) -> Result<()> {
3333

3434
fn criterion_benchmark(c: &mut Criterion) {
3535
let module = tinywasm_parse().expect("tinywasm_parse");
36-
let _twasm = tinywasm_to_twasm(&module).expect("tinywasm_to_twasm");
36+
let twasm = tinywasm_to_twasm(&module).expect("tinywasm_to_twasm");
3737
let mut group = c.benchmark_group("tinywasm");
3838
group.measurement_time(std::time::Duration::from_secs(10));
3939

40-
// group.bench_function("tinywasm_parse", |b| b.iter(tinywasm_parse));
41-
// group.bench_function("tinywasm_to_twasm", |b| b.iter(|| tinywasm_to_twasm(&module)));
42-
// group.bench_function("tinywasm_from_twasm", |b| b.iter(|| tinywasm_from_twasm(&twasm)));
40+
group.bench_function("tinywasm_parse", |b| b.iter(tinywasm_parse));
41+
group.bench_function("tinywasm_to_twasm", |b| b.iter(|| tinywasm_to_twasm(&module)));
42+
group.bench_function("tinywasm_from_twasm", |b| b.iter(|| tinywasm_from_twasm(&twasm)));
4343
group.bench_function("tinywasm", |b| b.iter(|| tinywasm_run(module.clone())));
4444
}
4545

crates/tinywasm/src/engine.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,15 @@ pub(crate) struct EngineInner {
4242
/// Fuel accounting policy for budgeted execution.
4343
#[derive(Debug, Clone, Copy)]
4444
#[non_exhaustive]
45+
#[derive(Default)]
4546
pub enum FuelPolicy {
4647
/// Charge one fuel unit per retired instruction.
48+
#[default]
4749
PerInstruction,
4850
/// Charge one fuel unit per instruction plus predefined extra cost for specific operations.
4951
Weighted,
5052
}
5153

52-
impl Default for FuelPolicy {
53-
fn default() -> Self {
54-
Self::PerInstruction
55-
}
56-
}
57-
5854
/// Default initial size for the 32-bit value stack (i32, f32 values).
5955
pub const DEFAULT_VALUE_STACK_32_SIZE: usize = 64 * 1024; // 64k slots
6056

0 commit comments

Comments
 (0)