📄 cachedoc.cpp
字号:
}
void CCacheDoc::OnWaySize8()
{
m_way_select=1;
NewBlock.CWay_Size=8;
}
void CCacheDoc::OnUpdateWaySize8(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_way_select==1);
pCmdUI->Enable(m_dark);
}
/*void CCacheDoc::OnFileOpen()
{
// TODO: Add your command handler code here
//CString Filename;
AfxMessageBox("111111111111111111");
//CFileDialog d;
//d.DoModal();
//Filename=d.GetPathName();
//char name[100];
//strcpy(name,Filename.GetBuffer(0));
}*/
BOOL CCacheDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
// TRACE("Enter doucument!");
if(!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
//获得新打开文件的文件名
GoodFile=readfile(lpszPathName);
return TRUE;
}
bool CCacheDoc::readfile(LPCTSTR filename)
{//按行读入文件,并调用translate转化成二进制代码
m_dark_begin=true;
int i=-1;
int j=-1;
FILE *fp;
//CString str="error:no such file";
//clear();
if((fp=fopen(filename,"r"))==NULL)
{
//AfxMessageBox(str);
return false;
}
while(1)
{
i++;
j++;
fscanf( fp, "%c", &buffer[i]);
while(buffer[i]==' '||buffer[i]=='\t'||buffer[i]=='\n')
fscanf(fp, "%c", &buffer[i]);
if(buffer[i]=='e')//文件结束
break;
NewBlock.CWorR=buffer[i];
//CString c;
//c.Format("%c",NewBlock.CWorR);
//AfxMessageBox(c);
fscanf(fp,"%ld",&Add_buffer[j]);
//c.Format("%ld",&Add_buffer[j]);
//AfxMessageBox(c);
/*i=0;
temp=getc(fp);
while(temp==' '||temp=='\t'||temp=='\n')
temp=getc(fp);
if(temp==EOF)
break;
while(temp!='\n'&&temp!=EOF)
{
buffer[i++]=temp;
temp=getc(fp);
if(i>=29)
break;
}
buffer[i]=0;
standard(buffer);
uptolow(buffer);
//读入一行到buffer经过规整化后,传入translate
if(!translate(&IM[N_im],buffer))
{
str="error:illeage instruction";
AfxMessageBox(str);
for(i=0;i<=N_im;i++)
{//非法语句时,清空已经读入的语句
IM[i]=0;
attr[i][0]='\0';
}
return false;
}
else
{
strcpy(attr[N_im],buffer);
N_im++;
}*/
}
fclose(fp);
return true;
}
/*void CCacheDoc::OnContunue()
{
// TODO: Add your command handler code here
// for(int kk=0;kk<9;kk++)
// {
// a1();
// //UpdateAllViews(NULL);
// Sleep(1000);
// if(this->NewBlock.CWorR=='e')
// break;
// }
}*/
void CCacheDoc::a1()
{
I_count++;
J_count++;
m_hit=0;
Ins_pointer++;
m_dark=false;
NewBlock.CCache_Size=NewBlock.CBlock_Size*NewBlock.CSet_Size*NewBlock.CWay_Size;
m_draw=true;
//this->UpdateAllViews(NULL);
this->CAddress=Add_buffer[I_count];
this->NewBlock.CWorR=buffer[J_count];
//long CAddress=144521;
///////////////////////////////////读入地址和CWorR
///////////////////////////////////Instruction+1
Ins_Set_Num=Ins_pointer%NewBlock.CSet_Size;
for(Ins_Count=0;Ins_Count<NewBlock.CWay_Size;Ins_Count++)//扫描是否hit!!!
{
if(CIns_Cache[Ins_Set_Num][Ins_Count].valid==0)
{
//srand(85647);
//Ins_Count=rand()%NewBlock.CWay_Size;
CIns_Cache[Ins_Set_Num][Ins_Count].valid=1;
CIns_Cache[Ins_Set_Num][Ins_Count].tag=Ins_pointer/4;
CIns_Cache[Ins_Set_Num][Ins_Count].dirty=0;
break;
}
else
int qq;
}
//开始数据的cache
switch (NewBlock.CWorR) {
case 'r' :
{
Count=0;
Set_Num=CAddress%NewBlock.CSet_Size;//
for(Count=0;Count<NewBlock.CWay_Size;Count++)//扫描是否hit!!!
{
if(CCache[Set_Num][Count].valid==1)//已被占用
{
if(CCache[Set_Num][Count].tag==(CAddress/4))
{
//AfxMessageBox("HIT!!!!!!!!!!!!!");
m_hit=1;
this->UpdateAllViews(NULL);
Sleep(100);
CCache[Set_Num][Count].valid=1;
CCache[Set_Num][Count].tag=CAddress/4;
CCache[Set_Num][Count].dirty=0;
//delay();
//Wait(m_timeout);
break;
}
else
//AfxMessageBox("This is Not Match!!");
//CString f;
//f.Format("%d",this->CCache[Set_Num][Count].valid);
//AfxMessageBox(f);
//wait(1);
int a;
}
else
//AfxMessageBox("This is Empty!");
int b;
}
if(m_hit!=1)//不命中目标
{
for(Count=0;Count<NewBlock.CWay_Size&&CCache[Set_Num][Count].valid==1;Count++);
//AfxMessageBox(Count);
if(Count==NewBlock.CWay_Size)//本set全满
{
//替换
srand(85647);
Count=rand()%NewBlock.CWay_Size;
CCache[Set_Num][Count].valid=1;
CCache[Set_Num][Count].tag=CAddress/4;
CCache[Set_Num][Count].dirty=0;
//AfxMessageBox("替换");
this->UpdateAllViews(NULL);
Sleep(100);
//Wait(m_timeout);
}
else
{
CCache[Set_Num][Count].valid=1;
CCache[Set_Num][Count].tag=CAddress/4;
CCache[Set_Num][Count].dirty=0;
//AfxMessageBox("miss写入");
this->UpdateAllViews(NULL);
Sleep(100);
//图形表示
}
}
}
//dcache[index*cfg.asso_way+i].dirty=true;
break;
case 'w' :
{
Count=0;
Set_Num=CAddress%NewBlock.CSet_Size;//
for(Count=0;Count<NewBlock.CWay_Size;Count++)//扫描是否hit!!!
{
if(CCache[Set_Num][Count].valid==1)//已被占用
{
if(CCache[Set_Num][Count].tag==(CAddress/4))
{
//AfxMessageBox("HIT!!!!!!!!!!!!!");
m_hit=1;
CCache[Set_Num][Count].valid=1;
CCache[Set_Num][Count].tag=CAddress/4;
CCache[Set_Num][Count].dirty=0;
this->UpdateAllViews(NULL);
Sleep(100);
break;
}
else
//AfxMessageBox("This is Not Match!!");
//CString f;
//f.Format("%d",this->CCache[Set_Num][Count].valid);
//AfxMessageBox(f);
int c;
}
else
//AfxMessageBox("This is Empty!");
int d;
}
if(m_hit!=1)//不命中目标
{
for(Count=0;Count<NewBlock.CWay_Size&&CCache[Set_Num][Count].valid==1;Count++);
//AfxMessageBox(Count);
if(Count==NewBlock.CWay_Size)//本set全满
{
//替换
srand(63454);
Count=rand()%NewBlock.CWay_Size;
CCache[Set_Num][Count].valid=1;
CCache[Set_Num][Count].tag=CAddress/4;
CCache[Set_Num][Count].dirty=0;
//AfxMessageBox("替换");
this->UpdateAllViews(NULL);
Sleep(100);
}
else
{
CCache[Set_Num][Count].valid=1;
CCache[Set_Num][Count].tag=CAddress/4;
CCache[Set_Num][Count].dirty=0;
//AfxMessageBox("miss写入");
this->UpdateAllViews(NULL);
Sleep(100);
//图形表示
}
}
}
//delay+=cfg.store_delay;
break;
case 'b':
{
Count=0;
Set_Num=CAddress%NewBlock.CSet_Size;//
for(Count=0;Count<NewBlock.CWay_Size;Count++)//扫描是否hit!!!
{
if(CCache[Set_Num][Count].valid==1)//已被占用
{
if(CCache[Set_Num][Count].tag==(CAddress/4))
{
//AfxMessageBox("HIT!!!!!!!!!!!!!");
m_hit=1;
CCache[Set_Num][Count].valid=1;
CCache[Set_Num][Count].tag=CAddress/4;
CCache[Set_Num][Count].dirty=1;
this->UpdateAllViews(NULL);
Sleep(100);
break;
}
else
//AfxMessageBox("This is Not Match!!");
//CString f;
//f.Format("%d",this->CCache[Set_Num][Count].valid);
//AfxMessageBox(f);
int e;
}
else
//AfxMessageBox("This is Empty!");
int g;
}
if(m_hit!=1)//不命中目标
{
for(Count=0;Count<NewBlock.CWay_Size&&CCache[Set_Num][Count].valid==1;Count++);
//AfxMessageBox(Count);
if(Count==NewBlock.CWay_Size)//本set全满
{
//替换
srand(8675);
Count=rand()%NewBlock.CWay_Size;
CCache[Set_Num][Count].valid=1;
CCache[Set_Num][Count].tag=CAddress/4;
CCache[Set_Num][Count].dirty=1;
//AfxMessageBox("替换");
this->UpdateAllViews(NULL);
Sleep(100);
}
else
{
CCache[Set_Num][Count].valid=1;
CCache[Set_Num][Count].tag=CAddress/4;
CCache[Set_Num][Count].dirty=1;
//AfxMessageBox("miss写入");
this->UpdateAllViews(NULL);
Sleep(100);
//图形表示
}
}
}
break;
}//End Of Switch
}
void CCacheDoc::OnUpdateEditDo(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_dark_begin);
}
void CCacheDoc::OnUpdateContinu(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_dark_begin);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -