4.1.23 · HinglishComputer Architecture (Deep)

Superscalar — multiple execution units

1,917 words9 min readRead in English

4.1.23 · Coding › Computer Architecture (Deep)


WHAT is it?


WHY does it exist? (first-principles)

Ek single-issue 5-stage pipeline zyada se zyada ek instruction per cycle finish kar sakti hai. Lekin real code mein aisi instructions hoti hain jo ek-doosre par depend nahi karti. Example:

a = b + c     // uses b, c
d = e + f     // uses e, f  — independent of line 1!

Agar do adders idle baithein, toh hum silicon waste kar rahe hain. Puri motivation yeh hai: transistors saste hain, time keemti hai — functional units replicate karo aur independent kaam simultaneously chalao.


HOW: deriving the performance model from scratch

Universal CPU performance equation se shuru karte hain. Hum ise derive karte hain, quote nahi.

Ek program run karne ka time = (instructions ki sankhya) × (time per instruction).

jahan = dynamic instruction count, = average Cycles Per Instruction, = clock period. Ab CPI ko invert karo:

Yeh kyun matter karta hai: ek superscalar machine IPC term ko attack karti hai. Ek scalar pipeline IPC ko 1 par cap karti hai; ek N-wide superscalar ceiling ko N tak raise karta hai. Toh:

Hum IPC = N rarely kyun achieve karte hain (Amdahl-flavoured reasoning)

Maano fraction instructions perfectly N units mein parallelize ho sakti hain, aur fraction serially chalani padti hain (chained dependencies). Tab effective IPC bounded hai:


Figure — Superscalar — multiple execution units

Teen obstacles (aur superscalars unse kaise ladte hain)

Weapons:

  • Register renaming false dependencies (WAR, WAW) hatata hai ek hi architectural register name ko alag physical registers se map karke.
  • Out-of-order execution + Reorder Buffer (ROB) ready instructions ko stalled walon ko overtake karne deta hai, phir correctness ke liye order mein retire karta hai.
  • Branch prediction + speculation units ko branches ke baad bhi fed rakhta hai.
  • Multiple ports register file/caches par structural hazards khatam karte hain.

Worked Example 1 — cycles count karna, in-order, 2-wide

Code (har op 1 cycle leta hai, latency 1):

I1: r1 = r2 + r3
I2: r4 = r5 + r6     (independent of I1)
I3: r7 = r1 + r4     (needs r1 from I1, r4 from I2)
I4: r8 = r9 + r10    (independent)

2-wide, in-order, do integer ALUs.

Cycle Issued together Why this step?
1 I1, I2 Dono independent hain → dono ALUs fill karo.
2 I3 stalls? Nahi — r1,r4 C1 ke end mein ready → I3, I4 I3 ke operands C1 mein produce hue, C2 mein available; I4 independent → dono issue.

Total = 2 cycles for 4 instructions → IPC = 2 (peak!). Ek scalar machine 4 cycles leti (IPC = 1). Speedup = 2×.

Worked Example 2 — ek dependency chain ILP barbad kar deti hai

I1: r1 = r2 + r3
I2: r4 = r1 + r5     (needs r1)
I3: r6 = r4 + r7     (needs r4)
I4: r8 = r6 + r9     (needs r6)

Har instruction pichli wali par depend karti hai.

Cycle Issued Why this step?
1 I1 I2 issue nahi ho sakta, r1 abhi ready nahi. Doosra ALU idle.
2 I2 r1 ab ready hai; I3 abhi bhi r4 ka wait kar rahi hai.
3 I3 chain jaari hai.
4 I4 chain jaari hai.

4 cycles, IPC = 1 — doosre unit se koi fayda nahi. Yeh hamare formula mein hai. Steel-man lesson: width sirf tabhi help karta hai jab independent kaam exist kare.

Worked Example 3 — renaming se false dependency fix hoti hai

I1: r1 = r2 + r3
I2: r1 = r4 + r5     (WAW: r1 dobara likhta hai — lekin value independent!)

In-order naive view kehta hai "dono r1 likhte hain, serialize karo." Lekin values independent hain. Rename karo: I2 physical p7 likhta hai r1 ka physical reg reuse karne ki jagah. Ab woh saath issue hote hain, IPC = 2.

Why this step? Renaming prove karta hai ki conflict ek naming artifact tha, real data flow nahi.



Recall Feynman: ek 12-saal ke bachche ko explain karo

Socho ek kitchen hai jisme ek cook ek ek karke sandwiches bana raha hai — yeh normal CPU hai. Ek superscalar CPU ek aisi kitchen hai jisme kai cooks ek saath kaam karte hain. Agar orders independent hain ("ek ham sandwich" aur "ek cheese sandwich"), toh saare cooks saath kaam karte hain aur khaana bahut jaldi aata hai. Lekin agar ek order kehta hai "pehle bread toast karo, phir butter lagao, phir jam lagao" — har step ko pichla chahiye — extra cooks bas khade rehte hain wait karte hue. Toh zyada cooks sirf tabhi help karte hain jab share karne ke liye independent kaam ho.


Flashcards

"Superscalar" ka matlab kya hai?
Ek pipelined CPU jisme multiple execution units hain jo ek clock cycle mein ek se zyada instructions issue/complete kar sakta hai (IPC 1 se zyada ho sakta hai).
Issue width N kya hai?
Zyada se zyada itni instructions jo ek cycle mein execution units ko dispatch ki ja sakti hain; yeh IPC ki ceiling hai.
IPC aur CPI ka relationship?
IPC = 1/CPI; yeh dono reciprocals hain.
CPU performance equation?
T = N_inst × CPI × T_cycle = N_inst × T_cycle / IPC.
N units par parallel fraction p ke liye Effective-IPC formula?
IPC_eff = 1 / ((1-p) + p/N).
Real IPC N se itna kam kyun hota hai?
Data hazards (dependency chains), structural hazards, aur control hazards (branches) full parallel issue nahi hone dete.
Superscalar aur superpipelining mein fark?
Superscalar widen karta hai (zyada units → lower CPI); superpipelining deepen karta hai (zyada stages → higher clock). Orthogonal hain, aksar combine hote hain.
Register renaming kya fix karta hai?
False dependencies (WAR aur WAW) jo register names reuse karne se hoti hain, distinct physical registers se map karke.
Out-of-order execution sahi kyun rehta hai?
Instructions out of order execute hoti hain lekin Reorder Buffer ke zariye program order mein commit/retire hoti hain.
Teen hazard types?
Data, Structural, Control.
Agar p=0 (pure dependency chain) ho toh N-wide core par IPC kya hogi?
1 — jab har instruction pichli par depend karti hai toh width se koi fayda nahi.

Connections

Concept Map

uses

runs independent work

exploits

defined by

caps

inverse of

lowers

IPC less than N due to

raises real

requires

can be

Superscalar CPU

Multiple execution units

Instruction-Level Parallelism

Issue width N

IPC

CPI

Program time T

Out-of-order issue

Register renaming plus ROB

Dependencies and hazards