Posts

Direct Mapped Cache

A direct-mapped cache is the simplest form of cache mapping, where each memory block is mapped to exactly one cache line.  Key Concepts of Direct-Mapped Cache Indexing : A portion of the memory address selects the cache line. Tag Comparison : The tag is stored alongside the data and compared to the incoming address. Eviction Policy : If a new block is mapped to an occupied cache line, the old block is evicted (replaced). Address Breakdown (Typical Structure) Assuming a 32-bit address and a cache with lines: Offset : Identifies bytes within a block. Index : Selects a cache line. Tag : Identifies which memory block is stored. Example (Cache with 64 Lines, Block Size = 16B) A 32-bit address layout: Offset (log₂(16) = 4 bits) Index (log₂(64) = 6 bits) Tag (32 - 6 - 4 = 22 bits)

Cache Sizes

Common cache sizes depend on the level of cache (L1, L2, L3, or L4) and the architecture (mobile, desktop, server, or embedded systems). Here’s a general breakdown: 1. L1 Cache (Instruction & Data) Size : 16KB – 128KB per core Latency : ~1-4 cycles Associativity : 4-way to 8-way set-associative Use case : Extremely fast, directly connected to the CPU core for low-latency access 2. L2 Cache Size : 256KB – 8MB per core Latency : ~10-20 cycles Associativity : 8-way to 16-way Use case : Acts as a backup for L1, slightly slower but much larger 3. L3 Cache (Shared across multiple cores) Size : 2MB – 128MB (varies by CPU type) Latency : ~30-50 cycles Associativity : 12-way to 32-way Use case : Shared between cores, reducing memory access bottlenecks 4. L4 Cache (Rare, used in some high-end CPUs & GPUs) Size : 32MB – 256MB Latency : ~100+ cycles Use case : Mostly in enterprise CPUs or GPUs for large-scale data processing Cache Sizes by Platform If we’re wor...

Cache Basics

A cache is: 1. a small memory 2. Fast Memory between the CPU and main memory that stores frequently accesos data. Key parameters: Cache Line Size : Number of bytes fetched at once (e.g., 64B). Associativity :  1. Direct-mapped,  2. set-associative,  3. or fully associative. Replacement Policy :  1. LRU,  2. PLRU,  3. Round Robin,  4. etc.

Cache Memory for RISC V

To become an expert in cache memory for RISC-V, we'll need to focus on: Cache Fundamentals – Understand direct-mapped, set-associative, and fully associative caches, along with policies like LRU, PLRU, and replacement strategies. RISC-V Cache Architecture – Study how RISC-V implementations handle cache hierarchies (L1, L2, L3) and coherence protocols (MESI, MOESI). Cache Verification – Since we're already working with UVM, mastering cache verification (hit/miss testing, replacement validation, coherence checking) will be key. Performance Optimization – Explore prefetching, write policies, and latency reduction techniques in RISC-V. Hardware Implementation – Get hands-on experience designing and optimizing cache controllers in SystemVerilog.