lukmac
lukmac

Reputation: 4841

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!!

Upvotes: 3

Views: 2095

Answers (1)

user3594160
user3594160

Reputation: 11

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)

Upvotes: 1

Related Questions