Review MIPS Pipeline Data and Control Paths PCSrc

  • Slides: 15
Download presentation
Review: MIPS Pipeline Data and Control Paths PCSrc ID/EX EX/MEM Control IF/ID Add Reg.

Review: MIPS Pipeline Data and Control Paths PCSrc ID/EX EX/MEM Control IF/ID Add Reg. Write 4 Read Addr 1 Instruction Memory PC Shift left 2 Add Data Memory Register Read Addr 2 Data 1 Read Address File Write Addr Write Data 16 Sign Extend MEM/WB Branch ALUSrc ALU Read Data 2 Address Memto. Reg Read Data Write Data ALU cntrl 32 Mem. Write Mem. Read ALUOp Reg. Dst CSE 431 L 07 Overcoming Data Hazards. 1 Irwin, PSU, 2005

Control Settings EX Stage R lw Reg Dst 1 MEM Stage WB Stage ALU

Control Settings EX Stage R lw Reg Dst 1 MEM Stage WB Stage ALU ALU Brch Mem Reg Mem Op 1 Op 0 Src Read Write to. Reg 1 0 0 0 1 0 1 1 sw X 0 0 1 0 X beq X 0 1 0 0 0 X CSE 431 L 07 Overcoming Data Hazards. 2 Irwin, PSU, 2005

Review: One Way to “Fix” a Data Hazard Reg DM Reg IM Reg DM

Review: One Way to “Fix” a Data Hazard Reg DM Reg IM Reg DM IM Reg ALU IM ALU O r d e r add $1, ALU I n s t r. Fix data hazard by waiting – stall – but impacts CPI stall sub $4, $1, $5 and $6, $7, $1 CSE 431 L 07 Overcoming Data Hazards. 3 Reg DM Reg Irwin, PSU, 2005

Review: Another Way to “Fix” a Data Hazard or $8, $1 sw $4, 4($1)

Review: Another Way to “Fix” a Data Hazard or $8, $1 sw $4, 4($1) CSE 431 L 07 Overcoming Data Hazards. 4 IM Reg DM IM Reg ALU and $6, $7, $1 DM ALU sub $4, $1, $5 Reg ALU IM ALU O r d e r add $1, ALU I n s t r. Fix data hazards by forwarding results as soon as they are available to where they are Reg needed Reg Reg DM Reg Irwin, PSU, 2005

Data Forwarding (aka Bypassing) q Take the result from the earliest point that it

Data Forwarding (aka Bypassing) q Take the result from the earliest point that it exists in any of the pipeline state registers and forward it to the functional units (e. g. , the ALU) that need it that cycle q For ALU functional unit: the inputs can come from any pipeline register rather than just from ID/EX by l adding multiplexors to the inputs of the ALU l connecting the Rd write data in EX/MEM or MEM/WB to either (or both) of the EX’s stage Rs and Rt ALU mux inputs l adding the proper control hardware to control the new muxes q Other functional units may need similar forwarding logic (e. g. , the DM) q With forwarding can achieve a CPI of 1 even in the presence of data dependencies CSE 431 L 07 Overcoming Data Hazards. 5 Irwin, PSU, 2005

Data Forwarding Control Conditions 1. EX/MEM hazard: if (EX/MEM. Reg. Write and (EX/MEM. Register.

Data Forwarding Control Conditions 1. EX/MEM hazard: if (EX/MEM. Reg. Write and (EX/MEM. Register. Rd Forward. A = 10 if (EX/MEM. Reg. Write and (EX/MEM. Register. Rd Forward. B = 10 2. != 0) = ID/EX. Register. Rs)) != 0) = ID/EX. Register. Rt)) Forwards the result from the previous instr. to either input of the ALU MEM/WB hazard: if (MEM/WB. Reg. Write and (MEM/WB. Register. Rd Forward. A = 01 if (MEM/WB. Reg. Write and (MEM/WB. Register. Rd Forward. B = 01 CSE 431 L 07 Overcoming Data Hazards. 6 != 0) = ID/EX. Register. Rs)) != 0) = ID/EX. Register. Rt)) Forwards the result from the second previous instr. to either input of the ALU Irwin, PSU, 2005

Forwarding Illustration sub $4, $1, $5 and $6, $7, $1 Reg DM IM Reg

Forwarding Illustration sub $4, $1, $5 and $6, $7, $1 Reg DM IM Reg ALU IM ALU O r d e r add $1, ALU I n s t r. EX/MEM hazard forwarding CSE 431 L 07 Overcoming Data Hazards. 7 Reg DM Reg MEM/WB hazard forwarding Irwin, PSU, 2005

Yet Another Complication! add $1, $2 O r d e r add $1, $3

Yet Another Complication! add $1, $2 O r d e r add $1, $3 add $1, $4 CSE 431 L 07 Overcoming Data Hazards. 9 IM Reg DM IM Reg ALU I n s t r. ALU 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? ALU q Reg DM Reg Irwin, PSU, 2005

