Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: non simd sha256 for incompatible systems #427

Merged
merged 47 commits into from
Jan 14, 2025

Conversation

matthewkeil
Copy link
Member

@matthewkeil matthewkeil commented Dec 18, 2024

Motivation

An issue was posted about systems that do not support simd feature set. Made library compatible with those systems.

See ChainSafe/lodestar#7177 for more information.

Description of Changes

  • as-sha25
    • make common.ts that holds non-simd functionality
    • make simd and non-simd entrance files
    • call common from both entrance files and implement simd only in simd version
    • modify codegen and package scripts to build both versions of the code
    • modify TS wrapper code to load correct version of bindings depending on simd presence
    • modify TS wrapper code to call correct methods depending on presence of simd
    • fix tests to exercise both sets of bindings fully

@twoeths
Copy link
Contributor

twoeths commented Dec 20, 2024

I don't see we're using simd sha256 in lodestar, we haven't enabled batch hash yet

Update: nvm, we haven't used but the wasm code was loaded anyway

@matthewkeil matthewkeil force-pushed the mkeil/non-simd-sha256 branch from f55d080 to bdf755c Compare December 20, 2024 17:45
@matthewkeil matthewkeil force-pushed the mkeil/non-simd-sha256 branch from ddd5c17 to 51b1bdd Compare January 5, 2025 18:32
@matthewkeil matthewkeil changed the title feat: non simd sha256 for incompatible systems feat!: non simd sha256 for incompatible systems Jan 6, 2025
Copy link
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to use WebAssembly.validate to synchronously do "feature detection" and avoid a lot of complexity related to async initialization here.
(It appears that wasm-feature-detect is using WebAssembly.validate under the hood.)

eg:

import {wasmCode} from "./wasmCode.js";
import {wasmSimdCode} from "./wasmSimdCode.js";

const hasSimd = WebAssembly.validate(wasmSimdCode);

const _module = new WebAssembly.Module(hasSimd ? wasmSimdCode : wasmCode);

@matthewkeil matthewkeil changed the title feat!: non simd sha256 for incompatible systems feat: non simd sha256 for incompatible systems Jan 7, 2025
Copy link
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
looks like the repo also got linted?

@matthewkeil matthewkeil merged commit 9729005 into master Jan 14, 2025
8 checks passed
@matthewkeil matthewkeil deleted the mkeil/non-simd-sha256 branch January 14, 2025 14:32
@matthewkeil matthewkeil restored the mkeil/non-simd-sha256 branch January 15, 2025 15:47
@matthewkeil matthewkeil deleted the mkeil/non-simd-sha256 branch January 15, 2025 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants