Repository navigation
Expand file tree
/
Copy pathnru.h
More file actions
143 lines (102 loc) · 2.8 KB
/
Copy pathnru.h
File metadata and controls
143 lines (102 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include<bits/stdc++.h>
using namespace std;
static long long int **cacheNru;
static int **validNru , **referencedNru ;
void check(long long int setNumber,int noOfWays)
{
int i;
//printf("inside check\n");
for ( i = 0; i < noOfWays; ++i)
{
//printf("%d is way,%d is referencedNru\n",i,referencedNru[setNumber][i]);
if(referencedNru[setNumber][i] == 0)
return;
}
for ( i = 0; i < noOfWays; ++i)
{
referencedNru[setNumber][i] = 0;
}
}
void replacement(long long int setNumber,long long int tagNumber,int noOfWays)
{
int i;
for(i=0;i<noOfWays;i++)
if(validNru[setNumber][i] == 0)
{
validNru[setNumber][i] = 1;
cacheNru[setNumber][i] = tagNumber;
referencedNru[setNumber][i] = 1;
check(setNumber,noOfWays);
referencedNru[setNumber][i] = 1;
return;
}
for(i=0;i<noOfWays;i++)
if(referencedNru[setNumber][i] == 0)
{
// validNru[setNumber][i] = 1;
referencedNru[setNumber][i] = 1;
cacheNru[setNumber][i] = tagNumber;
check(setNumber,noOfWays);
referencedNru[setNumber][i] = 1;
return;
}
}
/*
void displ(int setno)
{
for(int j=0;j<noOfWays;j++)
printf("%d is way %lld is tag and %d is validNruity and %d is referencedNru\n",j,cacheNru[setno][j],validNru[setno][j],referencedNru[setno][j]);
printf("\n\n");
}*/
int nru(long long int tagNumber, int setNumber,int noOfWays,int size)
{
int i,j,hits=0, flag = 0;
static int noOfSets = pow(2,15)/ (noOfWays*size);
static int count = 0;
// cout << setNumber << "is setnumber and " << tagNumber<< "is tagnumber\n";
// printf("creating sets\n");
// printf("sets initialized with memory\n");
if(count == 0)
{
cacheNru = (long long int **)malloc(noOfSets * sizeof(long long int *));
validNru = (int **)malloc(noOfSets * sizeof(int *));
referencedNru = (int **)malloc(noOfSets * sizeof(int *));
for (i=0; i<noOfSets; i++)
{
cacheNru[i] = (long long int *)malloc(noOfWays * sizeof(long long int));
validNru[i] = (int *)malloc(noOfWays * sizeof(int));
referencedNru[i] = (int *)malloc(noOfWays * sizeof(int));
}
for (int i = 0; i < noOfSets; ++i)
{
for (int j = 0; j < noOfWays; ++j)
{
validNru[i][j] = 0;
cacheNru[i][j]= 0;
referencedNru[i][j] = 0;
}
}
count = 1;
}
// printf("starting nru simulation\n");
// for(i=0;i<size;i++)
// flag = 0;
// setNumber = setValue[i];
// tagNumber = tagValue[i];
//printf("%d is setNumber and %lld is tagNumber\n",setNumber,tagNumber );
for(j=0;j<noOfWays;j++)
{
if(cacheNru[setNumber][j] == tagNumber)
{
// flag = 1;
referencedNru[setNumber][j] = 1;
check(setNumber,noOfWays);
referencedNru[setNumber][j] = 1;
//displ(setNumber);
//printf("\nhit at position %d\n",j);
return 1;
}
}
replacement(setNumber,tagNumber,noOfWays);
return 0;
}