forked from jiangxincode/CacheSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetInput.cpp
130 lines (108 loc) · 3.18 KB
/
GetInput.cpp
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
#include "base.h"
using namespace std;
void GetInput(void)
{
short temp = 0; //for switch
puts("\nPlease input the number of the cache size(Unit:KB)");
puts("\n\t(for example:1,2,4,8,16,32,64...2^18)");
cin >> i_cache_size;
while(i_cache_size<1 || i_cache_size>= 262144 || (i_cache_size&(~i_cache_size+1))!=i_cache_size)
{
puts("\nPlease input the number of the cache size(Unit:KB)");
puts("\n\t(for example:1,2,4,8,16,32,64...2^18)");
cin >> i_cache_size;
}
puts("\nPlease input the number of the cacheline size(Unit:Byte)");
puts("\n\t(for example:1,2,4,8,16,32,64...2^18)");
cin >> i_cache_line_size;
while(i_cache_line_size<1 || i_cache_line_size>= 262144 || (i_cache_line_size&(~i_cache_line_size+1))!=i_cache_line_size)
{
puts("\nPlease input the number of the cache size(Unit:KB)");
puts("\n\t(for example:1,2,4,8,16,32,64...2^18)");
cin >> i_cache_line_size;
}
get_assoc:
puts("\nPlease input the method of assoiativity between main memory and cache:");
puts("\n\t directive_mapped:input 1");
puts("\n\t set_associative:input 2");
puts("\n\t full_associative:input 3");
cin >> temp;
switch(temp)
{
case 1:
t_assoc = direct_mapped;
break;
case 2:
t_assoc = set_associative;
break;
case 3:
t_assoc = full_associative;
break;
default:
cout << "Input Error!Please input again:" << endl;
goto get_assoc;
}
if(t_assoc == direct_mapped) //If the associativity_way is direct_mapped,the replacement polacy can be none only;
{
t_replace = none;
goto get_write;
}
else if(t_assoc == full_associative)
{
goto get_replacement;
}
else
{
puts("\nInput the how many lines in each set:");
puts("\n\t(for example:1,2,4,8,16,32,64...2^18)");
cin >> i_cache_set;
while(i_cache_set<1 || i_cache_set>= 262144 || (i_cache_set&(~i_cache_set+1))!=i_cache_set)
{
puts("\nInput the how many lines in each set:");
puts("\n\t(for example:1,2,4,8,16,32,64...2^18)");
cin >> i_cache_set;
}
}
get_replacement:
puts("\nPlease input the replacement policy:");
puts("\n\t FIFO(First In First Out):input 1");
puts("\n\t LRU(Least Recently Used):input 2");
puts("\n\t LFU(Least Frequently Used):input 3");
puts("\n\t Random:input 4");
cin >> temp;
switch(temp)
{
case 1:
t_replace = FIFO;
break;
case 2:
t_replace = LRU;
break;
case 3:
t_replace = LFU;
break;
case 4:
t_replace = Random;
break;
default:
cout << "Input Error!Please input again:" << endl;
goto get_replacement;
}
get_write:
puts("\nPlease input write policy:");
puts("\n\t Write through:input 1");
puts("\n\t Write back:input 2");
cin >> temp;
switch(temp)
{
case 1:
t_write = write_through;
break;
case 2:
t_write = write_back;
break;
default:
cout << "Input Error!Please input again:" << endl;
goto get_write;
}
}