Skip to content

Commit a5f70d9

Browse files
committed
refactor: remove step = 1 from TS calls
1 parent 61d6410 commit a5f70d9

14 files changed

+116
-78
lines changed

packages/as-sha256/assembly/common.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export function digest(length: i32): void {
293293
final(outputPtr);
294294
}
295295

296-
export function digest64(inPtr: usize, outPtr: usize, step: i32): void {
296+
export function digest64WithStep(inPtr: usize, outPtr: usize, step: i32): void {
297297
init();
298298
hashBlocks(wPtr, inPtr, step);
299299
hashPreCompW(w64Ptr);
@@ -305,4 +305,8 @@ export function digest64(inPtr: usize, outPtr: usize, step: i32): void {
305305
store32(outPtr, 5, bswap(H5));
306306
store32(outPtr, 6, bswap(H6));
307307
store32(outPtr, 7, bswap(H7));
308-
}
308+
}
309+
310+
export function digest64(inPtr: usize, outPtr: usize): void {
311+
digest64WithStep(inPtr, outPtr, 1);
312+
}

packages/as-sha256/assembly/index.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
import {INPUT_LENGTH, PARALLEL_FACTOR, input, output, init, update, final, digest, digest64, inputPtr} from "./common";
1+
import {
2+
INPUT_LENGTH,
3+
PARALLEL_FACTOR,
4+
input,
5+
output,
6+
init,
7+
update,
8+
final,
9+
digest,
10+
digest64,
11+
digest64WithStep,
12+
inputPtr,
13+
} from "./common";
214

315
export const HAS_SIMD = false;
416

@@ -11,7 +23,7 @@ export function batchHash4UintArray64s(outPtr: usize): void {
1123
for (let i = 0; i < 4; i++) {
1224
const inOffset = changetype<usize>(i * 64);
1325
const outOffset = changetype<usize>(i * 32);
14-
digest64(inputPtr + inOffset, outPtr + outOffset, 1);
26+
digest64(inputPtr + inOffset, outPtr + outOffset);
1527
}
1628
}
1729

@@ -22,6 +34,6 @@ export function batchHash4HashObjectInputs(outPtr: usize): void {
2234
for (let i = 0; i < 4; i++) {
2335
const inOffset = changetype<usize>(i * 4);
2436
const outOffset = changetype<usize>(i * 32);
25-
digest64(inputPtr + inOffset, outPtr + outOffset, 4);
37+
digest64WithStep(inputPtr + inOffset, outPtr + outOffset, 4);
2638
}
2739
}
-22 Bytes
Binary file not shown.

packages/as-sha256/build/optimized.simd.wat

+15-24
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
(type $2 (func (param i32 i32) (result i32)))
55
(type $3 (func (param i32)))
66
(type $4 (func))
7-
(type $5 (func (param i32 i32 i32)))
8-
(type $6 (func (param i32 i32 i32 i32)))
9-
(type $7 (func (param i32 i32 i64)))
7+
(type $5 (func (param i32 i32 i32 i32)))
8+
(type $6 (func (param i32 i32 i64)))
109
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
1110
(global $assembly/simd/H0V128 (mut v128) (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000))
1211
(global $assembly/simd/H1V128 (mut v128) (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000))
@@ -5636,7 +5635,8 @@
56365635
i32.const 0
56375636
global.set $assembly/common/bytesHashed
56385637
)
5639-
(func $assembly/common/hashBlocks (param $0 i32) (param $1 i32) (param $2 i32)
5638+
(func $assembly/common/hashBlocks (param $0 i32) (param $1 i32)
5639+
(local $2 i32)
56405640
(local $3 i32)
56415641
global.get $assembly/common/H0
56425642
global.set $assembly/common/a
@@ -5661,30 +5661,26 @@
56615661
i32.const 16
56625662
i32.lt_u
56635663
if
5664-
local.get $0
56655664
global.get $assembly/common/i
56665665
i32.const 2
56675666
i32.shl
5667+
local.tee $2
5668+
local.get $0
56685669
i32.add
56695670
local.get $1
5670-
global.get $assembly/common/i
56715671
local.get $2
5672-
i32.mul
5673-
i32.const 2
5674-
i32.shl
5675-
local.tee $3
56765672
i32.const 3
56775673
i32.add
56785674
i32.add
56795675
i32.load8_u
56805676
local.get $1
5681-
local.get $3
5677+
local.get $2
56825678
i32.add
56835679
i32.load8_u
56845680
i32.const 24
56855681
i32.shl
56865682
local.get $1
5687-
local.get $3
5683+
local.get $2
56885684
i32.const 1
56895685
i32.add
56905686
i32.add
@@ -5693,7 +5689,7 @@
56935689
i32.shl
56945690
i32.or
56955691
local.get $1
5696-
local.get $3
5692+
local.get $2
56975693
i32.const 2
56985694
i32.add
56995695
i32.add
@@ -5794,11 +5790,11 @@
57945790
i32.const 64
57955791
i32.lt_u
57965792
if
5797-
local.get $0
57985793
global.get $assembly/common/i
57995794
i32.const 2
58005795
i32.shl
58015796
local.tee $1
5797+
local.get $0
58025798
i32.add
58035799
i32.load
58045800
local.get $1
@@ -5846,16 +5842,16 @@
58465842
i32.rotr
58475843
i32.xor
58485844
global.get $assembly/common/b
5849-
local.tee $1
5850-
global.get $assembly/common/c
58515845
local.tee $2
5846+
global.get $assembly/common/c
5847+
local.tee $3
58525848
i32.and
5853-
local.get $1
58545849
global.get $assembly/common/a
58555850
local.tee $1
5851+
local.get $2
58565852
i32.and
58575853
local.get $1
5858-
local.get $2
5854+
local.get $3
58595855
i32.and
58605856
i32.xor
58615857
i32.xor
@@ -5959,7 +5955,6 @@
59595955
local.set $1
59605956
global.get $assembly/common/wPtr
59615957
global.get $assembly/common/mPtr
5962-
i32.const 1
59635958
call $assembly/common/hashBlocks
59645959
i32.const 0
59655960
global.set $assembly/common/mLength
@@ -5988,7 +5983,6 @@
59885983
local.get $0
59895984
local.get $2
59905985
i32.add
5991-
i32.const 1
59925986
call $assembly/common/hashBlocks
59935987
local.get $3
59945988
i32.const 1
@@ -6071,7 +6065,6 @@
60716065
end
60726066
global.get $assembly/common/wPtr
60736067
global.get $assembly/common/mPtr
6074-
i32.const 1
60756068
call $assembly/common/hashBlocks
60766069
i32.const 0
60776070
global.set $assembly/common/mLength
@@ -6130,7 +6123,6 @@
61306123
i32.store offset=60
61316124
global.get $assembly/common/wPtr
61326125
global.get $assembly/common/mPtr
6133-
i32.const 1
61346126
call $assembly/common/hashBlocks
61356127
local.get $0
61366128
global.get $assembly/common/H0
@@ -6320,11 +6312,10 @@
63206312
i32.add
63216313
global.set $assembly/common/H7
63226314
)
6323-
(func $assembly/common/digest64 (param $0 i32) (param $1 i32) (param $2 i32)
6315+
(func $assembly/common/digest64 (param $0 i32) (param $1 i32)
63246316
call $assembly/common/init
63256317
global.get $assembly/common/wPtr
63266318
local.get $0
6327-
local.get $2
63286319
call $assembly/common/hashBlocks
63296320
global.get $assembly/common/w64Ptr
63306321
call $assembly/common/hashPreCompW
32 Bytes
Binary file not shown.

packages/as-sha256/build/optimized.wat

+58-38
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
(type $0 (func (param i32 i32)))
33
(type $1 (func (param i32)))
44
(type $2 (func (param i32) (result i32)))
5-
(type $3 (func (param i32 i32 i32)))
6-
(type $4 (func (param i32 i32) (result i32)))
7-
(type $5 (func))
5+
(type $3 (func (param i32 i32) (result i32)))
6+
(type $4 (func))
7+
(type $5 (func (param i32 i32 i32)))
88
(type $6 (func (param i32 i32 i32 i32)))
99
(type $7 (func (param i32 i32 i64)))
1010
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
@@ -1330,7 +1330,7 @@
13301330
i32.rotr
13311331
i32.or
13321332
)
1333-
(func $assembly/common/digest64 (param $0 i32) (param $1 i32) (param $2 i32)
1333+
(func $assembly/common/digest64WithStep (param $0 i32) (param $1 i32) (param $2 i32)
13341334
call $assembly/common/init
13351335
global.get $assembly/common/wPtr
13361336
local.get $0
@@ -1371,17 +1371,64 @@
13711371
call $~lib/polyfills/bswap<u32>
13721372
i32.store offset=28
13731373
)
1374-
(func $assembly/index/batchHash4UintArray64s (param $0 i32)
1374+
(func $assembly/common/digest64 (param $0 i32) (param $1 i32)
13751375
local.get $0
1376+
local.get $1
13761377
i32.const 1
1377-
i32.const 6
1378-
call $byn$mgfn-shared$assembly/index/batchHash4UintArray64s
1378+
call $assembly/common/digest64WithStep
1379+
)
1380+
(func $assembly/index/batchHash4UintArray64s (param $0 i32)
1381+
(local $1 i32)
1382+
loop $for-loop|0
1383+
local.get $1
1384+
i32.const 4
1385+
i32.lt_s
1386+
if
1387+
global.get $assembly/common/inputPtr
1388+
local.get $1
1389+
i32.const 6
1390+
i32.shl
1391+
i32.add
1392+
local.get $0
1393+
local.get $1
1394+
i32.const 5
1395+
i32.shl
1396+
i32.add
1397+
call $assembly/common/digest64
1398+
local.get $1
1399+
i32.const 1
1400+
i32.add
1401+
local.set $1
1402+
br $for-loop|0
1403+
end
1404+
end
13791405
)
13801406
(func $assembly/index/batchHash4HashObjectInputs (param $0 i32)
1381-
local.get $0
1382-
i32.const 4
1383-
i32.const 2
1384-
call $byn$mgfn-shared$assembly/index/batchHash4UintArray64s
1407+
(local $1 i32)
1408+
loop $for-loop|0
1409+
local.get $1
1410+
i32.const 4
1411+
i32.lt_s
1412+
if
1413+
global.get $assembly/common/inputPtr
1414+
local.get $1
1415+
i32.const 2
1416+
i32.shl
1417+
i32.add
1418+
local.get $0
1419+
local.get $1
1420+
i32.const 5
1421+
i32.shl
1422+
i32.add
1423+
i32.const 4
1424+
call $assembly/common/digest64WithStep
1425+
local.get $1
1426+
i32.const 1
1427+
i32.add
1428+
local.set $1
1429+
br $for-loop|0
1430+
end
1431+
end
13851432
)
13861433
(func $assembly/common/update (param $0 i32) (param $1 i32)
13871434
(local $2 i32)
@@ -1671,31 +1718,4 @@
16711718
global.get $assembly/common/output
16721719
global.set $assembly/common/outputPtr
16731720
)
1674-
(func $byn$mgfn-shared$assembly/index/batchHash4UintArray64s (param $0 i32) (param $1 i32) (param $2 i32)
1675-
(local $3 i32)
1676-
loop $for-loop|0
1677-
local.get $3
1678-
i32.const 4
1679-
i32.lt_s
1680-
if
1681-
global.get $assembly/common/inputPtr
1682-
local.get $3
1683-
local.get $2
1684-
i32.shl
1685-
i32.add
1686-
local.get $0
1687-
local.get $3
1688-
i32.const 5
1689-
i32.shl
1690-
i32.add
1691-
local.get $1
1692-
call $assembly/common/digest64
1693-
local.get $3
1694-
i32.const 1
1695-
i32.add
1696-
local.set $3
1697-
br $for-loop|0
1698-
end
1699-
end
1700-
)
17011721
)
12 Bytes
Binary file not shown.

packages/as-sha256/build/untouched.simd.wat

+7-1
Original file line numberDiff line numberDiff line change
@@ -11830,7 +11830,7 @@
1183011830
i32.add
1183111831
global.set $assembly/common/H7
1183211832
)
11833-
(func $assembly/common/digest64 (param $0 i32) (param $1 i32) (param $2 i32)
11833+
(func $assembly/common/digest64WithStep (param $0 i32) (param $1 i32) (param $2 i32)
1183411834
(local $3 i32)
1183511835
(local $4 i32)
1183611836
(local $5 i32)
@@ -11975,6 +11975,12 @@
1197511975
local.get $26
1197611976
i32.store
1197711977
)
11978+
(func $assembly/common/digest64 (param $0 i32) (param $1 i32)
11979+
local.get $0
11980+
local.get $1
11981+
i32.const 1
11982+
call $assembly/common/digest64WithStep
11983+
)
1197811984
(func $~start
1197911985
call $start:assembly/index.simd
1198011986
)
10 Bytes
Binary file not shown.

packages/as-sha256/build/untouched.wat

+8-3
Original file line numberDiff line numberDiff line change
@@ -2437,7 +2437,7 @@
24372437
i32.or
24382438
return
24392439
)
2440-
(func $assembly/common/digest64 (param $0 i32) (param $1 i32) (param $2 i32)
2440+
(func $assembly/common/digest64WithStep (param $0 i32) (param $1 i32) (param $2 i32)
24412441
(local $3 i32)
24422442
(local $4 i32)
24432443
(local $5 i32)
@@ -2582,6 +2582,12 @@
25822582
local.get $26
25832583
i32.store
25842584
)
2585+
(func $assembly/common/digest64 (param $0 i32) (param $1 i32)
2586+
local.get $0
2587+
local.get $1
2588+
i32.const 1
2589+
call $assembly/common/digest64WithStep
2590+
)
25852591
(func $assembly/index/batchHash4UintArray64s (param $0 i32)
25862592
(local $1 i32)
25872593
(local $2 i32)
@@ -2607,7 +2613,6 @@
26072613
local.get $0
26082614
local.get $3
26092615
i32.add
2610-
i32.const 1
26112616
call $assembly/common/digest64
26122617
local.get $1
26132618
i32.const 1
@@ -2643,7 +2648,7 @@
26432648
local.get $3
26442649
i32.add
26452650
i32.const 4
2646-
call $assembly/common/digest64
2651+
call $assembly/common/digest64WithStep
26472652
local.get $1
26482653
i32.const 1
26492654
i32.add

0 commit comments

Comments
 (0)