Repository navigation
Add -Oinline-pushregs: save and restore registers inline in P2 hub functions - #517
Merged
totalspectrum merged 1 commit intoOct 13, 2026
Merged
Conversation
…nctions On the P2, a function in hub memory that needs a frame calls pushregs_ and popregs_ in COG memory to save and restore its registers. Each of those calls goes into COG memory and back to hub, which reloads the instruction FIFO. With -Oinline-pushregs the same setq/wrlong and setq/rdlong sequences are emitted inline in the function's entry and exit code. They build the identical frame, so __unwind_stack, popregs_, setjmp/longjmp and gosub_ are unchanged. Functions placed in COG or LUT memory keep the calls, and P1 is not affected. The flag is part of -O2 (EXTRA_ASM_OPTS); -O1 and -Os generate the same code as before.
Owner
|
Thank you for the pull request! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the inline save/restore from item 3 of totalspectrum/flexprop#118, behind an optimization flag as you suggested there.
With
-Oinline-pushregs, a P2 function in hub memory that needs a frame saves and restores its registers withsetq/wrlongandsetq/rdlonginline in its entry and exit code, instead of callingpushregs_andpopregs_in COG memory. The frame is the same, so__unwind_stack,popregs_, setjmp/longjmp andgosub_are untouched. Functions placed in COG or LUT memory keep the calls, and P1 is not affected.The flag is in EXTRA_ASM_OPTS, so -O2 turns it on, and -O1 and -Os generate the same code as before. It can also be turned on by itself (
-O1,inline-pushregs) or for one function with__attribute__(opt(inline-pushregs)). doc/general.md has an entry for it.Cost and benefit are as measured in the flexprop issue: about 32 clocks less per call of such a function, 5 to 9 more longs per function, and +6.3% speed on a PDP-11 emulator. Over the C programs below, binaries grow by 8.9% on average (0.5% to 13.4%).
Checked, with flexspin built from this branch (master 28d434d plus this commit):
make test_offline: the same tests pass as on master. The P2 asm expectations are COG code, so none of them is affected.Test/runtests_p2.shon a P2-EDGE: 27 of 27 pass. They are built with -O2, so every test now uses the inline sequences and none callspushregs_. The BASIC try/catch and Spin abort tests unwind through these frames.-O1,inline-pushregsfor all of them, -O2 for a quarter of them.-O1,inline-pushregs: all 321 fuzzer programs that build pass their own checks, and 238 test programs print the same as master's builds of them.