-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBlock.java
More file actions
81 lines (59 loc) · 1.59 KB
/
Block.java
File metadata and controls
81 lines (59 loc) · 1.59 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
// Cache Project (ECE 521)
// Neal O'Hara
// ngohara @ ngohara@ncsu.edu
// 10/4/2013
/* Blocks functions
createBlock(Integer )
getAddress()
getCountLRU()
incrementCountLRU(int )
isValid()
isDirty()
setDirty()
*/
// All Addresses are 32 bits,
// Addresses are addressed in hexadecimal format
// Addresses are divided into parts via
// (MSB) Tag | Index | Block offset (LSB)
// num_block_offset = log_2(blockSize)
// num_index_bits = log_2(numSets)
// num_tag_bits = 32 - num_index_bits - num_block_offset
//The block is the virtual representation of a block of memory
//Each block will hold it's own valid & dirty bits
// Null block declarations, ie for empty cache sets and streams,
// should have valid bits of zero
public class Block{
//A Blocks Fields
private Integer address;
private boolean valid;
private boolean dirty;
public Block(Integer new_address){
if(new_address == null){
this.address = 0; //valid is false, so address doesn't matter
this.valid = false;
this.dirty= false;
}else{
this.address = new_address;
this.valid = true;
this.dirty= false;
}
}//end create block
public int getAddress(){
return (int) this.address;
}
public Integer getTag(int num_tag_bits){
return (Integer) this.address>>>(32-num_tag_bits);
}
public boolean isValid(){
return this.valid;
}
public void setValid(boolean val){
this.valid = val;
}
public boolean isDirty(){
return this.dirty;
}
public void setDirty(boolean xyz){
this.dirty = xyz;
}
}//end Block class