GATE / CS ARCHIVE

SIMILAR QUESTIONS / COMPUTER ORGANIZATION & ARCHITECTURE

Schedule dependent instructions through multicycle execution stages

4 questions solved the same way, newest first. Back to Computer Organization & Architecture

How these are solved

Build a cycle-by-cycle stage occupancy schedule for the supplied dependent arithmetic instruction sequence.

2 marks · NAT
Report issue

Pipelining & Hazards

Question 53, GATE 2021: Five-stage IF,ID,EX,MEM,WB pipeline; stages each one cycle except MUL EX needs two; ADD EX needs one. ID only decodes; register read happens in EX. Eight instructions alternate ADD,MUL starting ADD, each dependent on previous. Ignore pipeline register delays. Find execution time without forwarding divided by time with forwarding, rounded to two decimals.
Tap to enlarge
Answer & solution

Official answer: 1.87 to 1.88

Our answer: 1.88

With forwarding, dependent instructions enter EX immediately after the previous EX result is ready. EX occupies cycles 3; 4–5; 6; 7–8; 9; 10–11; 12; 13–14. The last WB is cycle 16. Without forwarding, register operands must wait for the previous instruction to finish WB: EX intervals 3; 6–7; 10; 13–14; 17; 20–21; 24; 27–28, and final WB30. Thus speedup=30/16=1.875, rounding to 1.88, inside official 1.87–1.88. This uses the intended cycle-boundary model: a WB result becomes available to an EX register read in the following cycle. Allowing same-cycle WB-to-EX visibility would require a different timing convention; the prompt does not explicitly specify subcycle register timing.

For any instruction with EX finishing in cycle c, MEM occurs c+1 and WB c+2. Forwarding allows the dependent EX to start c+1, whereas the adopted no-forwarding convention requires c+3. Initial IF,ID place first EX in cycle 3; the last instruction then needs two drain cycles after EX. Counting only EX work or omitting pipeline fill/drain produces an incorrect speedup.

Original paper, page 87 · Answer key

2 marks · NAT
Report issue

Pipelining & Hazards

Question 53, GATE 2015: Instructions are MUL R5, R0, R1; DIV R6, R2, R3; ADD R7, R5, R6; SUB R8, R7, R4. Pipeline stages IF, OF and WB take one cycle; PO takes 3 for MUL, 5 for DIV and 1 for ADD/SUB. PO output can forward to OF. Find total cycles under the stated single occupied PO-stage interpretation.
Tap to enlarge
Answer & solution

Official answer: 13

Step through it (6 steps)

With a single occupied PO stage and the stated forwarding, MUL uses IF1, OF2, PO3–5, WB6. DIV uses PO6–10, ADD uses PO11 and SUB uses PO12; SUB writes back in cycle 13. The dependent ADD/SUB operand fetches use the forwarded results at the end of the preceding producer PO cycle. Thus total 13 cycles. This is the conventional in-order, non-internally-pipelined PO-stage model; independent or internally pipelined functional units would require more scheduling details.

Count occupied execution cycles rather than adding all independent instruction latencies. MUL starts PO in cycle 3 and occupies cycles 3–5. DIV cannot use the same PO stage until cycle 6, then occupies 6–10. ADD depends on both results and uses PO in cycle 11 after forwarding; SUB follows in cycle 12. Its WB is cycle 13. The explicit resource model matters: a separately pipelined multiplier/divider would permit a different schedule, and a non-forwarding design would add dependency stalls.

Original paper, page 47 · Answer key

2 marks · MCQ
Report issue

Variable-latency pipeline execution

Pipelining & Hazards

Question 33, GATE 2010: A five-stage pipeline has IF, ID, OF, PO and WO stages. IF, ID, OF and WO each take one cycle. PO takes one cycle for ADD/SUB, three for MUL and six for DIV. Operand forwarding is used. How many cycles execute this instruction sequence?
I₀: MUL R₂,R₀,R₁   (R₂←R₀×R₁)
I₁: DIV R₅,R₃,R₄   (R₅←R₃/R₄)
I₂: ADD R₂,R₅,R₂   (R₂←R₅+R₂)
I₃: SUB R₅,R₂,R₆   (R₅←R₂−R₆)
Options: (A) 13; (B) 15; (C) 17; (D) 19.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step through it (6 steps)

With the single shared PO stage, the first MUL occupies PO in cycles 4–6 after IF,ID,OF in cycles 1–3. DIV occupies PO in cycles 7–12; the dependent ADD then uses the forwarded DIV result in PO cycle 13, and SUB uses PO cycle 14. The last WO is cycle 15. Earlier stages stall as necessary while PO is occupied, but forwarding avoids waiting for an extra writeback before dependent execution. Total 15, B. This assumes the ordinary unpipelined multi-cycle PO unit implicit in this question, not separate independently pipelined arithmetic units.

A compact timing schedule is MUL: PO 4–6, WO 7; DIV: PO 7–12, WO 13; ADD: PO 13, WO 14; SUB: PO 14, WO 15. PO is the bottleneck and its occupied cycles sum to 3+6+1+1=11. Three initial stages plus eleven PO cycles plus the final writeback give 3+11+1=15. Forwarding handles the DIV→ADD and ADD→SUB true dependencies.

Original paper, page 8

2 marks · MCQ
Report issue

Forwarded multicycle pipeline timing

Pipelining & Hazards

Question 37, GATE 2007: A pipeline has IF, ID (decode/operand fetch), EX, WB. IF, ID and WB each take one cycle; EX takes one cycle for ADD/SUB and three for MUL. Operand forwarding is available. How many cycles complete this sequence?
ADD R2,R1,R0   (R2←R1+R0)
MUL R4,R3,R2   (R4←R3×R2)
SUB R6,R5,R4   (R6←R5−R4)
Options:
(A) 7
(B) 8
(C) 10
(D) 14
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step through it (5 steps)

1. Approach. Draw one timeline per instruction. Forwarding removes waiting for register writeback, but it cannot make the three-cycle multiply result available before its EX stage finishes.

2. Derivation and interpretation. ADD uses IF1,ID2,EX3,WB4. Its result is forwarded to MUL, which uses IF2,ID3,EX4–6,WB7. SUB uses IF3,ID4 and waits for the EX unit/result, then executes EX7 and WB8. Therefore completion requires 8 cycles, B, assuming the stated forwarding permits consuming an EX result in the next cycle and no additional structural conflicts.

Original paper, page 9