diff --git a/evm/src/cpu/kernel/asm/hash/ripemd/main.asm b/evm/src/cpu/kernel/asm/hash/ripemd/main.asm index 1ea3ee1d..32d1994b 100644 --- a/evm/src/cpu/kernel/asm/hash/ripemd/main.asm +++ b/evm/src/cpu/kernel/asm/hash/ripemd/main.asm @@ -22,21 +22,28 @@ global ripemd: // stack: length %shl_const(3) // stack: abcdefgh - %extract_and_store_byte(64) - // stack: abcdefg - %extract_and_store_byte(65) - // stack: abcdef - %extract_and_store_byte(66) - // stack: abcde - %extract_and_store_byte(67) - // stack: abcd - %extract_and_store_byte(68) - // stack: abc - %extract_and_store_byte(69) - // stack: ab - %extract_and_store_byte(70) - // stack: a - %mstore_kernel_general(71) + DUP1 + %extract_and_store_byte(31, 64) + // stack: abcdefgh + DUP1 + %extract_and_store_byte(30, 65) + // stack: abcdefgh + DUP1 + %extract_and_store_byte(29, 66) + // stack: abcdefgh + DUP1 + %extract_and_store_byte(28, 67) + // stack: abcdefgh + DUP1 + %extract_and_store_byte(27, 68) + // 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 %mstore_kernel_general(72) @@ -113,19 +120,11 @@ process: SUB %endmacro - -%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) +%macro extract_and_store_byte(byte, offset) // stack: xs + PUSH $byte + BYTE + // stack: xs[byte] + %mstore_kernel_general($offset) + // stack: %endmacro diff --git a/evm/src/cpu/kernel/asm/util/basic_macros.asm b/evm/src/cpu/kernel/asm/util/basic_macros.asm index 6640892f..a68d832d 100644 --- a/evm/src/cpu/kernel/asm/util/basic_macros.asm +++ b/evm/src/cpu/kernel/asm/util/basic_macros.asm @@ -289,7 +289,7 @@ // given u32 bytestring abcd return dcba %macro reverse_bytes_u32 - // stack: abcd + // stack: abcd DUP1 PUSH 28 BYTE @@ -308,11 +308,11 @@ PUSH 31 BYTE %shl_const(24) - // stack: d000, b0, a, c00 + // stack: d000, b0, a, c00 OR OR OR - // stack: dcba + // stack: dcba %endmacro %macro reverse_bytes_u64