forked from chm-diederichs/sha512-wasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
automator.js
46 lines (38 loc) · 1.31 KB
/
automator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const fs = require('fs')
const rollWordBE = `
(i64.load8_u (i32.add (i32.const 7) (get_local $ptr)))
(i64.shl (i64.load8_u (i32.add (i32.const 6) (get_local $ptr))) (i64.const 8))
(i64.or)
(i64.shl (i64.load8_u (i32.add (i32.const 5) (get_local $ptr))) (i64.const 16))
(i64.or)
(i64.shl (i64.load8_u (i32.add (i32.const 4) (get_local $ptr))) (i64.const 24))
(i64.or)
(i64.shl (i64.load8_u (i32.add (i32.const 3) (get_local $ptr))) (i64.const 32))
(i64.or)
(i64.shl (i64.load8_u (i32.add (i32.const 2) (get_local $ptr))) (i64.const 40))
(i64.or)
(i64.shl (i64.load8_u (i32.add (i32.const 1) (get_local $ptr))) (i64.const 48))
(i64.or)
(i64.shl (i64.load8_u (get_local $ptr)) (i64.const 56))
(i64.or)
`
function loadWordBE (wordIndex) {
return `${rollWordBE}
(set_local $w${wordIndex})
(set_local $block_position (i32.add (get_local $block_position) (i32.const 8)))`
}
function makeBlock (depth) {
if (depth === 0) return `(block $switch`
return `(block $${16 - depth}
${makeBlock(depth - 1)}
(set_local $w${16 - depth} (get_local $last_word))
(br $break)`
//${loadWordBE(16 - depth)}
}
function loadWordsFromMemory () {
for (let i = 16; i > 0; i--) {
str.write(`(set_local $w${i-1} (i64.load offset=${64 + 8 * (i - 1)} (get_local $ctx)))\n`)
}
}
const str = fs.createWriteStream('output.txt')
loadWordsFromMemory()