Corrected Data Forwarding Control Conditions 2. MEM/WB hazard: if (MEM/WB. Reg. Write and (MEM/WB.

Corrected Data Forwarding Control Conditions 2. MEM/WB hazard: if (MEM/WB. Reg. Write and (MEM/WB. Register. Rd != 0) and (EX/MEM. Register. Rd != ID/EX. Register. Rs) and (MEM/WB. Register. Rd = ID/EX. Register. Rs)) Forward. A = 01 if (MEM/WB. Reg. Write and (MEM/WB. Register. Rd != 0) and (EX/MEM. Register. Rd != ID/EX. Register. Rt) and (MEM/WB. Register. Rd = ID/EX. Register. Rt)) Forward. B = 01 CSE 431 L 07 Overcoming Data Hazards. 10 Irwin, PSU, 2005

Datapath with Forwarding Hardware PCSrc ID/EX EX/MEM Control IF/ID Add Shift left 2 4

Datapath with Forwarding Hardware PCSrc ID/EX EX/MEM Control IF/ID Add Shift left 2 4 PC Instruction Memory Read Address Add Read Addr 1 Data Memory Register Read Addr 2 Data 1 File Write Addr Write Data 16 Sign Extend MEM/WB Branch ALU Read Data 2 Address Read Data Write Data ALU cntrl 32 EX/MEM. Register. Rd ID/EX. Register. Rt ID/EX. Register. Rs CSE 431 L 07 Overcoming Data Hazards. 12 Forward Unit MEM/WB. Register. Rd Irwin, PSU, 2005

Memory-to-Memory Copies q For loads immediately followed by stores (memory-tomemory copies) can avoid a

Memory-to-Memory Copies q For loads immediately followed by stores (memory-tomemory copies) can avoid a stall by adding forwarding hardware from the MEM/WB register to the data memory input. l sw $1, 4($3) CSE 431 L 07 Overcoming Data Hazards. 13 IM Reg DM IM Reg ALU O r d e r lw $1, 4($2) ALU I n s t r. Would need to add a Forward Unit and a mux to the memory access stage Reg DM Reg Irwin, PSU, 2005

Forwarding with Load-use Data Hazards or xor $8, $1, $9 $4, $1, $5 xor

Forwarding with Load-use Data Hazards or xor $8, $1, $9 $4, $1, $5 xor $4, $1, $5 CSE 431 L 07 Overcoming Data Hazards. 15 Reg DM IM Reg ALU or $6, $1, $7 $8, $1, $9 and IM ALU and $4, $1, $5 $6, $1, $7 sub DM ALU stall $4, $1, $5 sub Reg ALU $1, 4($2)IM ALU O r d e r lw ALU I n s t r. Reg Reg Reg DM Irwin, PSU, 2005

Load-use Hazard Detection Unit q Need a Hazard detection Unit in the ID stage

Load-use Hazard Detection Unit q Need a Hazard detection Unit in the ID stage that inserts a stall between the load and its use ID Hazard Detection if (ID/EX. Mem. Read and ((ID/EX. Register. Rt = IF/ID. Register. Rs) or (ID/EX. Register. Rt = IF/ID. Register. Rt))) stall the pipeline 2. q The first line tests to see if the instruction now in the EX stage is a lw; the next two lines check to see if the destination register of the lw matches either source register of the instruction in the ID stage (the load-use instruction) q After this one cycle stall, the forwarding logic can handle the remaining data hazards CSE 431 L 07 Overcoming Data Hazards. 16 Irwin, PSU, 2005

Stall Hardware q Along with the Hazard Unit, we have to implement the stall

Stall Hardware q Along with the Hazard Unit, we have to implement the stall q Prevent the instructions in the IF and ID stages from progressing down the pipeline – done by preventing the PC register and the IF/ID pipeline register from changing l q Insert a “bubble” between the lw instruction (in the EX stage) and the load-use instruction (in the ID stage) (i. e. , insert a noop in the execution stream) l q Hazard detection Unit controls the writing of the PC (PC. write) and IF/ID (IF/ID. write) registers Set the control bits in the EX, MEM, and WB control fields of the ID/EX pipeline register to 0 (noop). The Hazard Unit controls the mux that chooses between the real control values and the 0’s. Let the lw instruction and the instructions after it in the pipeline (before it in the code) proceed normally down the pipeline CSE 431 L 07 Overcoming Data Hazards. 17 Irwin, PSU, 2005

Adding the Hazard Hardware PCSrc Hazard Unit EX/MEM 0 Control 0 Shift left 2

Adding the Hazard Hardware PCSrc Hazard Unit EX/MEM 0 Control 0 Shift left 2 4 Instruction Memory PC ID/EX. Mem. Read 1 IF/ID Add ID/EX Read Address Add Read Addr 1 Data Memory Register Read Addr 2 Data 1 File Write Addr Write Data 16 Sign Extend Read Data 2 32 ID/EX. Register. Rt CSE 431 L 07 Overcoming Data Hazards. 19 MEM/WB Branch ALU Address Read Data Write Data ALU cntrl Forward Unit Irwin, PSU, 2005