🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #1015

Re: CISC are not "unreduced"

#1015
From: Waldek Hebisch
Date: Wed, 02 Dec 2026 02:54
159 lines
8905 bytes
EricP <ThatWouldBeTelling@thevillage.com> wrote:
> On 2026-Dec-01 13:54, MitchAlsup wrote:
>> antispam@fricas.org (Waldek Hebisch) posted:
>> 
>> 
>>>                 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.
>> 
>> Registers 00..08 are for arguments {R0 is return address}
>> Registers 09..15 are temporary {unused arguments are also temp}
>> Registers 16..31 are preserved. R30 is FP, R31 is SP
>> 
>>>                     IIUC Risc-V and ARM need at least one
>>> register to generate large constants which may be needed for
>>> addressing.
>> 
>> That is a typical RISC problem--but not for my ISA
>> 
>>>               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.
>> 
>> Don't forget the free access to memory via address modes.
> 
> Yes, VAX had a bunch of temp registers for holding intermediate
> addressing results. IIRC the 780 had a whole 16 register file for them.
> The instruction's operand specifiers were processed as they were
> parsed so any opspec accesses and side effects took place serially
> before the next opspec was fetched, parsed and executed.

I did not look at all VAX addressing modes.  But AFAICS scheme
that I propose can handle most (if not all) VAX modes and many
modes which I believe are not available on the VAX.  To explain
it more, with 4 reserved registers I can use all of them when
computing address of first operand.  After computing its address
I load it to register.  So I have 3 registers left that I can
use to compute address of the second operand.  After that
I load the operand and perform the operation.  After that
I have 1 register that I need to preserve and 3 registers that
I can use to compute address of destination.  Once address
of destination is computed, I store it.

Note that Intel style SIB mode (IIUC not available on the VAX)
can be done using 2 registers: in 1 register we generate
constant displacement, then we add to it base.  We copy
index to the second register, then we shift (scale) it,
then we add scaled index to previousy computed sum of
base and constant.

At any stage of this we can copy intermediate result back
to different register, so this convers preinctement and
predecrement.  For postincrement and postdecrement we
can simply emit separate instructions that modify register.
And we can do this either after whole instruction or
after a selected operand.  So, if needed we can emulate
VAX behaviour of updating registers after each operand.
Similarly, we can easily introduce extra indirections
by emiting extra load(s) after computing initial address.
Note that at such time we have at most one register holding
operand or value and the second containing address, so we
still have to registers to do something extra (if needed).

If you thing that this scheme is complex, note that we
can put result of operation in the same register as the
first operand.  So "load to register" needs to preserve
one register and can use 3.  We could use all four
reserved registers for computing address of the first
operand but for simplicity we can reuse address calculation.

Let me add that simple compiler is likely to use only
some address modes.  A naive toy backend that I have just
lowers expression to 3 address form, introducing stack
temporaries if needed.  It is very simple, generated
code is quite bad, but it only generates RISC instructions.
Sligtly better version of this toy backend posses result
of previous operation to the next in a register.  Generated
code is still bad, but visibly better than from the first
one.  It also only generates RISC instructions.  I have
looked at CDC6000 Pascal compiler by U. Amman.  Amman
added a bunch of special cases for frequent Pascal
constructs.  More importantly, he treats registers as
a cache for recently computed values.  CDC 6000 in
a sense is most strict RISC, that is IIUC it does not
allow constants as arguments to computational instructions.
But similar compiler structure was used for CISC-s
and AFAICS while some CISC instructions reduce number
of instrucions in generated code, having them does not
seem to lead to simplification.

In different compiler, there is machine independent part
that translates program to abstract instructions and
performs some simlifications.  This machine dependent
part generates code for for each abstract instruction
separately.  The abstract instruction set has visible
VAX smell, but uses only small part of VAX instruction
set and only selected addressing modes.  So it is no
wonder that VAX code generator is the smallest one
(1164 lines).  ARM64 and Risc-V code generators are
significantly bigger (1731 and 1767 lines respectively).
Part of that is that VAX handles 3 sizes for loads and
stores, that is 1, 2 and 4 bytes, while ARM64 and Risc-V
handle 4 sizes (that is also 8 bytes) which adds
additional cases in few places.  On Risc-V 20 lines
emulate autoindexing (due to compiler structure and
structure of Risc-V instruction set emulated
autoindexing gives better code than handling this
in machine independent part).  Part of difference may
be due to different authors and differnt code styles
(VAX backed was probably created 45 years ago and
last change seem to be 31 years ago, ARM64 and Risc-V
are very recent).  But the biggest difference comes
from fact that VAX backend has very simple map from
addresing modes to VAX assembler, while other targets
need to emulate (some) VAX addressing modes.

