Skip to content

Commit 09711e0

Browse files
committed
Optimize build_jumpdest_map()
Optimize the build_jumpdest_map() procedure by comparing opcode as signed integer and eliminating always true op <= OP_PUSH32 (0x7f) check.
1 parent 48964fc commit 09711e0

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/evmone/baseline.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ 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;
19-
2015
JumpdestMap map(code_size); // Allocate and init bitmap with zeros.
2116
for (size_t i = 0; i < code_size; ++i)
2217
{
2318
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.
19+
20+
// To find if op is any PUSH opcode (OP_PUSH1 <= op <= OP_PUSH32)
21+
// it can be noticed that OP_PUSH32 is INT8_MAX (0x7f) therefore
22+
// static_cast<int8_t>(op) <= OP_PUSH32 is always true and can be skipped.
23+
if (static_cast<int8_t>(op) >= OP_PUSH1) // If any PUSH opcode .
24+
i += op - size_t{OP_PUSH1 - 1}; // Skip PUSH data.
2625
else if (INTX_UNLIKELY(op == OP_JUMPDEST))
2726
map[i] = true;
2827
}

0 commit comments

Comments
 (0)