5.2.2 · D4 · HinglishProcessor Datapath & Pipelining

ExercisesMulti-cycle datapath

3,264 words15 min read↑ Read in English

5.2.2 · D4 · Hardware › Processor Datapath & Pipelining › Multi-cycle datapath

Yeh page ek self-test ladder hai. Har problem ko solution kholne se pehle solve karo. Levels recognising the five steps se shuru hokar designing and comparing whole machines tak jaate hain. Har symbol jo tumhe chahiye woh parent note Multi-cycle datapath (5.2.2) mein build kiya gaya tha — yahan hum sirf tools use karte hain.

Neeche wali figure dikhati hai ki kyun woh step delays wahi hain jo hain — Level 2 se pehle ise padhna, phir L2-Q1 solve karte waqt wapas aana.

Figure — Multi-cycle datapath

Bar chart us key claim ko visual banata hai: clock (dashed line) tallest bar (ID = 300 ps) par pin hai, na ki saare bars ke sum par. Notice karo ki IF, EX, aur MEM har ek 200 ps par hain aur WB 100 ps par — woh stages us period ke remaining time ko waste karti hain jo unki height aur dashed line ke beech hota hai. Yahi wasted headroom exactly is particular machine ko raw speed mein harane ka karan hai (Level 3).


Level 1 — Recognition

Recall Solution L1-Q1

(a) IR IF mein write hota hai — yeh raw instruction bits Memory[PC] hold karta hai. (b) A and B ID mein write hote hain — yeh do source-register values Reg[rs], Reg[rt] hold karte hain. (c) ALUOut pehli baar ID mein write hota hai — yeh speculatively pre-computed branch target PC + (sign-ext(imm) << 2) hold karta hai. (Yeh R-type/address results ke liye EX mein dobara write hota hai — lekin pehla write ID mein hota hai.) (d) MDR MEM mein write hota hai — yeh lw ke dauran memory se padha gaya data hold karta hai. Yeh ordering kyun? Har register ek "sticky note" hai jo clock edge se pehle ek combinational value pakadta hai, taaki baad ka cycle use padh sake.

Recall Solution L1-Q2

(a) add = 4 (IF ID EX WB — koi memory nahi). (b) lw = 5 (IF ID EX MEM WB — akela 5-cycle instruction). (c) sw = 4 (IF ID EX MEM — MEM mein khatam, koi write-back nahi). (d) beq = 3 (IF ID EX — PC, EX mein update hota hai). (e) j = 3 (IF ID EX — PC, EX mein update hota hai).


Level 2 — Application

Recall Solution L2-Q1
  • IF = ps. Kyun? IF mein do cheezein parallel mein hoti hain: memory read IR ← Memory[PC] (200 ps) aur ALU par PC+4 add (200 ps). Kyunki yeh independent hardware par same time par run hote hain — memory IR ko feed karta hai jabki ALU PC ko feed karta hai — stage delay dono ka maximum hoti hai, ps, na ki unka sum. Yeh ID (neeche) se crucial difference hai, jahaan do operations chained hain.
  • ID = RegFile read phir ALU branch-target calc sequence mein same cycle mein ps. Yahan ALU ko register-read result input ke roop mein chahiye, toh use wait karna padta hai — delays add hoti hain.
  • EX = ALU = ps.
  • MEM = memory access = ps.
  • WB = RegFile write = ps. Clock ko worst step fit karni chahiye, toh ps. ID kyun dominate karta hai: yeh ek register read aur ek ALU op ko chain karta hai (ek doosre ko feed karta hai), toh unki delays add hoti hain; IF isse bachta hai kyunki uska memory read aur PC+4 add independent aur parallel hain.
Recall Solution L2-Q2

lw 5 cycles use karta hai: ps. Single-cycle lw = ps. Toh lw akele ke liye, multi-cycle slower hai (). Yeh step kyun: execution time = cycles × period. Clock speeds compare mat karo; times compare karo.

Recall Solution L2-Q3

beq 3 cycles use karta hai: ps. Yeh single-cycle ke 800 ps ke kareeb hai, lekin yahan thoda slower hai kyunki perfectly balanced nahi hai.


Level 3 — Analysis

Recall Solution L3-Q1

Har term kyun: yeh hai — program ka woh fraction jo type ka hai, multiply by us type ka cycle count. Saare types par sum karne se cycles ki weighted average milti hai jo ek "typical" instruction mein lagti hai.

Recall Solution L3-Q2

Kyunki , multi-cycle inhi numbers ke liye raw time mein slower hai. Kyun: ID stage (300 ps) unbalanced hai — yeh clock period par kabza kar leti hai jabki doosri stages us period ka 100–200 ps waste karti hain. Multi-cycle ka guaranteed benefit yahan kam hardware (shared ALU aur unified memory) hai, speed nahi.

Recall Solution L3-Q3

Break-even: ps. Toh multi-cycle single-cycle ko tabhi beat karta hai jab worst step ≈197.5 ps se neeche aaye. Kyunki ek memory access already 200 ps leta hai, yeh practically impossible hai jab tak hum CPI ya memory delay bhi kam na karein. Yeh quantify karta hai ki yeh particular machine speed mein kyun harti hai. Yeh step kyun: donon program-times ko equal set karo aur unknown ke liye solve karo — classic break-even technique.


Level 4 — Synthesis

Recall Solution L4-Q1

