5.3.9 · D3 · HinglishAdvanced Microarchitecture

Worked examplesBranch target buffer (BTB)

3,793 words17 min read↑ Read in English

5.3.9 · D3 · Hardware › Advanced Microarchitecture › Branch target buffer (BTB)

Yeh page ek drill hai. Parent note mein explain kiya gaya tha ki BTB kya hai; yahan hum har tarah ki situation ko ek BTB pe throw karte hain aur haath se solve karte hain. Shuru karne se pehle, ek reminder plain words mein taaki baad mein kuch bhi surprise na ho.

Hum prerequisite ideas pe bhi depend karte hain: Pipeline Hazards (kyun ek galat PC cycles cost karta hai), Instruction Cache (I-Cache) (BTB ke saath parallel mein fetch hota hai), Return Address Stack (RAS) aur Speculative Execution (jinhein BTB feed karta hai), aur Cache Organization (kyun aliasing hoti hai). Hinglish version: 5.3.09 Branch target buffer (BTB) (Hinglish).


Scenario matrix

BTB ek choti si yes/where machine hai. Sirf kuch dimensions hi outcome decide karte hain, isliye hum har case class enumerate kar sakte hain. Har row ek cell hai jise humein kam se kam ek worked example se cover karna hai.

Cell Kya yeh ek branch hai? BTB mein hai? (hit/miss) Predictor kya kehta hai Prediction sahi hai? Outcome jo humein dikhana hai
A haan miss (cold, pehli baar) full penalty, phir BTB update
B haan hit taken sahi 0-cycle, happy path
C haan hit not taken sahi pe fall through, 0 penalty
D haan hit taken galat (branch not taken) mispredict flush
E haan hit, galat tag (aliasing) forced miss → penalty
F nahi (plain add) miss sahi, koi nuksaan nahi
G haan, indirect (target badalta hai) hit but stale target taken target galat sahi direction, galat address
H zero/degenerate: branch to self () / empty BTB limiting behaviour
W real-world word problem mix mix mix average penalty compute karo
X exam twist hit taken sahi lekin BTB 1 cycle late "bubble" even on a hit

Aath lettered cells logic cases hain; W throughput problem hai; X gotcha hai. Neeche ke examples inhe sab cover karte hain.


Example 1 — Cell A: cold miss, branch ki pehli baar sighting


Example 2 — Cell B: happy path (0-cycle taken branch)


Example 3 — Cell C: hit lekin predictor kehta hai not taken


Example 4 — Cell D: hit, predicted taken, lekin branch not taken hai


Example 5 — Cell E: aliasing (sahi index, galat tag)


Example 6 — Cell F: bilkul branch nahi (common case jeet jaata hai)


Example 7 — Cell G: indirect branch with stale target


Example 8 — Cell H: degenerate / limiting inputs


Example 9 — Cell W: real-world throughput problem


Example 10 — Cell X: exam twist (hit pe bhi ek bubble)


Recall Quick self-test

Single-cycle BTB ke saath Cell B best-case penalty ::: 0 cycles Predictor "not taken" ke saath BTB hit kaun sa next PC use karta hai ::: (target ignore hota hai) Do branches ek BTB slot share karte hain lekin tag mein differ — hit ya miss ::: miss (aliasing) Indirect branch, sahi direction, stale target — kiska dosh ::: BTB ka cached target stale hai (indirect predictor chahiye) 20% branches, 60% taken, 10% failure, 2-cycle penalty ke saath, CPI cost ::: 0.024 cycles/instruction 2-cycle-latency BTB, perfectly correct hit — penalty ::: 1 cycle (latency − 1)