simplify byte extraction

This commit is contained in:
Dmitry Vagner 2023-02-16 16:30:50 -08:00
parent 4e4cfb06b3
commit a6ffb4b3c3
2 changed files with 31 additions and 32 deletions

View File

@ -22,21 +22,28 @@ global ripemd:
// stack: length // stack: length
%shl_const(3) %shl_const(3)
// stack: abcdefgh // stack: abcdefgh
%extract_and_store_byte(64) DUP1
// stack: abcdefg %extract_and_store_byte(31, 64)
%extract_and_store_byte(65) // stack: abcdefgh
// stack: abcdef DUP1
%extract_and_store_byte(66) %extract_and_store_byte(30, 65)
// stack: abcde // stack: abcdefgh
%extract_and_store_byte(67) DUP1
// stack: abcd %extract_and_store_byte(29, 66)
%extract_and_store_byte(68) // stack: abcdefgh
// stack: abc DUP1
%extract_and_store_byte(69) %extract_and_store_byte(28, 67)
// stack: ab // stack: abcdefgh
%extract_and_store_byte(70) DUP1
// stack: a %extract_and_store_byte(27, 68)
%mstore_kernel_general(71) // stack: abcdefgh
DUP1
%extract_and_store_byte(26, 69)
// stack: abcdefgh
DUP1
%extract_and_store_byte(25, 70)
// stack: abcdefgh
%extract_and_store_byte(24, 71)
// stack: 0x80 // stack: 0x80
%mstore_kernel_general(72) %mstore_kernel_general(72)
@ -113,19 +120,11 @@ process:
SUB SUB
%endmacro %endmacro
%macro extract_and_store_byte(byte, offset)
%macro extract_and_store_byte(offset)
// stack: xsy
PUSH 0x100
DUP2
MOD
// stack: y, xsy
%stack (y, xsy) -> (xsy, y, 0x100, y)
// stack: xsy, y, 0x100, y
SUB
DIV
SWAP1
// stack: y, xs
%mstore_kernel_general($offset)
// stack: xs // stack: xs
PUSH $byte
BYTE
// stack: xs[byte]
%mstore_kernel_general($offset)
// stack:
%endmacro %endmacro

View File

@ -289,7 +289,7 @@
// given u32 bytestring abcd return dcba // given u32 bytestring abcd return dcba
%macro reverse_bytes_u32 %macro reverse_bytes_u32
// stack: abcd // stack: abcd
DUP1 DUP1
PUSH 28 PUSH 28
BYTE BYTE
@ -308,11 +308,11 @@
PUSH 31 PUSH 31
BYTE BYTE
%shl_const(24) %shl_const(24)
// stack: d000, b0, a, c00 // stack: d000, b0, a, c00
OR OR
OR OR
OR OR
// stack: dcba // stack: dcba
%endmacro %endmacro
%macro reverse_bytes_u64 %macro reverse_bytes_u64