Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(EVM-emulator): add all unused opcodes #836

Conversation

vladimirradosavljevic
Copy link

@vladimirradosavljevic vladimirradosavljevic commented Oct 3, 2024

What ❔

This PR adds all unused opcodes.

Why ❔

Since opcodes are 8-bit long and if we implement all cases in the switch of that range (0-255), LLVM will optimize out default case (as it is shown here where for default case will generate unreachable BB), thus will remove checks before jump table instruction. As a result, this will remove 1 instruction that is executed in a loop header for each opcode.
Before this patch, we had following assembly generated in a loop header:

	sub.s	31, r14, r1
	ldmi.h	r1, r2, r14
	and	255, r2, r2
	sub.s!	255, r2, r0        <- This check is not needed
	jump.ne	code[@JTI3_0+r2]
	jump	@.BB3_1053         <- This branch is not needed

After this patch:

	sub.s	31, r14, r1
	ldmi.h	r1, r2, r14
	and	255, r2, r2
	jump	code[@JTI3_0+r2]

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.

Signed-off-by: Vladimir Radosavljevic <[email protected]>
@vladimirradosavljevic
Copy link
Author

@0xVolosnikov PTAL.

@0xVolosnikov
Copy link

LGTM, but I'd prefer to maybe create a new branch for these combined optimizations

@0xVolosnikov 0xVolosnikov changed the base branch from evm-vv-lazy-stack to evm-emulator/compiler-based-optimizations October 7, 2024 09:39
@0xVolosnikov 0xVolosnikov merged commit 2d77ceb into matter-labs:evm-emulator/compiler-based-optimizations Oct 7, 2024
19 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants