[80] | 1 | #ifndef ENVIRONMENT_CACHE_CACHE_ONELEVEL_PARAMETERS_H |
---|
| 2 | #define ENVIRONMENT_CACHE_CACHE_ONELEVEL_PARAMETERS_H |
---|
[78] | 3 | |
---|
| 4 | #include <iostream> |
---|
| 5 | #include <sstream> |
---|
| 6 | #include <math.h> |
---|
| 7 | |
---|
[80] | 8 | namespace environment { |
---|
[78] | 9 | namespace cache { |
---|
| 10 | namespace cache_onelevel { |
---|
| 11 | |
---|
| 12 | class Parameters |
---|
| 13 | { |
---|
| 14 | public : uint32_t nb_port ; |
---|
| 15 | public : uint32_t nb_line ; |
---|
| 16 | public : uint32_t size_line ; |
---|
| 17 | public : uint32_t size_word ; |
---|
| 18 | public : uint32_t associativity; |
---|
| 19 | public : uint32_t hit_latence ; |
---|
| 20 | public : uint32_t miss_penality; |
---|
| 21 | |
---|
| 22 | public : Parameters (uint32_t nb_port , |
---|
| 23 | uint32_t nb_line , |
---|
| 24 | uint32_t size_line , |
---|
| 25 | uint32_t size_word , |
---|
| 26 | uint32_t associativity, |
---|
| 27 | uint32_t hit_latence , |
---|
| 28 | uint32_t miss_penality) |
---|
| 29 | { |
---|
| 30 | this->nb_port = nb_port ; |
---|
| 31 | this->nb_line = nb_line ; |
---|
| 32 | this->size_line = size_line ; |
---|
| 33 | this->size_word = size_word ; |
---|
| 34 | this->associativity = associativity; |
---|
| 35 | this->hit_latence = hit_latence ; |
---|
| 36 | this->miss_penality = miss_penality; |
---|
| 37 | |
---|
| 38 | if ((nb_line * size_line * associativity) == 0) |
---|
| 39 | { |
---|
| 40 | std::cerr << "{Cache_OneLevel} all parameter must be greater that 0" << std::endl; |
---|
| 41 | exit(1); |
---|
| 42 | } |
---|
| 43 | if ((nb_line % associativity) != 0) |
---|
| 44 | { |
---|
| 45 | std::cerr << "{Cache_OneLevel} nb_line must be a mutiple of associativity" << std::endl; |
---|
| 46 | exit(1); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | if ((double)nb_line != ::pow(2,::log2(nb_line))) |
---|
| 50 | { |
---|
| 51 | std::cerr << "{Cache_OneLevel} nb_line must be a mutiple of 2^n" << std::endl; |
---|
| 52 | exit(1); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | if ((double)size_line != ::pow(2,::log2(size_line))) |
---|
| 56 | { |
---|
| 57 | std::cerr << "{Cache_OneLevel} size_line must be a mutiple of 2^n" << std::endl; |
---|
| 58 | exit(1); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | if ((double)size_word != ::pow(2,::log2(size_word))) |
---|
| 62 | { |
---|
| 63 | std::cerr << "{Cache_OneLevel} size_word must be a mutiple of 2^n" << std::endl; |
---|
| 64 | exit(1); |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | public : std::string print (uint32_t depth) |
---|
| 69 | { |
---|
| 70 | std::string tab (depth,'\t'); |
---|
| 71 | std::stringstream str; |
---|
| 72 | |
---|
| 73 | str << tab << "* Capacity : " << (nb_line * size_line * size_word) << " bytes" << std::endl |
---|
| 74 | << tab << " * Nb line : " << nb_line << std::endl |
---|
| 75 | << tab << " * Size line : " << size_line << std::endl |
---|
| 76 | << tab << " * Size word (in byte) : " << size_word << std::endl |
---|
| 77 | << tab << "* Timing : " << std::endl |
---|
| 78 | << tab << " * Hit latence : " << hit_latence << std::endl |
---|
| 79 | << tab << " * Miss penality : " << miss_penality << std::endl |
---|
| 80 | << tab << "* Other : " << std::endl |
---|
| 81 | << tab << " * Associativity : " << associativity << std::endl |
---|
| 82 | << tab << " * Nb port : " << nb_port << std::endl; |
---|
| 83 | |
---|
| 84 | if (associativity == 1) |
---|
| 85 | str << tab << " * Cache Direct Map"; |
---|
| 86 | else |
---|
| 87 | if (associativity == nb_line) |
---|
| 88 | str << tab << " * Cache Full Associative"; |
---|
| 89 | else |
---|
| 90 | str << tab << " * Cache Semi Associative"; |
---|
| 91 | return str.str(); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | friend std::ostream& operator<< (std::ostream& output, Parameters &x) |
---|
| 96 | { |
---|
| 97 | output << x.print(0); |
---|
| 98 | return output; |
---|
| 99 | } |
---|
| 100 | }; |
---|
| 101 | |
---|
| 102 | }; |
---|
| 103 | }; |
---|
| 104 | }; |
---|
| 105 | #endif |
---|