But that is historical artifact, VAX was one of early
targets.  More importantly, VAX was first 32-bit target
which allowed system expansion, so it is natural
that compiler structure was made to match VAX well.
Without such history it is likely that compier would
have different structure, making difference smaller.
Also, whole compiler is some tens thousend lines,
(the compiler if part of larger system and it is not so
easy to tell what is compiler proper and what has other
function).  Comparing  to the whole compiler difference
in backend size is modest.

> VAX reserved use of some registers:
> R15   PC
> R14   SP
> R13   FP
> R12   AP Argument Pointer
> R3,R5 Address counter in character and decimal instructions
> R2,R4 Length counter in character and decimal instructions
> R1    High function result value (optional), result of varous instructions
> R0    Low  function result value, result of various instructions
> 
> The CALLS, CALLG and RET instructions and routine entry mask required
> R12..R15 to be used this way.
> 
> There was no separate FPU register file. Double, quad and octal precision
> FP values took 2, 4, or 8 sets of aligned register ids.
> 
> There was no multi threading then, otherwise they'd have needed a
> TP thread pointer register too.

In normal use modern machines need stack pointer, either as
hardware feature or as software convention, so I do not count
it separately.  Maybe I am wrong, but my impression was that
FP and AP are usable as temporary registers between calls, so
this use is similar to link register on machines that use it
and to register(s) reserved on some machines for use by dynamic
linking stubs.  From software point of view they do not differ
much from other registers which are not preserved by calls.

-- 
                              Waldek Hebisch
Technical Details
Message-ID: <11eo18a$2vsc7$1@paganini.bofh.team>
Path: mbox-mo1.pugleaf.net!news-ams.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!paganini.bofh.team!not-for-mail
References: <11cpqih$acf5$1@dont-email.me> <11cti0c$1lilf$4@dont-email.me> <11cuoa4$21279$1@dont-email.me> <jwvcxscsjsa.fsf-monnier+comp.arch@gnu.org> <1794357499-5857@newsgrouper.org> <jwvik23o10u.fsf-monnier+comp.arch@gnu.org> <2026Nov12.072121@mips.complang.tuwien.ac.at> <jwvy0axmx8f.fsf-monnier+comp.arch@gnu.org> <2026Nov13.192642@mips.complang.tuwien.ac.at> <11ekc0r$2dni3$1@paganini.bofh.team> <1796151298-5857@newsgrouper.org> <OyFPS.84961$cKd4.69588@fx38.iad>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-ams.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!paganini.bofh.team!not-for-mail
From: antispam@fricas.org (Waldek Hebisch)
Newsgroups: comp.arch
Subject: Re: CISC are not "unreduced"
Date: Wed, 2 Dec 2026 02:54:04 -0000 (UTC)
Organization: bofh.team Usenet service
Message-ID: <11eo18a$2vsc7$1@paganini.bofh.team>
References: <11cpqih$acf5$1@dont-email.me>   <11cti0c$1lilf$4@dont-email.me> <11cuoa4$21279$1@dont-email.me> <jwvcxscsjsa.fsf-monnier+comp.arch@gnu.org> <1794357499-5857@newsgrouper.org> <jwvik23o10u.fsf-monnier+comp.arch@gnu.org> <2026Nov12.072121@mips.complang.tuwien.ac.at> <jwvy0axmx8f.fsf-monnier+comp.arch@gnu.org> <2026Nov13.192642@mips.complang.tuwien.ac.at> <11ekc0r$2dni3$1@paganini.bofh.team> <1796151298-5857@newsgrouper.org> <OyFPS.84961$cKd4.69588@fx38.iad>
Injection-Date: Wed, 2 Dec 2026 02:54:04 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="3142023"; mail-complaints-to="usenet@bofh.team"; posting-host="d028f9ad2fa2c51f22dbfed0d81d7daf"; posting-account="69e66f1681224ab92235b464ce7a90b6"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
X-Postfilter: Postfilter-NG 2026.10.2