A CPU has a five-stage pipeline and runs at 1 GHz frequency. Instruction fetch…
A CPU has a five-stage pipeline and runs at 1 GHz frequency. Instruction fetch happens in the first stage of the pipeline. A conditional branch instruction computes the target address and evaluates the condition in the third stage of the pipeline. The processor stops fetching new instructions following a conditional branch until the branch outcome is known. A program executes 109 instructions out of which 20% are conditional branches. If each instruction takes one cycle to complete on average, the total execution time of the program is:
Answer: A. 1.4 seconds — Answer: 1.4 seconds. Explanation: Total instructions = 10^9. Fraction of conditional branches = 20% → number of branches = 0.2 × 10^9 = 2 × 10^8. Branch…
- A.
1.4 seconds
- B.
1.0 second
- C.
1.2 seconds
- D.
1.6 seconds
Attempted by 6 students.
Show answer & explanation
Correct answer: A
Answer: 1.4 seconds.
Explanation:
Total instructions = 10^9.
Fraction of conditional branches = 20% → number of branches = 0.2 × 10^9 = 2 × 10^8.
Branch penalty: The branch outcome is known in the 3rd stage while instruction fetch is in the 1st stage, so fetching is stalled for the 2 intervening cycles. Therefore penalty per branch = 2 cycles.
Total penalty cycles = 2 × (2 × 10^8) = 4 × 10^8 cycles.
Total cycles = base cycles + penalty = 10^9 + 4 × 10^8 = 1.4 × 10^9 cycles.
At 1 GHz (1 × 10^9 cycles/second), execution time = (1.4 × 10^9 cycles) / (1 × 10^9 cycles/s) = 1.4 seconds.
Thus the correct total execution time is 1.4 seconds.
A video solution is available for this question — log in and enroll to watch it.