Brian Fox <
bria...@brianfox.ca> writes:
>I read an article by Sam Falvo on trying to make machine Forth for
>RISC V and the instruction set seemed to require a lot of
>instructions per Forth primitive. Is that the "state of the art" for
>"risc".
RISC-V and ARM A64 (aka Aarch64) are both RISCs in my book (they are
load/store architectures), but follow quite different design
philosophies.
ARM A64 has 32-bit wide instructions and puts as much functionality in
as fits and fits the basic RISC principles, sometimes crossing the
border. It does not try for minimal implementation, ARM has another
instruction set (T32/A32, the 32-bit ARM instruction set with Thumb2
compression) for that.
By contrast, RISC-V tends to keep instructions minimal, supports a
compressed extension (that supports common instructions in 16 bits in
addition to the 32-bit encoding for all instructions), allowing for
smaller minimal implementations; for more sophisticated
implementations, the idea is that the instruction decoder combines
instructions into more capable microinstructions (sometimes called
macroinstructions because they are actually larger than the
architectural instructions). But of course you don't see that on the
architectural level. E.g., here's gforth-fast's +:
RISC-V ARM A64 AMD64 RTL
ld a5,$8(s8) ldr x0, [x25,#0x8]! tmp = load(SP+8)
addi s10,s10,8 add x26, x26, #0x8 add r13,$08 IP = IP+8
addi s8,s8,8 add r15,$08 SP = SP+8
add s7,s7,a5 add x27, x0, x27 add r8,[r15] TOS = TOS+tmp
ld a4,$-8(s10) ldur x1, [x26,#-0x8] mov rcx,-$08[r13] tmp = load(IP-8)
jr a4 br x1 jmp ecx jmp tmp
RTL is "register-transfer language", a pseudocode for describing
instructions. I use Forth virtual machine register names here.
I rearranged the AMD64 instructions to match the order of the others;
originally the first and second AMD64 instructions were swapped.
Here A64 combines the first and third instruction of the RISC-V code
in its first instruction. We wrote it such that the last two
instructions can be separated from the others, otherwise the compiler
would probably have combined the second A64 instruction with the ldur
into one instruction.
As a non-RISC, AMD64 has load-and-op instructions, as demonstrated by
combining the first and fourth RISC-V instruction into the third AMD64
instruction. AMD64 also could combine the last two instructions into
one, but gcc has not done that after gcc-2.95 (there for IA-32).
- anton
--
M. Anton Ertl
http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs:
http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard:
https://forth-standard.org/
EuroForth 2022:
https://euro.theforth.net