clean up macros, remove ripemd segment

This commit is contained in:
Dmitry Vagner 2022-10-03 12:21:43 -07:00
parent 0dc1a40306
commit cb88dadd29
7 changed files with 23 additions and 28 deletions

View File

@ -41,9 +41,9 @@ pub(crate) fn combined_kernel() -> Kernel {
include_str!("asm/memory/txn_fields.asm"),
include_str!("asm/ripemd/compression.asm"),
include_str!("asm/ripemd/constants.asm"),
include_str!("asm/ripemd/functions.asm"),
include_str!("asm/ripemd/main.asm"),
include_str!("asm/ripemd/memory.asm"),
include_str!("asm/ripemd/ripemd.asm"),
include_str!("asm/ripemd/subroutines.asm"),
include_str!("asm/ripemd/update.asm"),
include_str!("asm/rlp/encode.asm"),
include_str!("asm/rlp/decode.asm"),

View File

@ -62,7 +62,7 @@
// stack: value
%endmacro
%macro mload_kernel_code_label(label)
%macro mload_kernel_code(label)
// stack: shift
PUSH $label
ADD
@ -71,17 +71,6 @@
// stack: byte
%endmacro
%macro mload_kernel_code_label_u32(label)
// stack: u32_shift
%mul_const(4)
// stack: byte_shift
PUSH $label
ADD
// stack: label + byte_shift
%mload_kernel_code_u32
// stack: u32
%endmacro
// Load a big-endian u32, consisting of 4 bytes (c_3, c_2, c_1, c_0),
// from kernel code.
%macro mload_kernel_code_u32
@ -112,6 +101,17 @@
// stack: (((((c_3 << 8) | c_2) << 8) | c_1) << 8) | c_0
%endmacro
%macro mload_kernel_code_u32(label)
// stack: u32_shift
%mul_const(4)
// stack: byte_shift
PUSH $label
ADD
// stack: label + byte_shift
%mload_kernel_code_u32
// stack: u32
%endmacro
// Store a single byte to kernel code.
%macro mstore_kernel_code
// stack: offset, value

View File

@ -136,7 +136,7 @@ update_round_vars:
// stack: rnd, rnd, STATE, F', K , 16, rounds, sides, virt, retdest
SWAP8
POP
%mload_kernel_code_label_u32(k_data)
%mload_kernel_code_u32(k_data)
SWAP7
POP
// stack: STATE, F', K', 16, rounds, sides, virt, retdest
@ -195,7 +195,7 @@ pre_rol:
// stack: box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
DUP12
DUP2
%mload_kernel_code_label(r_data)
%mload_kernel_code(r_data)
ADD
// stack: virt + r, box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
%load_u32_from_block
@ -211,7 +211,7 @@ pre_rol:
PUSH mid_rol
SWAP2
// stack: box, a, mid_rol, b, c, d, e, F, K, boxes, rounds, sides, virt
%mload_kernel_code_label(s_data)
%mload_kernel_code(s_data)
// stack: s, a, mid_rol, b, c, d, e, F, K, boxes, rounds, sides, virt
%jump(rol)
mid_rol:

View File

@ -115,21 +115,21 @@ store_input:
// stack: value
PUSH $offset
// stack: offset, value
%mstore_kernel(@SEGMENT_RIPEMD)
%mstore_kernel(@SEGMENT_KERNEL_GENERAL)
// stack:
%endmacro
%macro mstore_ripemd
// stack: offset, value
%mstore_kernel(@SEGMENT_RIPEMD)
%mstore_kernel(@SEGMENT_KERNEL_GENERAL)
// stack:
%endmacro
%macro mload_ripemd
%mload_kernel(@SEGMENT_RIPEMD)
%mload_kernel(@SEGMENT_KERNEL_GENERAL)
%endmacro
// Load LE u32 from 4 contiguous bytes a, b, c, d in SEGMENT_RIPEMD
// Load LE u32 from 4 contiguous bytes a, b, c, d
%macro load_u32_from_block
// stack: offset
DUP1
@ -155,7 +155,7 @@ store_input:
// stack: a | (b << 8) | (c << 16) | (d << 24)
%endmacro
// set offset i to offset j in SEGMENT_RIPEMD
// set offset i to offset j in memory
%macro mupdate_ripemd
// stack: j, i
%mload_ripemd

View File

@ -36,12 +36,10 @@ pub(crate) enum Segment {
/// `StorageTriePointers` with `StorageTrieCheckpointPointers`.
/// See also `StateTrieCheckpointPointer`.
StorageTrieCheckpointPointers = 14,
/// RipeMD storage
RipeMd = 15,
}
impl Segment {
pub(crate) const COUNT: usize = 16;
pub(crate) const COUNT: usize = 15;
pub(crate) fn all() -> [Self; Self::COUNT] {
[
@ -60,7 +58,6 @@ impl Segment {
Self::StorageTrieAddresses,
Self::StorageTriePointers,
Self::StorageTrieCheckpointPointers,
Self::RipeMd,
]
}
@ -82,7 +79,6 @@ impl Segment {
Segment::StorageTrieAddresses => "SEGMENT_STORAGE_TRIE_ADDRS",
Segment::StorageTriePointers => "SEGMENT_STORAGE_TRIE_PTRS",
Segment::StorageTrieCheckpointPointers => "SEGMENT_STORAGE_TRIE_CHECKPOINT_PTRS",
Segment::RipeMd => "SEGMENT_RIPEMD",
}
}
@ -104,7 +100,6 @@ impl Segment {
Segment::StorageTrieAddresses => 160,
Segment::StorageTriePointers => 32,
Segment::StorageTrieCheckpointPointers => 32,
Segment::RipeMd => 8,
}
}
}