Changeset 393
- Timestamp:
- May 28, 2013, 9:35:16 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/generic_cache_tsar/include/generic_cache.h
r365 r393 34 34 // This object is a generic, set associative, cache. 35 35 // Each slot can be in three states: VALID, EMPTY or ZOMBI. 36 // The ZOMBI state is used by cache coherence protocol es to indicate36 // The ZOMBI state is used by cache coherence protocols to indicate 37 37 // a pending cleanup request. 38 38 // Hit if ( (matching tag) and (state == VALID). … … 59 59 // Template parameter is : 60 60 // - addr_t : address format to access the cache 61 // The address can be larger than 32 bits, but the TAG field62 // cannot be larger than 32 bits.63 61 ///////////////////////////////////////////////////////////////////////////////// 64 62 … … 88 86 { 89 87 typedef uint32_t data_t; 90 typedef uint32_t tag_t;91 88 typedef uint32_t be_t; 92 89 93 90 data_t *r_data ; 94 tag_t *r_tag ;91 addr_t *r_tag ; 95 92 int *r_state; 96 93 bool *r_lru ; … … 111 108 112 109 ////////////////////////////////////////////// 113 inline tag_t &cache_tag(size_t way, size_t set)110 inline addr_t &cache_tag(size_t way, size_t set) 114 111 { 115 112 return r_tag[(way*m_sets)+set]; … … 146 143 } 147 144 148 //////////////////////////////// /////////////145 //////////////////////////////// 149 146 inline data_t be2mask( be_t be ) 150 147 { … … 159 156 public: 160 157 161 ////////////////////////////////////////// ////158 ////////////////////////////////////////// 162 159 GenericCache( const std::string &name, 163 160 size_t nways, … … 187 184 188 185 #ifdef GENERIC_CACHE_DEBUG 189 std::cout 190 << " m_x: " << m_x 191 << " m_y: " << m_y 192 << " m_z: " << m_z 193 << std::endl; 186 std::cout << "constructing " << name << std::endl 187 << "- nways = " << nways << std::endl 188 << "- nsets = " << nsets << std::endl 189 << "- nwords = " << nwords << std::endl 190 << " m_x: " << m_x 191 << " m_y: " << m_y 192 << " m_z: " << m_z 193 << std::endl; 194 194 #endif 195 195 196 196 r_data = new data_t[nways*nsets*nwords]; 197 r_tag = new tag_t[nways*nsets];197 r_tag = new addr_t[nways*nsets]; 198 198 r_state = new int[nways*nsets]; 199 199 r_lru = new bool[nways*nsets]; … … 226 226 data_t* dt) 227 227 { 228 const tag_ttag = m_z[ad];228 const addr_t tag = m_z[ad]; 229 229 const size_t set = m_y[ad]; 230 230 const size_t word = m_x[ad]; … … 255 255 size_t* selword) 256 256 { 257 const tag_ttag = m_z[ad];257 const addr_t tag = m_z[ad]; 258 258 const size_t set = m_y[ad]; 259 259 const size_t word = m_x[ad]; … … 292 292 int* state ) 293 293 { 294 const tag_ttag = m_z[ad];294 const addr_t tag = m_z[ad]; 295 295 const size_t set = m_y[ad]; 296 296 const size_t word = m_x[ad]; … … 340 340 size_t* selword) 341 341 { 342 const tag_ttag = m_z[ad];342 const addr_t tag = m_z[ad]; 343 343 const size_t set = m_y[ad]; 344 344 const size_t word = m_x[ad]; … … 375 375 size_t* selword) 376 376 { 377 const tag_ttag = m_z[ad];377 const addr_t tag = m_z[ad]; 378 378 const size_t set = m_y[ad]; 379 379 const size_t word = m_x[ad]; … … 417 417 int* state ) 418 418 { 419 const tag_ttag = m_z[ad];419 const addr_t tag = m_z[ad]; 420 420 const size_t set = m_y[ad]; 421 421 const size_t word = m_x[ad]; … … 470 470 size_t* selword) 471 471 { 472 const tag_ttag = m_z[ad];472 const addr_t tag = m_z[ad]; 473 473 const size_t set = m_y[ad]; 474 474 const size_t word = m_x[ad]; … … 490 490 491 491 /////////////////////////////////////////////////////////////////////////////// 492 // Checks the cache state for a given address, w ehn the ZOMBI state is used.492 // Checks the cache state for a given address, when the ZOMBI state is used. 493 493 // Only the directory is accessed. 494 494 // Returns the access status in the state argument: … … 506 506 size_t* word) 507 507 { 508 const tag_tad_tag = m_z[ad];508 const addr_t ad_tag = m_z[ad]; 509 509 const size_t ad_set = m_y[ad]; 510 510 const size_t ad_word = m_x[ad]; … … 534 534 inline void read_dir( size_t way, 535 535 size_t set, 536 tag_t* tag,536 addr_t* tag, 537 537 int* state ) 538 538 { … … 542 542 543 543 //////////////////////////////////////////// 544 inline tag_t get_tag(size_t way, size_t set)544 inline addr_t get_tag(size_t way, size_t set) 545 545 { 546 546 return cache_tag(way, set); … … 684 684 *way = _way; 685 685 *set = m_y[ad]; 686 *victim = (addr_t)((cache_tag(*way,_set) * m_sets) + _set);686 *victim = cache_tag(*way,_set) * m_sets + _set; 687 687 return; 688 688 } … … 697 697 *way = _way; 698 698 *set = m_y[ad]; 699 *victim = (addr_t)((cache_tag(*way,_set) * m_sets) + _set);699 *victim = cache_tag(*way,_set) * m_sets + _set; 700 700 return; 701 701 } … … 715 715 size_t set ) 716 716 { 717 tag_t tag = m_z[ad];717 addr_t tag = m_z[ad]; 718 718 719 719 cache_tag(way, set) = tag; … … 731 731 int state) 732 732 { 733 tag_t tag = m_z[ad];733 addr_t tag = m_z[ad]; 734 734 735 735 assert( ( (state == CACHE_SLOT_STATE_VALID) or … … 751 751 752 752 ////////////////////////////////////////////////////////////////// 753 // This function write the directory partof a slot753 // This function change the state of a slot 754 754 // identified by the way & set, when using the ZOMBI state. 755 // Does not affect the tag755 // It does not affect the tag 756 756 ////////////////////////////////////////////////////////////////// 757 757 inline void write_dir( size_t way, … … 785 785 data_t* buf) 786 786 { 787 tag_t tag = m_z[ad];787 addr_t tag = m_z[ad]; 788 788 789 789 cache_tag(way, set) = tag; … … 825 825 for ( size_t set = 0 ; set < m_sets ; set++ ) 826 826 { 827 std::cout << std::dec << cache_state(way, set) << " | " ; 828 std::cout << "way " << way << " | " ; 829 std::cout << "set " << set << std::hex << " | " ; 830 std::cout << "@ " << (cache_tag(way,set)*m_words*m_sets+m_words*set)*4 ; 827 addr_t addr = (((addr_t)cache_tag(way,set))*m_words*m_sets+m_words*set)*4; 828 std::cout << std::dec << cache_state(way, set) 829 << " | way " << way 830 << " | set " << set 831 << std::hex << " | @ " << addr; 832 831 833 for ( size_t word = 0 ; word < m_words ; word++ ) 832 834 { … … 845 847 { 846 848 bool hit = false; 847 const tag_ttag = m_z[ad];849 const addr_t tag = m_z[ad]; 848 850 const size_t set = m_y[ad]; 849 851 … … 869 871 size_t* selset ) 870 872 { 871 bool 872 const tag_ttag = m_z[ad];873 bool hit = false; 874 const addr_t tag = m_z[ad]; 873 875 const size_t set = m_y[ad]; 874 876 … … 914 916 data_t dt) 915 917 { 916 const tag_ttag = m_z[ad];918 const addr_t tag = m_z[ad]; 917 919 const size_t set = m_y[ad]; 918 920 const size_t word = m_x[ad]; … … 939 941 be_t be) 940 942 { 941 tag_ttag = m_z[ad];943 const addr_t tag = m_z[ad]; 942 944 const size_t set = m_y[ad]; 943 945 const size_t word = m_x[ad]; … … 966 968 size_t* nway) 967 969 { 968 const tag_ttag = m_z[ad];970 const addr_t tag = m_z[ad]; 969 971 const size_t set = m_y[ad]; 970 972 const size_t word = m_x[ad]; … … 993 995 be_t be) 994 996 { 995 const tag_ttag = m_z[ad];997 const addr_t tag = m_z[ad]; 996 998 const size_t set = m_y[ad]; 997 999 const size_t word = m_x[ad];
Note: See TracChangeset
for help on using the changeset viewer.