Skip to content

Commit

Permalink
chore: unify hash4Input64s() name
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Apr 19, 2024
1 parent 792e412 commit d7d8b6a
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/as-sha256/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export function digest64(inPtr: usize, outPtr: usize): void {
* remaining 48 items are computed inside hashBlocksV128 loop.
* @param outPtr
*/
export function hash4Inputs(outPtr: usize): void {
export function hash4Input64s(outPtr: usize): void {
for (i = 0; i < 16; i++) {
store32(wPtr, PARALLEL_FACTOR * i, load32be(inputPtr, i));
store32(wPtr, PARALLEL_FACTOR * i + 1, load32be(inputPtr, i + 16));
Expand All @@ -333,7 +333,7 @@ export function hash4Inputs(outPtr: usize): void {
}

/*
* Hash 8 hash objects which are 4 inputs of 64 bytes each similar to hash4Inputs
* Hash 8 hash objects which are 4 inputs of 64 bytes each similar to hash4Input64s
*
* Input pointer is 64 u32 (256 bytes) as below:
* input 0 input 1 input 2 input 3
Expand Down
Binary file modified packages/as-sha256/build/optimized.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/as-sha256/build/optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
(export "final" (func $assembly/index/final))
(export "digest" (func $assembly/index/digest))
(export "digest64" (func $assembly/index/digest64))
(export "hash4Inputs" (func $assembly/index/hash4Inputs))
(export "hash4Input64s" (func $assembly/index/hash4Input64s))
(export "hash8HashObjects" (func $assembly/index/hash8HashObjects))
(export "memory" (memory $0))
(start $~start)
Expand Down Expand Up @@ -5751,7 +5751,7 @@
call $~lib/polyfills/bswap<i32>
i32.store offset=124
)
(func $assembly/index/hash4Inputs (param $0 i32)
(func $assembly/index/hash4Input64s (param $0 i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
Expand Down
Binary file modified packages/as-sha256/build/untouched.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/as-sha256/build/untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
(export "final" (func $assembly/index/final))
(export "digest" (func $assembly/index/digest))
(export "digest64" (func $assembly/index/digest64))
(export "hash4Inputs" (func $assembly/index/hash4Inputs))
(export "hash4Input64s" (func $assembly/index/hash4Input64s))
(export "hash8HashObjects" (func $assembly/index/hash8HashObjects))
(export "memory" (memory $0))
(start $~start)
Expand Down Expand Up @@ -10635,7 +10635,7 @@
local.get $180
i32.store
)
(func $assembly/index/hash4Inputs (param $0 i32)
(func $assembly/index/hash4Input64s (param $0 i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function hash4Input64s(inputs: Uint8Array[]): Uint8Array[] {
inputUint8Array.set(inputs[2], 128);
inputUint8Array.set(inputs[3], 192);

ctx.hash4Inputs(wasmOutputValue);
ctx.hash4Input64s(wasmOutputValue);

const output0 = outputUint8Array.slice(0, 32);
const output1 = outputUint8Array.slice(32, 64);
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/src/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface WasmContext {

digest(length: number): void;
digest64(inPtr: number, outPtr: number): void;
hash4Inputs(outPtr: number): void;
hash4Input64s(outPtr: number): void;
hash8HashObjects(outPtr: number): void;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/src/wasmCode.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/as-sha256/test/perf/simd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {byteArrayToHashObject} from "../../src/hashObject";
/**
* Mac M1 Apr 2024
*
digest64 vs hash4Inputs vs hash8HashObjects
digest64 vs hash4Input64s vs hash8HashObjects
✓ digest64 200092 times 6.816078 ops/s 146.7119 ms/op - 66 runs 10.3 s
✓ hash 200092 times using hash4Input64s 8.093460 ops/s 123.5566 ms/op - 78 runs 10.2 s
✓ hash 200092 times using hash8HashObjects 8.141334 ops/s 122.8300 ms/op - 78 runs 10.2 s
*/
describe("digest64 vs hash4Inputs vs hash8HashObjects", function () {
describe("digest64 vs hash4Input64s vs hash8HashObjects", function () {
this.timeout(0);

setBenchOpts({
Expand All @@ -24,7 +24,7 @@ describe("digest64 vs hash4Inputs vs hash8HashObjects", function () {
for (let j = 0; j < iterations * 4; j++) sha256.digest64(input);
});

// hash4Inputs do 4 sha256 in parallel
// hash4Input64s do 4 sha256 in parallel
itBench(`hash ${iterations * 4} times using hash4Input64s`, () => {
for (let j = 0; j < iterations; j++) {
sha256.hash4Input64s([input, input, input, input]);
Expand Down
8 changes: 4 additions & 4 deletions packages/as-sha256/test/unit/simd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {byteArrayToHashObject, hashObjectToByteArray} from "../../src/hashObject
import * as sha256 from "../../src";

describe("Test SIMD implementation of as-sha256", () => {
it("testHash4Inputs", () => {
it("testHash4Input64s", () => {
const input1 = "gajindergajindergajindergajinder";
const input2 = "gajindergajindergajindergajinder";
const input = Buffer.from(input1 + input2, "utf8");
Expand All @@ -14,11 +14,11 @@ describe("Test SIMD implementation of as-sha256", () => {
131, 72, 178, 215, 235, 20, 207, 110,
]);
for (let i = 0; i < 4; i++) {
expect(outputs[i]).to.be.deep.equal(expectedOutput, "incorrect hash4Inputs result " + i);
expect(outputs[i]).to.be.deep.equal(expectedOutput, "incorrect hash4Input64s result " + i);
}
});

it("testHash4Inputs 1000 times", () => {
it("testHash4Input64s 1000 times", () => {
for (let i = 0; i < 1000; i++) {
const input = crypto.randomBytes(64);
const outputs = sha256.hash4Input64s([input, input, input, input]);
Expand All @@ -41,7 +41,7 @@ describe("Test SIMD implementation of as-sha256", () => {
for (let i = 0; i < 4; i++) {
const output = new Uint8Array(32);
hashObjectToByteArray(outputs[i], output, 0);
expect(output).to.be.deep.equal(expectedOutput, "incorrect hash4Inputs result " + i);
expect(output).to.be.deep.equal(expectedOutput, "incorrect hash4Input64s result " + i);
}
});
});

0 comments on commit d7d8b6a

Please sign in to comment.