How psnjk/simplecache works
Project Type and Purpose
• This is an FPGA-based hardware simulation project, written in Verilog, that implements and demonstrates a simple direct-mapped cache co-working with a RAM module.
• The goal is to simulate cache hits and misses: reads go through the cache (on miss it fetches from RAM), writes go to RAM (and update cache line if it’s present).
File Structure Analysis
• Top-level directory
• Completed/ ← Quartus project files (.mpf) and Verilog sources & testbenches
– cache.v
– ram.v
– cache_and_ram.v
– testbench.v, testbench2.v
– cache.v, cache_and_ram.v, ram.v under work/ for synthesis database
• LICENSE
• README.md
• Key observation: a single top-level module (cache_and_ram) instantiates two submodules (cache, ram) and is driven by testbench(es).
README Insights
• Three main modules:
• ram.v – 4096-word 32-bit RAM
• cache.v – 64-line direct-mapped cache with valid bits and tag storage
• cache_and_ram.v – glue logic: on read/write inputs, splits 32-bit address into tag & index, does hit/miss logic, updates cache or RAM
• Clocked always block triggers read or write on mode signal, outputs 32-bit data.
a. Main Components
• Testbench/CPU Interface (stimulus generator)
• cache_and_ram (Top-level)
• ↳ Cache submodule
• ↳ RAM submodule
b. Relationships and Data Flows
• Address bus (32-bit) and Data bus (32-bit) and control line (“mode”: read=0/write=1) flow from Testbench into cache_and_ram.
• cache_and_ram splits the address into index and tag:
– index → selects one of 64 cache lines
– tag → compared against tag_array at that index
• On read: if valid & tag match → return cache.data[index] → out; else → read ram.data[address], update cache.data[index] & tag_array[index], set valid_array[index], then out.
• On write: always write ram.data[address] = data; if cache line matches index+tag → overwrite cache.data[index].
c. Architectural Patterns & Principles
• Hierarchical design: top-level module instantiates lower-level modules
• Single-port synchronous memories (cache, ram) as reg arrays
• Direct-mapped cache: fixed one-to-one mapping of memory blocks to cache lines
d. Technologies & Frameworks
• Verilog HDL modules, simulated in Quartus (project .mpf files)
• Testbench harness generates clock and stimuli
Details to Capture
• Hierarchical instantiation relationships
• Data width and bus labels
• Hit/miss logic flow (include small conditional symbol)
• Update rules for valid_array and tag_array
• Clock domain (all synchronous to clk)