6 icsim_t::icsim_t(size_t _sets
, size_t _ways
, size_t _linesz
)
12 if(sets
== 0 || (sets
& (sets
-1)))
13 throw std::logic_error("sets not a power of 2");
14 if(linesz
== 0 || (linesz
& (linesz
-1)))
15 throw std::logic_error("linesz not a power of 2");
17 throw std::logic_error("set associativity currently unsupported");
24 tags
= new uint64_t[sets
*ways
];
25 memset(tags
, 0, sets
*ways
*sizeof(uint64_t));
30 float mr
= 100.0f
*misses
/accesses
;
31 float cr
= 100.0f
*bytes_fetched
/(4*accesses
);
33 std::cout
<< "Instruction cache statsistics" << std::endl
;
34 std::cout
<< "Bytes fetched: " << bytes_fetched
<< std::endl
;
35 std::cout
<< "Hits: " << (accesses
-misses
) << std::endl
;
36 std::cout
<< "Misses: " << misses
<< std::endl
;
37 std::cout
<< "Miss rate: " << std::setprecision(3) << mr
<< '%' << std::endl
;
38 std::cout
<< "RVC compression ratio: " << cr
<< '%' << std::endl
;
43 void icsim_t::tick(uint64_t pc
, int insnlen
)
46 bytes_fetched
+= insnlen
;
48 size_t idx
= (pc
>> idx_shift
) & idx_mask
;
49 size_t tag
= (pc
>> idx_shift
) | VALID
;