Anton Ertl <ant…@mips.complang.tuwien.ac.at> wrote:
> Stefan Monnier <monn…@iro.umontreal.ca> writes:
>>Anton Ertl [2026-11-12 06:21:21] wrote:
>>> Stefan Monnier <monn…@iro.umontreal.ca> writes:
>>>>Yeah, if we take CISC as motivated by the desire to provide an assembly >>>>language that is comfortable for humans, we can also take RISC as >>>>motivated by the desire to provide an assembly language that's >>>>convenient for compilers (which would rather not need to worry about >>>>tradeoffs between using LD+ADD+ST vs using some fancy addressing mode >>>>on ADD).
>>> The fancy addressing mode is the same whether you use it with a LD, a >>> ST, or an ADD.
>> >>That's beside the point. With a load/store architecture you don't need >>to choose between using the ADD-with-addressing mode or using explicit >>loads and stores. Makes life simpler for the compiler.
> > No. With an architecture like the VAX, RISC is actually harder: > > VAX: If operand src1 is in memory, accessed with d(SP), use the ADD > instruction with d(SP) as second operand. Likewise for src2 and dst. > > RISC: If operand src2 is in memory, allocate a register for it (but > why is it in memory? Probably because there are no registers > available, so first spill some other value); then load the operand > from d(SP) into the register; possibly do the same for the other > source operand (but don't spill the register for src2). If the > destination is in memory, allocate a register for storing it in the > meantime (again with the potential for spilling). Finally do the add. > Store the result if necessary. And now refill all the spilled values. > > It's all doable, but simpler? No.
Partially playing devil's advocate: if you reserve registers for arguments and for handlinig addressing modes, then all one has to do is generating code for loads. But some loads seem to be neccessary even for VAX, so you need function which generates loads in the compiler anyway. For RISC, you generate much more loads than for VAX, but decision when to generate a load is quite simple. I estimate that for typical instructions one needs to reserve between 3 and 8 registers, that is 2 for arguments, one for result and additional registers to handle addressing modes. IIUC Risc-V and ARM need at least one register to generate large constants which may be needed for addressing. Now, with 4 registers reserved on 32 bit ARM there remain 11 general purpose registers (plus PC), that is significantly less than 15 general purpose registers on VAX. But Risc-V and 64 bit ARM even after reserving a few still have more usable general purpose registers than VAX. Of course, that assumes out of order RISC. For superscalar in-order RISC one needs to schedule instructions and that significantly complicates register allocation.
> For the more common CISC style with load-and-op and read-modify-write, > things are harder than on the VAX, but RISC still is not simpler.
In simple (almost naive) compiler main issue is how much you care about possibly redundant temporary registers. Due to software conventions, it seems that one actually does not need to care much. That is, there is limited supply of registers usable for local variables. More precisely, to avoid excessive spill code around calls variables that need to persists after function call need to be allocated in call-preserved registers, and those are relatively small fraction of all registers. And in a simple compiler it is reasonable to assume that all variables that are allocated to registers should survive after function call (otherwise compiler need to do some real work like livenes ananlysis, rage splitting etc.). So there are plenty of registers that are usable only for temporaries.
-- Waldek Hebisch