60 likes | 246 Views
Pipeline Programming. Programming Techniques & Datapath Requirements. Hazard Avoidance Example Sample code: for (int i = 0; i < 100; i++) { A[i] = B[i] + c; } Assume: A is in reg 1 B is in reg 2 c is in reg 3 Write the LC2K code to minimize stalls – assume:
E N D
Pipeline Programming Programming Techniques& Datapath Requirements
Hazard Avoidance Example • Sample code: for (int i = 0; i < 100; i++) { A[i] = B[i] + c;} • Assume: • A is in reg 1 • B is in reg 2 • c is in reg 3 • Write the LC2K code to minimize stalls – assume: • a single cycle delayed branch (branch delay slot of size 1) • any necessary/possible data forwarding
Hazard Avoidance: Example • The unoptimized codebased on a simplehand-compile:
Hazard Avoidance: Unoptimized Load stall!
Hazard Avoidance: Optimized Branch delay slot Branch delay slot
Performance Analysis • N iterations (N = 100 in the example) • Unoptimized: • Overhead: 2 cycles are required to get to the loop • Each iteration takes 15 – 3 + 1 = 13 cycles • 1 more cycle to finish last instruction in the pipeline • Total cycles for unoptimized version 2 + 13 * N + 1 = 1303 • Total instructions = 2 + 9 * N = 902 • CPI 1.445 • Optimized: • Each iteration takes 11 – 3 + 1 = 9 cycles • 4 more cycles to finish last instruction in the pipeline • Total cycles for optimized version 2 + 9 * N + 4 = 906 • CPI 1.004