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

Optimize CPU instructions to use less memory. #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

madpilot78
Copy link

I tried to optimize the virtual CPU to use less memory for its code.

I took inspiration from what I remember of the Z80 CPU assembly.

This simple optimization creates specific opcodes for CPU instructions for each register they are operating on, shedding the need to pass the register as an argument in most cases.

It makes little sense to apply such optimization for indirect references, since the CPU supports offsets that would anyway need to be passed as an argument, so no memory saving there.

With these changes the compiled Hello World example uses 12 bytes less.

These changes make the virtual CPU incompatible with binaries for the previous one, also due to me renumbering all opcodes.

In theory it would be possible to make it binary compatible by creating some compatibility opcodes with the correct numbers and shifting the new optimized ones. It would also require compatibility code to handle those "old" opcodes, It looks overkill in this case.

The assembler interface is unchanged though.

I tried to optimize the virtual CPU to use less memory for its code.

I took inspiration from what I remember of the Z80 CPU assembly.

This simple optimization creates specific opcodes for CPU instructions for each register they are operating on, shedding the need to pass the register as an argument in most cases.

It makes little sense to apply such optimization for indirect references, since the CPU supports offsets that would anyway need to be passed as an argument, so no memory saving there.

With these changes the compiled Hello World example uses 12 bytes less.

These changes make the virtual CPU incompatible with binaries for the previous one, also due to me renumbering all opcodes.

In theory it would be possible to make it binary compatible by creating some compatibility opcodes with the correct numbers and shifting the new optimized ones. It would also require compatibility code to handle those "old" opcodes, It looks overkill in this case.

The assembler interface is unchanged though.
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.

None yet

1 participant