资源简介
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魔方程序
- 一个labview仿真的函数信号发生器.vi
- labview编程软件滤波器以及编写程序设
- labview语音输入输出
- labview中的DAQ助手采集多个通道电压
- Labview与CH372CH375的通信测试
- LabVIEW钢琴实例
- 编程实现二维DCT变换
- silicon lab公司的收音IC SI47XX全套开发工
- 图像二值化
- 用FFT对信号进行频谱分析
- nachos-lab 02
- Tone-Reservation
- cache参数测量程序
- QGA 量子遗传算法
- 差分形式的阻滞增长模型
- 遗传算法的M文件
- LabVIEW入门与实战开发100例190153
- LABVIEW做的蓝牙数据发送程序.vi
- VCS lab 和 VCS lab guide
- 基于labview的变声器
- 基于labview的方差标准差计算(求方差
- smart和labview通讯(smart_connet.vi)
- LabVIEW 数据采集 模拟量+编码器(Daq
- LabVIEW 声音信号的采集与存储.vi
- LabVIEW步进电机控制.vi
- 多通道数据采集.vi(labview)
- labview智能电梯(6层电梯.vi)
- 用labview编写的一个神经网络Vi图
- 基于Labview的电子秤的设计.docx
评论
共有 条评论