C C M M L L C C M M L L CS 230: Computer CS 230: Computer Organization and Organization and Assembly Language Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics Arizona State University Slides courtesy: Prof. Yann Hang Lee, ASU, Prof. Mary Jane Irwin, PSU, Ande Carle, UCB
23
Embed
CS 230: Computer Organization and Assembly Language
CS 230: Computer Organization and Assembly Language. Aviral Shrivastava. Department of Computer Science and Engineering School of Computing and Informatics Arizona State University. Slides courtesy: Prof. Yann Hang Lee, ASU, Prof. Mary Jane Irwin, PSU, Ande Carle, UCB. Announcements. - PowerPoint PPT Presentation
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
CCMMLLCCMMLL
CS 230: Computer CS 230: Computer Organization and Organization and
Assembly LanguageAssembly LanguageAviral
ShrivastavaDepartment of Computer Science and
EngineeringSchool of Computing and Informatics
Arizona State University
Slides courtesy: Prof. Yann Hang Lee, ASU, Prof. Mary Jane Irwin, PSU, Ande Carle, UCB
CCMMLLCCMMLL
AnnouncementsAnnouncements• Project 4
– MIPS Simulator– Due Nov 10, 2009
• Alternate Project
• Quiz 5– Thursday, Nov 19, 2009– Pipelining
• Finals– Tuesday, Dec 08, 2009– Please come on time (You’ll need all the time)– Open book, notes, and internet– No communication with any other human
CCMMLLCCMMLL
Benefits of PipeliningBenefits of Pipelining
• Pipeline latches: pass the status and result of the current instruction to next stage
Illustrating a data Illustrating a data hazardhazard
ALU
RegMem DM Reg
ALU
RegMem DM Reg
ALU
RegMem DM
RegMem
Time
ADD R1, R2, R3
SUB R4, R1, R5
AND R6, R1, R7
OR R8, R1, R9
XOR R10, R1, R11
ALU
RegMem
ADD instruction causes a hazard in next 3 instructions b/c register not written until after
those 3 read it.
CCMMLLCCMMLL
stall
stall
One Way to “Fix” a Data One Way to “Fix” a Data HazardHazard
Instr.
Order
add $1,
AL
UIM Reg DM Reg
sub $4,$1,$5
and $6,$7,$1
AL
UIM Reg DM Reg
AL
UIM Reg DM Reg
Fix data hazard by waiting –
stall – but impacts CPI
CCMMLLCCMMLL
stall
stall
One Way to “Fix” a Data One Way to “Fix” a Data HazardHazard
Instr.
Order
add $1,
AL
UIM Reg DM Reg
sub $4,$1,$5
and $6,$7,$1
AL
UIM Reg DM Reg
AL
UIM Reg DM Reg
Fix data hazard by waiting –
stall – but impacts CPI
CCMMLLCCMMLL
Another Way to “Fix” a Another Way to “Fix” a Data HazardData Hazard
Instr.
Order
add $1,
AL
UIM Reg DM Reg
sub $4,$1,$5
and $6,$7,$1A
LUIM Reg DM Reg
AL
UIM Reg DM Reg
Fix data hazards by
forwarding results as
soon as they are
available to where they
are needed
sw $4,4($1)
or $8,$1,$1
AL
UIM Reg DM Reg
AL
UIM Reg DM Reg
CCMMLLCCMMLL
Data Forwarding (aka Data Forwarding (aka Bypassing)Bypassing)
• 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
• For ALU functional unit: the inputs can come from any pipeline register rather than just from ID/EX by– adding multiplexors to the inputs of the ALU
– 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
– adding the proper control hardware to control the new muxes
• Other functional units may need similar forwarding logic (e.g., the DM)
• With forwarding can achieve a CPI of 1 even in the presence of data dependencies
CCMMLL
When can we When can we forward?forward?
ALU
RegMem DM Reg
ALU
RegMem DM Reg
ALU
RegMem DM
RegMem
Time
ADD R1, R2, R3
SUB R4, R1, R5
AND R6, R1, R7
OR R8, R1, R9
XOR R10, R1, R11
ALU
RegMem
SUB gets info. from EX/MEM pipe register
AND gets info. from MEM/WB pipe register
OR gets info. by forwarding fromregister file
Rule of thumb: If line goes “forward” you can do forwarding. If its drawn backward, it’s physically impossible.
CCMMLLCCMMLL
Datapath with Forwarding Datapath with Forwarding HardwareHardware PCSrc
ReadAddress
InstructionMemory
Add
PC
4
Write Data
Read Addr 1
Read Addr 2
Write Addr
Register
File
Read Data 1
Read Data 2
16 32
ALU
Shiftleft 2
Add
DataMemory
Address
Write Data
ReadData
IF/ID
SignExtend
ID/EXEX/MEM
MEM/WB
Control
ALUcntrl
Branch
ForwardUnit
ID/EX.RegisterRt
ID/EX.RegisterRs
EX/MEM.RegisterRd
MEM/WB.RegisterRd
ForwardA
ForwardB
CCMMLLCCMMLL
Data Forwarding Control Data Forwarding Control ConditionsConditions
Yet Another Complication!Yet Another Complication!
Instr.
Order
add $1,$6,$2
AL
UIM Reg DM Reg
add $1,$1,$3
add $5,$1,$4
AL
UIM Reg DM Reg
AL
UIM Reg DM Reg
• 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?
CCMMLLCCMMLL
Corrected Data Forwarding Control Corrected Data Forwarding Control ConditionsConditions