small optimizations

This commit is contained in:
Nicholas Ward 2023-03-08 12:34:50 -08:00
parent fda2e19054
commit 33ccf8987e
2 changed files with 39 additions and 18 deletions

View File

@ -3,28 +3,38 @@
// are in the range 0..16) in the internal state.
// The internal state is stored in memory starting at the address start.
// stack: a, b, c, d, x, y, start
%stack (indices: 4) -> (indices, indices)
DUP4
DUP4
DUP4
DUP4
// stack: a, b, c, d, a, b, c, d, x, y, start
DUP11
// stack: start, a, b, c, d, a, b, c, d, x, y, start
%stack (start, a, b, c, d) -> (d, start, c, start, b, start, a, start)
// stack: d, start, c, start, b, start, a, start, a, b, c, d, x, y, start
ADD
%mload_kernel_general
// stack: v[d], c, start, b, start, a, start, a, b, c, d, x, y, start
%stack (vd, remaining: 6) -> (remaining, vd)
// stack: c, start, b, start, a, start, v[d], a, b, c, d, x, y, start
// stack: v[a], b, c, d, a, b, c, d, x, y, start
SWAP1
// stack: b, v[a], c, d, a, b, c, d, x, y, start
DUP11
// stack: start, b, v[a], c, d, a, b, c, d, x, y, start
ADD
%mload_kernel_general
%stack (vc, remaining: 4) -> (remaining, vc)
// stack: b, start, a, start, v[c], v[d], a, b, c, d, x, y, start
// stack: v[b], v[a], c, d, a, b, c, d, x, y, start
SWAP2
// stack: c, v[a], v[b], d, a, b, c, d, x, y, start
DUP11
// stack: start, c, v[a], v[b], d, a, b, c, d, x, y, start
ADD
%mload_kernel_general
// stack: v[b], a, start, v[c], v[d], a, b, c, d, x, y, start
%stack (vb, remaining: 2) -> (remaining, vb)
// stack: a, start, v[b], v[c], v[d], a, b, c, d, x, y, start
// stack: v[c], v[a], v[b], d, a, b, c, d, x, y, start
SWAP3
// stack: d, v[a], v[b], v[c], a, b, c, d, x, y, start
DUP11
// stack: start, d, v[a], v[b], v[c], a, b, c, d, x, y, start
ADD
%mload_kernel_general
// stack: v[d], v[a], v[b], v[c], a, b, c, d, x, y, start
%stack (vd, vs: 3) -> (vs, vd)
// stack: v[a], v[b], v[c], v[d], a, b, c, d, x, y, start
DUP2
// stack: v[b], v[a], v[b], v[c], v[d], a, b, c, d, x, y, start

View File

@ -58,17 +58,28 @@ global permutation_9_constants:
BYTES 15, 11, 9, 14
BYTES 3, 12, 13, 0
%macro blake2b_permutation
// stack: round, i
global blake2b_permutation:
// stack: i, round, retdest
PUSH permutation_0_constants
// stack: permutation_0_constants, round, i
SWAP1
// stack: round, permutation_1_constants, i
// stack: permutation_0_constants, i, round, retdest
SWAP2
// stack: round, i, permutation_0_constants, retdest
%mod_const(10)
// stack: round % 10, permutation_1_constants, i
// stack: round % 10, i, permutation_0_constants, retdest
%mul_const(16)
ADD
// stack: permutation_(round)_constants, i
ADD
%mload_kernel_code
// stack: permutation_(round%10)_constants[i], retdest
SWAP1
JUMP
%macro blake2b_permutation
// stack: round, i
PUSH %%after
// stack: %%after, round, i
SWAP2
// stack: i, round, %%after
%jump(blake2b_permutation)
%%after:
%endmacro