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 Questions on This Chapter (6)
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?
A non-pipelined processor runs at () with average . A 5-stage pipelined version has stage delays plus pipeline latch overhead , and achieves due to stalls. What is the speedup of the pipelined processor over the non-pipelined processor?
A processor has an L1 cache with hit time and hit rate , an L2 cache with hit time and local hit rate , and main memory access penalty (hierarchical inclusive serial lookup: L2 accessed only on L1 miss; RAM accessed only on L2 miss). What is the Average Memory Access Time (AMAT) in nanoseconds?