“it specializes in doing things weirdly.”
— Dr Non
What happened
RISC-V's RV32IC (and RV32EC) is intended as a low-cost microcontroller core primarily focused on interfacing with hardware blocks in larger systems. The core handles minimal processing, relying instead on custom IP to manage the bulk of the workload. The document demonstrates this limitation by examining its interrupt handling capabilities through an illustrative example involving a CSRRW register manipulation and subsequent C handler call.
The author dissects the latency associated with interrupt responses. Using a CSRRW instruction to stash a register (t0) and get a base address, followed by stashing RA, SP, GP, TP and t1-t6, and a0-a7. Then, another CSRRW to read the old value of t0 and stash that as well. The core needs 21 cycles before any work is done in the C handler. Outgoing data likewise requires 20 cycles with the same sequence of operations when exiting the C handler through a JAL instruction (2 cycles) and RET (2 cycles). Thus, each interrupt has at least a 44-cycle cost.
Why it matters
The key issue isn’t just about RISC-V's architecture; it’s about its application as a cheap microcontroller. The document highlights that the core’s architecture is intrinsically ill-suited for low-cost scenarios where interrupt latency and code density are paramount – factors critical in devices like MP3 players, SD card readers, or USB sticks. This undermines the broader narrative of RISC-V's dominance across all computing scales.
But, but, but…
The author’s criticism centers on the RV32IC core’s design choices, particularly its lack of a dedicated register like $k0 and $k1 used by MIPS microcontrollers. The absence of this register forces RISC-V to use alternative mechanisms (mscratch / sscratch) for interrupt handling, creating inefficiencies and adding latency—analogous to the ‘weirdly’ specialized behavior of 8051 cores. This underlines how even small architectural differences can drastically impact performance in these niche applications.
The counter-take
The prevalent excitement surrounding RISC-V's broad capabilities often obscures its practical limitations in specialized applications like cheap microcontrollers. Ignoring these constraints risks overhyping the architecture’s potential and potentially leading to disappointing adoption rates.
The AI angle
AI’s influence on microcontroller design will shift towards highly optimized code density and low-latency interrupt handling. This asymmetry favors advanced architectures like RISC-V with adaptable microarchitectures for improved performance in embedded systems.
