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

MathInterpreter: Replace Instruction polymorphism with bytecode #20

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

mspraggs
Copy link
Contributor

Hi Antonin,

I hope you're keeping well.

This change replaces the Instruction class hierarchy with a bytecode-based instruction representation. Instead of an Instruction instance, each instruction opcode is specified by a single byte, and instruction arguments are packed into the bytecode array. The arithmetic operations are represented by a single byte, the load, store and call operations are encoded as a byte followed by the variable or function address, and the constant instruction is encoded as a single opcode followed by the double-precision floating point value. I hope this makes sense. If not, this should provide a fuller explanation.

Replacing the polymorphic instruction classes with a packed bytecode array increases the locality of reference during execution. After some rough benchmarks I found the improvement was a factor of two, though more performance could be squeezed out through other modifications. For example, the std::deque container wrapped by the std::stack could be replaced with a std::vector.

Let me know what you think.

Best,

Matt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant