Skip to content

MathInterpreter: Replace Instruction polymorphism with bytecode#20

Open
mspraggs wants to merge 1 commit intoaportelli:developfrom
mspraggs:develop
Open

MathInterpreter: Replace Instruction polymorphism with bytecode#20
mspraggs wants to merge 1 commit intoaportelli:developfrom
mspraggs:develop

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