Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CPU Cache implementation in C or C++ or SystemC

I need a very basic C or C++ source code of CPU cache. Google didnt help me find a proper one. The implementation only needs to provide the most fundamental functionality of a cache. For ex, in C++:

class Cache{
  ... //parameter setup of way, capacity, etc
  public: access(addr){
             miss=inspect(addr);
             if(miss){ fetch_mem(addr); replace_policy...;}
             else{...}              
           }
 ...
};

Does someone know some source code as such?

Thanks!!

like image 702
lukmac Avatar asked Feb 16 '26 17:02

lukmac


1 Answers

my 2 cents: use the strategy pattern so to be able to model different "most fundamental functionality of a cache" ideas. obviously, you already have some kind of implementation. one thing you might consider is looking at your code include cache sizes parameters, to try simulate L1 versus L2 (although it is much more complicate in real life)

like image 128
user3594160 Avatar answered Feb 19 '26 05:02

user3594160



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!