Skip to main content

3 RISCV Single-Cycle Control and Pipelining

Basics​

20220310173933

20220310173933

Instruction Table​

Inst[31:0]BrEqBrLTPCSelImmSelBrUnASelBSelALUSelMemRWRegWEnWBSel
add**+4**RegRegAddRead1 (Y)ALU
sub**+4**RegRegSubRead1ALU
(R-ROp)**+4**RegReg(Op)Read1ALU
addi**+4I*RegImmAddRead1ALU
lw**+4I*RegImmAddRead1Mem
sw**+4S*RegImmAddWrite0 (N)*
beq0*+4B*PCImmAddRead0*
beq1*ALUB*PCImmAddRead0*
bne0*ALUB*PCImmAddRead0*
bne1*+4B*PCImmAddRead0*
blt*1ALUB0PCImmAddRead0*
bltu*1ALUB1PCImmAddRead0*
jalr**ALUI*RegImmAddRead1PC+4
jal**ALUJ*PCImmAddRead1PC+4
auipc**+4U*PCImmAddRead1ALU

Single Cycle​

20220310173933

Critical Path:

tLoadβ‰₯tclkβˆ’toβˆ’q+tIMEMread+tRFRead+tmux+tALU+tDMEMRead+tmux+tRFsetupt_{Load}\geq t_{clk-to-q}+t_{IMEMread}+t_{RFRead}+t_{mux}+t_{ALU}+t_{DMEMRead}+t_{mux}+t_{RFsetup}

tArithmeticIβˆ’Typeβ‰₯tclkβˆ’toβˆ’q+tIMEMread+max(tRFRead,timm)+tmux+tALU+tmux+tRFsetupt_{Arithmetic I-Type}\geq t_{clk-to-q}+t_{IMEMread}+max(t_{RFRead},t_{imm})+t_{mux}+t_{ALU}+t_{mux}+t_{RFsetup}

tSβˆ’Typeβ‰₯tclkβˆ’toβˆ’q+tIMEMread+tRFRead+tmux+tALU+tDMEMWrite+tRFsetupt_{S-Type}\geq t_{clk-to-q}+t_{IMEMread}+t_{RFRead}+t_{mux}+t_{ALU}+t_{DMEMWrite}+t_{RFsetup}

  • 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 RFReadRF_{Read}

Note: comparator is omitted because branch comparison is done in parallel with RegFile/ALU, which takes much longer time.

Control Logic

  • ImmSel:

    20220331174415

    20220310173933

  • BrUn,BrEq,BrLT:

    20220310173933

  • ALUSel:

    20220310173933

Pipelined​

Overview​

20220331211348

IF : tclkβˆ’toβˆ’q+tIMEMread+tRegsetupt_{clk-to-q} + t_{IMEMread} + t_{Regsetup}

ID : tclkβˆ’toβˆ’q+tRFread+tRegsetupt_{clk-to-q}+ t_{RFread} + t_{Regsetup}

EX : tclkβˆ’toβˆ’q+tmux+tALU+tRegsetupt_{clk-to-q}+ t_{mux} + t_{ALU} + t_{Regsetup}

MEM : tclkβˆ’toβˆ’q+tDMEMread+tRegsetupt_{clk-to-q} + t_{DMEMread} + t_{Regsetup}

WB : tclkβˆ’toβˆ’q+tmux+tRFsetupt_{clk-to-q} + t_{mux} + t_{RFsetup}

tclkβ‰₯max(IF,ID,EX,MEM,WB)t_{clk}\geq max(IF, ID, EX,MEM,WB)

Forwarding Path

Compare destination of older instructions in pipeline with sources of new instruction in decode stage

20220331211348

Hazard​

Structural Hazard​

  1. Problem

    Two or more instructions in the pipeline compete for access to a single physical resource

  2. Solution

    (1)Instructions take turns using resource, some instructions have to stall (wait)

    (2)Add more hardware to machine

  3. Example:

    RegFile Hazard

    20220310173933

    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

    20220310173933

    Solution:

    Instruction and Data Caches 20220310173933

Data Hazard​

Data dependency between instructions

  1. R Type Instructions

    20220402173254

    Solution

    (1)Stalling

    Bubble: NOP(add x0 x0 x0)

    20220402173254

    (2)Forwarding(Bypass)

    20220402173254

  2. Load

    Forwarding Problem 20220402174121

    Solution

    (1)Hardware Stall

    20220402174121

    (2)Stall

    20220402211539

    (3)Code Scheduling

    20220402211539

Control Hazard​