5.2.3 · D4 · HinglishProcessor Datapath & Pipelining

ExercisesClassic 5-stage pipeline (IF - ID - EX - MEM - WB)

3,917 words18 min read↑ Read in English

5.2.3 · D4 · Hardware › Processor Datapath & Pipelining › Classic 5-stage pipeline (IF - ID - EX - MEM - WB)

Yeh page 5-stage pipeline ke liye ek graded workout hai. Har problem ka ek fully worked solution hai jise tum chupa ke khud se derive kar sakte ho. Levels "kya tum ise naam de sakte ho?" se "kya tum khud reasoning bana sakte ho?" tak chadti hain. Ek level karo, phir uska trap padho.

Figure s01 (neeche) har timing problem ke peeche ki mental picture hai: rows instructions hain, columns cycles hain. Coloured cells ka diagonal pipeline ka "filling" hai. Columns touched count karo = total cycles.

Figure — Classic 5-stage pipeline (IF - ID - EX - MEM - WB)

Level 1 — Recognition

Recall Solution L1.1
  1. IF — Instruction Fetch: PC mein address par instruction memory se instruction padho; phir PC ← PC + 4.
  2. ID — Instruction Decode / register read: opcode decode karo, register file se source registers padho, immediate ko sign-extend karo.
  3. EX — Execute: ALU arithmetic/logic karta hai, ya memory address compute karta hai, ya branch condition check karta hai.
  4. MEM — Memory access: loads data memory padhti hain, stores likhti hain; baaki sab yahan idle rehte hain.
  5. WB — Write Back: result ko register file mein likho.
Recall Solution L1.2

Registers ID mein read hote hain aur results WB mein write hote hain. Mnemonic: Decode reads, Write writes.

Recall Solution L1.3

Charo hain IF/ID, ID/EX, EX/MEM, MEM/WB. Har ek data (operand values, immediate, ALU result, loaded value) aur control signals (RegWrite, MemRead, MemWrite, …) carry karta hai. ID mein decide kiye gaye control signals WB tak, chaar cycles baad, pahunchne chahiye — registers unhe wahan tak ferry karte hain.


Level 2 — Application

Recall Solution L2.1

Step (kya): apply karo. Kyun: cycles pipe fill karne mein (pehla result cycle 5 par), phir aur results, har ek subsequent cycle mein. Pehli instruction cycle mein finish hoti hai (usse saare paanch stages pass karne hain). Figure s01 dekho: top row ka last coloured cell column 5 mein baitha hai.

Recall Solution L2.2

Step (kya): maximum delay lo. Kyun: saare stages ek clock share karte hain; cycle itni lambi honi chahiye ki slowest stage finish kar sake, warna us stage ka result latch hone ke liye ready nahi hoga. Step: latch overhead add karo, kyunki har cycle pipeline register mein likhne mein bhi spend karta hai.

Recall Solution L2.3

Step: cycles . Step: time ps ns. Cycles ko se multiply kyun? Har clock cycle exactly chalta hai, aur cycles ek ke baad ek hote hain; isliye total wall-clock time simply "kitne cycles" times "har cycle kitni lambi hai" hai.


Level 3 — Analysis

Recall Solution L3.1

Single-cycle time per instruction: ek bada cycle saara combinational kaam plus ek latch fit karna chahiye: Pipelined time per instruction (large ): har ps mein ek instruction finish hoti hai. Speedup: Yeh ratio kyun aur kyun nahi? Kyunki dono machines ke yahan alag cycle times hain (915 vs. 265), isliye hum seedha per instruction wall-clock time compare karte hain, exactly jaise intro formula box ne warn kiya tha. 5× kyun nahi? Stages unbalanced hain: WB (100 ps) aur ID (120 ps) apne 265-ps slot ka zyaadatar hissa waste karte hain, jabki IF/MEM (250 ps) pace set karte hain. Ideal 5× ke liye har stage equal hona chahiye aur hona chahiye. Dekho Clocking & Latch Overhead ki kabhi zero kyun nahi ho sakta.

Recall Solution L3.2
  • lw $t0, 8($s1) : IF · ID(s1+8) · MEM(read) · WB($t0 likho). Saare paanch use karta hai.
  • add $t2,$t3,$t4 : IF · ID(t4 padho) · EX(add) · MEM(idle) · WB($t2 likho).
  • sw $t5, 0($s2) : IF · ID(t5 padho) · EX(addr = $s2+0) · MEM(write) · koi WB nahi. Idle slots kyun rakhte hain? Taaki har instruction ki ek jaisi 5-stage shape ho. Uniform shape ⇒ simple control ⇒ ek instruction phir bhi har cycle finish hoti hai. Stages skip karne se assembly line ka steady rhythm toot jaata.
Recall Solution L3.3
  • 5-stage: ps.
  • 10-stage: ps. Step (kya): throughput ratio banao. Yeh throughput ratio kyun hai? Lambi stream ke liye, har mein ek instruction finish hoti hai, isliye throughput = 1 / (instructions per second). Do throughputs compare karna isliye hai — throughput cycle time ke inverse ke saath scale karta hai, isliye chhota proportionally faster hai. Result us naive 2× se kam hai jo tum stages double karne par umeed karte. Kyun? Latch overhead nahi shrink hua; yeh ab cycle ka hai instead of . Jaise stages thinner hote hain, bada fraction khaata hai. Bahut aage push karo aur speedup saturate ho jaata hai ya reverse ho jaata hai.

