- Fixed implementation for Wasm32

- Added steps for GitHub Actions to run tests for Wasm32.
This commit is contained in:
Kirill Kuzminykh
2026-01-07 03:55:20 +03:00
parent 8a63461b78
commit 4dd3cf310a
4 changed files with 31 additions and 11 deletions
+21 -2
View File
@@ -11,6 +11,7 @@ env:
CARGO_TERM_COLOR: always
DONT_SAVE_RESULT: 1
RAYON_NUM_THREADS: 4
CARGO_TARGET_WASM32_WASIP2_RUNNER: "wasmtime --dir=. --"
jobs:
run_tests:
@@ -29,6 +30,10 @@ jobs:
with:
cache-on-failure: "true"
- name: Check compilation for no_std
run: |
cargo build --no-default-features --features=no_std
- name: Run single-thread tests
run: |
cargo check
@@ -39,6 +44,20 @@ jobs:
cargo check --features rayon
cargo test --features rayon
- name: Check compilation for no_std
- name: Setup `wasmtime`
if: "${{ matrix.os == 'ubuntu-latest' }}"
# Use the action provided by the Bytecode Alliance
uses: bytecodealliance/actions/wasmtime/setup@v1
with:
version: "40.0"
- name: Check compilation for no_std + WASI
if: "${{ matrix.os == 'ubuntu-latest' }}"
run: |
cargo build --no-default-features --features=no_std
cargo build --target=wasm32-wasip2 --no-default-features --features=no_std
- name: Run tests for WASI
if: "${{ matrix.os == 'ubuntu-latest' }}"
run: |
cargo check --target=wasm32-wasip2
cargo test --target=wasm32-wasip2
+6 -6
View File
@@ -40,6 +40,12 @@ an env variable with the number of days as a result lifetime:
WRITE_COMPARE_RESULT=1 RESULTS_LIFETIME=5 cargo bench -- Compare
```
Run a specific benchmark in `quick` mode:
```shell
cargo bench --bench bench_resize -- --color=always --quick
```
# Wasm32
Specify build target and runner in `.cargo/config.toml` file.
@@ -64,12 +70,6 @@ Run tests with saving result images as files in `./data` directory:
CARGO_TARGET_WASM32_WASIP2_RUNNER="wasmtime --dir=. --env SAVE_RESULT=1 --" cargo test
```
Run a specific benchmark in `quick` mode:
```shell
cargo bench --bench bench_resize -- --color=always --quick
```
Run benchmarks to compare with other crates for image resizing and write results into
report files, such as `./benchmarks-wasm32.md`:
+1
View File
@@ -1,5 +1,6 @@
use core::arch::wasm32::*;
use crate::compat::*;
use crate::convolution::optimisations::Normalizer16;
use crate::pixels::U8;
use crate::{wasm32_utils, ImageView, ImageViewMut};
+3 -3
View File
@@ -1,5 +1,4 @@
use core::arch::wasm32::*;
use core::mem::transmute;
use crate::convolution::optimisations::Normalizer16;
use crate::pixels::U8x3;
@@ -153,7 +152,8 @@ unsafe fn horiz_convolution_four_rows(
for i in 0..4 {
let sss = i16x8_narrow_i32x4(sss_a[i], ZERO);
let pixel: u32 = transmute(i32x4_extract_lane::<0>(u8x16_narrow_i16x8(sss, ZERO)));
let pixel: u32 =
i32::cast_unsigned(i32x4_extract_lane::<0>(u8x16_narrow_i16x8(sss, ZERO)));
let bytes = pixel.to_le_bytes();
dst_rows[i].get_unchecked_mut(dst_x).0 = [bytes[0], bytes[1], bytes[2]];
}
@@ -269,7 +269,7 @@ unsafe fn horiz_convolution_one_row(
sss = i32x4_shr(sss, precision);
sss = i16x8_narrow_i32x4(sss, sss);
let pixel: u32 = transmute(i32x4_extract_lane::<0>(u8x16_narrow_i16x8(sss, sss)));
let pixel: u32 = i32::cast_unsigned(i32x4_extract_lane::<0>(u8x16_narrow_i16x8(sss, sss)));
let bytes = pixel.to_le_bytes();
dst_row.get_unchecked_mut(dst_x).0 = [bytes[0], bytes[1], bytes[2]];
}