commit a5febee25e237d6795e10ea5b6c2f51a4c7734ea Author: Ting-Jun Wang Date: Fri Dec 31 02:21:58 2021 +0800 feat: components diff --git a/block.cpp b/block.cpp new file mode 100644 index 0000000..5de18a4 --- /dev/null +++ b/block.cpp @@ -0,0 +1,7 @@ +#include "block.h" + +CacheSim::Block::Block(short tagSize) { + this->valid = false; + this->tag.assign(tagSize, 0); + this->tagSize = tagSize; +} \ No newline at end of file diff --git a/block.h b/block.h new file mode 100644 index 0000000..fa56d5e --- /dev/null +++ b/block.h @@ -0,0 +1,17 @@ +#include +using std::vector; + +namespace CacheSim{ + class Block + { + private: + bool valid; + vector tag; + short tagSize; + // data; + + public: + Block(){}; + Block(short tagSize); + }; +} \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..5c475e6 --- /dev/null +++ b/main.cpp @@ -0,0 +1,30 @@ +#include +#include +// #include "block.h" +#include "simulator.h" +// using namespace std; + +int main(){ + std::string temp; + int machineBits, cacheSize, waySize, blockSize; + short setSize; + short offsetSize, tagSize, indexSize; + + std::cin >> temp >> temp >> machineBits; + std::cin >> temp >> temp >> cacheSize; + std::cin >> temp >> waySize; + std::cin >> temp >> temp >> blockSize; + + setSize = cacheSize * 1024 / blockSize / waySize; + std::cout << setSize << " sets" << std::endl << std::endl; + + offsetSize = log2(blockSize); + indexSize = log2(setSize); + tagSize = machineBits - offsetSize - indexSize; + + std::cout << "offset: " << offsetSize << std::endl; + std::cout << "index : " << indexSize << std::endl; + std::cout << "tag : " << tagSize << std::endl; + + CacheSim::Simulator(setSize, waySize, tagSize); +} diff --git a/set.cpp b/set.cpp new file mode 100644 index 0000000..73e35ea --- /dev/null +++ b/set.cpp @@ -0,0 +1,13 @@ +#include "set.h" + +using std::vector; +using CacheSim::Block; +using CacheSim::Set; + +Set::Set(short waySize, short tagSize){ + this->waySize = waySize; + + for(int i=0; iblocks.push_back(Block(tagSize)); + } +} \ No newline at end of file diff --git a/set.h b/set.h new file mode 100644 index 0000000..27ecfb2 --- /dev/null +++ b/set.h @@ -0,0 +1,17 @@ +#include "block.h" +#include + +using std::vector; +using CacheSim::Block; + +namespace CacheSim{ + class Set + { + private: + short waySize; + vector blocks; + + public: + Set(short waySize, short tagSize); + }; +} \ No newline at end of file diff --git a/simulator.cpp b/simulator.cpp new file mode 100644 index 0000000..fc0a369 --- /dev/null +++ b/simulator.cpp @@ -0,0 +1,9 @@ +#include "simulator.h" +using CacheSim::Simulator; + +Simulator::Simulator(short setSize, short waySize, short tagSize){ + this->setSize = setSize; + for(int i=0; isets.push_back(Set(waySize, tagSize)); + } +} \ No newline at end of file diff --git a/simulator.h b/simulator.h new file mode 100644 index 0000000..1ff814c --- /dev/null +++ b/simulator.h @@ -0,0 +1,15 @@ +#include "set.h" +#include +using CacheSim::Set; +using std::vector; + +namespace CacheSim{ + class Simulator + { + private: + short setSize; + vector sets; + public: + Simulator(short setSize, short waySize, short tagSize); + }; +} \ No newline at end of file