beq IF, ID, EX use karta hai — ALU teeno mein kaam karta hai:

  • IF: operands = PC aur 4 → result PC+4, PC mein latch hota hai (default next instruction). Yeh ALU add memory read IR ← Memory[PC] ke parallel mein run karta hai, toh IF stage ko 200 ps se aage nahi badhaata (dekho L2-Q1).
  • ID: operands = PC aur sign-ext(imm) << 2 → result = branch target, ALUOut mein speculatively latch hota hai.
  • EX: operands = A aur B → ALU test karne ke liye subtract karta hai; agar zero-flag set ho, toh PC ← ALUOut (ID se target). Teeno uses kyun: multiplexers har cycle mein single shared ALU ke inputs re-route karte hain — wahi reuse multi-cycle ka point hai. (Figure dekho.)
Figure — Multi-cycle datapath
Recall Solution L4-Q2

(a) . (b) Time per instruction ps. (c) , toh multi-cycle abhi bhi slower hai — memory-heavy lw fraction CPI ko upar push karta hai, neeche nahi. Kyun: zyada lw matlab zyada 5-cycle instructions, CPI badhta hai. Multi-cycle tabhi help karta hai jab step delay ka advantage cycle-count penalty se zyada ho — jo yahan nahi hota.

Recall Solution L4-Q3

sw memory likhta hai: MEM mein yeh Memory[ALUOut] ← B karta hai. Uska kaam — ek register value ko memory mein move karna — ek baar memory likh jaane par complete ho jaata hai. Koi register update nahi karna, toh WB nahi. lw memory padhta hai: MEM mein yeh MDR ← Memory[ALUOut] karta hai, data ko MDR mein capture karta hai. Lekin destination ek register hai, aur register file sirf ek alag cycle mein write ho sakti hai (WB): Reg[rt] ← MDR. Isliye lw ko extra 5th step chahiye. Asymmetry kyun: store ka destination memory hai (MEM mein likha jaata hai); load ka destination register hai (WB mein likha jaata hai). Data flow ki direction last step decide karti hai.


Level 5 — Mastery

Recall Solution L5-Q1

New cycle counts (har ek +1): lw=6, sw=5, R-type=5, beq=4, j=4. (a) . (b) Time/instr ps. (c) single-cycle ke muqable: → abhi bhi single-cycle se slower, lekin kareeb. (d) original multi-cycle ke muqable: → rebalanced machine original multi-cycle se 20% faster hai. Trade-off kyun matter karta hai: clock ko shorten karna (300→200) extra cycle ki cost se multi-cycle family ke andar zyada compensate kar gaya, even though na hi single-cycle ko beat kar saka is mix par. Yahi exact tension hai jo pipelining resolve karta hai — dekho Pipelining.

Recall Solution L5-Q2

Multi-cycle yahan jeetata hai — lekin hardware ke liye, speed ke liye nahi. Reasoning:

  • Workload memory-heavy hai, toh CPI high hai (bahut saare 4–5 cycle instructions) → multi-cycle ka time advantage weak hai (humne 0.66–0.79 speedups dekhe, matlab slower).
  • Lekin constraint transistor budget hai. Multi-cycle ek unified memory aur ek shared ALU cycles mein use karta hai, jabki single-cycle ko separate I/D memories aur aksar multiple adders chahiye. Yeh ek chhoti chip ke liye decisive saving hai.
  • Full Pipelining best throughput deta lekin sabse zyada hardware cost karta (pipeline registers, forwarding, hazard logic) — chhote budget ke liye galat. Conclusion: multi-cycle choose karo: uska defining benefit — hardware reuse — binding constraint se match karta hai. Throughput trade-off ke liye CPI and CPU performance equation dekho aur multi-step control kaise build hota hai uske liye Control unit — FSM vs microprogramming dekho.
Recall Solution L5-Q3

Equal instruction counts cancel ho jaate hain: , CPI ke saath: ps chahiye (L3-Q3 se match karta hai). General rule: multi-cycle tabhi jeetata hai jab longest step single-cycle period divided by average cycle count se chhota ho. Kyun: yeh sirf "program time smaller" hai divided out ke saath — poore trade-off ka sabse clean statement.


Recall Quick self-check (cloze)

Multi-cycle clock period longest single step ki delay ke barabar hoti hai. Program time = N × CPI × T_step. R-type ke chaar steps hain IF, ID, EX, WB (yeh MEM skip karta hai). Multi-cycle single-cycle ko tabhi beat karta hai jab T_single / CPI. Multi-cycle ko sirf one (unified) memory chahiye kyunki IF aur MEM alag cycles mein hote hain.

Multi-cycle single-cycle ko kab beat karta hai?
Jab — longest step single-cycle period over CPI se chhota ho.
R-type MEM kyun skip karta hai?
Yeh koi memory access perform nahi karta; uska result seedha WB mein jaata hai.
Ek memory instructions aur data dono ko kaise serve kar sakti hai?
IF (fetch) aur MEM (data) alag cycles mein hote hain, kabhi simultaneously nahi.
IF ka PC+4 ALU add IF stage ko kyun nahi badhaata?
Yeh add memory read ke parallel run karta hai, toh IF delay max (200) hoti hai, sum nahi.

Parent: Multi-cycle datapath · Prereqs: Single-cycle datapath, ALU design, Memory hierarchy · Next: Pipelining, CPI and CPU performance equation.