1 / 12

(Recap) Pipeline Hazards

(Recap) Pipeline Hazards. Reg. Reg. Reg. Reg. Reg. Reg. Reg. Reg. Reg. Reg. ALU. ALU. ALU. ALU. ALU. Ifetch. Ifetch. Ifetch. Ifetch. Ifetch. DMem. DMem. DMem. DMem. DMem. EX. WB. MEM. IF. ID/RF. I n s t r. O r d e r. add r1 ,r2,r3. sub r4, r1 ,r3.

karl
Télécharger la présentation

(Recap) Pipeline Hazards

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. (Recap)Pipeline Hazards

  2. Reg Reg Reg Reg Reg Reg Reg Reg Reg Reg ALU ALU ALU ALU ALU Ifetch Ifetch Ifetch Ifetch Ifetch DMem DMem DMem DMem DMem EX WB MEM IF ID/RF I n s t r. O r d e r add r1,r2,r3 sub r4,r1,r3 and r6,r1,r7 or r8,r1,r9 xor r10,r1,r11 Data Hazard on r1 Time (clock cycles)

  3. Data Hazards • Read After Write (RAW)InstrJ tries to read operand before InstrI writes it • Caused by a “Dependence” (in compiler nomenclature). This hazard results from an actual need for communication. I: add r1,r2,r3 J: sub r4,r1,r3

  4. I: sub r4,r1,r3 J: add r1,r2,r3 K: mul r6,r1,r7 Data Hazards • Write After Read (WAR) InstrJ writes operand before InstrI reads it • Called an “anti-dependence” by compiler writers.This results from reuse of the name “r1”. • Can’t happen in MIPS 5 stage pipeline because: • All instructions take 5 stages, and • Reads are always in stage 2, and • Writes are always in stage 5

  5. I: sub r1,r4,r3 J: add r1,r2,r3 K: mul r6,r1,r7 Data Hazards • Write After Write (WAW) InstrJ writes operand before InstrI writes it. • “Output dependence” by compiler writers • This also results from the reuse of name “r1”. • Can’t happen in MIPS 5 stage pipeline because: • All instructions take 5 stages, and • Writes are always in stage 5 • Will see WAR and WAW in complicated pipelines

  6. DM DM DM Reg Reg Reg Reg Reg Reg stall IM IM IM ALU ALU ALU stall sub r4,r1,r3 and r6,r7,r1 Stall: One Way to “Fix” a Data Hazard Can fix data hazard by waiting – stall – but affects throughput add r1,r2,r3 I n s t r. O r d e r

  7. Reg Reg Reg Reg Reg Reg Reg Reg Reg Reg ALU ALU ALU ALU ALU Ifetch Ifetch Ifetch Ifetch Ifetch DMem DMem DMem DMem DMem I n s t r. O r d e r add r1,r2,r3 sub r4,r1,r3 and r6,r1,r7 or r8,r1,r9 xor r10,r1,r11 Solution: Data Forwarding Time (clock cycles)

  8. ALU HW Change for Forwarding ID/EX EX/MEM MEM/WR NextPC mux Registers Data Memory mux mux Immediate

  9. DM DM DM Reg Reg Reg Reg Reg Reg IM IM IM ALU ALU ALU Yet Another Complication! • Another potential data hazard can occur when there is a conflict between the result of the WB stage instruction and the MEM stage instruction – which should be forwarded? I n s t r. O r d e r add r1,r1,r2 add r1,r1,r3 add r1,r1,r4

  10. ALU Reg Mem ALU Reg Reg Mem ALU Reg Reg IF Mem Data Hazard Even with Forwarding Time (clock cycles) lw r1, 0(r2) I n s t r. O r d e r ALU Reg Reg IF Mem Bubble sub r4,r1,r6 Reg IF Bubble and r6,r1,r7 IF Bubble or r8,r1,r9

  11. DM DM DM DM DM WB WB WB WB WB Reg Reg Reg Reg Reg flush IF IF IF IF IF IF ALU ALU ALU ALU ALU ALU and r6,r1,r7 and r6,r1,r7 or r8, r1, r9 or r8, r1, r9 xor r4,r1,r5 xor r4,r1,r5 DM Reg Forwarding with Load-use Data Hazards lw r1,100(r2) I n s t r. O r d e r sub r4,r1,r5 sub r4,r1,r5

  12. Software Scheduling Try producing fast code for a = b + c; d = e – f; assuming a, b, c, d ,e, and f in memory. Slow code: LW Rb,b LW Rc,c ADD Ra,Rb,Rc SW a,Ra LW Re,e LW Rf,f SUB Rd,Re,Rf SW d,Rd Fast code: LW Rb,b LW Rc,c LW Re,e ADD Ra,Rb,Rc LW Rf,f SW a,Ra SUB Rd,Re,Rf SW d,Rd Compiler optimizes for performance. Hardware checks for safety.

More Related