1 / 41

Review: Datapath for MIPS

Learn the intricacies of pipeline design in CPUs, exploring hazards and control mechanisms for optimal performance.

dalbrecht
Download Presentation

Review: Datapath for MIPS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. inst.eecs.berkeley.edu/~cs61c/su05CS61C : Machine StructuresLecture #19: Pipelining II2005-07-21Andy Carle

  2. rd instruction memory registers PC rs Data memory rt IFtch Dcd Exec Mem WB +4 imm ALU 2. Decode/ Register Read 5. WriteBack 1. Instruction Fetch 4. Memory 3. Execute I$ D$ Reg Reg ALU Review: Datapath for MIPS • Use datapath figure to represent pipeline

  3. Review: Problems for Computers • Limits to pipelining:Hazards prevent next instruction from executing during its designated clock cycle • Structural hazards: HW cannot support this combination of instructions (single person to fold and put clothes away) • Control hazards: Pipelining of branches & other instructions stall the pipeline until the hazard; “bubbles” in the pipeline • Data hazards: Instruction depends on result of prior instruction still in the pipeline (missing sock)

  4. Review: C.f. Branch Delay vs. Load Delay • Load Delay occurs only if necessary (dependent instructions). • Branch Delay always happens (part of the ISA). • Why not have Branch Delay interlocked? • Answer: Interlocks only work if you can detect hazard ahead of time. By the time we detect a branch, we already need its value … hence no interlock is possible!

  5. FYI: Historical Trivia • First MIPS design did not interlock and stall on load-use data hazard • Real reason for name behind MIPS: Microprocessor without Interlocked Pipeline Stages • Word Play on acronym for Millions of Instructions Per Second, also called MIPS • Load/Use  Wrong Answer!

  6. Outline • Pipeline Control • Forwarding Control • Hazard Control

  7. Piped Proc So Far …

  8. A S S B M D New Representation: Regs more explicit IF/DE DE/EX EX/ME ME/WB Reg. File Reg File Exec IR PC Next PC Inst. Mem Data Mem IF/DE.Ir = Instruction DE/EX.A = BusA out of Reg EX/ME.S = AluOut EX/ME.D = Bus B pass-through for sw ME/WB.S = ALuOut pass-through ME/WB.M = Mem Result from lw

  9. A S S B M D New Representation: Regs more explicit IF/DE DE/EX EX/ME ME/WB Reg. File Reg File Exec IR PC Next PC Inst. Mem Data Mem What’s Missing???

  10. A D S B M Data Mem Pipelined Processor (almost) for slides Idea: Parallel Piped Control … Valid IRex IR IRwb IRmem WB Ctrl Inst. Mem Ex Ctrl Dcd Ctrl Mem Ctrl Equal Reg. File Reg File Exec PC Next PC Mem Access

  11. A S B M D Pipelined Control IR <- Mem[PC]; PC <– PC+4; A <- R[rs]; B<– R[rt] S <– A + B; S <– A or ZX; S <– A + SX; S <– A + SX; If Cond PC < PC+SX; M <– Mem[S] Mem[S] <- B R[rd] <– S; R[rt] <– S; R[rd] <– M; Equal Reg. File Reg File Exec PC IR Next PC Inst. Mem Mem Access Data Mem

  12. Data Stationary Control • The Main Control generates the control signals during Reg/Dec • Control signals for Exec (ExtOp, ALUSrc, ...) are used 1 cycle later • Control signals for Mem (MemWr Branch) are used 2 cycles later • Control signals for Wr (MemtoReg MemWr) are used 3 cycles later Reg/Dec Exec Mem Wr ExtOp ExtOp ALUSrc ALUSrc ALUOp ALUOp Main Control RegDst RegDst Ex/Mem Register IF/ID Register Mem/Wr Register ID/Ex Register MemWr MemWr MemWr Branch Branch Branch MemtoReg MemtoReg MemtoReg MemtoReg RegWr RegWr RegWr RegWr

  13. Let’s Try it Out 10 lw r1, 36(r2) 14 addI r2, r2, 3 20 sub r3, r4, r5 24 beq r6, r7, 100 28 ori r8, r9, 17 32 add r10, r11, r12 100 and r13, r14, 15

  14. A M S B = IF D Next PC 10 PC Start: Fetch 10 n n n n Inst. Mem Decode WB Ctrl Mem Ctrl IR im rs rt Reg. File Reg File Exec Mem Access Data Mem 10 lw r1, 36(r2) 14 addI r2, r2, 3 20 sub r3, r4, r5 24 beq r6, r7, 100 30 ori r8, r9, 17 34 add r10, r11, r12 100 and r13, r14, 15

  15. A M S B = ID D IF Next PC 14 PC Fetch 14, Decode 10 n n n lw r1, 36(r2) Inst. Mem Decode WB Ctrl Mem Ctrl IR im 2 rt Reg. File Reg File Exec Mem Access Data Mem 10 lw r1, 36(r2) 14 addI r2, r2, 3 20 sub r3, r4, r5 24 beq r6, r7, 100 30 ori r8, r9, 17 34 add r10, r11, r12 100 and r13, r14, 15

  16. M S B = D ID IF Next PC 20 PC Fetch 20, Decode 14, Exec 10 n n addI r2, r2, 3 Inst. Mem Decode WB Ctrl lw r1 Mem Ctrl IR 36 2 rt Reg. File Reg File r2 Exec Mem Access Data Mem EX 10 lw r1, 36(r2) 14 addI r2, r2, 3 20 sub r3, r4, r5 24 beq r6, r7, 100 30 ori r8, r9, 17 34 add r10, r11, r12 100 and r13, r14, 15

  17. M B = D EX ID Next PC 24 IF PC Fetch 24, Decode 20, Exec 14, Mem 10 n sub r3, r4, r5 addI r2, r2, 3 Inst. Mem Decode WB Ctrl lw r1 Mem Ctrl IR 3 4 5 Reg. File Reg File r2 r2+36 Exec Mem Access Data Mem M 10 lw r1, 36(r2) 14 addI r2, r2, 3 20 sub r3, r4, r5 24 beq r6, r7, 100 30 ori r8, r9, 17 34 add r10, r11, r12 100 and r13, r14, 15

  18. r5 = WB D M EX Next PC ID 30 IF PC Fetch 30, Dcd 24, Ex 20, Mem 14, WB 10 beq r6, r7 100 Inst. Mem Decode WB Ctrl addI r2 lw r1 sub r3 Mem Ctrl IR 6 7 Reg. File Reg File M[r2+36] r4 r2+3 Exec Mem Access Data Mem 10 lw r1, 36(r2) 14 addI r2, r2, 3 20 sub r3, r4, r5 24 beq r6, r7, 100 30 ori r8, r9, 17 34 add r10, r11, r12 100 and r13, r14, 15 Note Delayed Branch: always execute ori after beq

  19. r7 = D Next PC EX 100 ID PC IF Fetch 100, Dcd 30, Ex 24, Mem 20, WB 14 ori r8, r9 17 Inst. Mem Decode WB Ctrl addI r2 sub r3 Mem Ctrl beq IR 9 xx 100 r1=M[r2+35] Reg. File Reg File r6 r2+3 r4-r5 Exec Mem Access Data Mem 10 lw r1, 36(r2) 14 addI r2, r2, 3 20 sub r3, r4, r5 24 beq r6, r7, 100 30 ori r8, r9, 17 34 add r10, r11, r12 100 and r13, r14, 15 WB M

  20. A D S B M Data Mem ? ? ? ? Valid • Remember: means triggered on edge. • What is wrong here? IRex IR IRwb Inst. Mem IRmem WB Ctrl Dcd Ctrl Ex Ctrl Mem Ctrl Equal Reg. File Reg File Exec PC Next PC Mem Access

  21. Valid IRex IR IRwb Inst. Mem IRmem WB Ctrl Dcd Ctrl Ex Ctrl Mem Ctrl Equal Reg. File Reg File Exec PC Next PC Mem Access A S D B M Data Mem Double-Clocked Signals • Some signals are double clocked! • In general: Inputs to edge components are their own pipeline regs • Watch out for stalls and such!

  22. Administrivia • Proj 2 – Due Sunday • HW6 – Due Tuesday • Midterm 2: • Friday, July 29: 11:00 – 2:00 • Location TBD • If you are really so concerned about the drop deadline that this is a problem for you, talk to me about the possibility of taking the exam on Thursday

  23. Megahertz Myth?

  24. Outline • Pipeline Control • Forwarding Control • Hazard Control

  25. IF ID/RF EX MEM WB add $t0,$t1,$t2 Reg Reg ALU I$ D$ sub $t4,$t0,$t3 D$ Reg Reg I$ ALU D$ Reg Reg and $t5,$t0,$t6 I$ ALU I$ D$ Reg Reg or $t7,$t0,$t8 * ALU xor $t9,$t0,$t10 I$ D$ Reg Reg ALU Review: Forwarding Fix by Forwarding result as soon as we have it to where we need it: * “or” hazard solved by register hardware

  26. Forwarding In general: • For each stage i that has reg inputs • For each stage j after I that has reg output • If i.reg == j.reg  forward j value back to i. • Some exceptions ($0, invalid) • ALUinput  (ALUResult, MemResult) • MemInput  (MemResult) In particular:

  27. Pending Writes In Pipeline Registers IAU npc I mem Regs op rw rs rt PC im n B A alu n S D mem m n Regs

  28. Pending Writes In Pipeline Registers IAU • Current operand registers • Pending writes • hazard <= ((rs == rwex) & regWex) OR ((rs == rwmem) & regWme) OR ((rs == rwwb) & regWwb) OR ((rt == rwex) & regWex) OR ((rt == rwmem) & regWme) OR ((rt == rwwb) & regWwb) npc I mem Regs op rw rs rt PC im n op rw B A alu n op rw S D mem m n op rw Regs

  29. Forwarding Muxes IAU • Detect nearestvalid write op operand register and forward into op latches, bypassing remainder of the pipe • Increase muxes to add paths from pipeline registers • Data Forwarding = Data Bypassing npc I mem Regs op rw rs rt PC Forward mux im n op rw B A alu n op rw S D mem m n op rw Regs

  30. R D T What about memory operations? op Rd Ra Rb Tricky situation: MIPS: lw 0($t0) sw 0($t1) RTL: R1 <- Mem[ R2 + I ]; Mem[R3+34] <- R1 op Rd Ra Rb A B Rd Mem Rd to reg file

  31. R D T What about memory operations? op Rd Ra Rb Tricky situation: MIPS: lw 0($t0) sw 0($t1) RTL: R1 <- Mem[ R2 + I ]; Mem[R3+34] <- R1 Solution: Handle with bypass in memory stage! op Rd Ra Rb A B Rd Mem Rd to reg file

  32. Outline • Pipeline Control • Forwarding Control • Hazard Control

  33. IF ID/RF EX MEM WB lw $t0,0($t1) Reg Reg ALU I$ D$ I$ ALU sub $t3,$t0,$t2 D$ Reg Reg Data Hazard: Loads (1/4) • Forwarding works if value is available (but not written back) before it is needed. But consider … • Need result before it is calculated! • Must stall use (sub) 1 cycle and thenforward. …

  34. IF ID/RF EX MEM WB lw$t0, 0($t1) Reg Reg ALU I$ D$ I$ ALU sub $t3,$t0,$t2 D$ Reg Reg I$ ALU D$ Reg Reg and $t5,$t0,$t4 bubble bubble bubble or $t7,$t0,$t6 I$ D$ Reg ALU Data Hazard: Loads (2/4) • Hardware must stall pipeline • Called “interlock”

  35. Data Hazard: Loads (3/4) • Instruction slot after a load is called “load delay slot” • If that instruction uses the result of the load, then the hardware interlock will stall it for one cycle. • If the compiler puts an unrelated instruction in that slot, then no stall • Letting the hardware stall the instruction in the delay slot is equivalent to putting a nop in the slot (except the latter uses more code space)

  36. Reg Reg Reg Reg Reg Reg ALU ALU ALU I$ I$ I$ D$ D$ D$ bubble bubble bubble bubble bubble or $t7,$t0,$t6 I$ D$ Reg ALU Data Hazard: Loads (4/4) • Stall is equivalent to nop lw$t0, 0($t1) nop sub $t3,$t0,$t2 and $t5,$t0,$t4

  37. Hazards / Stalling In general: • For each stage i that has reg inputs • If I’s reg is being written later on in the pipe but is not ready yet • Stages 0 to i: Stall (Turn CEs off so no change) • Stage i+1: Make a bubble (do nothing) • Stages i+2 onward: As usual • ALUinput  (MemResult) In particular:

  38. Hazards / Stalling Alternative Approach: • Detect non-forwarding hazards in decode • Possible since our hazards are formal. • Not always the case. • Stalling then becomes: • Issue nop to EX stage • Turn off nextPC update (refetch same inst) • Turn off InstReg update (re-decode same inst)

  39. Stall Logic IAU • 1. Detect non-resolving hazards. • 2a. Insert Bubble • 2b. Stall nextPC, IF/DE npc I mem Regs op rw rs rt PC Forward mux im n op rw B A alu n op rw S D mem m n op rw Regs

  40. Stall Logic • Stall-on-issue is used quite a bit • More complex processors: many cases that stall on issue. • More complex processors: cases that can’t be detected at decode • E.g. value needed from mem is not in cache – proc must stall multiple cycles

  41. By the way … • Notice that our forwarding and stall logic is stateless! • Big Idea: Keep it simple! • Option 1: Store old fetched inst in reg (“stall_temp”), keep state reg that says whether to use stall_temp or value coming off inst mem. • Option 2: Re-fetch old value by turning off PC update.

More Related