6 ms·
RISC in 2022
- rwmj 4y agoShould be "32-ish architectural registers". Real processors have a lot more registers but they are not directly visible. This is the whole reason why x86-64 is usable despite having only 16 architectural integer registers (or actually a little less than that). The article doesn't get RISC-V instruction encoding right. It mentions compressed instructions, but instructions can also be longer than 32 bits. The important thing about RISC-V is that the instruction stream can easily be divided at instruction boundaries (unlike, say, x86 which is horrific to decode). This gives you most of the benefits of fixed size instructions and the benefits of extensibility when you need it.
- weinzierl 4y ago> "This is the whole reason why x86-64 is usable despite having only 16 architectural integer registers [..]" Who'd have thought thirty year ago we'd all be sittin' here talking tens of registers, eh? In them days we was glad to have two or three. If we were lucky. My first computer had 1 (one). One with less bits than fingers on our hands. It was so dear to us we even gave it a name. "Accu" it was called. If you tell that to the young people today, they won't believe you.
- speed_spread 4y agoSounds as comfortable as living with two teenagers in a house with single bathroom. You have to optimize around it and use clever tricks that shouldn't be documented.
- _joel 4y agoLuxury
- kstrauser 4y agoMy first (usable) computer was a Commodore 64, with 3 registers but a special addressing mode for RAM in the 0x00-0xFF range. It was largely used as 256 bytes of “kinda like a register but not exactly” storage.
- weinzierl 4y agoBrilliant little machine, the good old 64. You are absolutely right about the zeropage (0x00-0xFF) and the three registers. Two of those three were pretty special and limited however. So, I'd say the C64 (and all 6502 or 6510 based systems) had really only one general purpose register.
- Dylan16807 4y agoThe 68k was quite a popular chip, with almost 20 registers and a clear trend towards more, and it came out over 40 years ago.
- adwn 4y ago> Should be "32-ish architectural registers". The entire article is about instruction sets, not about their physical implementation, so I don't think this clarification is necessary.
- ajross 4y agox86 isn't that difficult to decode. Instructions all fall on byte boundaries, so if you want to decode 16 bytes of instructions in a cycle you need 16 parallel decode engines. That sounds awful by the standards of 1987 RISC transistor budgets, but for modern CPUs it's mostly noise.
- avianes 4y agoThe difficulty is not to decode a single instruction, the difficulty is to decode multiple instructions in parallel (let's say from 5 to 8 instructions in parallel). In a modern high performance processor instructions are decoded in batches: Decoding the first instruction is straightforward. But x86 instructions range from 1 to 15 bytes, therefore the second instruction can start from byte-offset 1 up to 15. 3rd instruction has a byte-offset ranging from 2 to 30, ans so on. Furthermore, figuring out an x86 instruction length requires reading several byte from the instruction. In the end, the 8th instruction has 99 possible byte-offset, and assuming that we put, as you suggest, a decoder for each position and length, we need about 1590 decoders and many multiplexer to decode 8 full instructions per cycle. Of course we don't do that, it would consume a lot of energy for nothing. To handle that, modern x86 processor instruction decoding involves a instruction length decode before the instruction decode. The instruction length decode is responsible for identifying the instruction positions and boundaries, and this instruction length decode is a challenging part of the x86 processor to design. We don't know how Intel or AMD exactly do instruction length decode, but we know that some published techniques include a length predictor. That's why, for simplicity and energy efficiency, instruction boundaries must be easily identified and the number of instruction lengths must be kept low.
- ajross 4y ago> In the end, the 8th instruction has 99 possible byte-offset, and assuming that we put, as you suggest, a decoder for each position and length, we need about 1590 decoders and many multiplexer to decode 8 full instructions per cycle. Um... wat? No CPU tries to decode 99 bytes of memory in a cycle. ADL is at 32 currently, I believe. And the instruction starting at byte 12 doesn't change depending on anything but it's own data. It either exists (because the previous instruction ended on byte 11) or it doesn't. So you decode 32 instructions starting at each byte you've fetched (the last ones can be smaller subset engines because they don't need to decode longer instruction forms), and then mask them on or off based on earlier instruction state. Then feed your 1-32 decoded instructions through a mux tree to pack them and you're done. Surely there's more complexity, since this is going to have to be pipelined in practice, and a depth of 32 is going to require something akin to a carry-lookahead adder instead of being chained. But the combinatorics you're citing seem ridiculous, I don't understand that at all.
- renox 4y agoI remember an interesting message about 'scalable' vector extensions which pointed that they weren't necessary compatible with loop unrolling. An interesting point to keep in mind.
- bumblebritches5 4y ago
- ranma42 4y ago> 64 registers with 3 registers per instruction would require 21 bits Actually only 18. With 21 bits you can get 128 registers.
- klelatti 4y agoA minor historical quibble: > RISC was a set of design principles developed in the 1980’s that enabled hardware to get much faster and more efficient. There is a strong argument that RISC as a set of design principles (if not as an acronym) started in the 1970s with the IBM 801 [1] and many of the ideas date back to the 1960s with the CDC 6600 mainframes which were very RISCy. On a more substantive point, I don't think small code size was ever 'officially' part of the RISC concept. Arm pioneered it with Thumb but I think that was a pragmatic decision to get Arm into devices with limited memory space such as early mobile phones. [1] https://thechipletter.substack.com/p/the-first-risc-john-cocke-and-the https://thechipletter.substack.com/p/the-first-risc-john-coc...
- speed_spread 4y agoNitpick: Hitachi pioneered small code size with the SuperH processors, which ARM licensed and marketed as Thumb.
- klelatti 4y agoNitpick accepted - you're absolutely right. To be precise they licensed the relevant patents of course.
- danybittel 4y agoIf you think about it, instruction encoding is really a compression method. I wonder, if it would make sense to decouple compression and microcodes. So you could take a body of Code and find the best compression for it. Or even be able to change "lookup tables" before starting the operating system. Possibly have different compression methods (x86 / arm..) run on the same CPU, without any drawbacks. Which could get you around licensing an ISA. (Yes I'm a software engineer thinking about hardware)
- Someone 4y agoThat is more or less what Transmeta did (https://en.wikipedia.org/wiki/Transmeta#Code_Morphing_Software https://en.wikipedia.org/wiki/Transmeta#Code_Morphing_Softwa...) The “without any drawbacks” part never panned out, though. It also is fairly similar to what Apple has done with emulating 68k on PPC, PPC on x64, and x64 on ARM (but those, AFAIK, do not offer full emulation of the host CPU, as they don’t need to run code in kernel mode)
- ThrowawayR2 4y ago"The jack of all trades is the master of none." Being able to do any type of ISA means you have to put in the circuits to do everything those ISAs can do and those extra circuits are just expensive deadweight when the processor is configured as a specific ISA.
- ip26 4y agoThe most interesting concept here (to me) is the idea of taking a variable length instruction set and optionally promising to align instructions. If you did this, the code could switch between dense and wide as it pleased, getting either the best footprint in the instruction cache or allowing extremely wide decode.
- fulafel 4y ago> RISC was a set of design principles developed in the 1980’s that enabled hardware to get much faster and more efficient. We tend to still call modern-looking instruction sets “RISC-y”, but really, a bunch of the original design principles of RISC CPU’s have not stood the test of time. So let’s look at the things that have worked and not worked between the 1980’s and 2022. I think the design principles of RISC were actually on a meta level above this: take the quantitative approach, use your transistors to best serve the software you have and compilers you can build. "Nice ISA to write assembly code for" was thrown out, or at least demoted significantly. In that 80s moment in the transistor count curve, it meant simplifying the ISA very radically in order to implement fewer instructions in hard coded way without microcode, to the point of ditching HW multiply instructions. The microarchitecture could either do fast, pipelined execution or large instruction set in the transitor budget, you optimized for bang for the buck in the whole-system sense. You could make simple fast machines that were designed to run Unix (so had just enough VM, exception, etc support).
- klelatti 4y agoLargely agree with you here but I think there were two other factors in RISC's early success: 1. As microprocessors became dominant freezing complex microcode - with possible bugs - on an IC was a really bad idea. Better to run with simpler instructions and less microcode. Look at the debugging issues that National Semiconductor had with the NS32016 - which I think really hindered its adoption. 2. You needed a much smaller team to design a RISC CPU - low double figures for IBM 801, Berkeley RISC, MIPS and Arm. This opened the door to lots of experiments and business models that would not have been possible with CISC.
- _0ffh 4y agoYep, RISC is really a KISS CPU, paired with the attempt to draw the maximal advantage from the potential strengths of the underlying concept. And it turned out pretty nicely imho.
- sitkack 4y agoAlmost no systems use fixed microcode. What RISC took advantage of was decoupling the memory bus from the CPU clock rate and the introduction of instruction and data caches. RISC is a simple interface, but the internal processor complexity is as high or higher than CISC (thanks to RISC simplicity). Speculative execution, reordering instructions, hazards, branch prediction these issues are the same across both. The front end isn't this huge deal. CPUs all do the same thing, attempt to unroll huge state machines and compress time. The ISA is just a way to get that problem into the CPU.
- klodolph 4y agoYou can think of "fused multiply-add" as an instruction that does two things at once, but I think of FMA more as a single operation these days. There's a critical difference in floating-point, where the result of FMA can be rounded, so you're not actually getting the same result as separate multiply + add.
- Findecanor 4y agoI suppose you meant to write that: a FMA instruction rounds only once at the end, but both the Multiply and Add instructions also round once each = total two times. BTW. Some MIPS processors did have a FMA instruction that did round twice. The compiler was thus able to fuse instructions without the code giving different results. This was deprecated in later versions, however.
- klodolph 4y agoI thought I did write that?
- vardump 4y agoYeah, FMA is really just one operation. Except when it's time to boast about FLOPS. Then it's always counted as two operations. :-)
- cesarb 4y ago> Nobody besides x86_64 seems to have dedicated stack registers anymore, they’re defined only by convention. Aarch64 also has a dedicated SP register.
- renox 4y agoI remember reading that in fact it was an important improvement from ARM32 to Aarch64 to have a dedicated stack register. Not surprisingly Risc-V has also a dedicated stack register.
- zozbot234 4y ago> Not surprisingly Risc-V has also a dedicated stack register. I don't think this is correct. It has a suggested SP register, which merely gets some special support in the C subset. But that's just an optional compression scheme and not really part of the ISA design.
- renox 4y agoThanks for correcting me. I was mistaken by the assembly language.
- kragen 4y agoRV32I, RV64I, and RV128I (the base RISC-V architecture) don't have a dedicated stack register in the instruction set, and I'm not even sure if your code will even run faster on fancy implementations if you use x2 as the stack pointer in the standard way. However, the compressed instruction extension has "compressed" (16-bit-long) instructions that implicitly index from x2: C.LWSP, C.LDSP (on RV64C and theoretically RV128C), C.LQSP (RV128C only), C.FLWSP, and C.FLDSP; and corresponding store instructions. These instructions incorporate a 6-bit immediate offset field which is added to x2 to form the effective address. As far as I know, that's the full extent to which RISC-V has a dedicated stack register: it has a compressed instruction format that uses x2 as a base register, but not in the base ISA, just a standard extension. There's no dedicated PUSH or POP instruction, no dedicated instruction for storing the link register into the stack, no dedicated instructions for incrementing or decrementing x2 (you do that with ADDI, which can be compressed as C.ADDI as long as the stack frame size is less than 32 bytes, which means it has to be 16 bytes in the standard ABI), not even autoincrement and autodecrement addressing modes.
- gbin 4y agoAFAIK the weak memory model is interesting when you start to scale multicore. It is up to the programmer to sync correctly accesses so when it is not necessary all the units accessing the memory can operate more independently.
- deleted 4y ago[deleted]
- q-big 4y ago> MIPS, Itanium, SPARC and POWER all have weak memory models. This does not seem to hold for SPARC: according to > https://www.cl.cam.ac.uk/~pes20/weakmemory/x86tso-paper.tphols.pdf https://www.cl.cam.ac.uk/~pes20/weakmemory/x86tso-paper.tpho... the (strong) memory models of x86 and SPARCv8 are very related: "We give two equivalent definitions of x86-TSO: an intuitive operational model based on local write buffers, and an axiomatic total store ordering model, similar to that of the SPARCv8." "Our x86-TSO axiomatic memory model is based on the SPARCv8 memory model specification [20, 21], but adapted to x86 and in the same terms as our ear- lier x86-CC model." "We have described x86-TSO, a memory model for x86 processors that does not suffer from the ambiguities, weaknesses, or unsoundnesses of earlier models. Its abstract-machine definition should be intuitive for programmers, and its equiva- lent axiomatic definition supports the memevents exhaustive search and permits an easy comparison with related models; the similarity with SPARCv8 suggests x86-TSO is strong enough to program above."
- vodou 4y agoPoor OpenRISC... Not even mentioned when they talk about RISC.
- rcgorton 4y agoRe: register windows. I disagree: code size wasn't the killer here, it was how DEEP the stack got. If your architectural register window spilled at 4 deep, then calls 3 deep were fine, but if you had a set of code attempting to iterate over a tight loop which had 8 calls deep, you were in [performance] trouble. Another divot: asymmetric functional units. Some versions of Alpha supported a PopCount instruction, but it only worked in a single functional unit, which made scheduling a pain, esp. if you had to write in assembly language. I'm not convinced that AVX 256 and AVX 512 are useful for non-matrix operations. Most strings (more importantly, parsing bounded by whitespace) are much shorter than 512 bits (32 bytes). In English, I cannot come up with many words longer than 16 bytes (some place names, antidisestablishmentarianism, chemical compound names, and some other stuff)
- loup-vaillant 4y ago> I'm not convinced that AVX 256 and AVX 512 are useful for non-matrix operations. I've observed that compared to regular x86-64 code without SIMD, using AVX 256 speeds up the Chacha20 cipher (for long messages so they can be processed in 512-bytes chuncks (8 blocks)) by a factor of 5. Network packets easily exceed 1KB, and files are usually much bigger. Matrix operations aren't the only viable niche.
- sitkack 4y agoSIMD has many non-matrix uses. https://simdjson.org/ https://simdjson.org/
- cpeterso 4y agoAndrew Waterman’s PhD dissertation, “Design of the RISC-V Instruction Set Architecture”, is quite accessible and starts with a similar analysis of other ISAs (including OpenRISC): https://www2.eecs.berkeley.edu/Pubs/TechRpts/2016/EECS-2016-1.pdf https://www2.eecs.berkeley.edu/Pubs/TechRpts/2016/EECS-2016-...
- inkyoto 4y agoCuriously, the dissertation does not take into account for a comparison POWER and PA-RISC v2.0 architectures that had already been well established by the time, and are «better» RISC architectures in multiple aspects compared to orthodox RISC designs such as MIPS, OpenRISC, SPARC v8 and ARM v7. One of my personal favourite quotes comes from the foreword to the PA-RISC v2.0 manual[0] by Michael Mahon, the PA-RISC v2.0 principal architect: > Efficiency also has evident value to users, but there is no simple recipe for achieving it. Optimizing architectural efficiency is a complex search in a multidimensional space, involving disciplines ranging from device physics and circuit design at the lower levels of abstraction, to compiler optimizations and application structure at the upper levels. > Because of the inherent complexity of the problem, the design of processor architecture is an iterative, heuristic process which depends upon methodical comparison of alternatives (“hill climbing”) and upon creative flashes of insight (“peak jumping”), guided by engineering judgement and good taste. > To design an efficient processor architecture, then, one needs excellent tools and measurements for accurate comparisons when “hill climbing,” and the most creative and experienced designers for superior “peak jumping.” Engineering and good taste! – we do not come across those very often. [0] http://ftp.parisc-linux.org/docs/arch/parisc2.0.pdf http://ftp.parisc-linux.org/docs/arch/parisc2.0.pdf
- drpixie 4y agoSeparate FP registers - it seems most modern architectures have distinct register sets for integers and floats. This looks to have started when FPUs were optional and/or physically separate, but that's no longer the case. Any examples-of/thoughts-on of systems that normally put floats and integers in the same registers?
- spc476 4y agoOne architecture I know of that used its general purpose registers for floating point is the VAX. I have no thoughts on this though.
- flopsamjetsam 4y agoI seem to remember the original Intel MMX aliased its integer SIMD registers with the x87 FPU registers (for compatibility with non-MMX OSes when saving/restoring state when switching between processes). I never wrote code for it, but I remember it was slow to switch between the two modes.
- astrange 4y agoIt does, which meant the ISA has the strange requirement that you have to emit an 'emms' instruction once you're done using MMX or else x87 operations won't work. This makes MMX very unpopular outside controlled situations, so compiler autovectorization doesn't support it.
- avianes 4y ago> Separate FP registers - This looks to have started when FPUs were optional and/or physically separate, but that's no longer the case. Using a separate register set for FP is not just about making floats optional. It also allows to better isolate the float and int units and to build a more efficient micro-architecture. For example: using a single physical register bank for floats and integers would be expensive (as the size of the register bank grows quadratically with the number of read/write ports), therefore using separate physical register bank for float and integer is more efficient.