From 097c9e9586d6b4a415499818a70e9e4cab52e1d3 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Sun, 28 Sep 2025 04:03:30 +0000 Subject: [PATCH] feat(web/wasm): use simd128 if available Signed-off-by: Xe Iaso --- package-lock.json | 9 ++++++++- package.json | 5 +++-- web/js/algorithms/wasm.ts | 9 +++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index c1398271..1659a143 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "license": "ISC", "dependencies": { "@aws-crypto/sha256-js": "^5.2.0", - "preact": "^10.27.2" + "preact": "^10.27.2", + "wasm-feature-detect": "^1.8.0" }, "devDependencies": { "cssnano": "^7.1.1", @@ -2685,6 +2686,12 @@ "dev": true, "license": "MIT" }, + "node_modules/wasm-feature-detect": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/wasm-feature-detect/-/wasm-feature-detect-1.8.0.tgz", + "integrity": "sha512-zksaLKM2fVlnB5jQQDqKXXwYHLQUVH9es+5TOOHwGOVJOCeRBCiPjwSg+3tN2AdTCzjgli4jijCH290kXb/zWQ==", + "license": "Apache-2.0" + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", diff --git a/package.json b/package.json index 619eb520..c57cb444 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ }, "dependencies": { "@aws-crypto/sha256-js": "^5.2.0", - "preact": "^10.27.2" + "preact": "^10.27.2", + "wasm-feature-detect": "^1.8.0" } -} \ No newline at end of file +} diff --git a/web/js/algorithms/wasm.ts b/web/js/algorithms/wasm.ts index 83032797..2f4bb6bd 100644 --- a/web/js/algorithms/wasm.ts +++ b/web/js/algorithms/wasm.ts @@ -1,4 +1,5 @@ import { u } from "../../lib/xeact"; +import { simd } from "wasm-feature-detect"; type ProgressCallback = (nonce: number) => void; @@ -22,9 +23,13 @@ export default function process( console.debug(options); const { basePrefix, version, algorithm } = options; - let wasmFeatures = "baseline"; - return new Promise(async (resolve, reject) => { + let wasmFeatures = "baseline"; + + if (await simd()) { + wasmFeatures = "simd128"; + } + const module = await fetch(u(`${basePrefix}/.within.website/x/cmd/anubis/static/wasm/${wasmFeatures}/${algorithm}.wasm?cacheBuster=${version}`)) .then(x => WebAssembly.compileStreaming(x));