@@ -57,64 +57,63 @@ public class Cache
5757 public int SetIndexLength { get ; set ; } = 0 ;
5858 public CacheConfiguration CacheConfig { get ; set ; }
5959
60- public readonly int NumberOfSets ;
61- public readonly int SetSize ;
60+ public int NumberOfSets ;
61+ public int SetSize ;
6262
6363 public string RamFileName { get ; set ; }
6464 public string TraceFileName { get ; set ; }
6565
6666 private List < int > fifoIndexQueue { get ; set ; }
6767
68- private readonly SecureRandom csprng ;
68+ private SecureRandom csprng ;
6969
7070 /// <summary>
7171 /// Index of the latest cache entry.
7272 /// </summary>
7373 private int lifoIndex { get ; set ; }
7474
75- public Cache ( ( string ramFileName , int size , int associativity ) cacheInfo , CacheConfiguration config )
75+ public Cache ( string ramFileName , CacheConfiguration config )
7676 {
77- if ( config . BlockSize >= cacheInfo . size )
77+ RamFileName = ramFileName ;
78+ CacheConfig = config ;
79+ }
80+
81+ public void CreateCache ( )
82+ {
83+ if ( CacheConfig . BlockSize >= Size )
7884 {
79- throw new Exception ( $ "Size of the cache line ({ config . BlockSize } B) can't be larger than the total cache size ({ cacheInfo . size } B).") ;
85+ throw new Exception ( $ "Size of the cache line ({ CacheConfig . BlockSize } B) can't be larger than the total cache size ({ Size } B).") ;
8086 }
8187
82- RamFileName = cacheInfo . ramFileName ;
83-
8488 // Explanation for this check implementation https://stackoverflow.com/questions/2751593/how-to-determine-if-a-decimal-double-is-an-integer .
85- if ( ! CheckNumberForPowerOfTwo ( config . BlockSize ) )
89+ if ( ! CheckNumberForPowerOfTwo ( CacheConfig . BlockSize ) )
8690 {
8791 throw new Exception ( "Block size is not a power of 2." ) ;
8892 }
89- else if ( ! CheckNumberForPowerOfTwo ( cacheInfo . associativity ) )
93+ else if ( ! CheckNumberForPowerOfTwo ( Associativity ) )
9094 {
9195 throw new Exception ( "Associativity is not a power of 2." ) ;
9296 }
9397
94- Size = cacheInfo . size ;
95-
96- // Add cache config information.
97- CacheConfig = config ;
98-
9998 NumberOfLines = Size / CacheConfig . BlockSize ;
10099
101- if ( cacheInfo . associativity > NumberOfLines )
100+ if ( Associativity > NumberOfLines )
102101 {
103- throw new Exception ( $ "The cache with { NumberOfLines } -lines can't be { cacheInfo . associativity } -way set-associative.") ;
102+ throw new Exception ( $ "The cache with { NumberOfLines } -lines can't be { Associativity } -way set-associative.") ;
104103 }
105104
106- SetSize = Associativity = cacheInfo . associativity ;
105+ SetSize = Associativity ;
107106
108107 NumberOfSets = Size / ( SetSize * CacheConfig . BlockSize ) ;
109108 BlockOffsetLength = ( int ) Math . Ceiling ( Math . Log ( CacheConfig . BlockSize , 2 ) ) ;
110109 SetIndexLength = ( int ) Math . Ceiling ( Math . Log ( Size / ( SetSize * CacheConfig . BlockSize ) , 2 ) ) ;
111110
112111
113- if ( config . ReplacementPolicy == ReplacementPolicy . FirstInFirstOut )
112+ if ( CacheConfig . ReplacementPolicy == ReplacementPolicy . FirstInFirstOut )
114113 {
115114 fifoIndexQueue = new List < int > ( ) ;
116115 }
117- else if ( config . ReplacementPolicy == ReplacementPolicy . RandomReplacement )
116+ else if ( CacheConfig . ReplacementPolicy == ReplacementPolicy . RandomReplacement )
118117 {
119118 csprng = new ( new DigestRandomGenerator ( new Sha256Digest ( ) ) ) ;
120119 csprng . SetSeed ( DateTime . Now . Ticks ) ;
@@ -153,7 +152,7 @@ public Instruction TraceLineParser(string line)
153152 }
154153 }
155154
156- public void CreateColdCache ( )
155+ private void CreateColdCache ( )
157156 {
158157 CacheEntries = new List < CacheEntry > ( ) ;
159158 for ( var i = 0 ; i < NumberOfLines ; ++ i )
0 commit comments