Changeset 823 for branches/RWT/lib/generic_cache_tsar/include
- Timestamp:
- Sep 30, 2014, 3:32:13 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RWT/lib/generic_cache_tsar/include/generic_cache.h
r814 r823 89 89 typedef uint32_t be_t; 90 90 91 data_t 92 addr_t 93 int 94 bool 95 96 size_t 97 size_t 98 size_t 91 data_t *r_data ; 92 addr_t *r_tag ; 93 int *r_state; 94 bool *r_lru ; 95 96 size_t m_ways; 97 size_t m_sets; 98 size_t m_words; 99 99 100 100 const soclib::common::AddressMaskingTable<addr_t> m_x ; … … 105 105 inline data_t &cache_data(size_t way, size_t set, size_t word) 106 106 { 107 return r_data[(way *m_sets*m_words)+(set*m_words)+word];107 return r_data[(way * m_sets * m_words) + (set * m_words) + word]; 108 108 } 109 109 … … 111 111 inline addr_t &cache_tag(size_t way, size_t set) 112 112 { 113 return r_tag[(way *m_sets)+set];113 return r_tag[(way * m_sets) + set]; 114 114 } 115 115 … … 117 117 inline bool &cache_lru(size_t way, size_t set) 118 118 { 119 return r_lru[(way *m_sets)+set];119 return r_lru[(way * m_sets) + set]; 120 120 } 121 121 … … 123 123 inline int &cache_state(size_t way, size_t set) 124 124 { 125 return r_state[(way *m_sets)+set];125 return r_state[(way * m_sets) + set]; 126 126 } 127 127 … … 149 149 { 150 150 data_t mask = 0; 151 if ( (be & 0x1) == 0x1) mask = mask | 0x000000FF;152 if ( (be & 0x2) == 0x2) mask = mask | 0x0000FF00;153 if ( (be & 0x4) == 0x4) mask = mask | 0x00FF0000;154 if ( (be & 0x8) == 0x8) mask = mask | 0xFF000000;151 if ((be & 0x1) == 0x1) mask = mask | 0x000000FF; 152 if ((be & 0x2) == 0x2) mask = mask | 0x0000FF00; 153 if ((be & 0x4) == 0x4) mask = mask | 0x00FF0000; 154 if ((be & 0x8) == 0x8) mask = mask | 0xFF000000; 155 155 return mask; 156 156 } … … 160 160 ////////////////////////////////////////// 161 161 GenericCache(const std::string &name, 162 163 164 162 size_t nways, 163 size_t nsets, 164 size_t nwords) 165 165 : m_ways(nways), 166 166 m_sets(nsets), … … 169 169 #define l2 soclib::common::uint32_log2 170 170 171 m_x( 172 m_y( 173 m_z( 174 171 m_x(l2(nwords), l2(sizeof(data_t))), 172 m_y(l2(nsets), l2(nwords) + l2(sizeof(data_t))), 173 m_z(8*sizeof(addr_t) - l2(nsets) - l2(nwords) - l2(sizeof(data_t)), 174 l2(nsets) + l2(nwords) + l2(sizeof(data_t))) 175 175 #undef l2 176 176 { … … 196 196 #endif 197 197 198 r_data = new data_t[nways *nsets*nwords];199 r_tag = new addr_t[nways *nsets];200 r_state = new int[nways *nsets];201 r_lru = new bool[nways *nsets];198 r_data = new data_t[nways * nsets * nwords]; 199 r_tag = new addr_t[nways * nsets]; 200 r_state = new int[nways * nsets]; 201 r_lru = new bool[nways * nsets]; 202 202 } 203 203 … … 214 214 inline void reset() 215 215 { 216 std::memset(r_data, 0, sizeof(*r_data) *m_ways*m_sets*m_words);217 std::memset(r_tag, 0, sizeof(*r_tag) *m_ways*m_sets);218 std::memset(r_state, CACHE_SLOT_STATE_EMPTY, sizeof(*r_state) *m_ways*m_sets);219 std::memset(r_lru, 0, sizeof(*r_lru) *m_ways*m_sets);216 std::memset(r_data, 0, sizeof(*r_data) * m_ways * m_sets * m_words); 217 std::memset(r_tag, 0, sizeof(*r_tag) * m_ways * m_sets); 218 std::memset(r_state, CACHE_SLOT_STATE_EMPTY, sizeof(*r_state) * m_ways * m_sets); 219 std::memset(r_lru, 0, sizeof(*r_lru) * m_ways * m_sets); 220 220 } 221 221 … … 239 239 for (size_t way = 0; way < m_ways; way++) 240 240 { 241 if ((tag == cache_tag(way, set)) 242 && ((cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) or (cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC)) ) 241 if ((tag == cache_tag(way, set)) and 242 ((cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) or 243 (cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC))) 243 244 { 244 245 *dt = cache_data(way, set, word); … … 269 270 { 270 271 if ((tag == cache_tag(way, set)) and 271 ((cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC)or (cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC))) 272 ((cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) or 273 (cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC))) 272 274 { 273 275 *selway = way; … … 314 316 if (tag == cache_tag(way, set)) // matching tag 315 317 { 316 317 318 if (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) 318 319 { … … 362 363 for (size_t way = 0; way < m_ways; way++) 363 364 { 364 if ((tag == cache_tag(way, set)) 365 && ((cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) or (cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC) )) 365 if ((tag == cache_tag(way, set)) and 366 ((cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) or 367 (cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC))) 366 368 { 367 369 *selway = way; 368 370 *selset = set; 369 371 *selword = word; 370 *dt = cache_data(way, set, word);372 *dt = cache_data(way, set, word); 371 373 return true; 372 374 } … … 384 386 // This function is used by the cc_vcache to get a 64 bits page table entry. 385 387 ///////////////////////////////////////////////////////////////////////////// 386 inline bool read( 387 388 389 390 391 388 inline bool read(addr_t ad, 389 data_t* dt, 390 data_t* dt_next, 391 size_t* selway, 392 size_t* selset, 393 size_t* selword) 392 394 { 393 395 const addr_t tag = m_z[ad]; … … 397 399 for (size_t way = 0; way < m_ways; way++) 398 400 { 399 if ((tag == cache_tag(way, set)) 400 &&((cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC)))401 if ((tag == cache_tag(way, set)) and 402 ((cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC))) 401 403 { 402 404 *dt = cache_data(way, set, word); … … 507 509 for (size_t way = 0; way < m_ways; way++) 508 510 { 509 if ((tag == cache_tag(way, set)) 510 && ((cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC)or(cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC))) 511 if ((tag == cache_tag(way, set)) and 512 ((cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) or 513 (cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC))) 511 514 { 512 515 *selway = way; … … 614 617 addr_t* nline) 615 618 { 616 if ((cache_state(way,set) == CACHE_SLOT_STATE_VALID_CC) or (cache_state(way,set) == CACHE_SLOT_STATE_VALID_NCC)) 619 if ((cache_state(way,set) == CACHE_SLOT_STATE_VALID_CC) or 620 (cache_state(way,set) == CACHE_SLOT_STATE_VALID_NCC)) 617 621 { 618 622 cache_state(way,set) = CACHE_SLOT_STATE_EMPTY; 619 *nline = (data_t) cache_tag(way,set)* m_sets + set;623 *nline = (data_t) cache_tag(way, set) * m_sets + set; 620 624 return true; 621 625 } … … 643 647 644 648 // Search first empty slot 645 for (size_t _way = 0 ; _way < m_ways && !found ; _way++) 646 { 647 if ((cache_state(_way, *set) != CACHE_SLOT_STATE_VALID_CC) and (cache_state(_way, *set) != CACHE_SLOT_STATE_VALID_NCC )) // empty 649 for (size_t _way = 0; _way < m_ways && !found; _way++) 650 { 651 // empty 652 if ((cache_state(_way, *set) != CACHE_SLOT_STATE_VALID_CC) and 653 (cache_state(_way, *set) != CACHE_SLOT_STATE_VALID_NCC)) 648 654 { 649 655 found = true; … … 656 662 if (!found) 657 663 { 658 for (size_t _way = 0 ; _way < m_ways && !found; _way++)664 for (size_t _way = 0; _way < m_ways && !found; _way++) 659 665 { 660 666 if (not cache_lru(_way, *set)) … … 668 674 669 675 assert(found && "all ways can't be new at the same time"); 670 *victim = (addr_t) ((cache_tag(*way, *set) * m_sets) + *set);676 *victim = (addr_t) ((cache_tag(*way, *set) * m_sets) + *set); 671 677 return cleanup; 672 678 } … … 693 699 694 700 // Search first empty slot 695 for (size_t _way = 0 ; _way < m_ways && !(*found); _way++)701 for (size_t _way = 0; _way < m_ways && !(*found); _way++) 696 702 { 697 703 if (cache_state(_way, _set) == CACHE_SLOT_STATE_EMPTY) … … 706 712 707 713 // Search first not zombi old slot 708 for (size_t _way = 0 ; _way < m_ways && !(*found); _way++)714 for (size_t _way = 0; _way < m_ways && !(*found); _way++) 709 715 { 710 716 if (not cache_lru(_way, _set) and 711 717 (cache_state(_way, _set) != CACHE_SLOT_STATE_ZOMBI)) 712 718 { 713 719 *found = true; … … 720 726 } 721 727 // Search first not zombi slot 722 for (size_t _way = 0 ; _way < m_ways && !(*found); _way++)728 for (size_t _way = 0; _way < m_ways && !(*found); _way++) 723 729 { 724 730 if (cache_state(_way, _set) != CACHE_SLOT_STATE_ZOMBI) … … 746 752 size_t set) 747 753 { 748 addr_t tag= m_z[ad];749 750 cache_tag(way, set) 754 addr_t tag = m_z[ad]; 755 756 cache_tag(way, set) = tag; 751 757 cache_state(way, set) = CACHE_SLOT_STATE_VALID_CC; 752 758 cache_set_lru(way, set); … … 764 770 addr_t tag = m_z[ad]; 765 771 766 assert( ((state == CACHE_SLOT_STATE_VALID_CC) or767 768 769 (state == CACHE_SLOT_STATE_EMPTY)) and772 assert(((state == CACHE_SLOT_STATE_VALID_CC) or 773 (state == CACHE_SLOT_STATE_VALID_NCC) or 774 (state == CACHE_SLOT_STATE_ZOMBI) or 775 (state == CACHE_SLOT_STATE_EMPTY)) and 770 776 "illegal slot state argument in Generic Cache write_dir()"); 771 777 772 assert( 778 assert((way < m_ways) and 773 779 "too large way index argument in Generic Cache write_dir()"); 774 780 775 assert( 781 assert((set < m_sets) and 776 782 "too large set index argument in Generic Cache write_dir()"); 777 783 … … 779 785 cache_state(way, set) = state; 780 786 781 if ((state == CACHE_SLOT_STATE_VALID_CC) or (state == CACHE_SLOT_STATE_VALID_NCC)) cache_set_lru(way, set); 787 if ((state == CACHE_SLOT_STATE_VALID_CC) or (state == CACHE_SLOT_STATE_VALID_NCC)) 788 cache_set_lru(way, set); 782 789 } 783 790 … … 791 798 int state) 792 799 { 793 assert( ((state == CACHE_SLOT_STATE_VALID_CC) or794 795 796 800 assert(((state == CACHE_SLOT_STATE_VALID_CC) or 801 (state == CACHE_SLOT_STATE_VALID_NCC) or 802 (state == CACHE_SLOT_STATE_ZOMBI) or 803 (state == CACHE_SLOT_STATE_EMPTY) ) and 797 804 "illegal slot state argument in Generic Cache write_dir()"); 798 805 799 assert( 806 assert((way < m_ways) and 800 807 "too large way index argument in Generic Cache write_dir()"); 801 808 802 assert( 809 assert((set < m_sets) and 803 810 "too large set index argument in Generic Cache write_dir()"); 804 811 805 812 cache_state(way, set) = state; 806 813 807 if ( (state == CACHE_SLOT_STATE_VALID_CC) or (state == CACHE_SLOT_STATE_VALID_NCC) ) cache_set_lru(way, set); 814 if ((state == CACHE_SLOT_STATE_VALID_CC) or (state == CACHE_SLOT_STATE_VALID_NCC)) 815 cache_set_lru(way, set); 808 816 } 809 817 … … 820 828 addr_t tag = m_z[ad]; 821 829 822 cache_tag(way, set) 830 cache_tag(way, set) = tag; 823 831 cache_state(way, set) = CACHE_SLOT_STATE_VALID_CC; 824 832 cache_set_lru(way, set); 825 for (size_t word = 0 ; word < m_words; word++)826 { 827 cache_data(way, set, word) = buf[word] 833 for (size_t word = 0; word < m_words; word++) 834 { 835 cache_data(way, set, word) = buf[word]; 828 836 } 829 837 } … … 832 840 void fileTrace(FILE* file) 833 841 { 834 for (size_t nway = 0 ; nway < m_ways; nway++)835 { 836 for (size_t nset = 0 ; nset < m_sets; nset++)837 { 838 fprintf(file, "%d / ", (int) cache_state(nway, nset));839 fprintf(file, "way %d / ", (int) nway);840 fprintf(file, "set %d / ", (int) nset);842 for (size_t nway = 0; nway < m_ways; nway++) 843 { 844 for (size_t nset = 0; nset < m_sets; nset++) 845 { 846 fprintf(file, "%d / ", (int) cache_state(nway, nset)); 847 fprintf(file, "way %d / ", (int) nway); 848 fprintf(file, "set %d / ", (int) nset); 841 849 fprintf(file, "@ = %08zX / ", 842 850 ((cache_tag(nway, nset) * m_sets + nset) * m_words * 4)); 843 for (size_t nword = m_words ; nword > 0; nword--)851 for (size_t nword = m_words; nword > 0; nword--) 844 852 { 845 853 unsigned int data = cache_data(nway, nset, nword - 1); … … 854 862 inline void printTrace() 855 863 { 856 for (size_t way = 0; way < m_ways 857 { 858 for (size_t set = 0 ; set < m_sets; set++)859 { 860 addr_t addr = (((addr_t) cache_tag(way,set))*m_words*m_sets+m_words*set)*4;864 for (size_t way = 0; way < m_ways; way++) 865 { 866 for (size_t set = 0; set < m_sets; set++) 867 { 868 addr_t addr = (((addr_t) cache_tag(way, set)) * m_words * m_sets + m_words * set) * 4; 861 869 std::cout << std::dec << cache_state(way, set) 862 870 << " | way " << way … … 864 872 << std::hex << " | @ " << addr; 865 873 866 for (size_t word = 0 ; word < m_words; word++)867 { 868 std::cout << " | " << cache_data(way, set,word) ;874 for (size_t word = 0; word < m_words; word++) 875 { 876 std::cout << " | " << cache_data(way, set, word) ; 869 877 } 870 878 std::cout << std::dec << std::endl ;
Note: See TracChangeset
for help on using the changeset viewer.