1 #ifndef _RISCV_CACHE_SIM_H
2 #define _RISCV_CACHE_SIM_H
14 lfsr_t(const lfsr_t
& lfsr
) : reg(lfsr
.reg
) {}
15 uint32_t next() { return reg
= (reg
>>1)^(-(reg
&1) & 0xd0000001); }
23 cache_sim_t(size_t sets
, size_t ways
, size_t linesz
, const char* name
);
24 cache_sim_t(const cache_sim_t
& rhs
);
25 virtual ~cache_sim_t();
27 void access(uint64_t addr
, size_t bytes
, bool store
);
29 void set_miss_handler(cache_sim_t
* mh
) { miss_handler
= mh
; }
31 static cache_sim_t
* construct(const char* config
, const char* name
);
34 static const uint64_t VALID
= 1ULL << 63;
35 static const uint64_t DIRTY
= 1ULL << 62;
37 virtual uint64_t* check_tag(uint64_t addr
);
38 virtual uint64_t victimize(uint64_t addr
);
41 cache_sim_t
* miss_handler
;
50 uint64_t read_accesses
;
53 uint64_t write_accesses
;
54 uint64_t write_misses
;
55 uint64_t bytes_written
;
63 class fa_cache_sim_t
: public cache_sim_t
66 fa_cache_sim_t(size_t ways
, size_t linesz
, const char* name
);
67 uint64_t* check_tag(uint64_t addr
);
68 uint64_t victimize(uint64_t addr
);
70 static bool cmp(uint64_t a
, uint64_t b
);
71 std::map
<uint64_t, uint64_t> tags
;
74 class cache_memtracer_t
: public memtracer_t
77 cache_memtracer_t(const char* config
, const char* name
)
79 cache
= cache_sim_t::construct(config
, name
);
85 void set_miss_handler(cache_sim_t
* mh
)
87 cache
->set_miss_handler(mh
);
94 class icache_sim_t
: public cache_memtracer_t
97 icache_sim_t(const char* config
) : cache_memtracer_t(config
, "I$") {}
98 bool interested_in_range(uint64_t begin
, uint64_t end
, bool store
, bool fetch
)
102 void trace(uint64_t addr
, size_t bytes
, bool store
, bool fetch
)
104 if (fetch
) cache
->access(addr
, bytes
, false);
108 class dcache_sim_t
: public cache_memtracer_t
111 dcache_sim_t(const char* config
) : cache_memtracer_t(config
, "D$") {}
112 bool interested_in_range(uint64_t begin
, uint64_t end
, bool store
, bool fetch
)
116 void trace(uint64_t addr
, size_t bytes
, bool store
, bool fetch
)
118 if (!fetch
) cache
->access(addr
, bytes
, store
);