Professional Documents
Culture Documents
Lec12 - Pipelined Implementation I
Lec12 - Pipelined Implementation I
4 ADD
64 bits 128 bits
PC <<2 97 bits 64 bits
Instruction I
ADDR RD
32 16 32
Instruction 5 5 5
lw $rt, immed($rs)
The load word instruction adds an immed or constant value to the contents of source
register ($rs) to obtain the address in memory whose contents are written to
destination register ($rt)
The instruction is read from memory using the contents of PC and placed in the IF/ID register. The PC address is
incremented by 4 and written back to the PC register, as well as placed in the IF/ID register in case it is needed later
for am insruction, such as beq.
Note: the datapath does not know that we are performing a load word at this point so it forwards the PC+4 value,
so it must prepare for any instruction, passing potentially needed information down the pipeline..
In the diag, the right half of memory is shaded meaning it is being read. The left half of IF/ID is shaded because it is
being written.
BITS Pilani, Pilani Campus
Instruction Decode and Register
File Read (ID):
The register numbers $rs and $rt are read from the register file and stored in the ID/EX pipeline register.
The 16-bit immediate field is sign-extended to 32-bits and stored in the ID/EX pipeline register.
The PC+4 value is copied from the IF/ID register into the ID/EX register in case the instruction needs it later.
From the ID/EX pipeline register, take the contents of $rs and the sign-extended immediate field as inputs to the
ALU, which performs an add operation. The sum is placed in the EX/MEM pipeline register.
Take the address stored in the EX/MEM pipeline register and use it to access data memory. The data read from
memory is stored in the MEM/WB pipeline register.
Read the data from the MEM/WB register and write it back to the register file in the middle of the datapath.
4 ADD
64 bits 128 bits
PC <<2 97 bits 64 bits
Instruction I
ADDR RD
32 16 32
Instruction 5 5 5
4 ADD
PC
Instruction I <<2
ADDR RD
32 16 32
Instruction
5 5 5
16
E
X 32
Memory U
X
T WD
N
D
ADD
ADD
4 64 bits 133 bits
<<2 102 bits 69 bits
PC
ADDR RD 5
RN1 RD1
32 Zero
Instruction RN2 ALU
5
Memory WN
Register
5
WD
File RD2 M
U ADDR
X
Data RD
Memory
M
E U
16 X 32 X
T WD
N
5 D
preserve the destination register number in the load instruction. Destination register number is also
passed through ID/EX, EX/MEM and MEM/WB registers, which are now wider by 5 bits
Execution/Address Write-back
Calculation stage control Memory access stage stage control
lines control lines lines
Reg ALU ALU ALU Branc Mem Mem Reg Mem
Instruction Dst Op1 Op0 Src h Read Write write to Reg
R-format 1 1 0 0 0 0 0 1 0
lw 0 0 0 1 0 1 0 1 1
sw X 0 0 1 0 0 1 0 X
beq X 0 1 0 1 0 0 0 X
In IF, in addition to fetching the instruction and computing the new PC,
we store the incremented PC both into the PC and into a pipeline register
(NPC) for later use in computing the branch-target address, the PC is updated in IF
from one of two sources
In ID, we fetch the registers, extend the sign of the lower 16 bits of the IR (the
immediate field), and pass along the IR and NPC
Structural Hazards: A structural hazard in the laundry room would occur if we used a washer-dryer
combination instead of a separate washer and dryer
Arise from resource conflicts when the hardware cannot support all possible combinations of instructions in
simultaneous overlapped instructions.
E.g., suppose you have a single – not separate – instruction and data memory in pipeline with one read port. in
the same clock cycle. the first instruction is accessing data from memory while the fourth instruction is fetching an
instruction from that same memory. Without two memories, our pipeline could have a structural hazard.
Program
execution 2 4 6 8 10 12 14
Time
order
(in instructions)
Instruction Data
lw $1, 100($0) Reg ALU Reg
fetch access
Pipelined
Instruction Data
lw $2, 200($0) 2 ns Reg ALU Reg
fetch access
Instruction Data
lw $3, 300($0) 2 ns Reg ALU Reg
fetch access
Instruction Data
lw $4, 400($0) Reg ALU Reg
2 ns fetch access
2 ns 2 ns 2 ns 2 ns 2 ns
-When an instruction is stalled all instructions issued later from the stalled
instruction also stalled.
IM REG ALU DM
IM REG ALU
If the results can be moved from where the ADD produces it, the EX/MEM
register, to where the SUB needs it, the ALU input latches, then the need for stall
can be avoided.
ALU result from the EX/MEM register is always fedback to ALU input latches.
Forwarding logic detects whether previous ALU operation has written the register
corresponding to a source for the current ALU operation, if so, then control logic
selects the forwarded result as the ALU input rather than value read from register
file.
Forward results not only from the immediately previous instruction, but possibly
from instruction started three clock cycles earlier.