DIRECT MAPPED CACHE:

#### What is a cache? In modern computer systems, cache memory serves as a small, fast memory layer between the CPU and the slower main memory (RAM). It stores frequently accessed data and instructions to reduce access latency and improve overall system performance.

  • When the CPU needs data, it first checks the cache:

  • If the data is found, it’s a cache hit (faster access).

  • If not, it’s a cache miss, and the data is fetched from main memory and placed in the cache.

Types of Cache Mapping:

There are three primary techniques to map memory blocks to cache lines:

  • Direct-Mapped Cache: Each memory block maps to exactly one cache line. It is Simple and fast but there is Higher chance of conflict misses.

  • Fully Associative Cache: Any memory block can go into any cache line. It is Very flexible but Expensive and slower to implement (requires searching all tags)

  • Set-Associative Cache: A compromise between the above two: the cache is divided into sets, and each set has multiple ways (lines). It Balances between cost and flexibility and is Slightly more complex than direct-mapped

What is a Direct-Mapped Cache?

A direct-mapped cache maps each memory block to exactly one cache line using the index bits derived from the memory address.

Specifications of Our Direct-Mapped Cache:

Our first implementation is a direct-mapped cache with the following configuration:

Parameter Value
Cache Size 1 KB (1024 bytes)
Block Size 128 bits (16 bytes)
Line Size 64 lines
Tag Bits 24 bits
Valid Bit 1 bit
Dirty Bit 1 bit
Total Bits/Line 154 bits

TOP LEVEL DIAGRAM:

Inputs:

Signal Width Direction Description
req_type 1 bit Input Request type: 0 = Read, 1 = Write
req_valid 1 bit Input Indicates a valid request from CPU
address 32 bits Input Address for read/write operation
data_in 32 bits Input Data input from CPU (for writes)
data_out 32 bits Output Data output to CPU (for reads)
data_in_mem 128 bits Input Cache line (block) fetched from memory
clk 1 bit Input Clock signal
rst 1 bit Input Reset signal

Outputs:

Signal Width Direction Description
req_type 1 bit Output Pass-through or processed request type (read/write)
address 32 bits Output Address to memory or next stage
dirty_blockout 128 bits Output Dirty block sent to memory if eviction occurs

DataPath

Datapath (Brief)

## βš™οΈ Module-by-Module Explanation

1️⃣ cache_decoder

Port Width Direction Description
clk 1 bit Input Clock signal
address 32 bits Input CPU address
tag 24 bits Output Upper bits [31:8], used for tag comparison
index 6 bits Output Bits [7:2], used to locate cache line
blk_offset 2 bits Output Bits [1:0], used to select word within a block

2️⃣ cache_controller

div align="center">