Question
Consider an instruction pipeline with five stages without any branch prediction: Fetch Instruction (FI), Decode Instruction (DI), Fetch Operand (FO), Execute Instruction (EI) and Write Operand (WO). The stage delays for FI, DI, FO, EI and WO are 5 ns, 7 ns, 10 ns, 8 ns and 6 ns, respectively. There are intermediate storage buffers after each stage and the delay of each buffer is 1 ns. A program consisting of 12 instructions I1, I2, I3, ..., I12 is executed in this pipelined processor. Instruction I4 is the only branch instruction and its branch target is I9. If the branch is taken during the execution of this program, the time (in ns) needed to complete the program is
Official answer and solution
- Official answer
- B
- From
- Official GATE 2013 answer key
Solution
Calculate the clock cycle time from the stage and buffer delays, determine the cycle in which the branch penalty resolves, and sum the execution time.
-
Determine the clock cycle time:
Each stage delay must be added to the buffer delay of 1 ns:- FI:
- DI:
- FO:
- EI:
- WO:
The clock cycle duration is the maximum stage latency:
-
Analyze the pipeline execution with branch:
- There are 12 instructions .
- is a branch instruction to target .
- Without branch prediction, the branch outcome is determined during the Execute Instruction (EI) stage of .
- Cycle trace for :
- Cycle 4: is fetched (FI).
- Cycle 5: is decoded (DI).
- Cycle 6: operand fetch (FO).
- Cycle 7: execution (EI). The branch target is resolved at the end of cycle 7.
- Meanwhile, instructions complete normally:
- finishes WO at cycle 5.
- finishes WO at cycle 6.
- finishes WO at cycle 7.
- finishes WO at cycle 8.
- Because the branch is taken, the target instruction can only be fetched starting at cycle 8.
- The instructions executed following the branch are (a sequence of 4 instructions).
- In an empty 5-stage pipeline, executing 4 instructions requires:
- These 8 cycles take place from cycle 8 through cycle .
- Thus, instruction finishes at the end of cycle 15.
-
Compute total time:
This matches option (B).
B
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2013 Computer Science and Information Technology (CS)
- Question
- 45 of 65, printed as CS Q.45
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.