300 likes | 371 Views
Data Hazards. 0x30 sub $6 $0 $1 0x34 add $7 $6 $1. Step 3, we calculate $0 - $1. Reg. 0x30 sub $6 $0 $1. IM. DM. Reg. 0x34 add $7 $6 $1. Reg. IM. DM. Reg. ! ! ! HAZARD ! ! ! OLD VALUE OF $6. Step 4, we calculate $1 + $6. Reg. 0x30 sub $6 $0 $1. IM. DM. Reg.
E N D
Data Hazards • 0x30 sub $6 $0 $1 • 0x34 add $7 $6 $1 • ... • .. • .
Step 3, we calculate $0 - $1 Reg • 0x30 sub $6 $0 $1 IM DM Reg • 0x34 add $7 $6 $1 Reg IM DM Reg ! ! ! HAZARD ! ! ! OLD VALUE OF $6
Step 4, we calculate $1 + $6 Reg • 0x30 sub $6 $0 $1 IM DM Reg • 0x34 add $7 $6 $1 Reg IM DM Reg
Step 5, Now we write $6 Reg • 0x30 sub $6 $0 $1 IM DM Reg • 0x34 add $7 $6 $1 Reg IM DM Reg HAZARD OVER NEW VALUE OF $6 WRITTEN TO REGFILE
Step 2, nop Reg • 0x30 sub $6 $0 $1 IM DM Reg • 0x34 nop Reg IM DM Reg Reg IM DM Reg Reg IM DM Reg
Step 3, nop Reg • 0x30 sub $6 $0 $1 IM DM Reg • 0x34 nop Reg IM DM Reg • 0x38 nop Reg IM DM Reg Reg IM DM Reg
Step 4, add $7 $6 $1 Reg • 0x30 sub $6 $0 $1 IM DM Reg • 0x34 nop Reg IM DM Reg • 0x38 nop Reg IM DM Reg • 0x3C add $7 $6 $1 Reg IM DM Reg
Step 5, new $6 used Reg • 0x30 sub $6 $0 $1 IM DM Reg • 0x34 nop Reg IM DM Reg • 0x38 nop Reg IM DM Reg • 0x3C add $7 $6 $1 Reg IM DM Reg
Data Hazards • Read After Write • Solved by inserting “nop” operations (bubbles) • or by hardware “stalling” the pipe
Cost? • + Hardware inexpensive • - Performance (throughput)
Data Hazards sub $6 $0 $1 add $7 $6 $1 add $7 $7 $6 .. .
We calculate $0 - $1 Reg • 0x30 sub $6 $0 $1 IM DM Reg • 0x34 add $7 $6 $1 Reg IM DM Reg ! ! ! HAZARD ! ! ! OLD VALUE OF $6
We “forward” the new result Reg • 0x30 sub $6 $0 $1 IM DM Reg • 0x34 add $7 $6 $1 Reg IM DM Reg HAZARD SOLVED BY “FORWARDING”
Zeroext. HERE IS THE RESULT Branch logic 0 A ALU 4 B + 31 + Sgn/Ze extend • 0x30 sub $6 $0 $1 • 0x34 add $7 $6 $1 • > 0x38 add $7 $7 $1 • ... • ..
Zeroext. WE NEED IT HERE Branch logic 0 A ALU 4 B + 31 + Sgn/Ze extend • 0x30 sub $6 $0 $1 • 0x34 add $7 $6 $1 • > 0x38 add $7 $7 $1 • ... • ..
sub $6 $0 $1 • add $7 $6 $1 0 A B DATA WORD • 0x30 sub $6 $0 $1 • 0x34 add $7 $6 $1 • > 0x38 add $7 $7 $1 • ... • ..
sub $6 $0 $1 • add $7 $6 $1 = 0 A B REG NR • 0x30 sub $6 $0 $1 • 0x34 add $7 $6 $1 • > 0x38 add $7 $7 $1 • ... • ..
Zeroext. Branch logic 0 A ALU 4 B + 31 + Sgn/Ze extend • 0x30 sub $6 $0 $1 • 0x34 add $7 $6 $1 • 0x38 add $7 $7 $6 • > 0x3C sw $5 4($0)
add $7 $7 $6 • add $7 $6 $1 • sub $6 $0 $1 = 0 A ALU B = • 0x30 sub $6 $0 $1 • 0x34 add $7 $6 $1 • 0x38 add $7 $7 $6 • > 0x3C sw $5 4($0)
add $7 $7 $6 • add $7 $6 $1 • sub $6 $0 $1 = = 0 A ALU B = = • 0x30 sub $6 $0 $1 • 0x34 add $7 $6 $1 • 0x38 add $7 $7 $6 • > 0x3C sw $5 4($0)
Data Hazards sub $6 $0 $1 add $6 $6 $1 add $7 $6 $1 .. .
add $7 $6 $1 • add $6 $6 $1 • sub $6 $0 $1 = = 0 A ALU B = = • 0x30 sub $6 $0 $1 • 0x34 add $6 $6 $1 • > 0x38 add $7 $6 $1 • ... • ..
Performance • No “Bubbles” or “Stalls” • increased throughput • But did we change the critical path? • Topological sort • Static timing analysis
Zeroext. = = Branch logic 0 A ALU 4 B + = = 31 + Sgn/Ze extend
Forwarding Logic W Reg # DRD/DWT W >=1 = Reg # = & & DATA DATA
Critical path ALU? Zeroext. = = Branch logic 0 A ALU 4 B + = = 31 + Sgn/Ze extend
Critical path DATA MEMORY? Zeroext. = = Branch logic 0 A ALU 4 B + = = 31 + Sgn/Ze extend
All problems solved? • NO, what will happen if...... • lw $6 $0($1) • add $4 $6 $1 • add $7 $6 $2
OK, “DM” to “DE” Reg • 0x30 lw $6 $0($1) IM DM Reg Reg IM DM Reg • 0x34 add $4 $6 $1 • 0x38 add $7 $6 $2 Reg IM DM Reg
“DM” to “EX” ? Reg • 0x30 lw $6 $0($1) IM DM Reg Reg IM DM Reg • 0x34 add $4 $6 $1 • 0x38 add $7 $6 $2 Reg IM DM Reg