5-Stage Instruction Pipelining, Hazards & Cache Mapping Bit Math
Clock cycle formulas, stall penalties, operand forwarding, and Direct vs K-Way Set-Associative Tag/Index/Offset splits.
Physical Address Bit Split for Cache Mapping
Suppose Main Memory has bytes (-bit physical address), Cache size bytes, and Block (Line) size bytes:
- Number of Cache Lines:
- Block Offset bits:
| Mapping Scheme | Sets () | Index / Set Bits | Tag Bits | Comparator Count |
|---|---|---|---|---|
| Direct Mapped | ||||
| -Way Set Associative | ||||
| Fully Associative | bits |
Tag Directory Size: Always multiply the number of Cache Lines () by (Tag bits + Valid bit + Dirty bit + LRU bits)! Increasing associativity by a factor of decreases Set Index by bit and increases Tag by bit.
Data Hazard Classification
For instruction followed by instruction :
- RAW (Read After Write — True Dependency): reads a register before writes it. Solved via Operand Forwarding (except Load-Use hazard which still costs stall cycle!).
- WAR (Anti-Dependency) & WAW (Output Dependency): Name dependencies — eliminated completely by Register Renaming in out-of-order processors.
🎯 Practice PYQs on This Topic (4)
A computer has a -bit physical address space and a 4-way set-associative cache of total capacity with a cache block size of . How many bits are in the Tag field of the physical address?
A 4-way set-associative cache has block (line) size of in a system with a -bit physical address. How many bits are in the Tag field?
In a standard in-order 5-stage RISC instruction pipeline (IF, ID, EX, MEM, WB), which data hazard can actually occur and require stalling or operand forwarding?
An L1 cache has access time and hit ratio . Main memory access penalty on a cache miss (including block fill) is . Under simultaneous/hierarchical model , what is the Average Memory Access Time?