| ISA style | Typical implementation |
|---|---|
| Accumulator | Hardwired, unpipelined |
| CISC | Microcoded |
| RISC | Hardwired, pipelined |
| VLIW | Fixed-latency in-order parallel pipelines |
| JVM | Software interpretation |
RV32) and 64-bit (RV64) variantspc
x0–x31
x0 (zero) always reads 0x0 are ignored[1:0] ≠ 11[1:0] = 11 and bits [4:2] ≠ 111imm[12]=1, imm[11]=1, imm[10:5]=111111, imm[4:1]=1110imm[0]: targets are 2-byte aligned, so imm[0]=0imm[12:0], MSB → LSB:1 1 111111 1110 0 = −4 (two's complement)
ImmI, ImmS, ImmB, ImmU, ImmJopcode[1:0] always equal to?
opcode[1:0] is always 11.ADD x0, x1, x2?
x0 stays 0: it is hardwired to zero and writes to it have no effect.Condition? from the ALU, Busy? from memoryThe µPC is NOT the PC!
PC | µPC | |
|---|---|---|
| Kind | Architectural: visible to software | Microarchitectural: invisible to software |
| Lives in | Datapath | Control |
| Points to | Current RISC-V instruction in main memory | Current row of the microcode ROM |
| Steps | Once per instruction | Many times per instruction (one per cycle) |
One source drives the bus per cycle (*En); any number of destinations latch on the rising edge (*Ld).
InstLd=1; sends opcode to control, fields to datapathImmSel (ImmI/S/B/U/J); drives bus when ImmEn=1x0–x31 plus PC at address 32; RegSel = rs1|rs2|rd|32
RegW=0, RegEn=1 · Write: RegW=1, RegEn=0ALd, BLd load operands; ALU does ALUOp, outputs Condition?, drives bus when ALUEn=1MALd latches address; read when MemEn=1, write when MemW=1; asserts Busy? until done| Register transfer | Control signals asserted |
|---|---|
MA:=PC | RegSel=PC; RegW=0; RegEn=1; MALd=1 |
B:=Reg[rs2] | RegSel=rs2; RegW=0; RegEn=1; BLd=1 |
Reg[rd]:=A+B | ALUop=Add; ALUEn=1; RegSel=rd; RegW=1 |
MA,A:=PC sets MALd=1 and ALd=1*En drivers at once: they short the shared busµPC and the PC hold the same address during instruction execution.
PC is architectural and points to the current RISC-V instruction in memory; µPC is microarchitectural and points to the current microinstruction in the ROM.B:=ImmI.
ImmSel=ImmI; ImmEn=1; BLd=1 (all other enables, loads, writes = 0).Instruction fetch microcode:
MA,A:=PC | send PC to memory, save in A |
PC:=A+4 | increment PC |
| wait for memory | spin while Busy? |
IR:=Mem | latch instruction |
| dispatch on opcode |
In the ROM table later, PC:=A+4 is scheduled after IR:=Mem so the bus is free during the memory wait.
| ALU (R-type, e.g. ADD) | ALUI (I-type, e.g. ADDI) | LW (load word) |
|---|---|---|
A:=Reg[rs1] | A:=Reg[rs1] | A:=Reg[rs1] |
B:=Reg[rs2] | B:=ImmI | B:=ImmI |
Reg[rd]:=ALUOp(A,B) | Reg[rd]:=ALUOp(A,B) | MA:=A+B |
| goto fetch | goto fetch | wait for memory |
Reg[rd]:=Mem | ||
| goto fetch |
JAL (entering with A = PCorig+4)
Reg[rd]:=A | return address |
A:=A-4 | recover PCorig |
B:=ImmJ | |
PC:=A+B | |
| goto fetch |
Skipping A:=A-4 would offset the target by +4.
Branch
A:=Reg[rs1] | |
B:=Reg[rs2] | |
if !ALUOp(A,B) goto fetch | not taken: PC already +4 |
A:=PC | taken path |
A:=A-4 | recover PCorig |
B:=ImmB | |
PC:=A+B | |
| goto fetch |
M[rd] = M[rs1] + M[rs2]
| Row | Microinstruction | Next |
|---|---|---|
| MMA0 | MA:=Reg[rs1] | next |
| MMA1 | A:=Mem | spin |
| MMA2 | MA:=Reg[rs2] | next |
| MMA3 | B:=Mem | spin |
| MMA4 | MA:=Reg[rd] | next |
| MMA5 | Mem:=ALUOp(A,B) | spin |
| MMA6 | (idle) | fetch |
A:=A-4 after A:=PC when the branch is taken?
ImmB is relative to the branch's own address; A:=A-4 recovers it.M[rd] = M[rs1] + M[rs2] require changing the single-bus datapath?
$|\mu\text{address}| = |\mu\text{PC}| + |\text{opcode}| + 1 + 1$
$|\text{data}| = |\mu\text{PC}| + |\text{control}| = |\mu\text{PC}| + 18$
$\text{Size} = 2^{|\mu\text{address}|} \times |\text{data}|$
| µPC | Opcode | Cond? | Busy? | Control | Next µPC |
|---|---|---|---|---|---|
| fetch0 | X | X | X | MA,A:=PC | fetch1 |
| fetch1 | X | X | 1 | fetch1 | |
| fetch1 | X | X | 0 | IR:=Mem | fetch2 |
| fetch2 | ALU | X | X | PC:=A+4 | ALU0 |
| fetch2 | ALUI | X | X | PC:=A+4 | ALUI0 |
| fetch2 | LW | X | X | PC:=A+4 | LW0 |
| ALU0 | X | X | X | A:=Reg[rs1] | ALU1 |
| ALU1 | X | X | X | B:=Reg[rs2] | ALU2 |
| ALU2 | X | X | X | Reg[rd]:=ALUOp(A,B) | fetch0 |
[1:0]=11), plus Cond? and Busy?
$2^{13} \times 24 = 196{,}608 \text{ bits} = 24\text{ KiB}$
Opcode, Cond?, Busy? in small external logic instead of the ROM address| µPC jump | Meaning |
|---|---|
| next | µPC + 1 |
| spin | µPC if Busy?, else µPC + 1 |
| fetch | fetch0 |
| dispatch | Decode(Opcode) |
| ftrue | fetch0 if Cond? true, else µPC + 1 |
| ffalse | fetch0 if Cond? false, else µPC + 1 |
| Address | Control | Jump |
|---|---|---|
| fetch0 | MA,A:=PC | next |
| fetch1 | IR:=Mem | spin |
| fetch2 | PC:=A+4 | dispatch |
| ALU0 | A:=Reg[rs1] | next |
| ALU1 | B:=Reg[rs2] | next |
| ALU2 | Reg[rd]:=ALUOp(A,B) | fetch |
| Branch0 | A:=Reg[rs1] | next |
| Branch1 | B:=Reg[rs2] | next |
| Branch2 | A:=PC | ffalse |
| Branch3 | A:=A-4 | next |
| Branch4 | B:=ImmB | next |
| Branch5 | PC:=A+B | fetch |
Branch2 tests Cond? on Reg[rs1], Reg[rs2] during the cycle; A latches PC only at the clock edge$64 \times (3 + 18) = 1{,}344$ bits
= 168 bytes, >146× smaller
| Horizontal µcode | Vertical µcode | |
|---|---|---|
| Width | Wider µinstructions | Narrower µinstructions |
| Ops per step | Multiple parallel operations | Typically one datapath op |
| Branches | Folded into each µinstruction | Separate branch µinstructions |
| Steps per instruction | Fewer | More |
| Encoding | Sparse | Compact |
A:=Reg[rs1] in both ALU0 and ALUI0Branch2 (A:=PC with ffalse) corrupt A before Condition? is checked?
Reg[rs1], so the ALU computes Cond? on rs1/rs2; A latches PC only at the end of the cycle, if µPC falls through to Branch3.Except for the cheapest and fastest machines, almost every computer was microprogrammed: