Skip to content

Commit

Permalink
test: non-simd implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewkeil committed Dec 20, 2024
1 parent cfc722f commit f55d080
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/as-sha256/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {HashObject, byteArrayIntoHashObject, byteArrayToHashObject, hashObjectTo
import SHA256 from "./sha256.js";
export {HashObject, byteArrayToHashObject, hashObjectToByteArray, byteArrayIntoHashObject, SHA256};

const hasSimd = await simd();
let hasSimd = await simd();

let ctx: WasmSimdContext;
let wasmInputValue: number;
Expand All @@ -17,6 +17,7 @@ let outputUint8Array32: Uint8Array;
let inputUint32Array: Uint32Array;

function initializeInstance(useSimd: boolean): void {
hasSimd = useSimd;
ctx = newInstance(useSimd) as WasmSimdContext;
wasmInputValue = ctx.input.value;
wasmOutputValue = ctx.output.value;
Expand Down
7 changes: 4 additions & 3 deletions packages/as-sha256/test/unit/getSimdTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import crypto from "crypto";
import {byteArrayToHashObject, hashObjectToByteArray} from "../../src/hashObject.js";

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function getSimdTests(sha256: any, hasSimd: boolean): void {
describe(`Test as-sha256 ${hasSimd ? "with SIMD" : "without SIMD"}`, () => {
export function getSimdTests(sha256: any, useSimd: boolean): void {
describe(`Test as-sha256 ${useSimd ? "with SIMD" : "without SIMD"}`, () => {
before(function () {
expect(sha256.simdEnabled()).to.equal(hasSimd);
sha256.reinitializeInstance(useSimd);
expect(sha256.simdEnabled()).to.equal(useSimd);
});
it("testHash4UintArray64s", () => {
const input1 = "gajindergajindergajindergajinder";
Expand Down
1 change: 0 additions & 1 deletion packages/as-sha256/test/unit/noSimd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ import * as sha256 from "../../src/index.js";
import {getSimdTests} from "./getSimdTests.js";

const useSimd = false;
sha256.reinitializeInstance(useSimd);
getSimdTests(sha256, useSimd);
1 change: 0 additions & 1 deletion packages/as-sha256/test/unit/simd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ import * as sha256 from "../../src/index.js";
import {getSimdTests} from "./getSimdTests.js";

const useSimd = true;
sha256.reinitializeInstance(useSimd);
getSimdTests(sha256, useSimd);

0 comments on commit f55d080

Please sign in to comment.