Permalink
Browse files

Added increment for counter when block is accessed

  • Loading branch information...
SIddardha G
SIddardha G committed Aug 21, 2011
1 parent 4ee1880 commit 19c28f896b78cf0eda32fae0da9ce7fa0021f727
Showing with 34 additions and 0 deletions.
  1. +5 −0 Block.cpp
  2. +2 −0 Block.h
  3. +1 −0 Cache.cpp
  4. +1 −0 Cache.h
  5. +19 −0 Report.txt
  6. +5 −0 Set.cpp
  7. +1 −0 Set.h
View
@@ -22,6 +22,11 @@ int Block::get_word(int index) {
int Block::get_counter() {
return this->counter;
}
+
+void Block::set_counter(int counter) {
+ this->counter = counter;
+}
+
void Block::set_block(int counter, int tag_value, Block* new_block) {
this->counter = counter;
this->tag = tag_value;
View
@@ -12,7 +12,9 @@ class Block {
int get_tag();
int get_index();
int get_word(int index);
+
int get_counter();
+ void set_counter(int counter);
private:
int tag; // Tag bits of the block
View
@@ -48,6 +48,7 @@ int Cache::get_memory(int address) {
for(int i=0; i < this->assoc; i++) {
Block* cur_block = cur_set->get_block(i);
if(cur_block->get_tag() == tag_num) {
+ cur_set->inc_counter(cur_block->get_index());
this->hits++;
return cur_block->get_word(word_num);
}
View
@@ -15,6 +15,7 @@
* -----------------------------------
* | Tag Bits | Set Bits | Word Bits |
* -----------------------------------
+ *
* The number of bits for tag, set and word are calculated from
* the block size, cache size and associativity.
*/
View
@@ -0,0 +1,19 @@
+Cache Implementation:
+ We have implemented set-associative mapping i.e. a combination of
+ direct and associative-mapping techniques. Main memory Address is
+ parsed to the following format:
+ -----------------------------------
+ | Tag Bits | Set Bits | Word Bits |
+ -----------------------------------
+
+ The number of bits for tag, set and word are calculated from the
+ block size, cache size and associativity. When we require a
+ particular memory location, we calculate three variables -
+ set_num, tag_num, word_num. These are the values of the tag bits,
+ set bits and word bits, which we get by bitwise anding with
+ 2^tag_bits, 2^set_bits and 2^word_bits respectively.
+
+ If the block we require is present, then we return the word from
+ there. Otherwise, we return the word from the main memory and
+ add the block into the cache. When we want to add a block into
+ the cache, we
View
@@ -36,6 +36,11 @@ int Set::get_counter() {
return this->counter;
}
+void Set::inc_counter(int index) {
+ Block* temp_block = this->blocks[index];
+ temp_block->set_counter(this->get_counter());
+}
+
Set::~Set() {
for(int i=0; i < this->assoc; i++)
delete this->blocks[i];
View
1 Set.h
@@ -11,6 +11,7 @@ class Set {
Block* get_block(int index);
void insert_block(int tag_value, Block* new_block);
int get_counter();
+ void inc_counter(int index);
private:
int assoc; // Associativity

0 comments on commit 19c28f8

Please sign in to comment.