3 RISCV Single-Cycle Control and Pipelining
Basicsβ


Instruction Tableβ
| Inst[31:0] | BrEq | BrLT | PCSel | ImmSel | BrUn | ASel | BSel | ALUSel | MemRW | RegWEn | WBSel |
|---|---|---|---|---|---|---|---|---|---|---|---|
| add | * | * | +4 | * | * | Reg | Reg | Add | Read | 1 (Y) | ALU |
| sub | * | * | +4 | * | * | Reg | Reg | Sub | Read | 1 | ALU |
| (R-ROp) | * | * | +4 | * | * | Reg | Reg | (Op) | Read | 1 | ALU |
| addi | * | * | +4 | I | * | Reg | Imm | Add | Read | 1 | ALU |
| lw | * | * | +4 | I | * | Reg | Imm | Add | Read | 1 | Mem |
| sw | * | * | +4 | S | * | Reg | Imm | Add | Write | 0 (N) | * |
| beq | 0 | * | +4 | B | * | PC | Imm | Add | Read | 0 | * |
| beq | 1 | * | ALU | B | * | PC | Imm | Add | Read | 0 | * |
| bne | 0 | * | ALU | B | * | PC | Imm | Add | Read | 0 | * |
| bne | 1 | * | +4 | B | * | PC | Imm | Add | Read | 0 | * |
| blt | * | 1 | ALU | B | 0 | PC | Imm | Add | Read | 0 | * |
| bltu | * | 1 | ALU | B | 1 | PC | Imm | Add | Read | 0 | * |
| jalr | * | * | ALU | I | * | Reg | Imm | Add | Read | 1 | PC+4 |
| jal | * | * | ALU | J | * | PC | Imm | Add | Read | 1 | PC+4 |
| auipc | * | * | +4 | U | * | PC | Imm | Add | Read | 1 | ALU |
Single Cycleβ

Critical Path:
- R-TypeγArithmetic I-TypeγSB-Type: No DMem
- Load I-Type: DMem Read
- S-Type: DMem Write,No second Mux(WB)
- U-Type: No
Note: comparator is omitted because branch comparison is done in parallel with RegFile/ALU, which takes much longer time.
Control Logic
ImmSel:


BrUn,BrEq,BrLT:

ALUSel:

Pipelinedβ
Overviewβ

IF :
ID :
EX :
MEM :
WB :
Forwarding Path
Compare destination of older instructions in pipeline with sources of new instruction in decode stage

Hazardβ
Structural Hazardβ
Problem
Two or more instructions in the pipeline compete for access to a single physical resource
Solution
(1)Instructions take turns using resource, some instructions have to stall (wait)
(2)Add more hardware to machine
Example:
RegFile Hazard

Solution:
Double Pumping
Prepare to write during 1st half, write on falling edge, read during 2nd half of each clock cycle
Build RegFile with independent read and write ports
Memory

Solution:
Instruction and Data Caches

Data Hazardβ
Data dependency between instructions
R Type Instructions

Solution
(1)Stalling
Bubble: NOP(add x0 x0 x0)

(2)Forwarding(Bypass)

Load
Forwarding Problem

Solution
(1)Hardware Stall

(2)Stall

(3)Code Scheduling
