A configurable command-line cache simulator written in C. It reads hexadecimal memory-address traces, models a set-associative cache, and reports hits, misses, miss rate, and estimated execution time using least recently used (LRU) replacement.
- Configurable address, set-index, associativity, and block-offset widths
- LRU replacement within each cache set
- Per-access hit/miss output and aggregate performance statistics
- Included sample memory traces
- Warning-enabled build and smoke-test commands
Each address is divided into tag | set index | block offset. The simulator uses the set-index bits to locate a set and compares the tag against every valid line in that set. On a miss, it fills an empty line or evicts the least recently used line.
.
├── examples/ # Sample hexadecimal address traces
├── include/cachelab.h # Timing constants and result interface
├── src/cache_simulator.c # Simulator implementation
├── Makefile # Build, run, test, and clean targets
└── README.md
Requirements: a C11-compatible compiler and make.
makeThe executable is created at build/cachelab.
./build/cachelab -m 64 -s 4 -e 0 -b 4 -i examples/address01.txt -r lru| Option | Meaning |
|---|---|
-m |
Address width in bits |
-s |
Set-index bits; sets = 2^s |
-e |
Log2 of lines per set; lines = 2^e |
-b |
Block-offset bits; block size = 2^b bytes |
-i |
Hexadecimal address-trace path |
-r |
Replacement policy (currently lru) |
For this example, the simulator models 16 sets, one line per set, and 16-byte blocks.
make testThis builds the project with strict compiler warnings and runs every included trace.
- Add FIFO and random replacement policies
- Support Valgrind-style load/store traces
- Report eviction counts and per-set statistics
- Add automated unit tests and continuous integration
Aditya Raj Singh — Computer Science student at SUNY Oswego