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

Peephole optimizer & proc decoder fixes #2054

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

Conversation

ike709
Copy link
Collaborator

@ike709 ike709 commented Oct 21, 2024

This PR does a few things:

  1. Fixes peephole optimizations not being applied to opcodes created by peephole optimizations. E.g.:
    PushNull -> Assign -> Pop was being optimized to PushNull -> AssignPop, but the optimizer offset wasn't rolled back far enough to consider optimizing PushNull -> AssignPop to NullRef. It would only be rolled back to the new AssignPop opcode. This meant that the NullRef opcode was never used, which is now fixed.

  2. Fixes a few opcodes not being implemented in ProcDecoder. Because a few opcodes were specific to optimizations that were never applied, they never triggered any errors in the disassembler. DreamProcOpcode.NullRef and DreamProcOpcode.PushNOfStringFloats can now be decoded.

  3. Fixes PushNOfStringFloats only being applied to pairs of StringFloats. Because of how the peephole optimizer works, it would (now that it actually runs) try to run the PushNOfStringFloats optimization before every PushString and PushFloat in the sequence had been converted to StringFloats. The PushNOfStringFloats optimization has been folded into the StringFloat optimization, and it'll just use the relevant opcode depending on how many pairs of PushString and PushFloat opcodes there are. This has the added benefit of reducing the amount of optimizations that need to be applied.

We really need to implement a system for unit testing the peephole optimizer on input bytecode, but that is out of scope for this PR.

I made sure that TG doesn't explode, the NullRef opcode is now used, and that the PushNOfStringFormat optimization actually works correctly & disassembles with sane formatting:

	PushFloat 0 
	PushNOfStringFloats "y" 0 "size" 1 "repeat" 2 "radius" 0 "falloff" 1 "flags" 0
	CreateAssociativeList 7 

@boring-cyborg boring-cyborg bot added Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime labels Oct 21, 2024
@ike709 ike709 requested a review from wixoaGit October 21, 2024 02:44
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant