5.2.4 · D4 · HinglishProcessor Datapath & Pipelining

ExercisesPipeline registers and control signals

2,831 words13 min read↑ Read in English

5.2.4 · D4 · Hardware › Processor Datapath & Pipelining › Pipeline registers and control signals

Hum ek pipeline ke map ko baar baar refer karte rahenge. Shuru karne se pehle isko dekho.

Figure — Pipeline registers and control signals

Char vertical bars hain — yahi char pipeline registers hain. Left-to-right flow karte coloured chips control signals hain; har ek us stage pe drop off hota hai jo use karta hai.


Level 1 — Recognition

(Kya tum pieces ko naam de sakte ho aur map padh sakte ho?)

Recall Solution L1.1

Char pipeline registers hain (ek wall neighbouring stages ke beech hoti hai, toh 5 stages se 4 gaps milte hain):

  • IF/ID — Fetch aur Decode ke beech
  • ID/EX — Decode aur Execute ke beech
  • EX/MEM — Execute aur Memory ke beech
  • MEM/WB — Memory aur Write-back ke beech

WB ke baad koi register nahi hai: WB register file mein likhta hai, jo khud stateful storage hai. Toh count hai 4, 5 nahi.

Recall Solution L1.2

Inhe us stage ke hisaab se group karo jo signal use karti hai:

  • EX bundle (Execute mein use hota hai): ALUSrc, ALUOp, RegDst
  • MEM bundle (Memory mein use hota hai): MemRead, MemWrite, Branch
  • WB bundle (Write-back mein use hota hai): RegWrite, MemtoReg

Toh EX 3 consume karta hai, MEM 3, aur WB 2.

Recall Solution L1.3

Saare signals ID (Decode) mein generate hote hain. Sirf ID opcode padhta hai; jab tak ek instruction EX/MEM/WB tak pahunchti hai, instruction word consume ho chuka hota hai aur woh stages sirf data + already-latched control bits dekhti hain. Toh decode ek baar hota hai, ID mein, aur results travel karte hain.


Level 2 — Application

(Signals trace karo aur widths compute karo.)

Recall Solution L2.1

RegWrite ID mein decode hota hai lekin use sirf WB mein hota hai (3 stages baad). Ise har intermediate wall se guzarna hoga:

  • ID/EX mein latch hota hai (EX use nahi karta → carried).
  • EX/MEM mein copy hota hai (MEM use nahi karta → carried).
  • MEM/WB mein copy hota hai (WB se pehle yeh last wall hai).
  • WB mein use hota hai register-file write-enable drive karne ke liye, result $t0 mein likhne ke liye.

Toh yeh ID/EX, EX/MEM, MEM/WB — teen registers — mein rehta hai aur WB mein consume hota hai.

Recall Solution L2.2

Har woh field add karo jo baad ki stage ko chahiye (jo store nahi hua wo EX ke aage jane par kho jaata hai):

Recall Solution L2.3

Note karo ki MEM/WB, EX/MEM se narrower hai (71 < 107): isne MEM bundle, store data, branch target, aur Zero flag drop kar diya — woh sab WB mein use nahi hote.


Level 3 — Analysis

(Behaviour explain aur diagnose karo.)

Recall Solution L3.1

Jab lw ka result WB tak pahunchta hai, lw instruction 4 cycles pehle fetch hui thi; IF/ID ab ek alag, younger instruction hold karta hai. Us instruction ke bits 20–16 koi unrelated register number hain. Toh WB loaded word ko galat register mein likhega — $s0 mein nahi.

Fix (correct design): 5-bit destination ko ID mein decode karo aur ID/EX → EX/MEM → MEM/WB tak latch karo, taaki WB sahi, purani instruction ka apna target use kare. Figure mein upar dest-# chip ko WB tak travel karte dekho.

Recall Solution L3.2

Branch target EX mein ek adder se compute hota hai: Value Fetch mein generate hoti hai lekin EX mein chahiye hoti hai. Agar yeh sirf IF/ID mein rehta, toh EX tak aate aate gone ho jaata aur target adder ka pehla operand hi nahi hota. Toh PC+4 IF/ID → ID/EX (→ EX/MEM agar branch MEM mein resolve ho) ride karta hai, bilkul kisi bhi doosri value ki tarah jo early produce aur late consume hoti hai.

Recall Solution L3.3

