Skip to content

Commit

Permalink
core/vm: unroll loops in analysis bitmap population
Browse files Browse the repository at this point in the history
Unroll loops in bitvec.setN(): first one can at most run 2 times,
second one at most once.
  • Loading branch information
chfast committed Dec 15, 2021
1 parent 9064df7 commit d32bc09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/vm/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,20 @@ func codeBitmapInternal(code, bits bitvec) bitvec {
}
numbits := op - PUSH1 + 1
if numbits >= 8 {
for ; numbits >= 16; numbits -= 16 {
if numbits >= 16 {
bits.set16(pc)
pc += 16
numbits -= 16
}
for ; numbits >= 8; numbits -= 8 {
if numbits >= 16 {
bits.set16(pc)
pc += 16
numbits -= 16
}
if numbits >= 8 {
bits.set8(pc)
pc += 8
numbits -= 8
}
}
switch numbits {
Expand Down
2 changes: 2 additions & 0 deletions core/vm/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func TestJumpDestAnalysis(t *testing.T) {
{[]byte{byte(PUSH32)}, 0x7F, 0},
{[]byte{byte(PUSH32)}, 0xFF, 1},
{[]byte{byte(PUSH32)}, 0xFF, 2},
{[]byte{byte(PUSH32)}, 0xFF, 3},
{[]byte{byte(PUSH32)}, 0x80, 4},
}
for i, test := range tests {
ret := codeBitmap(test.code)
Expand Down

0 comments on commit d32bc09

Please sign in to comment.