6.5.11 · D1Advanced & Emerging Architectures

Foundations — RISC-V custom extensions for accelerators

1,929 words9 min readBack to topic

Before you can understand custom instructions, you must be able to read a plain instruction bit by bit. This page builds every word and symbol the parent note leans on, starting from "what is a bit" and ending at "why 1024 ops fit in one opcode slot". Nothing here is assumed — if the parent used it, we define it.


0. The absolute floor: bits, bytes, and a 32-bit word

Look at the figure: 32 little boxes in a row, numbered from the right. The rightmost box is bit , the leftmost is bit . This numbering direction matters because the CPU decides "what kind of instruction is this?" by reading the boxes on the right first.


1. Opcode — the "what family" tag

Since 7 bits can take different patterns, there are at most possible opcode families.


2. Registers, rs1, rs2, rd — the fast scratchpad

To name one of 32 registers you need a number from to , and , so 5 bits name exactly one register.

The figure shows the register file as a stack of 32 boxes with two arrows leaving it (the two read ports, feeding rs1 and rs2) and one arrow entering it (the one write port, driven by rd). This exact shape — two read, one write — is why the parent note keeps saying "the hardware barely changes": your custom instruction just plugs into ports that already exist.


3. funct3 and funct7 — the "which flavour" tags

Once the opcode says "this is an arithmetic-shaped instruction", the CPU still needs to know which one: add? subtract? multiply? These extra selector bits are the funct fields.


4. The R-type layout — one row that uses every field

The figure colours each field: the two data fields (rs2, rs1, rd) in one hue, the two operation-selector fields (funct7, funct3) in another, and the opcode in a third. Custom instructions borrow this exact skeleton so the CPU's existing decode wiring can be reused — see R-type instruction format.


5. Counting operations — where comes from

Now every symbol in the parent's key derivation is defined, so we can actually count.


6. Latency, cycles, and "coupling" — why tight beats a far-away device


7. Speedup and Amdahl — the "is it worth it?" number


The prerequisite map

bit

32-bit word

opcode inst 6 to 0

register file

rs1 rs2 rd fields

R-type format

funct3 and funct7

reserved custom opcodes

encoding budget 1024

custom extension

clock cycle and latency

tight vs loose coupling

speedup and Amdahl

Read top to bottom: bits build a word; the word's rightmost 7 bits are the opcode; the opcode plus the funct fields plus the register fields build the R-type row; counting the funct bits gives the 1024 budget; the reserved opcodes plus that budget give you a custom extension, and the latency/coupling and speedup ideas tell you when it's worth building.


Equipment checklist

How many bits is one RISC-V opcode, and where does it sit?
7 bits, in inst[6:0] — the rightmost 7 boxes of the 32-bit word.
Why do 5 bits name a register?
Because there are 32 registers and .
What do rs1, rs2, rd select — operation or data?
Data (which registers hold inputs/output), never the operation.
What do funct3 and funct7 select?
The specific operation (flavour) within an opcode family.
How many bits does an R-type instruction total, field by field?
.
Why does a -bit field hold patterns?
Each added bit doubles the possibilities.
Derive operations per custom slot.
.
Why is a custom instruction faster than MMIO for small ops?
Operands come from registers in a few cycles instead of a hundreds-of-cycles bus round-trip.
What does Amdahl's Law warn about accelerators?
The un-accelerated part caps the total speedup, so only harden the hot kernel.

Connections