4.1.3 · Coding › Computer Architecture (Deep)
Intuition The 80/20 core idea
ISA ek contract hai hardware aur software ke beech mein. Yeh kehta hai: "Yeh rahe woh instructions jo main (CPU) samajhne ka waada karta hoon, woh registers jo tum use kar sakte ho, aur memory tumhe kaisi dikhti hai." Compiler/assembler is contract ke hisaab se likhta hai; silicon usse implement karta hai.
RISC vs CISC ek design philosophy ki bahas hai ki har instruction kitna bada aur fancy hona chahiye.
CISC (Complex): kam-instruction wale programs, har instruction bahut ZYADA kaam karta hai (memory-to-memory math bhi). Hardware complicated hota hai.
RISC (Reduced): bahut saari simple instructions, har ek SIRF EK chhoti cheez fast karti hai. Hardware simple hota hai, compiler zyada mehnat karta hai.
80/20: agar sirf ek line yaad rakhni ho — CISC complexity ko hardware mein pack karta hai; RISC complexity ko compiler/software mein dhakelta hai . Baaki almost saare differences usi ek choice ka consequence hain.
Instruction Set Architecture woh abstract interface hai jo ek processor software ko expose karta hai : instructions ka set, registers, memory addressing modes, data types, aur exceptions/interrupts ka behavior. Yeh woh cheez hai jo ek programmer/compiler ko jaanni chahiye; yeh is baat se independent hai ki chip physically kaise bani hai (woh internal design microarchitecture kehlata hai).
Intuition ISA vs microarchitecture (inhe confuse mat karo)
ISA = restaurant ka menu (tum kya order kar sakte ho). Example menus: x86-64, ARMv8, RISC-V, MIPS.
Microarchitecture = kitchen (chef actually kaise pakata hai). Intel aur AMD dono x86-64 implement karte hain (same menu) lekin bilkul alag alag kitchens ke saath.
Ek ISA → kai saari microarchitectures.
Intuition Woh pressure jisne CISC banaya
1970s mein, memory chhoti aur mehengi thi , aur programmers aksar haath se assembly likhte the . Toh designers chahte the:
Aisi programs jo kam bytes lein (dense code → kam memory).
Single instructions jo high-level operations ko mirror karein (haath se assembly mein aasaan).
Result: ADD [mem1], [mem2] jaisi instructions (do memory locations padho, add karo, wapas likho) — ek instruction, andar se kai steps. Yahi hai CISC .
Intuition Woh pressure jisne RISC banaya
1980s tak, compilers achhe ho gaye aur studies (Patterson, Hennessy) ne dikhaya ki compilers fancy CISC instructions almost use hi nahi karte the — woh mostly ek chhota simple subset use karte the. Saath hi, pipelining un instructions ko reward karta hai jo sab ek jaisi shape/time leti hain. Toh RISC ne kaha:
Instructions ko simple, fixed-length, regular rakho → pipeline karna aasaan.
Sirf load/store memory ko touch karein; baaki sab register-to-register kaam kare.
Smart compiler ko simple instructions ko jodne do.
Definition Load–Store architecture (RISC ka dil)
Ek load/store ISA mein, ALU/arithmetic instructions sirf registers par operate karti hain. Memory use karne ke liye tumhe explicitly pehle LOAD karna hoga register mein aur baad mein STORE karna hoga. CISC, iske baraabar, arithmetic instructions ko directly memory operands read/write karne deta hai.
Worked example Same kaam:
mem[A] = mem[A] + mem[B]
CISC (x86-style, conceptual):
ADD A, B ; one instruction: load A, load B, add, store to A
Yeh kaise kaam karta hai: hardware ka microcode andar se kai memory accesses aur ek add karta hai — tumse chhupa hua.
RISC (ARM/RISC-V-style):
LW r1, A ; load word from A into r1
LW r2, B ; load word from B into r2
ADD r1, r1, r2 ; register + register
SW r1, A ; store r1 back to A
Yeh kaise kaam karta hai: har instruction ek chhota well-defined step hai → pipeline, decode, aur time karna aasaan. Yeh step (pehle LWs) kyun? Kyunki load/store ISA mein ek ADD ko memory touch karna forbidden hai; humein data ko registers mein stage karna hoga.
Intuition Hum actually optimize kya kar rahe hain?
Performance = ek program kitni jaldi khatam hota hai. Humein ek formula chahiye jo ISA choice ko runtime se connect kare . Famous wala hai Iron Law of Processor Performance .
Intuition RISC vs CISC Iron Law ke saath kaise "khelti" hain
Dono chahti hain T chhota ho, lekin woh alag alag levers kheenchti hain:
CISC I C ghataati hai (kam, moti instructions) — lekin zyada C P I se bhugataati hai (har instruction kai cycles leti hai) aur T cy c l e ko shrink karna mushkil hota hai (complex decode).
RISC I C badhata hai (zyada, patli instructions) — lekin low C P I se jeetta hai (ideally ~1 pipelining ke zariye) aur chhota T cy c l e (simple decode → faster clock).
Koi free lunch nahi hai : tum ek factor ko doosre ke liye trade karte ho. Winner workload + technology par depend karta hai.
Worked example Iron Law ke saath Forecast-then-Verify
Ek loop do tarah compile ki gayi hai. Pehle forecast karo kaun faster hai, phir calculate karo.
Design
I C
C P I
T cy c l e
CISC
8 instr
5 cyc
0.5 ns
RISC
16 instr
1.2 cyc
0.4 ns
Forecast: RISC ke paas 2× instructions hain lekin tiny CPI aur faster clock hai — guess hai ki RISC jeetta hai.
Verify:
CISC: T = 8 × 5 × 0.5 = 20 ns.
RISC: T = 16 × 1.2 × 0.4 = 7.68 ns.
Kyun: bhale hi I C double hua, C P I ~4× giraa aur clock faster hui — product chhota hai. RISC yahan jeetta hai. ✔ (Steel-man: agar CPI barabar hoti, toh CISC ka lower IC jeetta — isliye result workload/CPI dependent hai, nature ka koi law nahi.)
Definition RISC vs CISC at a glance
Aspect
RISC
CISC
Instruction length
Fixed (e.g. 32-bit)
Variable (1–15 bytes in x86)
Memory access
Sirf load/store ke zariye
Arithmetic memory touch kar sakti hai
Instruction count/program
Zyada
Kam
CPI
Kam (~1, pipelines achhi tarah)
Zyada (multi-cycle/microcoded)
Decode complexity
Simple, hardwired control
Complex, aksar microcoded
Registers
Zyada (e.g. 16–32)
Historically kam
Complexity kahan rehti hai
Compiler / software
Hardware
Examples
ARM, RISC-V, MIPS, SPARC
x86 / x86-64, VAX, System/360
Intuition Modern truth (1985 ki textbook mat yaad karo)
Aaj line blurry hai: x86-64 chips CISC instructions ko internally RISC-jaise "micro-ops (µops)" mein translate karti hain aur unhe RISC-style pipeline mein execute karti hain. Toh ek modern Intel CPU baahir se CISC, andar se RISC-ish hai. Meanwhile ARM ne bhi bahut saari instructions add kar li hain waqt ke saath. Philosophy distinction zinda hai; strict dichotomy nahi.
Common mistake "RISC hamesha CISC se faster hota hai."
Kyun sahi lagta hai: RISC ka low CPI aur fast clock real hain, aur ARM phones mein dominant hai. Flaw: performance = I C × C P I × T cy c l e — zyada I C CPI advantage ko code-density-bound ya memory-bound workloads mein khatam kar sakta hai. Fix: koi universal winner nahi; yeh workload aur technology par depend karta hai, jaise Iron Law dikhata hai.
Common mistake "RISC = Reduced
number of instructions."
Kyun sahi lagta hai: naam literally "reduced" kehta hai. Flaw: RISC ISAs mein bahut saari instructions ho sakti hain. Jo "reduced" hai woh har instruction ki complexity/regularity hai , count nahi. Fix: isko "Reduced Instruction-Set-Complexity Computer" padho.
Common mistake "ISA aur microarchitecture ek hi cheez hain."
Kyun sahi lagta hai: dono "CPU" describe karte hain. Flaw: ISA visible contract hai; microarchitecture hidden implementation hai. AMD aur Intel ek ISA (x86-64) share karte hain lekin microarchitecture mein bilkul alag hain. Fix: menu vs kitchen.
Common mistake "Zyada registers hamesha RISC ka matlab hota hai."
Kyun sahi lagta hai: RISC ne large register files popular kiye. Flaw: register count ek consequence hai (load/store ko data stage karne ke liye registers chahiye), definition nahi. x86-64 ne bhi registers add kiye. Fix: defining test hai load/store rule + fixed-length regular encoding .
ISA kya hai? Woh abstract hardware–software contract: instructions, registers, addressing modes, aur data types jo ek processor software ko expose karta hai (is baat se independent ki chip physically kaise bani hai).
ISA vs microarchitecture? ISA = visible interface/"menu" (e.g. x86-64); microarchitecture = internal implementation/"kitchen" (e.g. Intel ka vs AMD ka same ISA ka design).
RISC vs CISC mein sabse gehri ek difference? Complexity kahan rehti hai — CISC use hardware mein dhakelta hai (fat instructions); RISC use compiler/software mein dhakelta hai (simple instructions).
Load/store architecture define karo. Arithmetic/ALU instructions sirf registers par operate karti hain; memory sirf explicit LOAD aur STORE instructions ke zariye access hoti hai. (RISC hallmark.)
Iron Law of processor performance batao. Time = IC × CPI × T_cycle (instruction count × cycles per instruction × clock period).
Derive karo ki Iron Law ke units kyun kaam karte hain. (instr/prog)·(cyc/instr)·(s/cyc): instr aur cyc cancel hote hain → s/prog = total CPU time.
CISC Iron Law ka kaun sa factor reduce karta hai, aur iska kya cost hai? IC reduce karta hai; cost hai zyada CPI aur hard-to-shrink clock period.
RISC kaun se factors favor karta hai? Low CPI (~1 via pipelining) aur chhota T_cycle; zyada IC accept karta hai.
Fixed-length encoding RISC ko kyun help karta hai? Uniform instructions decode aur pipeline aasaani se hoti hain → low CPI aur faster clock.
"RISC" ka common galat padhna kya hai? Yeh sochna ki iska matlab hai ISA mein kam instructions ; actually matlab hai har instruction ki reduced complexity .
Modern x86 CPUs line ko kaise blur karte hain? Woh CISC instructions ko RISC-jaise micro-ops (µops) mein decode karte hain aur unhe RISC-style pipeline mein chalate hain — baahir CISC, andar RISC.
Do RISC ISAs aur do CISC ISAs? RISC: ARM, RISC-V (MIPS, SPARC bhi). CISC: x86/x86-64, VAX (System/360 bhi).
Recall Feynman: ek 12-saal ke bache ko samjhao (hidden — pehle khud try karo!)
Socho ki tum ek robot ko sandwich banane ke instructions de rahe ho.
CISC robot: tum kaho "sandwich banao!" — ek badi command. Robot ke paas bahut saari built-in machinery hai saari chhoti steps figure out karne ke liye. Tumhare liye chhota, complicated robot.
RISC robot: tumhe kehna padega "bread uthao… butter lagao… cheese daalo… bread band karo." — bahut saari tiny commands. Robot simple hai aur har chhoti step super fast karta hai, lekin tum (compiler) ko zyada soochna padhta hai aur zyada bolna padhta hai.
Koi "best" nahi hai — yeh depend karta hai ki tum ek clever robot chahte ho ya ek clever instructor. Aur ISA bas un words ki list hai jo robot samajhne ka waada karta hai.
Mnemonic Split yaad rakho
"CISC = Complex In Silicon (Chip); RISC = Responsibility In Software/Compiler."
Aur Iron Law ke liye: "I C the CPI Time" → T = I C × C P I × T cy c l e .
Microarchitecture vs ISA — ISA ke neeche ka implementation layer.
Pipelining — kyun RISC fixed-length, single-cycle-shaped instructions chahta hai.
CPI and the Iron Law of Performance — woh equation jo trade-off quantify karti hai.
Microcode — CISC ki complex instructions internally steps mein kaise tooti jaati hain.
Compilers and Code Generation — jahan RISC apni complexity dump karta hai.
Addressing Modes — CISC ka rich set vs RISC ka minimal set.
Registers and the Register File — load/store ko kai registers kyun chahiye.
Caches and Memory Hierarchy — load/store discipline memory speed ke saath interact karta hai.
1970s tiny memory + hand assembly
1980s good compilers + pipelining
Memory operands in arithmetic
Easy pipelining fixed-length