4.1.18 · HinglishComputer Architecture (Deep)

Pipelining — 5-stage pipeline, each stage

1,697 words8 min readRead in English

4.1.18 · Coding › Computer Architecture (Deep)


WHAT hai ek pipeline?

Classic RISC 5-stage pipeline (MIPS-style) ke stages hain:

# Stage Name Kya karta hai
1 IF Instruction Fetch PC par memory se instruction read karo
2 ID Instruction Decode / register read Opcode decode karo, source registers read karo
3 EX Execute / address calc ALU result ya memory address compute karta hai
4 MEM Memory access Load/store data memory ko read ya write karta hai
5 WB Write Back Result ko register file mein write karo
Figure — Pipelining — 5-stage pipeline, each stage

Speedup ko SCRATCH SE derive karna

HOW hum instructions ka time derive karte hain.

Maano har stage time leti hai. Ek akeli non-pipelined instruction ko saari stages chahiye:

Non-pipelined, instructions ek ke baad ek run hoti hain:

Pipelined: clock period slowest stage mein fit hona chahiye, to cycle time (balanced stages assume karte hue). Pehli instruction ko pipe fill karne mein cycles lagte hain. Uske baad, har cycle mein ek instruction finish hoti hai. To instructions ek-ek cycle add karte hain:


Throughput vs Latency


Clock faster kyun run kar sakta hai

Reality mein stages unbalanced hote hain aur registers latency add karte hain: Isliye hum stages balance karne ki koshish karte hain — slowest stage poori pace set karta hai.


Common mistakes (Steel-manned)


Active Recall

Recall 5 stages ko order mein naam bolo aur har ek ka ek kaam batao.

IF (PC par instruction fetch karo), ID (decode + registers read karo), EX (ALU compute / address calc), MEM (data memory read/write), WB (result ko register file mein likho).

Recall Max speedup stages ki sankhya ke barabar kyun hoti hai?

Kyunki bade ke liye har cycle mein ek instruction finish hoti hai (throughput ) vs non-pipelined , jo ratio hai; fill cycles negligible ho jaate hain.

Recall Kya pipelining ek single instruction ki latency reduce karta hai?

Nahi. Latency cycles par rehti hai (register overhead ke saath thodi aur buri). Yeh throughput improve karta hai.


Classic RISC pipeline ke 5 stages (order mein) kya hain?
IF, ID, EX, MEM, WB
IF stage kya karta hai?
Current PC par memory se instruction fetch karta hai.
ID stage kya karta hai?
Instruction decode karta hai aur register file se source operands read karta hai.
EX stage kya karta hai?
ALU operation perform karta hai ya memory address calculate karta hai.
MEM stage kya karta hai?
Data memory access karta hai (loads read karte hain, stores write karte hain).
WB stage kya karta hai?
Result ko register file mein wapas write karta hai.
n instructions, k stages, stage time t ke liye pipelined time ka formula?
T = (k + n - 1) * t
Ideal pipeline speedup ka formula?
S = nk / (k + n - 1), n→∞ par k approach karta hai.
k-stage pipeline ka maximum theoretical speedup kya hai?
k (stages ki sankhya).
Pipeline registers ka purpose kya hai?
Har instruction ki intermediate state ko stages ke beech latch karna taaki agle instruction se overwrite na ho.
Kya pipelining single-instruction latency reduce karta hai?
Nahi — sirf throughput improve hota hai; latency ~k cycles par rehti hai.
Pipeline clock period kya set karta hai?
Slowest stage delay plus pipeline-register overhead.
Chhota n poor speedup kyun deta hai?
Jab thodi instructions process hoti hain, k−1 fill (warm-up) cycles dominate karte hain.

Connections

Concept Map

overlaps steps of

goal

splits execution into

1

latched by

feed

feeds

feeds

feeds

cycle time set by

derives

gives

limit as n grows

Pipelining

Consecutive instructions

Higher throughput

5 RISC stages

IF Instruction Fetch

Pipeline registers

ID Decode and reg read

EX Execute or addr calc

MEM Memory access

WB Write Back

Slowest stage t

T pipe = k+n-1 times t

Speedup = nk / k+n-1

Max speedup = k stages