Title: Processor Basic steps to process an instruction
1Processor Basic steps to process an instruction
IF
ID/OF
EX
MEM
WB
2Datapath
NPC
A? RegIR 6..10 B? RegIR 11..15 Imm?
((IR16)16 IR 11..15
IR ? MemPC NPC ? PC 4
3Datapath (Arith/Logic Inst.)
ALUoutput ? A op B ALUoutput ? A op Imm
A? RegIR 6..10 B? RegIR 11..15 Imm?
((IR16)16 IR 11..15
IR ? MemPC NPC ? PC 4
RegIR16..20 ? ALUoutput
4Datapath (Load Inst.)
ALUoutput ? A op Imm
A? RegIR 6..10 B? RegIR 11..15 Imm?
((IR16)16 IR 11..15
IR ? MemPC NPC ? PC 4
RegIR11-15 ? LMD
5Datapath (Store Inst.)
ALUoutput ? A op Imm
A? RegIR 6..10 B? RegIR 11..15 Imm?
((IR16)16 IR 11..15
IR ? MemPC NPC ? PC 4
MemALUoutput ? B
6Datapath (Branch Inst.)
ALUoutput ? (PC4) op Imm
A? RegIR 6..10 B? RegIR 11..15 Imm?
((IR16)16 IR 11..15
IR ? MemPC NPC ? PC 4
7Instructions of a program
1
Time (clock cycles)
8Instructions of a program
1
2
3
4
5
6
7
8
CLOCK CYCLE
9Pipelining Lessons
- Pipelining doesnt help latency of single task,
it helps throughput of entire workload - Pipeline rate limited by slowest pipeline stage
- Multiple tasks operating simultaneously
- Potential speedup Number pipe stages
- Unbalanced lengths of pipe stages reduces speedup
- Time to fill pipeline and time to drain it
reduces speedup
10Datapath w/ pipeline
IF
ID
EX
MEM
WB
11Datapath w/ pipeline
12Pipeline
IF
1
2
3
4
INSTRUCTIONS
5
6
7
8
9
1
2
3
4
5
6
7
8
9
CLOCK CYCLE
13Pipeline Hazards
- Structural Hazards
- two or more instructions use same hardware at the
same time. - Data Hazards
- Data dependencies
- Result from inst. j is needed by inst. k
- Control Hazards
- Branch changes flow, what happen with the
following instruction(s)
14Resources
Mem (IM)
15Data Hazards
Mem (IM)
R1 R2R3
R5 R1R3
R8 R1-R6
16Data Forwarding
Mem (IM)
R1 R2R3
R5 R1R3
R8 R1-R6
17Datapath w/ pipeline
18Example
ADD R1,R2,R3
19Example
20Example
21Data Hazard Classification
j R1 ? k RY ? R1
- RAW (Read After Write)
- w/ forward only load presents a problem
- WAW
- WAR
- RAR
j R1 ? k R1 ?
j ? R1 k R1 ?
j ? R1 k ? R1
22Data Forwarding (load)
Mem (IM)
R1 LDMem
R5 R1R3
R8 R1-R6
23Data hazard (load)
R1
IF
LW R1,0(R1)
SUB R4,R1,R5
AND R6,R1,R7
OR R8,R1,R9
24Branch
BR R1, LABEL_A
ADD R2,R3,R7
AND R5,R7,R11
LD R4,R2,005
LABEL_A
25Branch
Mem (IM)
BR R1, LABEL_A
ADD R2,R3,R7
AND R5,R7,R11
LD R4,R2,005
26Datapath w/ pipeline
27What to do w/ branch
- Reduce the number of cycles to decide on a
branch. - Delayed branch (Software Solutions)
- NO-OP
- move instructions
- from before
- from target
- from fall through
28Branch
Mem (IM)
BR R1, LABEL_A
ADD R2,R3,R7
LD R4,R2,005
29NO-OP
Branch
NO-OP
30From Before
Branch
31From Target
Branch
32From Fall Through
Branch
33Multicycle Operations
I F
I D
MEM
W B
33
34FP operations
- FP Add 4 cycles
- FP Multiply 7 cycles
- FP Divide 25 cycles
34
35Example
1 IF
2 ID IF
3 m1 ID IF
4 m2 a1 ID IF
5 m3 a2 X ID
6 m4 a3 M X
7 m5 a4 W M
8 m6 M W
9 m7 W
10 M
11 W
MULTD ADDD LD SD
35
36MIPS R4000(Superpipelining)
DF Data fetch First half DS Data fetch
Second half TC Tag Check WB Write Back
IF Instruction fetch First half IS
Instruction fetch Second half RF Inst. Decode
Register Fetch EX Execution
36
37Load
CC1
CC2
CC3
CC4
CC5
CC6
CC7
LW R1
instruction memory
data memory
Reg
Reg
instruction memory
data memory
Reg
Reg
Instruction 1
instruction memory
data memory
Reg
Reg
Instruction 2
instruction memory
data memory
Reg
ADD R2,R1
37
38Branch
BEQZ
instruction memory
data memory
Reg
Reg
instruction memory
data memory
Reg
Reg
instruction memory
data memory
Reg
Reg
instruction memory
data memory
Reg
instruction memory
data memory
Reg
38
39Branch (taken)
Branch inst IF IS RF EX DF DS TC WB Delay slot
IF IS RF EX DF DS TC WB stall S S S S S S S S st
all S S S S S S S S Branch target
IF IS RF EX DF DS TC WB
39
40Branch (not taken)
Branch inst IF IS RF EX DF DS TC WB Delay slot
IF IS RF EX DF DS TC WB Branch inst2 IF IS RF E
X DF DS TC WB Branch inst3 IF IS RF EX DF DS T
C WB Branch inst4 IF IS RF EX DF DS TC WB
40