template<unsigned StackSize = 1024>
class psyqo::ScratchpadStackful< StackSize >
Stackful coroutine whose stack is the scratchpad.
Same as Stackful, except that the stack is not part of the object: it is the top StackSize bytes of the 1KB scratchpad, growing down from 0x1f800400. The scratchpad answers a load in one cycle where main RAM takes several, so a hot routine that spends its time saving and restoring registers and reloading spilled locals gets faster by running here. The scratchpad-stack example measures it.
The constraints all come from the scratchpad itself:
- Only one can be alive at a time, since every instance uses the same bytes. Let one return before initializing the next.
- DMA cannot reach the scratchpad, so a local of the coroutine cannot be a DMA source or target. That includes a primitive or fragment built on its stack and then chained to the GPU.
- The bottom
c_freeBytes bytes are left for data, such as variables placed with __attribute__((section(".scratchpad"))), which the linker allocates from 0x1f800000 upward. initialize aborts if the linked .scratchpad section, which ends at __scratchpad_end, reaches into the stack. A stack that overflows at run time still writes over that data silently.
- Only the main link's
.scratchpad section is checked: data an overlay module places in the scratchpad is not accounted for.
- Interrupts do not run on this stack: psyqo's exception handler saves the registers it needs to fixed addresses and switches to its own stack before calling into C++.
- Template Parameters
-
| StackSize | The number of bytes taken from the top of the scratchpad. A multiple of 8, at most 1024. |