3 ms·
SPARC CPUs do functionally have an on chip stack via register windows. Basically they have something like 256 registers set up so the output registers overlap
by olliej 6y ago
SPARC CPUs do functionally have an on chip stack via register windows.
Basically they have something like 256 registers set up so the output registers overlap the input registers of the next callframe. e.g.
iiirrrooo
iiirrrooo
iiirrrooo
Where i == input register, r == general purpose register, and o == output register. When code calls another function it places the first N arguments in the output registers. The called function reads arguments out of the input registers.
This results in very high call and return performance. Until you exhaust the available register windows. At which point you fault, and the kernel has to manually copy the register window stack to memory. Similarly on return you may have reached the top of the stack you fault and the kernel has to copy the windows back from memory into the register windows.
For SPARC this was apparently an ok tradeoff as the "big iron" machines of the past generally did not recurse heavily.
- compiler-guy 6y agoOne of the biggest problems with such an architecture is that you cannot predict whether a given function call will overflow the on-chip physical registers, and therefore will be expensive. So a simple change like adding a wrapper function, or a compiler choosing a different inline heuristic can affect the performance of your code in strange and unpredictable ways. Context switches also get more expensive, because you have to swap out the entire windowed register file, and not just what is visible to software. (That can be mitigated by additional hardware support, but the complexity is high.)
- olliej 6y agoYeah, that why it was considered acceptable for big iron/servers of the time. There not a huge amount of context switching (basically few processes relative to the number of cpus in the system), and known types of programs. They knew in general most code they ran would not blow the stack. The cost of course if you ran atypical (for their designed purpose) your perf would be clobbered.
- compiler-guy 6y agoDonald Knuth's MMIX from his updated _Art of Computer Programming_ is also a register window architecture.
- ajross 6y agoXtensa (c.f. ESP-32 et. al. -- it's actually a pretty popular embedded architecture) also has a register window scheme, simultaneously more and less complicated than SPARC's. Likewise the ia64 registers were rotating, with a hardware stack engine. To answer the main question: this wasn't abandoned in the industry. CPUs still do it. It just doesn't really provide much of a competetive benefit to architectures that do it, so it's largely been abandoned.
- olliej 6y agoWhat do you by rotating in x86? are you referring to the renaming? Where is the xtensa documentation? My random googling seems to indicate it has a more traditional fixed set of registers? On SPARC for instance (super super super pseudo code here, I haven't written sparc assembly for... almost 20 years?) mov %o0, an_argument call a_function ... a_function: ; the argument is now in %i0 or something like that.
- lokedhs 6y agoYou got the arguments backward. SPARC uses the proper order (source,dest) So it would be something like: ld [%l0],%o0 ; Load whatever is pointed to by %l0 into %o0 call some_function ; Stores the old pc in %o7 ; Result is now in %o0 some_function: save ; Move the register window ; The argument is now in %i0 ld %i0,%l0 ; This does not overwrite the caller's l0 ret ; Return, essentially a jump to %i7 restore ; Called due to delay slot, restores the window
- ajross 6y agox86 does not rotate its registers (though the 8087 did). I said "ia64", which is the Itanium architecture. It actually had a mix of fixed, caller-save registers and rotating argument registers, and an outrageously complicated hardware engine for moving them to and from the stack. Xtensa is simpler than Itanium, in that the windows are fixed 4-register sets and the spilling and filling is done in an exception handler. But it's more complicated than SPARC for sure. The details are in the "Xtensa Instruction Set Architecture Reference Manual", which is a PDF that is commonly available on the internet but not AFAIK actually distributed by Cadence itself.