Skip to content

Commit

Permalink
refactor: remove step = 1 from TS calls
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewkeil committed Jan 9, 2025
1 parent 61d6410 commit a5f70d9
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 78 deletions.
8 changes: 6 additions & 2 deletions packages/as-sha256/assembly/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export function digest(length: i32): void {
final(outputPtr);
}

export function digest64(inPtr: usize, outPtr: usize, step: i32): void {
export function digest64WithStep(inPtr: usize, outPtr: usize, step: i32): void {
init();
hashBlocks(wPtr, inPtr, step);
hashPreCompW(w64Ptr);
Expand All @@ -305,4 +305,8 @@ export function digest64(inPtr: usize, outPtr: usize, step: i32): void {
store32(outPtr, 5, bswap(H5));
store32(outPtr, 6, bswap(H6));
store32(outPtr, 7, bswap(H7));
}
}

export function digest64(inPtr: usize, outPtr: usize): void {
digest64WithStep(inPtr, outPtr, 1);
}
18 changes: 15 additions & 3 deletions packages/as-sha256/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import {INPUT_LENGTH, PARALLEL_FACTOR, input, output, init, update, final, digest, digest64, inputPtr} from "./common";
import {
INPUT_LENGTH,
PARALLEL_FACTOR,
input,
output,
init,
update,
final,
digest,
digest64,
digest64WithStep,
inputPtr,
} from "./common";

export const HAS_SIMD = false;

Expand All @@ -11,7 +23,7 @@ export function batchHash4UintArray64s(outPtr: usize): void {
for (let i = 0; i < 4; i++) {
const inOffset = changetype<usize>(i * 64);
const outOffset = changetype<usize>(i * 32);
digest64(inputPtr + inOffset, outPtr + outOffset, 1);
digest64(inputPtr + inOffset, outPtr + outOffset);
}
}

Expand All @@ -22,6 +34,6 @@ export function batchHash4HashObjectInputs(outPtr: usize): void {
for (let i = 0; i < 4; i++) {
const inOffset = changetype<usize>(i * 4);
const outOffset = changetype<usize>(i * 32);
digest64(inputPtr + inOffset, outPtr + outOffset, 4);
digest64WithStep(inputPtr + inOffset, outPtr + outOffset, 4);
}
}
Binary file modified packages/as-sha256/build/optimized.simd.wasm
Binary file not shown.
39 changes: 15 additions & 24 deletions packages/as-sha256/build/optimized.simd.wat
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
(type $2 (func (param i32 i32) (result i32)))
(type $3 (func (param i32)))
(type $4 (func))
(type $5 (func (param i32 i32 i32)))
(type $6 (func (param i32 i32 i32 i32)))
(type $7 (func (param i32 i32 i64)))
(type $5 (func (param i32 i32 i32 i32)))
(type $6 (func (param i32 i32 i64)))
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
(global $assembly/simd/H0V128 (mut v128) (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000))
(global $assembly/simd/H1V128 (mut v128) (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000))
Expand Down Expand Up @@ -5636,7 +5635,8 @@
i32.const 0
global.set $assembly/common/bytesHashed
)
(func $assembly/common/hashBlocks (param $0 i32) (param $1 i32) (param $2 i32)
(func $assembly/common/hashBlocks (param $0 i32) (param $1 i32)
(local $2 i32)
(local $3 i32)
global.get $assembly/common/H0
global.set $assembly/common/a
Expand All @@ -5661,30 +5661,26 @@
i32.const 16
i32.lt_u
if
local.get $0
global.get $assembly/common/i
i32.const 2
i32.shl
local.tee $2
local.get $0
i32.add
local.get $1
global.get $assembly/common/i
local.get $2
i32.mul
i32.const 2
i32.shl
local.tee $3
i32.const 3
i32.add
i32.add
i32.load8_u
local.get $1
local.get $3
local.get $2
i32.add
i32.load8_u
i32.const 24
i32.shl
local.get $1
local.get $3
local.get $2
i32.const 1
i32.add
i32.add
Expand All @@ -5693,7 +5689,7 @@
i32.shl
i32.or
local.get $1
local.get $3
local.get $2
i32.const 2
i32.add
i32.add
Expand Down Expand Up @@ -5794,11 +5790,11 @@
i32.const 64
i32.lt_u
if
local.get $0
global.get $assembly/common/i
i32.const 2
i32.shl
local.tee $1
local.get $0
i32.add
i32.load
local.get $1
Expand Down Expand Up @@ -5846,16 +5842,16 @@
i32.rotr
i32.xor
global.get $assembly/common/b
local.tee $1
global.get $assembly/common/c
local.tee $2
global.get $assembly/common/c
local.tee $3
i32.and
local.get $1
global.get $assembly/common/a
local.tee $1
local.get $2
i32.and
local.get $1
local.get $2
local.get $3
i32.and
i32.xor
i32.xor
Expand Down Expand Up @@ -5959,7 +5955,6 @@
local.set $1
global.get $assembly/common/wPtr
global.get $assembly/common/mPtr
i32.const 1
call $assembly/common/hashBlocks
i32.const 0
global.set $assembly/common/mLength
Expand Down Expand Up @@ -5988,7 +5983,6 @@
local.get $0
local.get $2
i32.add
i32.const 1
call $assembly/common/hashBlocks
local.get $3
i32.const 1
Expand Down Expand Up @@ -6071,7 +6065,6 @@
end
global.get $assembly/common/wPtr
global.get $assembly/common/mPtr
i32.const 1
call $assembly/common/hashBlocks
i32.const 0
global.set $assembly/common/mLength
Expand Down Expand Up @@ -6130,7 +6123,6 @@
i32.store offset=60
global.get $assembly/common/wPtr
global.get $assembly/common/mPtr
i32.const 1
call $assembly/common/hashBlocks
local.get $0
global.get $assembly/common/H0
Expand Down Expand Up @@ -6320,11 +6312,10 @@
i32.add
global.set $assembly/common/H7
)
(func $assembly/common/digest64 (param $0 i32) (param $1 i32) (param $2 i32)
(func $assembly/common/digest64 (param $0 i32) (param $1 i32)
call $assembly/common/init
global.get $assembly/common/wPtr
local.get $0
local.get $2
call $assembly/common/hashBlocks
global.get $assembly/common/w64Ptr
call $assembly/common/hashPreCompW
Expand Down
Binary file modified packages/as-sha256/build/optimized.wasm
Binary file not shown.
96 changes: 58 additions & 38 deletions packages/as-sha256/build/optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
(type $0 (func (param i32 i32)))
(type $1 (func (param i32)))
(type $2 (func (param i32) (result i32)))
(type $3 (func (param i32 i32 i32)))
(type $4 (func (param i32 i32) (result i32)))
(type $5 (func))
(type $3 (func (param i32 i32) (result i32)))
(type $4 (func))
(type $5 (func (param i32 i32 i32)))
(type $6 (func (param i32 i32 i32 i32)))
(type $7 (func (param i32 i32 i64)))
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
Expand Down Expand Up @@ -1330,7 +1330,7 @@
i32.rotr
i32.or
)
(func $assembly/common/digest64 (param $0 i32) (param $1 i32) (param $2 i32)
(func $assembly/common/digest64WithStep (param $0 i32) (param $1 i32) (param $2 i32)
call $assembly/common/init
global.get $assembly/common/wPtr
local.get $0
Expand Down Expand Up @@ -1371,17 +1371,64 @@
call $~lib/polyfills/bswap<u32>
i32.store offset=28
)
(func $assembly/index/batchHash4UintArray64s (param $0 i32)
(func $assembly/common/digest64 (param $0 i32) (param $1 i32)
local.get $0
local.get $1
i32.const 1
i32.const 6
call $byn$mgfn-shared$assembly/index/batchHash4UintArray64s
call $assembly/common/digest64WithStep
)
(func $assembly/index/batchHash4UintArray64s (param $0 i32)
(local $1 i32)
loop $for-loop|0
local.get $1
i32.const 4
i32.lt_s
if
global.get $assembly/common/inputPtr
local.get $1
i32.const 6
i32.shl
i32.add
local.get $0
local.get $1
i32.const 5
i32.shl
i32.add
call $assembly/common/digest64
local.get $1
i32.const 1
i32.add
local.set $1
br $for-loop|0
end
end
)
(func $assembly/index/batchHash4HashObjectInputs (param $0 i32)
local.get $0
i32.const 4
i32.const 2
call $byn$mgfn-shared$assembly/index/batchHash4UintArray64s
(local $1 i32)
loop $for-loop|0
local.get $1
i32.const 4
i32.lt_s
if
global.get $assembly/common/inputPtr
local.get $1
i32.const 2
i32.shl
i32.add
local.get $0
local.get $1
i32.const 5
i32.shl
i32.add
i32.const 4
call $assembly/common/digest64WithStep
local.get $1
i32.const 1
i32.add
local.set $1
br $for-loop|0
end
end
)
(func $assembly/common/update (param $0 i32) (param $1 i32)
(local $2 i32)
Expand Down Expand Up @@ -1671,31 +1718,4 @@
global.get $assembly/common/output
global.set $assembly/common/outputPtr
)
(func $byn$mgfn-shared$assembly/index/batchHash4UintArray64s (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
loop $for-loop|0
local.get $3
i32.const 4
i32.lt_s
if
global.get $assembly/common/inputPtr
local.get $3
local.get $2
i32.shl
i32.add
local.get $0
local.get $3
i32.const 5
i32.shl
i32.add
local.get $1
call $assembly/common/digest64
local.get $3
i32.const 1
i32.add
local.set $3
br $for-loop|0
end
end
)
)
Binary file modified packages/as-sha256/build/untouched.simd.wasm
Binary file not shown.
8 changes: 7 additions & 1 deletion packages/as-sha256/build/untouched.simd.wat
Original file line number Diff line number Diff line change
Expand Up @@ -11830,7 +11830,7 @@
i32.add
global.set $assembly/common/H7
)
(func $assembly/common/digest64 (param $0 i32) (param $1 i32) (param $2 i32)
(func $assembly/common/digest64WithStep (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
Expand Down Expand Up @@ -11975,6 +11975,12 @@
local.get $26
i32.store
)
(func $assembly/common/digest64 (param $0 i32) (param $1 i32)
local.get $0
local.get $1
i32.const 1
call $assembly/common/digest64WithStep
)
(func $~start
call $start:assembly/index.simd
)
Expand Down
Binary file modified packages/as-sha256/build/untouched.wasm
Binary file not shown.
11 changes: 8 additions & 3 deletions packages/as-sha256/build/untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2437,7 +2437,7 @@
i32.or
return
)
(func $assembly/common/digest64 (param $0 i32) (param $1 i32) (param $2 i32)
(func $assembly/common/digest64WithStep (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
Expand Down Expand Up @@ -2582,6 +2582,12 @@
local.get $26
i32.store
)
(func $assembly/common/digest64 (param $0 i32) (param $1 i32)
local.get $0
local.get $1
i32.const 1
call $assembly/common/digest64WithStep
)
(func $assembly/index/batchHash4UintArray64s (param $0 i32)
(local $1 i32)
(local $2 i32)
Expand All @@ -2607,7 +2613,6 @@
local.get $0
local.get $3
i32.add
i32.const 1
call $assembly/common/digest64
local.get $1
i32.const 1
Expand Down Expand Up @@ -2643,7 +2648,7 @@
local.get $3
i32.add
i32.const 4
call $assembly/common/digest64
call $assembly/common/digest64WithStep
local.get $1
i32.const 1
i32.add
Expand Down
Loading

0 comments on commit a5f70d9

Please sign in to comment.