The second design implements a highly configurable cache controller using SystemVerilog. It features a 4-way set associative cache by default, but can be parameterized for different configurations. The design follows a modular approach with separate components for the tag array, data array, and replacement policy logic.
ADDR_WIDTH
: 32 bits (CPU address width)DATA_WIDTH
: 32 bits (CPU data width)LINE_SIZE
: 64 bytes (Cache line size)NUM_SETS
: 64 (Number of cache sets)ASSOCIATIVITY
: 4 (Ways per set)CACHE_SIZE
: 16,384 bytes (Total cache capacity)
The top-level module manages the FSM and coordinates between CPU, memory, and cache components. It decodes addresses into tag, index, and offset components and maintains the cache state.
Stores and manages the tag information for each cache line, including:
- Tag bits
- Valid bit
- Dirty bit The module handles tag comparisons for hit detection and way selection.
Stores the actual cached data and supports:
- Single word reads/writes (for CPU operations)
- Full line reads/writes (for memory transfers)
Implements a replacement policy using a tree-based Least Recently Used algorithm:
- Maintains replacement state for each set
- Handles hit updates to track usage
- Provides replacement way selection on cache misses
The controller operates using a 6-state FSM:
IDLE
: Waits for CPU requestsTAG_CHECK
: Checks if address hits in cacheMEM_UPDATE
: Handles cache hits for reads/writesWRITEBACK
: Writes dirty cache lines to memoryFETCH
: Retrieves new cache lines from memoryCACHE_READ
: Completes read operation after fetch
- Address, data, and control signals for CPU read/write operations
- CPU ready signal for handshaking
- Address, data, and control signals for memory operations
- Memory ready signal for handshaking
- Parameterized Configuration: All key dimensions can be adjusted via parameters
- Modular Design: Separate modules with clear interfaces
- Full FSM Control: Well-defined state transitions for all cache operations
- Scalable Replacement: Tree-based LRU implementation that scales with associativity
- Clean Timing: State machine design with clear clock boundaries
- Write-back policy to reduce memory traffic
- Set associativity to reduce conflict misses
- LRU replacement to optimize cache utilization
- Full cache line transfers for memory efficiency
This design represents a modern cache controller architecture suitable for processors requiring good memory performance with configurable cache parameters to meet system requirements.