feat(web/wasm): use simd128 if available

Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
Xe Iaso
2025-09-28 04:03:30 +00:00
parent cf931cc0a5
commit 097c9e9586
3 changed files with 18 additions and 5 deletions
+8 -1
View File
@@ -10,7 +10,8 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@aws-crypto/sha256-js": "^5.2.0", "@aws-crypto/sha256-js": "^5.2.0",
"preact": "^10.27.2" "preact": "^10.27.2",
"wasm-feature-detect": "^1.8.0"
}, },
"devDependencies": { "devDependencies": {
"cssnano": "^7.1.1", "cssnano": "^7.1.1",
@@ -2685,6 +2686,12 @@
"dev": true, "dev": true,
"license": "MIT" "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": { "node_modules/wrap-ansi": {
"version": "7.0.0", "version": "7.0.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
+2 -1
View File
@@ -33,6 +33,7 @@
}, },
"dependencies": { "dependencies": {
"@aws-crypto/sha256-js": "^5.2.0", "@aws-crypto/sha256-js": "^5.2.0",
"preact": "^10.27.2" "preact": "^10.27.2",
"wasm-feature-detect": "^1.8.0"
} }
} }
+6 -1
View File
@@ -1,4 +1,5 @@
import { u } from "../../lib/xeact"; import { u } from "../../lib/xeact";
import { simd } from "wasm-feature-detect";
type ProgressCallback = (nonce: number) => void; type ProgressCallback = (nonce: number) => void;
@@ -22,9 +23,13 @@ export default function process(
console.debug(options); console.debug(options);
const { basePrefix, version, algorithm } = options; const { basePrefix, version, algorithm } = options;
return new Promise(async (resolve, reject) => {
let wasmFeatures = "baseline"; let wasmFeatures = "baseline";
return new Promise(async (resolve, reject) => { if (await simd()) {
wasmFeatures = "simd128";
}
const module = await fetch(u(`${basePrefix}/.within.website/x/cmd/anubis/static/wasm/${wasmFeatures}/${algorithm}.wasm?cacheBuster=${version}`)) const module = await fetch(u(`${basePrefix}/.within.website/x/cmd/anubis/static/wasm/${wasmFeatures}/${algorithm}.wasm?cacheBuster=${version}`))
.then(x => WebAssembly.compileStreaming(x)); .then(x => WebAssembly.compileStreaming(x));