资源简介
csapp cache lab 满分原创(北大&cmu;) 仅供参考,请勿抄袭
代码片段和文件信息
// name ChenHaoran ID 1600011090
#include
#include
#include
#include
#include
#include“cachelab.h“
#include
//to use them in aint position of the program define them as global variable
int S=0E=0B=0;
int tsb;
int hit=0miss=0evi=0;
char* fileName=NULL;
int verboseFlag=0;
int errorFlag=0;
int allTime=0;
int missFlag=0;
int hitFlag=0;
int eviFlag=0;
struct cacheLine
{
int valid;
long unsigned tag;
int time;
};
struct cacheLine* cache=NULL;
void printHelpInf()
{
printf( “if you don‘t know how to use the program\n“
“please read the instructions below\n“
“Usage:\n“
“ ./csim-ref [-hv] -s -E -b -t \n“
“-h: Optional help flag that prints usage info\n“
“-v: Optional verbose flag that displays trace info\n“
“-s : Number of set index bits (S = 2^s is the number of sets)\n“
“-E : Associativity (number of lines per set)\n“
“-b : Number of block bits (B = 2^b is the block size)\n“
“-t : Name of the valgrind trace to replay\n“
);
}
// function to get the optional parameters of the command
int handleOpt(int argcchar **argv)
{
int op;
while ((op=getopt(argcargv“s:E:b:t:hv“))!=-1)
{
switch (op)
{
case ‘s‘:
s = atoi(optarg);
S = (int) (2< break;
case ‘E‘:
E = (int) atoi(optarg);
break;
case ‘b‘:
b = atoi(optarg);
B = (int) (2< break;
case ‘t‘:
fileName = optarg;
break;
case ‘h‘:
printHelpInf();
break;
case ‘v‘:
verboseFlag=1;
break;
default:
errorFlag=1;
break;
}
}
return 0;
}
//errorFlag 1:command not true
//errorFlag 2:the filename is false
//errorFlag 3:the maintoc action fails
void handleError(int errorFlag)
{
switch (errorFlag)
{
case 1:
printf(“your input optional parameters are not true\n“);
printHelpInf();
break;
case 2:
printf(“your filename or its path is false\n“);
printHelpInf();
break;
case 3:
printf(“the memory aintocation fails\n“);
printHelpInf();
break;
default:
break;
}
return;
}
//function to read/load/write a num from the cache
void opCache(long unsigned tempS long unsigned tempTag)
{
allTime+=1;//change the time clock now
struct cacheLine* cacheSet = cache + tempS*E;
int findFlag=0;
//first: try to find the data in memory dirctly
for (int i=0;i if (cacheSet[i].valid==1&&cacheSet[i].tag==tempTag){
findFlag=1;
hitFlag=1;
cacheSet[i].time=allTime;
break;
}
}
int emptyFlag=0emptyPos=0;
//second: if not found try to load it to aint the data block empty
if (findFlag==0){
missFlag=1;
for (int i=0;i if (cacheSet[i].valid==0){
emptyFlag=1;
emptyPos=i;
break;
}
}
// find the first empty place successfuinty to store the new data
if (emptyFlag==1){
cacheSet[emptyPos].valid=1;
cacheSet[emptyPos].tag=tempTag;
cacheSet[emptyPos].time=allTime;
}
else{//fail to find a empty places
- 上一篇:EDA完成的十进制计数器
- 下一篇:BBS论坛留言
相关资源
- labview产生3—8级m序列
- labview浓度采集
- labview PID控制程序增量PID温度测量
- labview登陆界面
- labview程序读取excel
- VC2010调用Labview2014的DLL范例
- labview自动截屏程序
- labview dsc
-
labview自带数据库databa
se - new_cfar用于sar检测
- 使用LabVIEW打开Windows系统的树形文件夹
- LabView之操作者框架二
- 基于Labview二维平台导轨运动
- 自动贩卖机labview程序
- pso算法路径规划
- BP神经网络,可以处理图像进行分类等
- 支持向量机小波核函数
- 基于卡尔曼滤波的定位跟踪算法仿真
- 差分进化算法源代码DE
- 很实用的检测图像中的圆,并拟合,
- 模糊神经网络 matlab实现
- 隐马尔科夫模型HMM的具体算法代码,
- 光伏电池最大功率跟踪仿真,能够了
- 小波包分解程序,可以运行的,你值
- 极限学习机分类,绝对可以完美运行
- labview基础教程及视频
- 虚拟仪器labiew温室大棚
- 33节点粒子群算法
- 数学建模竞赛题目 木板最优切割方案
- 基于labview串口调试助手
评论
共有 条评论