Hardware stack
TMM
Posts: 19
In my ongoing quest to understand the P2 better level, I was wondering what about this 8-level hardware stack for fastest subroutine calls/returns and push/pop operations. And later K / Stack: The 8-level hardware stack used for subroutine calls (stores C, Z, and PC) and temporary 32-bit push/pop storage.
Does this mean that there's some extra ram in each cog that can hold 8 call frames for CALL/RET pairs? What happens if the call stack is deeper than 8? The Propeller-2-Assembly-Language-PASM2-Manual-20221101-1.pdf doesn't seem to mention this.
It seems that the CALLA and friends is a bit better described as it is all relative to a pointer to hubram.

Comments
Each cog has its own 8-level 32-bit hardware stack that will wrap around if stack level deeper than eight, which is unlikely to occur. HW stack is implemented in a logic as a big shift register and there's no stack pointer.
During skip sequences a CALL suspends skipping until there is a RET back to the same stack level as the CALL. This means a CALL counts as only one skip instruction and calls can be nested.
CALLA & CALLB are different from other CALL instructions as they use hub RAM for the stack with PTRA & PTRB as stack pointers. Note that stack grows upwards.
I understood the rest of your post. I've read this part several times now and looked up the
SKIPFandSKIPinstructions again to refresh my memory. However I really do not understand this section at allCould you give me a more step by step explanation? I had found no correlation between CALL/RET pairs and SKIPs, I'm quite confused.
Thank you!
If you never use
SKIPFthen you can ignore the rest of this message.Below is part of the rotate/shift code for an 8086 emulator. Most of these 8086 instructions have a direct P2 equivalent that can be used for multi-bit rotate/shift. However, multi-bit byte or word
RCLandRCRcannot be done by a single P2 instruction. The code below shows eight of 32 skipping instructions that follow aSKIPF. I can spare only one instruction each for 8086RCL&RCRbut that is all right as each P2CALLcounts as a single skipping instruction. Skipping is disabled insideRCL_dest_countandRCR_dest_countand both of these routines could contain aCALLto call a nested subroutine, which itself could also contain aCALL, etc.The skipping logic keeps track of the hardware stack level and after the
RETor_RET_at the end ofRCL_dest_countorRCR_dest_countthe HW stack level will be the same as it was when the initialCALLwas made and therefore skipping will resume. The a-h and A-H comment characters are used to automatically create the correct skipping patterns for byte and word data width, respectively, using a program I've written.Conclusion:
CALLand its associated subroutine (no matter how long) counts as only one instruction during skipping sequences, which makes skipping much more powerful.I understand now what you were trying to say! Thank you!
I suppose that if you try to
skiporskipfin a function beingcalled then things will go very wrong?Yes, subroutines called from a skipping sequence cannot themselves use skipping because that will destroy the original remaining skip bits. There is only one level of skip bits.
Ideally a future P3 or P2+ would have 64-bit wide stack so that skip bits could be pushed and popped and each stack level could support skipping.
That makes sense, yes! Thanks for all the explanations!