Load - store architecture model
5.1.9· Hardware › Instruction Set Architecture (ISA)
Load/store architecture kya hai?
YEH DESIGN KYO? Teen key reasons:
- Uniform instruction timing: Memory access unpredictable hoti hai (cache hits/misses). Isse alag karne se non-memory instructions fast aur predictable ban jaati hain.
- Simplified hardware: ALU ko memory interface logic ki zaroorat nahi. Decode simpler hoti hai (fewer instruction formats).
- Compiler optimization: Explicit data movement register allocation aur instruction scheduling ko optimize karna aasaan banata hai.
Alternative: Register-memory architectures
x86 se contrast (ek register-memory architecture):
; x86 yeh kar sakta hai:
ADD [memory_addr], EAX ; Read memory, add EAX, write back
; RISC load/store require karta hai:
LDR R1, [memory_addr] ; Load into register
ADD R1, R1, R2 ; Operate on registers
STR R1, [memory_addr] ; Store backx86 "better" kyun lagta hai: Fewer instructions! Lekin x86 ka ADD complexity hide karta hai—yeh actually internally 3 operations kar raha hai, aur iska timing cache behavior ke basis par wildly vary karta hai.
RISC actually better kyun hai:
- Har instruction ek kaam karta hai → pipelining aasaan hai
- Predictable timing → real-time deadlines meet karna aasaan
- Simpler decode → kam power, higher clock speeds
Performance advantage derive karna
First principles se shuru karte hain:
-
Execution time = (Number of instructions) × (Cycles per instruction) × (Clock period)
-
CPI alag kyun hoti hai?
- Register-memory: Har instruction memory ka wait karke stall ho sakti hai (variable latency)
- Load/store: Memory ops explicit aur isolated hoti hain, isliye pipeline ko exactly pata hota hai kab stall karna hai
-
Example scenario: Memory se do numbers add karna x86 (register-memory):
ADD [0x1000], EAX ; ~10 cycles if cache missARM (load/store):
LDR R1, [R0] ; ~10 cycles if cache miss ADD R1, R1, R2 ; ~1 cycle (register op) STR R1, [R0] ; ~10 cycles if cache missARM mein 3 instructions hain vs. 1, lekin:
- ARM loads/stores hone ke dauran ADD ko pipeline kar sakta hai
- ARM independent loads ko reorder kar sakta hai (out-of-order execution aasaan)
- ARM ka simple decoder 3 GHz par chalta hai vs. x86 ka 2.5 GHz (example numbers)
-
Average CPI nikalna (yeh "4" kahan se aaya?): Do memory ops mein se har ek miss par ~10 cycles lagti hai, ALU op ~1 cycle. Lekin woh numbers per-instruction latencies hain, throughput CPI nahi. Kyunki ek pipelined machine yeh instructions overlap karti hai, effective per-instruction cost bahut kam hoti hai. Aaiye explicitly compute karte hain.
Maano steady-state pipelining mein, ek cache miss pipe ko stall karta hai lekin baad ki independent instructions issue hoti rehti hain. Ek common textbook approximation hai:
Maano 3-instruction ARM sequence, overlap ke saath, 12 pipeline cycles total mein complete hoti hai (ek memory miss largely doosre kaam ke peechhe chupi hai, plus base pipeline fill):
x86 ke liye, single fused instruction apni internal read-modify-write ko overlap nahi kar sakti, isliye iska per-instruction cost poore ~10-cycle latency par rehta hai:
Isliye load/store ka low CPI (4) register-memory ke high CPI (10) ko haraata hai, zyada instructions hone ke bawajood.
-
Net result:
(Simplified hai, lekin trade-off dikhata hai. Practice mein, ARM aksar better pipelining ki wajah se jeetta hai.)
Recall Ek 12-saal ke bachche ko explain karo
Socho tum math homework kar rahe ho. Tumhare paas ek calculator hai (CPU registers) aur ek backpack full of notes (memory).
Load/store architecture = Ek strict teacher kehta hai: "Tum sirf apni desk par rakhi cheezein use kar sakte ho. Agar tumhe backpack se kuch chahiye, pehle bahar nikalo (load). Jab kaam ho jaaye, wapas rakh do (store). Tum backpack mein haath daalkaar math nahi kar sakte!"
Register-memory architecture = Ek relaxed teacher kehta hai: "Backpack se jo chahiye lo aur seedha wahan calculate karo."
Strict teacher ka rule better kyun hai? Kyunki:
- Jab sab kuch desk par ho toh tum tez kaam karte ho (registers memory se 100x faster hain)
- Tumhe pata hota hai exactly kab tum backpack mein reach kar rahe ho (predictable timing)
- Tumhari desk organized rehti hai (simpler hardware)
Trade-off: Tumhe badi desk chahiye (zyada registers) apne saare papers rakhne ke liye!
Load/store architectures ki key characteristics
1. Instruction format regularity
Yeh matter kyun karta hai: Simpler decode logic, faster instruction fetch.
Saari memory instructions ka same format hai:
Saari ALU instructions:
x86 se contrast: 1000 se zyada instruction variants, variable length (1-15 bytes), complex addressing modes.
2. Large register files
Kyun? Kyunki memory directly accessible nahi hai, isliye tumhe workspace chahiye.
| Architecture | Type | Registers |
|---|---|---|
| ARMv7 (32-bit) | Load/store | 16 registers R0–R15, lekin sirf R0–R12 truly general-purpose hain (R13=SP, R14=LR, R15=PC special hain) |
| AArch64 (ARM 64-bit) | Load/store | 31 general-purpose (X0–X30) |
| MIPS | Load/store | 32 general-purpose |
| RISC-V | Load/store | 32 general-purpose |
| x86 (32-bit) | Register-memory | 8 general (16 in x86-64) |
Register count derive karna:
Maano ek typical loop body use karta hai:
- 2-3 array pointers (base addresses)
- 3-4 loop variables (counters, temporaries)
- 2-3 intermediate calculation results
Minimum zaroorat: ~8-10 registers.
Lekin compiler optimization ke liye, tumhe iska 2-3× chahiye taaki compiler:
- Loops unroll kar sake (variables ki parallel copies chahiye)
- Frequently-used values iterations ke across "alive" rakhe
- "Spilling" se bache (registers ko memory mein wapas likhna)
Isliye: 32 registers = practical sweet spot (zyada hone par encoding bits bahut zyada lag jaati hain). Yahi wajah hai ki newer AArch64 31 GPRs tak jump kiya, jabki older 32-bit ARMv7 ne sirf 16 total (jinmein se ~13 general hain) se kaam chalaya.
3. Explicit memory ordering
Load/store programmers/compilers ko data movement ke baare mein sochne par majboor karta hai:
// C code
x = a[i] + b[i];
y = c[i] + d[i];Compiler ko generate karna padta hai:
LDR R1, [a, i] ; Yeh 4 loads
LDR R2, [b, i] ; compiler dwara
LDR R3, [c, i] ; optimal cache
LDR R4, [d, i] ; usage ke liye reorder ho sakte hain!
ADD R5, R1, R2
ADD R6, R3, R4
STR R5, [x]
STR R6, [y]Ek register-memory ISA mein, ADD [mem], reg mein implicit memory access yeh optimization opportunities hide kar deta hai.
Modern reality: Hybrid approaches
Observation: Pure load/store jeet gaya. Aaj ke almost saare high-performance CPUs load/store hain:
- ARM (phones, Apple M-series, servers)
- RISC-V (emerging)
- MIPS (legacy embedded)
- PowerPC (legacy servers)
Lekin: x86 bhi internally convert karta hai! Modern x86 CPUs:
- Complex x86 instructions ko simpler micro-ops (μops) mein decode karte hain
- Yeh μops load/store style ke hain
- RISC-like core par execute hote hain
Toh x86 ko dono duniya ka bura milta hai: complex decode + load/store execution. Isliye mobile mein ARM jeet raha hai (power efficiency).
Connections
- RISC vs CISC philosophy: Load/store defining RISC characteristic hai
- Instruction pipelining: Simple instructions efficient pipelines enable karte hain
- Register allocation: Compilers ko load/store architectures ke liye bahut registers chahiye
- Memory hierarchy: Explicit loads/stores cache behavior ko compiler ke liye expose karte hain
- Addressing modes: Load/store addressing mode complexity ko limit karta hai
- Instruction encoding: Uniform formats opcode space bachate hain
Flashcards
Load/store architecture kya hai? :: Ek ISA jahan sirf load aur store instructions memory access karti hain, aur saari arithmetic/logic operations exclusively registers par kaam karti hain. Isse register-register architecture bhi kaha jaata hai.