Level 4 — Synthesis

Recall Solution L4.1

IF aur MEM dono 250 ps hain. Koi bhi split karne se uske halves 125 ps ho jaate hain, lekin doosra 250-ps stage abhi bhi bacha rehta hai aur max re-set kar deta hai. Isliye akela split ko 250 se neeche nahi laata — naya bottleneck abhi bhi un-split 250-ps stage hai. Insight: koi gain dekhne ke liye tumhe dono 250-ps stages split karne honge. Sirf ek split karna ek extra latch waste karta hai bina kisi kaam ke. Yahi core lesson hai: doosra-slowest stage yeh limit karta hai ki slowest ki help kitni achieve kar sakti hai. Balance global hai, local nahi.

Recall Solution L4.2

Pipelined time < single-cycle time set karo: Isliye se pipeline already jeet jaata hai. Itni jaldi kyun? Single-cycle machine ki per-instruction cost (915) 265 ke comparison mein enormous hai; sirf 4 extra cycles ka fill penalty almost turant pay off ho jaata hai.


Level 5 — Mastery

Recall Solution L5.1

(a) ; ps. (b) Cycles . (c) Time ps ns. (d) Total kaam ps; single-cycle ps/instr. Large- pipelined ps/instr. Speedup . (e) Balanced ideal: har stage ps, isliye ps, jo deta hai — phir bhi 5× nahi. Theoretical 5× ke liye bhi chahiye, lekin latch overhead kabhi zero nahi ho sakta (real flip-flops mein setup + propagation time hota hai — dekho Clocking & Latch Overhead). Hazards ise aur erode karenge.

Recall Solution L5.2

Yaad karo ek stall cycle = ek inserted empty cycle jo instruction ko tab tak delay karta hai jab tak uski needed value reachable na ho jaaye. Dono instructions ko timeline par rakho; rows instructions hain, columns clock cycles hain (c1…c7), har cell woh stage hai jo us instruction us cycle mein occupy karti hai.

**Step 1 — find karo ki t0 apne WB mein likhta hai, jo cycle 5 hai:

instruction c1 c2 c3 c4 c5
add IF ID EX MEM WB

**Step 2 — find karo ki sub ko 6 - 3 = 3$ cycles se delay hua → 3 stall cycles. Corrected timeline:

instruction c1 c2 c3 c4 c5 c6 c7 c8 c9
add IF ID EX MEM WB
sub IF ID EX MEM WB

(teen "–" cells inserted bubbles hain). Step 5 — total cycles. Bina stalls ke do instructions cycles leti hain; 3 bubbles sub ko 3 se push karte hain, jo total cycles deta hai (last cell WB c9 mein). Forwarding kyun fix karta hai: ALU result add ke EX (c3) ke baad exist karta hai — ise seedha sub ke EX mein feed karo aur saare 3 stalls gayab ho jaate hain, wapas 6 cycles. Yahi Data Forwarding / Bypassing ka poora motivation hai.

Recall Solution L5.3

Goal: dikhao ki . Step 1 — fraction clear karo. Kyunki hai, dono sides ko inequality flip kiye bina multiply karo: Step 2 — right side expand karo. distribute karo: Step 3 — common term cancel karo. Dono sides mein hai (left mein hai), isliye ise subtract karo: Step 4 — factor aur interpret karo. . Kisi bhi real pipeline ke liye , aur dono positive hain, isliye hamesha true hai — lekin notice karo ki is step ne sirf use kiya, se independent. Wait: hum ne cancel kiya strict form maanke; strictness actually require karti hai taaki pipeline genuinely overlapping ho ( par dono sides ke barabar hain). Isliye har finite ke liye strict inequality hold karta hai. Step 5 — limit. Equality ke liye chahiye, ke liye impossible; lekin jaise , "" in negligible ho jaata hai aur ratio approach karta hai ko. Matlab: cycles ka fill/drain overhead almost nothing amortize ho sakta hai lekin finite stream ke liye kabhi actually remove nahi ho sakta.


Active recall

ko stage delays aur latch overhead ke terms mein kya hai?
— slowest stage plus woh latch cost jo har cycle pay karta hai.
-stage pipeline mein instructions chalane ke liye cycles, koi stalls nahi?
se fill karo, phir har cycle ek result.
Sirf ek slowest stage split karna aksar kyun help nahi karta?
Doosra-slowest stage naya bottleneck ban jaata hai; nahi girta, isliye unchanged rehta hai.
Real speedup exactly kyun kabhi nahi pahunch sakta?
Latch overhead , unbalanced stages slots waste karte hain, aur hazards stalls add karte hain; saare finite ke liye.
Kaun si assumption humein speedup likhne deti hai?
Dono machines ek hi share karte hain; jab cycle times alag hon (single-cycle vs. pipelined), seedha wall-clock times compare karo.
Stall cycle kya hota hai?
Ek inserted empty (bubble) cycle jahan ek stage koi useful kaam nahi karta kyunki woh kisi not-yet-reachable value ya resource ka wait kar raha hai; yeh cycle count mein ek add karta hai.