490 likes | 632 Views
Csci 136 Computer Architecture II – A Pipelined Datapath. Xiuzhen Cheng cheng@gwu.edu. Announcement. Homework assignment # 9 , Due time – Before class, April 05. Readings: Sections 6.1 – 6.3 Problems: 6.1-6.4, 6.13-6.14 Project #3 is due on April 10, 200 5. Topics.
E N D
Csci 136 Computer Architecture II– A Pipelined Datapath Xiuzhen Cheng cheng@gwu.edu
Announcement • Homework assignment #9, Due time –Before class, April 05. • Readings: Sections 6.1 – 6.3 • Problems: 6.1-6.4, 6.13-6.14 • Project #3 is due on April 10, 2005
Topics • Two pipelined datapath representations • Single cycle • Multiple cycle • Five functional units for pipelined datapath • Each can be used only within a single pipeline stage. Why? • Comparison of single cycle datapath, multi cycle datapath and pipelined datapath • From one to another • Sharing of functional unit • Number of clock cycles • Clock cycle time • Temporary registers – pass information • Complexity of control design ( hazards… )
Graphically Representing Pipelines multiple-clock-cycle pipeline datagrams • Can help with answering questions like: • how many cycles does it take to execute this code? • what is the ALU doing during cycle 4? • use this representation to help understand datapaths
Single-Cycle Pipeline Datagram • What do we need to add to split the datapath into stages?
Pipelined Datapath • how many bits stored in each pipeline register? 64 128 64 97
Observations • 5-stage pipeline • IF, ID, EX, MEM, WB • Left-to-right flow of instructions • Instructions and data move generally from left to right • Two exceptions: WB stage and the selection of PC • May lead to data hazards and control hazards • Why there is no pipeline register at the end of the WB stage? • Last stage must update either register file, or memory, or PC
1st lw Ifetch Reg/Dec Exec Mem Wr Ifetch Reg/Dec Exec Mem Wr Ifetch Reg/Dec Exec Mem Wr Pipelining the Load Instruction Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 • The five independent functional units in the pipeline datapath are: • Instruction Memory for the Ifetch stage • Register File’s Read ports (busA and busB) for the Reg/Decstage • ALU for the Exec stage • Data Memory for the Mem stage • Register File’s Write port (bus W) for the Wr stage Clock 2nd lw 3rd lw
Ifetch Reg/Dec Exec Wr The Four Stages of R-type Cycle 1 Cycle 2 Cycle 3 Cycle 4 • Ifetch: Instruction Fetch • Fetch the instruction from the Instruction Memory • Reg/Dec: Registers Fetch and Instruction Decode • Exec: • ALU operates on the two register operands • Wr: Write the ALU output back to the register file R-type
Ifetch Reg/Dec Exec Wr Ifetch Reg/Dec Exec Wr Ifetch Reg/Dec Exec Mem Wr Ifetch Reg/Dec Exec Wr Ifetch Reg/Dec Exec Wr Pipelining the R-type and Load Instruction • We have pipeline conflict or structural hazard: • Two instructions try to write to the register file at the same time! • Only one write port Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8 Cycle 9 Clock Oops! We have a problem! R-type R-type Load R-type R-type
1 2 3 4 5 Load Ifetch Reg/Dec Exec Mem Wr 1 2 3 4 R-type Ifetch Reg/Dec Exec Wr Important Observation • Each functional unit can only be used once per instruction • Each functional unit must be used at the same stage for all instructions: • Load uses Register File’s Write Port during its 5th stage • R-type uses Register File’s Write Port during its 4th stage • 2 ways to solve this pipeline hazard
Ifetch Reg/Dec Exec Wr Ifetch Reg/Dec Exec Mem Wr Ifetch Reg/Dec Exec Wr Ifetch Reg/Dec Exec Wr Ifetch Reg/Dec Exec Wr Ifetch Reg/Dec Exec Solution 1: Insert “Bubble” into the Pipeline Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8 Cycle 9 • Insert a “bubble” into the pipeline to prevent 2 writes at the same cycle • The control logic can be complex • Lose instruction fetch and issue opportunity • No instruction is started in Cycle 6! Clock Load R-type Pipeline R-type R-type Bubble
Ifetch Reg/Dec Wr Ifetch Reg/Dec Exec Mem Wr Ifetch Reg/Dec Exec Mem Wr Ifetch Reg/Dec Exec Mem Wr Ifetch Reg/Dec Exec Mem Wr Ifetch Reg/Dec Exec Mem Wr Solution 2: Delay R-type’s Write by One Cycle • Delay R-type’s register write by one cycle: • Now R-type instructions also use Reg File’s write port at Stage 5 • Mem stage is a NOOPstage: nothing is being done 4 1 2 3 5 Exec Mem R-type Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8 Cycle 9 Clock R-type R-type Load R-type R-type
Ifetch Reg/Dec Exec Mem The Four Stages of Store Cycle 1 Cycle 2 Cycle 3 Cycle 4 • Ifetch: Instruction Fetch • Fetch the instruction from the Instruction Memory • Reg/Dec: Registers Fetch and Instruction Decode • Exec: Calculate the memory address • Mem: Write the data into the Data Memory Store Wr
Ifetch Reg/Dec Exec The Three Stages of Beq Cycle 1 Cycle 2 Cycle 3 Cycle 4 • Ifetch: Instruction Fetch • Fetch the instruction from the Instruction Memory • Reg/Dec: • Registers Fetch and Instruction Decode • Exec: • compares the two register operand, • select correct branch target address • latch into PC Mem Beq Wr
Observations from Load and Store • Pass information needed from an earlier stage to a latter stage • Each logical component of the datapath – such as IM, Reg read ports, ALU, DM, Reg write port – can be used only within a single pipeline stage. Otherwise, we would have structural hazard • A bug in the pipelined datapath for load. Can you tell?
op 00 0000 00 1101 10 0011 10 1011 00 0100 00 0010 R-type ori lw sw beq jump RegDst 1 0 0 x x x ALUSrc 0 1 1 1 0 x MemtoReg 0 0 1 x x x RegWrite 1 1 1 0 0 0 MemWrite 0 0 0 1 0 0 Branch 0 0 0 0 1 0 Jump 0 0 0 0 0 1 ExtOp x 0 1 1 x x ALUop<N:0> “R-type” Or Add Add xx Subtract Overview on Datapath Control • For the subset of instructions under consideration, N=1. • ALUOp = 00 for Add, 01 for Sub, and 10 for R-type
Observations • No write control for all pipeline registers and PC since they are updated at every clock cycle. • To specify the control for the pipeline, set the control values during each pipeline stage. • Control lines can be divided into 5 groups: • IF – NONE • ID – NONE • ALU – RegDst, ALUOp, ALUSrc • MEM – Branch, MemRead, MemWrite • WB – MemtoReg, RegWrite • Group these nine control lines into 3 subsets: • ALUControl, MEMControl, WBControl • Control signals are generated at ID stage, how to pass them to other stages?
Pass Control Signals • Extend the pipeline registers to include control information
Example Pipeline Execution • Show the five instructions going through the pipeline: lw $10, 20($1) sub $11, $2, $3 and $12, $4, $5 or $13, $6, $7 add $14, $8, $9 Note that these instructions are independent with each other!