资源简介
程序使用C/C++混合编程,基本实现的Cache的模拟功能(通过读取trace文件得到相应的命中率),能够实现直接映射、全相联、组相联三种映射方式,其中全相联和组相联能够实现随机、LRU两种替换策略。目前三种映射方式均采用回写法,但已经定义了其它写策略的接口,可以很容易扩充。程序具有比较强的鲁棒性,能够接受一定范围的错误输入,并能够比较智能的提示用户输入。
代码片段和文件信息
/*********************************************
// base.cpp
// 1.definition of almost all globle variables.
*********************************************/
#include “base.h“
using namespace std;
/******************************************/
unsigned int long i_cache_size = 0; //cache size
unsigned int long i_cache_line_size = 0; //cacheline size
unsigned int long i_cache_set = 0; //cache set
unsigned int long i_num_line = 0; //How many lines of the cache.
unsigned int long i_num_set = 0; //How many sets of the cache.
ASSOC t_assoc = direct_mapped; //associativity methoddefault direct_mapped
REPLACE t_replace = none; //replacement policydefault Random
WRITE t_write = write_back; //write policydefault write_back
/******************************************/
/******************************************/
short unsigned int bit_block = 0; //How many bits of the block.
short unsigned int bit_line = 0; //How many bits of the line.
short unsigned int bit_tag = 0; //How many bits of the tag.
short unsigned int bit_set = 0; //How many bits of the set.
/******************************************/
/******************************************/
unsigned long int i_num_access = 0; //Number of cache access
unsigned long int i_num_load = 0; //Number of cache load
unsigned long int i_num_store = 0; //Number of cache store
unsigned long int i_num_space = 0; //Number of space line
unsigned long int i_num_hit = 0; //Number of cache hit
unsigned long int i_num_load_hit = 0; //Number of load hit
unsigned long int i_num_store_hit = 0; //Number of store hit
float f_ave_rate = 0.0; //Average cache hit rate
float f_load_rate = 0.0; //Cache hit rate for loads
float f_store_rate = 0.0; //Cache hit rate for stores
/******************************************/
bitset<32> cache_item[MAX_CACHE_LINE]; // [31]:valid[30]:hit[29]:dirty[28]-[0]:data
unsigned long int LRU_priority[MAX_CACHE_LINE]; //For LRU policy‘s priority
unsigned long int current_line = 0; // The line num which is processing
unsigned long int current_set = 0; // The set num which is processing
unsigned long int i=0j=0; //For loop
unsigned long int temp = 0; //A temp varibale
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-05-26 18:51 CacheSim\
文件 2209 2014-05-21 21:25 CacheSim\ba
文件 3689 2014-05-22 09:30 CacheSim\ba
目录 0 2014-05-26 18:50 CacheSim\bin\
目录 0 2014-05-26 18:50 CacheSim\bin\Debug\
文件 1205102 2014-05-22 15:04 CacheSim\bin\Debug\CacheSim.exe
目录 0 2014-05-26 18:50 CacheSim\bin\Release\
文件 486400 2014-05-12 22:15 CacheSim\bin\Release\CacheSim.exe
文件 1561 2014-05-22 13:23 CacheSim\CacheSim.cbp
文件 1476 2014-05-26 10:10 CacheSim\CacheSim.depend
文件 2878 2014-05-26 12:56 CacheSim\CacheSim.layout
文件 30860 2014-05-22 08:46 CacheSim\CacheSim.mmap
文件 2179 2014-05-22 08:41 CacheSim\CalcInfo.cpp
文件 420 2014-05-22 08:41 CacheSim\CreateCache.cpp
文件 1216 2014-05-22 08:42 CacheSim\FileTest.cpp
文件 10095 2014-05-22 14:47 CacheSim\functions.cpp
文件 593 2014-05-22 09:16 CacheSim\functions.h
文件 6703879 2013-10-29 13:00 CacheSim\gcc.trace
文件 3486 2014-05-21 21:10 CacheSim\GetInput.cpp
文件 6253572 2013-10-29 13:00 CacheSim\gzip.trace
文件 2747 2014-05-21 21:25 CacheSim\InitVariables.cpp
文件 204 2014-05-21 09:50 CacheSim\jiangxin.h
文件 1398 2014-05-20 16:53 CacheSim\jiangxin.trace
文件 1327 2014-05-21 09:49 CacheSim\libjiangxin.cpp
文件 2352 2014-05-22 15:04 CacheSim\LRU.cpp
文件 486 2014-05-21 09:38 CacheSim\main.cpp
文件 9453990 2013-10-29 13:00 CacheSim\mcf.trace
目录 0 2014-05-26 18:50 CacheSim\obj\
目录 0 2014-05-26 18:50 CacheSim\obj\Debug\
文件 35279 2014-05-22 09:30 CacheSim\obj\Debug\ba
文件 17152 2014-05-22 09:30 CacheSim\obj\Debug\CalcInfo.o
............此处省略22个文件信息
评论
共有 条评论