Skip to content
Official PYQ · 2010

GATE CS 2010 Q33 — Instruction Pipelining

Explain with AI

A 5−5-stage pipelined processor has Instruction Fetch (IF), Instruction Decode (ID), Operand Fetch (OF), Perform Operation (PO) and Write Operand (WO) stages. The IF, ID, OF and WO stages take 11 clock cycle each for any instruction. The PO stage takes 11 clock cycle for ADD and SUB instructions, 33 clock cycles for MUL instruction and 66 clock cycles for DIV instruction respectively. Operand forwarding is used in the pipeline. What is the number of clock cycles needed to execute the following sequence of instructions?

InstructionMeaning of instructiont_0: MUL R_2,R_0,R_1R2←R0∗R1t_1: DIV R_5,R_3,R_4R5←R3∕R4t_2: ADD R_2,R_5,R_2R2←R5+R2t3:SUB R5,R2,R6R5←R2−R6\begin{array}{|c|l||} \hline \textbf{Instruction} & \textbf{Meaning of instruction} \\ \hline \text{$t \_0$: MUL $R \_2$,$R \_0$,$R \_1$} & \text{R}_2 \gets \text{R}_0*\text{R}_1\\ \hline \text{$t \_1$: DIV $R \_5,R \_3,R \_4$} & \text{R}_5 \gets \text{R}_3 ∕ \text{R}_4\\ \hline \text{$t \_2$: ADD $R \_2,R \_5,R \_2$} & \text{R}_2 \gets \text{R}_5 + \text{R}_2 \\ \hline t_3: \text{SUB} \:\text{R}_5,\text{R}_2,\text{R}_6 & \text{R}_5 \gets \text{R}_2 - \text{R}_6 \\ \hline\end{array}

Choose one option
View worked solution

Answer: B

To find the total number of clock cycles, we must trace the execution of each instruction through the 5-stage pipeline: IF, ID, OF, PO, and WO.

Since the PO stage is non-pipelined and takes multiple cycles (3 for MUL, 6 for DIV), it can cause structural hazards. Additionally, data hazards are resolved using operand forwarding, which allows a dependent instruction to receive its operand immediately after the producer's PO stage completes.

The cycle-by-cycle execution is shown in the table below:

Instruction 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
t0t_0: MUL IF ID OF PO WO
t1t_1: DIV IF ID stall (OF) PO WO
t2t_2: ADD IF stall (ID) stall (OF) PO WO
t3t_3: SUB IF stall (ID) OF PO WO

Key Details:

  • t1t_1 (DIV) is stalled in the OF stage during cycles 4–6 because the PO stage is occupied by t0t_0 (structural hazard).
  • t2t_2 (ADD) requires R5R_5 from t1t_1. Since t1t_1's PO stage finishes at the end of cycle 12, R5R_5 is forwarded to t2t_2 at the start of cycle 13. Thus, t2t_2 stalls in OF during cycles 7–12.
  • t3t_3 (SUB) requires R2R_2 from t2t_2. Since t2t_2's PO stage finishes at the end of cycle 13, R2R_2 is forwarded to t3t_3 at the start of cycle 14.

Thus, the total execution time is 15 clock cycles.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Instruction Pipelining questions