A CPU has a five-stage pipeline and runs at 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 instructions out of which are conditional branches. If each instruction takes one cycle to complete on average, the total execution time of the program is:
View worked solution
Answer: C
To find the total execution time, we need to determine the total number of clock cycles required to execute the program, taking into account the stalls introduced by conditional branch instructions.
1. Determine the Branch Penalty (Stall Cycles)
The pipeline has 5 stages, and instruction fetch (IF) occurs in Stage 1. For a conditional branch instruction:
- Cycle 1: The branch instruction is fetched in Stage 1.
- Cycle 2: The branch instruction moves to Stage 2. Since the processor stops fetching new instructions until the branch outcome is known, no new instruction is fetched. (1st stall cycle)
- Cycle 3: The branch instruction moves to Stage 3, where the target address and condition are evaluated. Still, no new instruction is fetched. (2nd stall cycle)
- Cycle 4: The branch outcome is now known, and the next instruction (either the target or sequential instruction) is fetched in Stage 1.
Thus, each conditional branch instruction introduces a penalty of stall cycles.
2. Calculate Total Cycles
Given:
- Total instructions () =
- Base CPI (without stalls) = cycle per instruction
- Percentage of conditional branches = of
The total number of clock cycles is calculated as:
3. Calculate Execution Time
The CPU clock frequency is (cycles per second).
Therefore, the total execution time of the program is 1.4 seconds.
Free practice · Your answers on this page are not saved.
