Skip to content

Commit 3361221

Browse files
authored
Merge pull request #308 from ethereum/analysis_jumpdest_optimization
Optimize build_jumpdest_map()
2 parents 48964fc + 96ddad5 commit 3361221

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/evmone/baseline.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ namespace evmone
1212
{
1313
JumpdestMap build_jumpdest_map(const uint8_t* code, size_t code_size)
1414
{
15-
// Bitmask for PUSH opcode identification.
16-
// It clears the lower 5 bits of a byte.
17-
// The opcode is PUSH iff remaining byte value is 0x60 (OP_PUSH1).
18-
constexpr auto push_op_mask = 0xE0;
15+
// To find if op is any PUSH opcode (OP_PUSH1 <= op <= OP_PUSH32)
16+
// it can be noticed that OP_PUSH32 is INT8_MAX (0x7f) therefore
17+
// static_cast<int8_t>(op) <= OP_PUSH32 is always true and can be skipped.
18+
static_assert(OP_PUSH32 == std::numeric_limits<int8_t>::max());
1919

2020
JumpdestMap map(code_size); // Allocate and init bitmap with zeros.
2121
for (size_t i = 0; i < code_size; ++i)
2222
{
2323
const auto op = code[i];
24-
if ((op & push_op_mask) == OP_PUSH1) // If any PUSH opcode.
25-
i += op - size_t{OP_PUSH1 - 1}; // Skip PUSH data.
24+
if (static_cast<int8_t>(op) >= OP_PUSH1) // If any PUSH opcode (see explanation above).
25+
i += op - size_t{OP_PUSH1 - 1}; // Skip PUSH data.
2626
else if (INTX_UNLIKELY(op == OP_JUMPDEST))
2727
map[i] = true;
2828
}

0 commit comments

Comments
 (0)