Skip to content

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.

1 participant