Compare commits

...

4 Commits

5 changed files with 77 additions and 17 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ build/
*.solution
compile_commands.json
llvm/
.idea

17
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
}

View File

@ -59,7 +59,7 @@ struct CacheAnalysisPass : PassInfoMixin<CacheAnalysisPass> {
bool LoopUnrolling = true;
// Assume a 4kB Cache
// with 16 Sets, associativity of 4 and Cachelines fitting two
// with 16 Sets, associativity of 4 and Cachelines fitting two times the instruction size
CacheType Cache = CacheType(16, 4, 128);
StringRef EntryPoint = "main";
unsigned int EntryAddress;

View File

@ -7,7 +7,7 @@ clean () {
}
config () {
echo "==== Crating build folder ===="
echo "==== Creating build folder ===="
mkdir build
cd build
echo "==== Configuring cmake ===="

View File

@ -5,6 +5,7 @@
#include <cassert>
#include <cstddef>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
@ -98,10 +99,6 @@ public: // everything is public, because IDGAF
Unrolled = UnrolledIn;
}
// AbstractState(Address Addr) {
// Sets[Addr.Index].Associativity[0] = {{Addr.Tag}};
// }
void setUnrolled(unsigned int In) { Unrolled = In; }
bool operator==(AbstractState In) {
@ -135,9 +132,55 @@ public: // everything is public, because IDGAF
*/
void mustJoin(AbstractState In) {
/**
* The exercise is to Fill this function with an LRU must Join.
* TODO: Fill this function with an LRU must Join.
* For this you need to use Sets. Associativity and Blocks.
*/
// Loop through all 16 sets
for (int Index = 0; Index < 16; Index++) {
// create a temporary set of associativity
struct Set temp_set;
struct Set current_set = Sets[Index];
struct Set incoming_set = In.Sets[Index];
// loop through all Ages
for (auto associativity_map : current_set.Associativity) {
auto current_associativity_age = associativity_map.first;
std::list<unsigned int> current_associativity_blocklist =
associativity_map.second.Blocks;
// for every element of associativity_block_list
for (auto block : current_associativity_blocklist) {
// look through ALL incoming_set.Associativities.Entry.Blocklists for
// occurrences
for (auto incoming_associativity : incoming_set.Associativity) {
auto age = incoming_associativity.first;
struct Entry entry = incoming_associativity.second;
auto ret =
std::find(entry.Blocks.begin(), entry.Blocks.end(), block);
if (ret != entry.Blocks.end()) {
// take the maximum age
auto new_age = std::max(current_associativity_age, age);
// create a new entry at the maximum age and
std::list<unsigned int> new_block_list;
new_block_list.push_back((unsigned int) *ret);
struct Entry new_entry = {new_block_list};
// add it to temporary set
temp_set.Associativity.insert(
std::pair<unsigned int, struct Entry>(new_age, new_entry));
}
}
}
// print_block_list(associativity_age, associativity_block_list);
Sets[Index] = temp_set;
}
}
}
/**
@ -214,17 +257,17 @@ public: // everything is public, because IDGAF
}
}
void dumpSet(unsigned int Set) {
void dumpSet(unsigned int Set) {
std::cout << Addr << " {\n";
std::cout << "Set[" << Set << "]: \n";
for (auto EntryPair : this->Sets[Set].Associativity) {
std::cout << " Age[" << EntryPair.first << "]: ";
for (auto Block : EntryPair.second.Blocks) {
std::cout << Block << " ";
}
std::cout << "\n";
std::cout << "Set[" << Set << "]: \n";
for (auto EntryPair : this->Sets[Set].Associativity) {
std::cout << " Age[" << EntryPair.first << "]: ";
for (auto Block : EntryPair.second.Blocks) {
std::cout << Block << " ";
}
std::cout << "\n";
}
std::cout << "}\n";
}
@ -256,6 +299,5 @@ public: // everything is public, because IDGAF
}
std::cout << "}\n";
}
}; // namespace
#endif // STATE_H