feat: components
This commit is contained in:
commit
a5febee25e
7
block.cpp
Normal file
7
block.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include "block.h"
|
||||
|
||||
CacheSim::Block::Block(short tagSize) {
|
||||
this->valid = false;
|
||||
this->tag.assign(tagSize, 0);
|
||||
this->tagSize = tagSize;
|
||||
}
|
||||
17
block.h
Normal file
17
block.h
Normal file
@ -0,0 +1,17 @@
|
||||
#include <vector>
|
||||
using std::vector;
|
||||
|
||||
namespace CacheSim{
|
||||
class Block
|
||||
{
|
||||
private:
|
||||
bool valid;
|
||||
vector<bool> tag;
|
||||
short tagSize;
|
||||
// data;
|
||||
|
||||
public:
|
||||
Block(){};
|
||||
Block(short tagSize);
|
||||
};
|
||||
}
|
||||
30
main.cpp
Normal file
30
main.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
// #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);
|
||||
}
|
||||
13
set.cpp
Normal file
13
set.cpp
Normal file
@ -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; i<waySize; i++){
|
||||
this->blocks.push_back(Block(tagSize));
|
||||
}
|
||||
}
|
||||
17
set.h
Normal file
17
set.h
Normal file
@ -0,0 +1,17 @@
|
||||
#include "block.h"
|
||||
#include <vector>
|
||||
|
||||
using std::vector;
|
||||
using CacheSim::Block;
|
||||
|
||||
namespace CacheSim{
|
||||
class Set
|
||||
{
|
||||
private:
|
||||
short waySize;
|
||||
vector<Block> blocks;
|
||||
|
||||
public:
|
||||
Set(short waySize, short tagSize);
|
||||
};
|
||||
}
|
||||
9
simulator.cpp
Normal file
9
simulator.cpp
Normal file
@ -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; i<setSize; i++){
|
||||
this->sets.push_back(Set(waySize, tagSize));
|
||||
}
|
||||
}
|
||||
15
simulator.h
Normal file
15
simulator.h
Normal file
@ -0,0 +1,15 @@
|
||||
#include "set.h"
|
||||
#include <vector>
|
||||
using CacheSim::Set;
|
||||
using std::vector;
|
||||
|
||||
namespace CacheSim{
|
||||
class Simulator
|
||||
{
|
||||
private:
|
||||
short setSize;
|
||||
vector<Set> sets;
|
||||
public:
|
||||
Simulator(short setSize, short waySize, short tagSize);
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user