5.3.5 · D1 · Hardware › Advanced Microarchitecture › Reorder buffer (ROB)
Ek fast processor instructions ko out of order run karta hai (jo bhi pehle apne inputs ready kar le), lekin bahar ki duniya ko results exactly usi order mein dikhne chahiye jisme tumne likhe the. Reorder buffer ek waiting line hai jo kaam ko andar se kisi bhi order mein finish hone deti hai, phir bhi results strictly sabse purane-pehle "official" bante hain.
Is page mein koi assumption nahi hai. Reorder buffer (ROB) padhne se pehle tumhare paas kuch words aur pictures honi chahiye. Hum har ek ko ground up se build karte hain, ek aisi order mein jahan har symbol use hone se pehle earn kiya ja chuka ho.
Ek instruction ek chhota sa command hota hai jo processor manta hai, jaise "yeh do numbers add karo aur answer store karo". Isse ek recipe ki single line ki tarah socho.
Hum instructions aise likhenge:
ADD R 1 , R 2 , R 3
Isko padhein: "box R 2 ki value lo, box R 3 ki value se add karo, sum ko box R 1 mein rakho." Boxes R 1 , R 2 , R 3 ko registers kehte hain — unhe hum aage define karte hain.
Intuition Yeh kyun matter karta hai
ROB jo bhi karta hai woh sab instructions ke baare mein hai: unhe ek slot dena, unhe finish hote dekhna, aur sabse purane ko permanent hone dena. Agar tum ek instruction ko ek recipe line ki tarah nahi socho, toh baad mein kuch bhi samajh nahi aayega.
Ek register processor ke andar ek chhota, named storage box hota hai jo ek number hold karta hai. Names R 0 , R 1 , R 2 , … jaise dikhte hain.
Definition Register file (RF)
Register file , jise RF likhte hain, in saare boxes ki poori shelf hai. RF [ R k ] ka matlab hai "box R k mein abhi jo number rakha hai".
Figure dekho: register file sirf labelled cups ki ek row hai. RF [ R 1 ] cup R 1 ke andar ki value ko point karta hai. Jab ek program ek instruction ko sach mein "finish" karta hai, toh answer in cups mein se ek mein daal diya jaata hai — aur ek baar daal diya, toh woh permanent aur program ko visible ho jaata hai.
Intuition Is topic ko yeh kyun chahiye
ROB ka poora kaam yahi decide karna hai ki kab safe hai register file mein result daalna. Toh pehle tumhein register file ko "official, permanent" state ki tarah dekhna hoga — woh cheez jo hum galat order mein likhne se bachana chahte hain.
Register file ke contents ko hum architectural state kehte hain: woh state jo program ko honi chahiye . Related reading: Register-file-management .
Program order woh top-to-bottom order hai jisme tumne instructions likhe. I1 pehle, I2 baad mein, I3 uske baad, hamesha.
Definition Execution order
Execution order woh order hai jisme instructions actually computing finish karti hain, jo alag ho sakta hai — ek quick add ek slow multiply se pehle finish ho sakta hai chahe woh multiply pehle likha gaya ho.
Figure mein, left column program order hai (I1, I2, I3, I4 upar se neeche). Right column mein hai jab har instruction finish hoti hai: dekho I3 pehle finish hoti hai kyunki woh fast hai, chahe woh teesre number par likhi gayi thi. Yahi mismatch ROB ke existence ki poori wajah hai — dekhein Speculative-execution aur Superscalar-processors yeh samajhne ke liye ki processors out of order finish karne ki taklif kyun uthate hain.
Common mistake Common confusion
"Out of order" ka matlab yeh nahi ki results out of order official ban jaate hain. Sirf computing out of order hoti hai. Committing (register file mein daalna) strictly program order mein rehta hai.
Definition In-flight instruction
Ek in-flight instruction woh hoti hai jo shuru ho chuki hai (issue ho chuki) lekin abhi permanent nahi bani (retire nahi hui). Woh "hawa mein" hai, abhi bhi cancellable hai.
Socho woh planes jo take off kar chuke hain lekin land nahi kiye. Ground par woh abhi kuch bhi committed nahi hain. Agar hum ek flight cancel karein (jaise ek galat branch guess), register file par koi harm nahi pahunchta. ROB woh airspace hai jo saare in-flight planes ko hold karta hai.
Har instruction teen named moments se guzarti hai. Teeno tumhein verbatim pata honi chahiye.
Definition Issue, Execute, Retire
Issue : instruction ko admit kiya jaata hai aur ek slot diya jaata hai. Program order mein hota hai.
Execute : instruction actually apna answer compute karta hai. Out of order hota hai, jab bhi inputs ready hon.
Retire (jise commit bhi kehte hain) : finished result ko register file mein daala jaata hai aur permanent ban jaata hai. Program order mein hota hai, sabse purana pehle.
Yeh trio Instruction-retirement mein puri tarah aata hai aur parent note ki backbone hai.
Definition Queue aur FIFO
Ek queue ek line hai, jaise dukaan par wait karte log. FIFO ka matlab hai "First In, First Out": jo pehle aaya woh pehle nikla. Aage dhakka dena allowed nahi.
ROB ek FIFO hai kyunki retirement program order mein honi chahiye — pehle issue, pehle retire.
Definition Circular buffer
Ek circular buffer N slots ki ek fixed row hai jahan last slot ke baad tum pehle slot par wapas loop ho jaate ho. Ek clock face socho: 12 ke baad 1 aata hai.
Figure mein N = 8 slots ek ring ki tarah dikhaye gaye hain. Is ring par do arrows rehte hain:
Definition Head aur Tail pointers
Head sabse purani in-flight instruction ko point karta hai — agli woh jo retire hone ki permission rakhti hai.
Tail agli free slot ko point karta hai — jahan newly issued instruction jaayegi.
Jaise instructions retire hoti hain, Head aage badhta hai. Jaise naye issue hote hain, Tail aage badhta hai. Dono ring ke around loop karte hain.
Parent note mein mathematics se sirf ek hi symbol use hota hai — mod . Hum ise zero se define karte hain.
a mod N ("a mod N") ka matlab hai: a ko N se divide karo aur sirf remainder rakho. Yeh sawaal ka jawab deta hai "N marks wale clock par a steps count karoon toh kahan land karunga?"
Intuition Yeh tool kyun aur plain addition kyun nahi?
Ek seedhi row par, "pointer advance karna" sirf tail = tail + 1 hai. Lekin last slot par yeh end se gir jaayega . Hume advance karne ki zaroorat hai taaki wrap karke slot 0 par wapas aaye. Modulo exactly woh wrap-around counter hai — yeh ek clock ka mathematical naam hai. Koi doosra operation "N ke baad start par loop back" nahi deta.
next_tail = ( tail + 1 ) mod N
Worked example Concrete numbers
Maan lo N = 8 . Agar tail = 7 (last slot) toh
( 7 + 1 ) mod 8 = 8 mod 8 = 0.
Pointer slot 0 par wapas wrap ho jaata hai, exactly jaisa ring picture mein dikhta hai.
Common mistake Off-by-one trap
8 mod 8 = 0 hai, 8 nahi aur 1 bhi nahi . Remainder jab 8 ko 8 se evenly divide kiya jaaye toh zero hota hai. Slots 0 … N − 1 number kiye gaye hain, toh 0 ek valid slot hai.
Do conditions decide karti hain ki ring kaam accept ya release kar sakti hai ya nahi.
Intuition "tail+1 = head" full kyun matlab hai, empty nahi
Agar hum tail ko head tak pahunchne dein, toh hum full aur empty mein fark nahi bata sakte (dono head = tail padhenge). Isliye hum jaanboojhkar ek slot hamesha empty rakhte hain spacer ki tarah. Jab tail head se sirf ek step peeche ho, ring full declare ho jaati hai. Isse ek slot ka cost aata hai lekin ambiguity door hoti hai.
Ek completed instruction jo head par nahi hai use wait karna padega — uska answer ROB slot mein baitha hai, register file mein nahi. Yeh waiting hi in-order retirement ka essence hai.
Ek tag sirf ROB slot number hai jo ek in-progress result ke liye temporary naam ki tarah use hota hai. "Register R 1 ka wait karo" ki jagah, ek instruction "ROB slot 5 ka wait karo" kehti hai.
Intuition Slot number se rename kyun karein?
Do alag instructions dono R 1 mein likh sakti hain. Akela naam "R 1 " ambiguous hai — kaunsa R 1 ? Ek unique ROB slot number kabhi ambiguous nahi hota, isliye woh us specific in-progress value ki true identity ban jaata hai. Yeh Register-renaming ka seed hai, aur yahi idea Tomasulo-algorithm aur Reservation-stations ko power karta hai.
Instruction = one recipe line
Register and register file
Architectural state = official values
Program order vs execution order
Issue Execute Retire stages
Circular buffer with Head and Tail
Modulo wrap-around counter
Full and empty conditions
Slot status pending completed exception
Tag = slot number as temporary name
Har arrow ka matlab hai "target samajhne se pehle source samajhna zaroori hai." Poora graph Reorder buffer (ROB) node mein funnel hota hai. Downstream topics jo in foundations ko reuse karte hain inmein Precise-exceptions , Branch-prediction , Memory-ordering , aur Instruction-retirement shamil hain.
Self-test: kya tum reveal karne se pehle har ek ka jawab de sakte ho?
Ek program ki ek line ek instruction kya represent karti hai? Ek chhota sa command, jaise "R2 aur R3 add karo, R1 mein store karo".
Register file RF kya hai?Permanent named boxes ki shelf jo program ki official (architectural) values hold karti hai.
RF [ R k ] kya denote karta hai?Box R k mein abhi stored number.
Program order vs execution order? Program order = likha hua top-to-bottom order; execution order = woh order jisme instructions actually computing finish karti hain.
Ek instruction ki teen life stages ke naam batao, aur kaun si in-order hain. Issue (in order), Execute (out of order), Retire/commit (in order).
FIFO ka full form kya hai aur ROB ise kyun use karta hai? First In First Out; retirement program order follow karni chahiye, toh sabse purana pehle nikalta hai.
Head pointer kya point karta hai? Sabse purani in-flight instruction, jo retire hone ki line mein agli hai.
Tail pointer kya point karta hai? Agli free slot jahan newly issued instruction place hogi.
a mod N plain words mein kya hai?a ko N se divide karne ke baad remainder — ek wrap-around clock counter.
( 7 + 1 ) mod 8 compute karo.0 — pointer slot 0 par wapas wrap ho jaata hai.
ROB ki empty condition? head = tail .
ROB ki full condition? ( tail + 1 ) mod N = head (ek spacer slot hamesha empty rakha jaata hai).
Ek slot hamesha empty kyun rakhte hain? Taaki full aur empty dono head = tail na padhen; spacer ambiguity door karta hai.
Teen slot statuses kya hain? pending, completed, exception.
Ek completed instruction register file mein kyun nahi likh sakti abhi bhi? Agar woh head par nahi hai, toh purani instructions abhi retire nahi hui hain; in-order commit isse forbid karta hai.
Tag kya hai?ROB slot number jo ek in-progress result ke liye unique temporary naam ki tarah use hota hai.