Sizes: , , .

  • ID/EX mein EX+MEM+WB control bits hain.
  • EX/MEM mein MEM+WB control bits hain (EX bundle consumed & dropped).
  • MEM/WB mein WB control bits hain (MEM bundle consumed & dropped).

: strictly decreasing, kyunki har register woh bundle drop karta hai jo abhi use hua. Figure mein shrinking chip-stack dekho.


Level 4 — Synthesis

(Design aur combine karo.)

Recall Solution L4.1

Count karo ki har bundle kitne registers mein rehti hai:

  • EX bundle (3 bits): sirf ID/EX mein store hoti hai (EX mein consume hoti hai) → .
  • MEM bundle (3 bits): ID/EX aur EX/MEM mein store hoti hai (MEM mein consume hoti hai) → .
  • WB bundle (2 bits): ID/EX, EX/MEM, MEM/WB mein store hoti hai (WB mein consume hoti hai) → .

Total control flip-flops bits.

Per-register sums se cross-check: . ✓

Recall Solution L4.2

Yeh pipeline registers mein sabse wide hai — yeh decode ke baad directly khada hai aur sab kuch carry karta hai jo downstream stages ko kabhi bhi chahiye hoga.

Recall Solution L4.3

Pehle IF/ID: Grand total: edge-triggered storage sirf pipeline registers ke liye (data + control), register file aur memories ke alawa.


Level 5 — Mastery

(Poore design mein constraints ke saath reason karo.)

Recall Solution L5.1

MulEnable ID mein decode hota hai (opcode-derived, sabhi control ki tarah) aur EX mein consume hota hai. Ise ID se EX tak preserve karna hoga, yaani sirf ID/EX mein latch hoga (1 bit). Kyunki EX use consume karta hai, yeh drop ho jaata hai aur EX/MEM mein kabhi nahi jaata.

  • ID/EX 1 bit se bada hoga ().
  • EX/MEM, MEM/WB: unchanged.

Yeh existing EX bundle jaisa hi hai: ID mein paida, ek wall carry, use ke baad drop.

Recall Solution L5.2

Ise ID se apne last use (WB) tak survive karna hai. Toh yeh ID/EX, EX/MEM, aur MEM/WB mein latched hoga — WB-only signal jaisi hi span, kyunki "kitna far travel karta hai" uske latest consumer se set hota hai, na ki kitni stages padhti hain se.

  • Flip-flop cost: bits (ek per register jisse guzarta hai).
  • WB-only signal bhi wahi 3 bits cost karta hai. MEM mein bhi padhna koi extra storage nahi add karta — wire simply MEM mein tap hota hai raaste mein.

Key principle: transport cost sirf last stage par depend karta hai jo signal chahti hai.

Recall Solution L5.3

Storage compare: ID/EX, EX/MEM, MEM/WB mein se har ek mein 6-bit opcode carry karna bits cost karta hai — standard 15 bits se zyaada. Toh yeh flip-flops bhi nahi bachata. Correctness: ise kaam karaya ja sakta hai (har stage carried opcode se apna bundle re-decode kare), lekin yeh control-unit decode logic ko har stage mein duplicate karta hai, har stage ke critical path mein combinational delay add karta hai aur verification complicated ho jaati hai. Standard design ID mein ek baar decode karta hai aur sirf results transport karta hai — bits aur logic dono mein sasta. Verdict: lazy scheme dono axes pe worse hai (18 > 15 bits, plus replicated decoders). Classic "decode once, transport" jeetta hai.


Recall Master summary (saare levels finish karne ke baad hi kholo)
  • 4 registers, 32-bit MIPS ke liye total 383 bits store karte hain (64 + 141 + 107 + 71).
  • Control ID mein ek baar decode hota hai; ID/EX (8), EX/MEM (5), MEM/WB (2) mein total 15 control flip-flops hain.
  • Ek signal ki storage span uske latest consumer se set hoti hai; har register consumed bundles drop karta hai, toh control width strictly shrink hoti hai .

Connections

  • Single-cycle datapath — jahaan control combinational aur un-pipelined tha
  • Pipeline hazards — in staggered signals aur results ke overlap karne ki wajah se paida hote hain
  • Forwarding and stalling — woh fix jo values inhi registers se padhta hai
  • Control unit design — ID-stage signals pehle place mein kaise generate hoti hain
  • Clocking and edge-triggered flip-flops — walls clock edge pe kyun latch karte hain