Changeset 771 for branches/RWT/lib
- Timestamp:
- Aug 26, 2014, 4:40:29 PM (10 years ago)
- Location:
- branches/RWT/lib/generic_cache_tsar
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RWT/lib/generic_cache_tsar/include/generic_cache.h
r767 r771 86 86 ////////////////////////// 87 87 { 88 typedef uint32_t 89 typedef uint32_t 90 91 data_t 92 addr_t 93 int 94 bool 95 96 size_t 97 size_t 98 size_t 99 100 const soclib::common::AddressMaskingTable<addr_t> 101 const soclib::common::AddressMaskingTable<addr_t> 102 const soclib::common::AddressMaskingTable<addr_t> 88 typedef uint32_t data_t; 89 typedef uint32_t be_t; 90 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 100 const soclib::common::AddressMaskingTable<addr_t> m_x ; 101 const soclib::common::AddressMaskingTable<addr_t> m_y ; 102 const soclib::common::AddressMaskingTable<addr_t> m_z ; 103 103 104 104 ////////////////////////////////////////////////////////////// … … 134 134 cache_lru(way, set) = true; 135 135 136 for (way2 = 0; way2 < m_ways; way2++ 136 for (way2 = 0; way2 < m_ways; way2++) 137 137 { 138 138 if (cache_lru(way2, set) == false) return; 139 139 } 140 140 // all lines are new -> they all become old 141 for (way2 = 0; way2 < m_ways; way2++ 141 for (way2 = 0; way2 < m_ways; way2++) 142 142 { 143 143 cache_lru(way2, set) = false; … … 146 146 147 147 //////////////////////////////// 148 inline data_t be2mask( be_t be)148 inline data_t be2mask(be_t be) 149 149 { 150 150 data_t mask = 0; … … 159 159 160 160 ////////////////////////////////////////// 161 GenericCache( const std::string&name,162 size_t 163 size_t 164 size_t 161 GenericCache(const std::string &name, 162 size_t nways, 163 size_t nsets, 164 size_t nwords) 165 165 : m_ways(nways), 166 166 m_sets(nsets), … … 186 186 187 187 #ifdef GENERIC_CACHE_DEBUG 188 std::cout << "constructing " << name << std::endl188 std::cout << "constructing " << name << std::endl 189 189 << "- nways = " << nways << std::endl 190 190 << "- nsets = " << nsets << std::endl … … 196 196 #endif 197 197 198 r_data 199 r_tag 200 r_state 201 r_lru 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 … … 212 212 213 213 //////////////////// 214 inline void reset( 214 inline void reset() 215 215 { 216 216 std::memset(r_data, 0, sizeof(*r_data)*m_ways*m_sets*m_words); … … 230 230 // Both data & directory are accessed. 231 231 ///////////////////////////////////////////////////////////////////// 232 inline bool read( addr_tad,233 data_t*dt)234 { 235 const addr_t 236 const size_t 237 const size_t 238 239 for ( size_t way = 0; way < m_ways; way++)240 { 241 if ( 242 && ( 232 inline bool read(addr_t ad, 233 data_t* dt) 234 { 235 const addr_t tag = m_z[ad]; 236 const size_t set = m_y[ad]; 237 const size_t word = m_x[ad]; 238 239 for (size_t way = 0; way < m_ways; way++) 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)) ) 243 243 { 244 244 *dt = cache_data(way, set, word); … … 256 256 // The selected way, set and word index are returned in case of hit. 257 257 ///////////////////////////////////////////////////////////////////// 258 inline bool read( addr_tad,259 data_t*dt,260 size_t*selway,261 size_t*selset,262 size_t*selword)263 { 264 const addr_t 265 const size_t 266 const size_t 267 268 for ( size_t way = 0; way < m_ways; way++)269 { 270 if ( 271 ( 258 inline bool read(addr_t ad, 259 data_t* dt, 260 size_t* selway, 261 size_t* selset, 262 size_t* selword) 263 { 264 const addr_t tag = m_z[ad]; 265 const size_t set = m_y[ad]; 266 const size_t word = m_x[ad]; 267 268 for (size_t way = 0; way < m_ways; way++) 269 { 270 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 272 { 273 273 *selway = way; … … 292 292 // returned in the other arguments. 293 293 //////////////////////////////////////////////////////////////////// 294 inline void read( addr_tad,295 data_t*dt,296 size_t*selway,297 size_t*selset,298 size_t*selword,299 int* state)300 { 301 const addr_t 302 const size_t 303 const size_t 294 inline void read(addr_t ad, 295 data_t* dt, 296 size_t* selway, 297 size_t* selset, 298 size_t* selword, 299 int* state) 300 { 301 const addr_t tag = m_z[ad]; 302 const size_t set = m_y[ad]; 303 const size_t word = m_x[ad]; 304 304 305 305 // default return values … … 310 310 *dt = 0; 311 311 312 for ( size_t way = 0; way < m_ways; way++)313 { 314 if ( tag == cache_tag(way, set)) // matching tag315 { 316 317 if ( cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC)312 for (size_t way = 0; way < m_ways; way++) 313 { 314 if (tag == cache_tag(way, set)) // matching tag 315 { 316 317 if (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) 318 318 { 319 319 *state = CACHE_SLOT_STATE_VALID_CC; … … 324 324 cache_set_lru(way, set); 325 325 } 326 else if ( cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC)326 else if (cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC) 327 327 { 328 328 *state = CACHE_SLOT_STATE_VALID_NCC; … … 333 333 cache_set_lru(way, set); 334 334 } 335 else if ( cache_state(way, set) == CACHE_SLOT_STATE_ZOMBI)335 else if (cache_state(way, set) == CACHE_SLOT_STATE_ZOMBI) 336 336 { 337 337 *state = CACHE_SLOT_STATE_ZOMBI; … … 350 350 // The selected way, set and word index are returned in case of hit. 351 351 ///////////////////////////////////////////////////////////////////// 352 inline bool read_neutral( addr_tad,353 data_t*dt,354 size_t*selway,355 size_t*selset,356 size_t*selword)357 { 358 const addr_t 359 const size_t 360 const size_t 361 362 for ( size_t way = 0; way < m_ways; way++)363 { 364 if ( 365 && ( (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) or (cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC) ))352 inline bool read_neutral(addr_t ad, 353 data_t* dt, 354 size_t* selway, 355 size_t* selset, 356 size_t* selword) 357 { 358 const addr_t tag = m_z[ad]; 359 const size_t set = m_y[ad]; 360 const size_t word = m_x[ad]; 361 362 for (size_t way = 0; way < m_ways; way++) 363 { 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) )) 366 366 { 367 367 *selway = way; … … 384 384 // This function is used by the cc_vcache to get a 64 bits page table entry. 385 385 ///////////////////////////////////////////////////////////////////////////// 386 inline bool read( addr_t 387 data_t* 388 data_t* 389 size_t* 390 size_t* 391 size_t* 392 { 393 const addr_t 394 const size_t 395 const size_t 396 397 for ( size_t way = 0; way < m_ways; way++)398 { 399 if ( 400 &&( (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) ))401 { 402 *dt 403 if ( word+1 < m_words)404 { 405 *dt_next = cache_data(way, set, word +1);386 inline bool read( addr_t ad, 387 data_t* dt, 388 data_t* dt_next, 389 size_t* selway, 390 size_t* selset, 391 size_t* selword) 392 { 393 const addr_t tag = m_z[ad]; 394 const size_t set = m_y[ad]; 395 const size_t word = m_x[ad]; 396 397 for (size_t way = 0; way < m_ways; way++) 398 { 399 if ((tag == cache_tag(way, set)) 400 &&( (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC))) 401 { 402 *dt = cache_data(way, set, word); 403 if (word + 1 < m_words) 404 { 405 *dt_next = cache_data(way, set, word + 1); 406 406 } 407 407 *selway = way; … … 425 425 // returned in the other arguments. 426 426 //////////////////////////////////////////////////////////////////// 427 inline void read( addr_tad,428 data_t*dt,429 data_t*dt_next,430 size_t*selway,431 size_t*selset,432 size_t*selword,433 int* state)434 { 435 const addr_t 436 const size_t 437 const size_t 427 inline void read(addr_t ad, 428 data_t* dt, 429 data_t* dt_next, 430 size_t* selway, 431 size_t* selset, 432 size_t* selword, 433 int* state) 434 { 435 const addr_t tag = m_z[ad]; 436 const size_t set = m_y[ad]; 437 const size_t word = m_x[ad]; 438 438 439 439 // default return values … … 444 444 *dt = 0; 445 445 446 for ( size_t way = 0; way < m_ways; way++)447 { 448 if ( tag == cache_tag(way, set)) // matching tag449 { 450 451 if ( cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC)446 for (size_t way = 0; way < m_ways; way++) 447 { 448 if (tag == cache_tag(way, set)) // matching tag 449 { 450 451 if (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) 452 452 { 453 453 *state = CACHE_SLOT_STATE_VALID_CC; … … 456 456 *selword = word; 457 457 *dt = cache_data(way, set, word); 458 if ( word+1 < m_words)458 if (word + 1 < m_words) 459 459 { 460 460 *dt_next = cache_data(way, set, word+1); … … 463 463 } 464 464 465 else if ( cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC)465 else if (cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC) 466 466 { 467 467 *state = CACHE_SLOT_STATE_VALID_NCC; … … 470 470 *selword = word; 471 471 *dt = cache_data(way, set, word); 472 if ( word+1 < m_words)472 if (word + 1 < m_words) 473 473 { 474 *dt_next = cache_data(way, set, word +1);474 *dt_next = cache_data(way, set, word + 1); 475 475 } 476 476 cache_set_lru(way, set); 477 477 } 478 478 479 else if ( cache_state(way, set) == CACHE_SLOT_STATE_ZOMBI)479 else if (cache_state(way, set) == CACHE_SLOT_STATE_ZOMBI) 480 480 { 481 481 *state = CACHE_SLOT_STATE_ZOMBI; … … 496 496 // while we write in the data part with a different address in the same cycle. 497 497 /////////////////////////////////////////////////////////////////////////////// 498 inline bool hit( addr_tad,499 size_t*selway,500 size_t*selset,501 size_t*selword)502 { 503 const addr_t 504 const size_t 505 const size_t 506 507 for ( size_t way = 0; way < m_ways; way++)508 { 509 if ( 510 && ( (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC)or(cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC) ))498 inline bool hit(addr_t ad, 499 size_t* selway, 500 size_t* selset, 501 size_t* selword) 502 { 503 const addr_t tag = m_z[ad]; 504 const size_t set = m_y[ad]; 505 const size_t word = m_x[ad]; 506 507 for (size_t way = 0; way < m_ways; way++) 508 { 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 511 { 512 512 *selway = way; … … 531 531 // while we write in the data part with a different address in the same cycle. 532 532 /////////////////////////////////////////////////////////////////////////////// 533 inline void read_dir( addr_tad,534 int*state,535 size_t*way,536 size_t*set,537 size_t*word)538 { 539 const addr_t 540 const size_t 541 const size_t 542 for ( size_t _way = 0; _way < m_ways; _way++)543 { 544 if ( (ad_tag == cache_tag(_way, ad_set)) and545 (cache_state(_way, ad_set) != CACHE_SLOT_STATE_EMPTY))533 inline void read_dir(addr_t ad, 534 int* state, 535 size_t* way, 536 size_t* set, 537 size_t* word) 538 { 539 const addr_t ad_tag = m_z[ad]; 540 const size_t ad_set = m_y[ad]; 541 const size_t ad_word = m_x[ad]; 542 for (size_t _way = 0; _way < m_ways; _way++) 543 { 544 if ((ad_tag == cache_tag(_way, ad_set)) and 545 (cache_state(_way, ad_set) != CACHE_SLOT_STATE_EMPTY)) 546 546 { 547 547 *state = cache_state(_way, ad_set); … … 562 562 // Returns the access status and the tag value in the state and tag argument. 563 563 /////////////////////////////////////////////////////////////////////////////// 564 inline void read_dir( size_tway,565 size_tset,566 addr_t*tag,567 int* state)564 inline void read_dir(size_t way, 565 size_t set, 566 addr_t* tag, 567 int* state) 568 568 { 569 569 *state = cache_state(way, set); … … 581 581 // It does not use the directory and cannot miss. 582 582 ////////////////////////////////////////////////////////////////// 583 inline void write(size_t 584 size_t 585 size_t 586 data_t 583 inline void write(size_t way, 584 size_t set, 585 size_t word, 586 data_t data) 587 587 { 588 588 cache_data(way, set, word) = data; … … 594 594 // It does not use the directory and cannot miss. 595 595 //////////////////////////////////////////////////////////////////////////// 596 inline void write(size_t 597 size_t 598 size_t 599 data_t 600 be_t 596 inline void write(size_t way, 597 size_t set, 598 size_t word, 599 data_t data, 600 be_t be) 601 601 { 602 602 data_t mask = be2mask(be); … … 610 610 // It returns true if the line was valid, and returns the line index. 611 611 ////////////////////////////////////////////////////////////////////////// 612 inline bool inval(size_t 613 size_t 614 addr_t* 615 { 616 if ((cache_state(way,set) == CACHE_SLOT_STATE_VALID_CC) or (cache_state(way,set) == CACHE_SLOT_STATE_VALID_NCC))612 inline bool inval(size_t way, 613 size_t set, 614 addr_t* nline) 615 { 616 if ((cache_state(way,set) == CACHE_SLOT_STATE_VALID_CC) or (cache_state(way,set) == CACHE_SLOT_STATE_VALID_NCC)) 617 617 { 618 618 cache_state(way,set) = CACHE_SLOT_STATE_EMPTY; … … 631 631 // and a Boolean indicating that a cleanup is requested. 632 632 ////////////////////////////////////////////////////////////////////////////////// 633 inline bool victim_select(addr_t 634 addr_t* 635 size_t* 636 size_t* 637 { 638 bool 639 bool 633 inline bool victim_select(addr_t ad, 634 addr_t* victim, 635 size_t* way, 636 size_t* set) 637 { 638 bool found = false; 639 bool cleanup = false; 640 640 641 641 *set = m_y[ad]; … … 643 643 644 644 // 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 )) // empty645 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 648 648 { 649 649 found = true; … … 654 654 655 655 // If no empty slot, search first old slot (lru == false) 656 if ( !found)656 if (!found) 657 657 { 658 for ( size_t _way = 0 ; _way < m_ways && !found ; _way++)659 { 660 if ( not cache_lru(_way, *set))658 for (size_t _way = 0 ; _way < m_ways && !found ; _way++) 659 { 660 if (not cache_lru(_way, *set)) 661 661 { 662 662 found = true; … … 668 668 669 669 assert(found && "all ways can't be new at the same time"); 670 *victim = (addr_t) ((cache_tag(*way,*set) * m_sets) + *set);670 *victim = (addr_t) ((cache_tag(*way,*set) * m_sets) + *set); 671 671 return cleanup; 672 672 } … … 681 681 // and two Boolean indicating success and a required cleanup. 682 682 ////////////////////////////////////////////////////////////////////////////////// 683 inline void read_select(addr_t 684 addr_t* 685 size_t* 686 size_t* 687 bool* 688 bool* cleanup)683 inline void read_select(addr_t ad, 684 addr_t* victim, 685 size_t* way, 686 size_t* set, 687 bool* found, 688 bool* cleanup) 689 689 { 690 690 size_t _set = m_y[ad]; … … 693 693 694 694 // Search first empty slot 695 for ( size_t _way = 0 ; _way < m_ways && !(*found) ; _way++)696 { 697 if ( cache_state(_way, _set) == CACHE_SLOT_STATE_EMPTY)695 for (size_t _way = 0 ; _way < m_ways && !(*found) ; _way++) 696 { 697 if (cache_state(_way, _set) == CACHE_SLOT_STATE_EMPTY) 698 698 { 699 699 *found = true; … … 704 704 } 705 705 } 706 ////////////////////////////////////////////////////////////// 707 /*for ( size_t _way = 0 ; _way < m_ways && !(*found) ; _way++ ) 708 { 709 if ( not cache_lru(_way, _set) and 710 (cache_state(_way, _set) != CACHE_SLOT_STATE_ZOMBI) and 711 (cache_state(_way, _set) == CACHE_SLOT_STATE_VALID_NCC) ) 712 { 713 *found = true; 714 *cleanup = true; 715 *way = _way; 716 *set = m_y[ad]; 717 *victim = (addr_t)((cache_tag(*way,_set) * m_sets) + _set); 718 return; 719 } 720 }*/ 706 721 707 // Search first not zombi old slot 722 for ( size_t _way = 0 ; _way < m_ways && !(*found) ; _way++)723 { 724 if ( 725 (cache_state(_way, _set) != CACHE_SLOT_STATE_ZOMBI) 708 for (size_t _way = 0 ; _way < m_ways && !(*found) ; _way++) 709 { 710 if (not cache_lru(_way, _set) and 711 (cache_state(_way, _set) != CACHE_SLOT_STATE_ZOMBI)) 726 712 { 727 713 *found = true; … … 734 720 } 735 721 // Search first not zombi slot 736 for ( size_t _way = 0 ; _way < m_ways && !(*found) ; _way++)737 { 738 if ( 722 for (size_t _way = 0 ; _way < m_ways && !(*found) ; _way++) 723 { 724 if (cache_state(_way, _set) != CACHE_SLOT_STATE_ZOMBI) 739 725 { 740 726 *found = true; … … 756 742 // identified by the way & set. 757 743 ////////////////////////////////////////////////////////////////// 758 inline void victim_update_tag( addr_tad,759 size_tway,760 size_t set)744 inline void victim_update_tag(addr_t ad, 745 size_t way, 746 size_t set) 761 747 { 762 748 addr_t tag = m_z[ad]; … … 771 757 // identified by the way & set, when using the ZOMBI state. 772 758 ////////////////////////////////////////////////////////////////// 773 inline void write_dir( addr_tad,774 size_tway,775 size_tset,776 intstate)777 { 778 addr_t tag= m_z[ad];759 inline void write_dir(addr_t ad, 760 size_t way, 761 size_t set, 762 int state) 763 { 764 addr_t tag = m_z[ad]; 779 765 780 766 assert( ( (state == CACHE_SLOT_STATE_VALID_CC) or … … 793 779 cache_state(way, set) = state; 794 780 795 if ( (state == CACHE_SLOT_STATE_VALID_CC) or (state == CACHE_SLOT_STATE_VALID_NCC)) cache_set_lru(way, set);781 if ((state == CACHE_SLOT_STATE_VALID_CC) or (state == CACHE_SLOT_STATE_VALID_NCC)) cache_set_lru(way, set); 796 782 } 797 783 … … 801 787 // It does not affect the tag 802 788 ////////////////////////////////////////////////////////////////// 803 inline void write_dir( size_tway,804 size_tset,805 intstate)789 inline void write_dir(size_t way, 790 size_t set, 791 int state) 806 792 { 807 793 assert( ( (state == CACHE_SLOT_STATE_VALID_CC) or … … 827 813 // Both DATA and DIRECTORY are written 828 814 /////////////////////////////////////////////////////////////////// 829 inline void update(addr_t 830 size_t 831 size_t 832 data_t* 815 inline void update(addr_t ad, 816 size_t way, 817 size_t set, 818 data_t* buf) 833 819 { 834 820 addr_t tag = m_z[ad]; … … 837 823 cache_state(way, set) = CACHE_SLOT_STATE_VALID_CC; 838 824 cache_set_lru(way, set); 839 for ( size_t word = 0 ; word < m_words ; word++)825 for (size_t word = 0 ; word < m_words ; word++) 840 826 { 841 827 cache_data(way, set, word) = buf[word] ; … … 846 832 void fileTrace(FILE* file) 847 833 { 848 for (size_t nway = 0 ; nway < m_ways ; nway++)849 { 850 for (size_t nset = 0 ; nset < m_sets ; nset++)834 for (size_t nway = 0 ; nway < m_ways ; nway++) 835 { 836 for (size_t nset = 0 ; nset < m_sets ; nset++) 851 837 { 852 838 fprintf(file, "%d / ", (int)cache_state(nway, nset)); … … 854 840 fprintf(file, "set %d / ", (int)nset); 855 841 fprintf(file, "@ = %08zX / ", 856 ((cache_tag(nway, nset) *m_sets+nset)*m_words*4));857 for (size_t nword = m_words ; nword > 0 ; nword--)858 { 859 unsigned int data = cache_data(nway, nset, nword -1);860 fprintf(file, "%08X ", data 842 ((cache_tag(nway, nset) * m_sets + nset) * m_words * 4)); 843 for (size_t nword = m_words ; nword > 0 ; nword--) 844 { 845 unsigned int data = cache_data(nway, nset, nword - 1); 846 fprintf(file, "%08X ", data); 861 847 } 862 848 fprintf(file, "\n"); … … 868 854 inline void printTrace() 869 855 { 870 for ( size_t way = 0; way < m_ways ; way++)871 { 872 for ( size_t set = 0 ; set < m_sets ; set++)856 for (size_t way = 0; way < m_ways ; way++) 857 { 858 for (size_t set = 0 ; set < m_sets ; set++) 873 859 { 874 860 addr_t addr = (((addr_t)cache_tag(way,set))*m_words*m_sets+m_words*set)*4; … … 878 864 << std::hex << " | @ " << addr; 879 865 880 for ( size_t word = 0 ; word < m_words ; word++)866 for (size_t word = 0 ; word < m_words ; word++) 881 867 { 882 868 std::cout << " | " << cache_data(way,set,word) ; … … 886 872 } 887 873 } 888 889 /////////////////////////////////////////////////////////////////////////// 890 // This function is deprecated as it is difficult to implement in 1 cycle. 891 /////////////////////////////////////////////////////////////////////////// 892 __attribute__((deprecated)) 893 inline bool inval(addr_t ad) 894 { 895 bool hit = false; 896 const addr_t tag = m_z[ad]; 897 const size_t set = m_y[ad]; 898 899 for ( size_t way = 0 ; way < m_ways && !hit ; way++ ) 900 { 901 if ( (tag == cache_tag(way, set)) and 902 (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) ) 903 { 904 hit = true; 905 cache_state(way, set) = CACHE_SLOT_STATE_EMPTY; 906 cache_lru(way, set) = false; 907 } 908 } 909 return hit; 910 } 911 912 //////////////////////////////////////////////////////////////////////////////// 913 // This function is deprecated as it is difficult to implement in 1 cycle. 914 //////////////////////////////////////////////////////////////////////////////// 915 __attribute__((deprecated)) 916 inline bool inval( addr_t ad, 917 size_t* selway, 918 size_t* selset ) 919 { 920 bool hit = false; 921 const addr_t tag = m_z[ad]; 922 const size_t set = m_y[ad]; 923 924 for ( size_t way = 0 ; way < m_ways && !hit ; way++ ) 925 { 926 if ( (tag == cache_tag(way, set)) and 927 (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) ) 928 { 929 hit = true; 930 cache_state(way, set) = CACHE_SLOT_STATE_EMPTY; 931 cache_lru(way, set) = false; 932 *selway = way; 933 *selset = set; 934 } 935 } 936 return hit; 937 } 938 939 //////////////////////////////////////////////////////////////////////////////// 940 // This function is deprecated as the directory must be a dual port RAM... 941 //////////////////////////////////////////////////////////////////////////////// 942 __attribute__((deprecated)) 943 inline bool update( addr_t ad, 944 data_t* buf, 945 addr_t* victim ) 946 { 947 size_t set, way; 948 bool cleanup = victim_select(ad, victim, &way, &set); 949 victim_update_tag (ad, way, set); 950 951 for ( size_t word = 0 ; word < m_words ; word++ ) { 952 cache_data(way, set, word) = buf[word] ; 953 } 954 955 return cleanup; 956 } 957 958 //////////////////////////////////////////////////////////////////////////// 959 // this function is deprecated, as it is difficult to implement in 1 cycle. 960 //////////////////////////////////////////////////////////////////////////// 961 __attribute__((deprecated)) 962 inline bool write(addr_t ad, 963 data_t dt) 964 { 965 const addr_t tag = m_z[ad]; 966 const size_t set = m_y[ad]; 967 const size_t word = m_x[ad]; 968 969 for ( size_t way = 0; way < m_ways; way++ ) 970 { 971 if ( (tag == cache_tag(way, set)) and 972 (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) ) 973 { 974 cache_data(way, set, word) = dt; 975 cache_set_lru(way, set); 976 return true; 977 } 978 } 979 return false; 980 } 981 982 //////////////////////////////////////////////////////////////////////////// 983 // this function is deprecated, as it is difficult to implement in 1 cycle. 984 //////////////////////////////////////////////////////////////////////////// 985 __attribute__((deprecated)) 986 inline bool write(addr_t ad, 987 data_t dt, 988 be_t be) 989 { 990 const addr_t tag = m_z[ad]; 991 const size_t set = m_y[ad]; 992 const size_t word = m_x[ad]; 993 994 for ( size_t way = 0; way < m_ways; way++ ) 995 { 996 if ( (tag == cache_tag(way, set)) and 997 (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) ) 998 { 999 data_t mask = be2mask(be); 1000 data_t prev = cache_data(way, set, word); 1001 cache_data(way, set, word) = (mask & dt) | (~mask & prev); 1002 cache_set_lru(way, set); 1003 return true; 1004 } 1005 } 1006 return false; 1007 } 1008 1009 ///////////////////////////////////////////////////////////////////////////// 1010 // this function is deprecated, as it is difficult to implement in 1 cycle. 1011 ///////////////////////////////////////////////////////////////////////////// 1012 __attribute__((deprecated)) 1013 inline bool write(addr_t ad, 1014 data_t dt, 1015 size_t* nway) 1016 { 1017 const addr_t tag = m_z[ad]; 1018 const size_t set = m_y[ad]; 1019 const size_t word = m_x[ad]; 1020 1021 for ( size_t way = 0; way < m_ways; way++ ) 1022 { 1023 if ( (tag == cache_tag(way, set)) and 1024 (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) ) 1025 { 1026 cache_data(way, set, word) = dt; 1027 cache_set_lru(way, set); 1028 *nway = way; 1029 return true; 1030 } 1031 } 1032 return false; 1033 } 1034 1035 ///////////////////////////////////////////////////////////////////////////// 1036 // this function is deprecated, as it is difficult to implement in 1 cycle. 1037 ///////////////////////////////////////////////////////////////////////////// 1038 __attribute__((deprecated)) 1039 inline bool write(addr_t ad, 1040 data_t dt, 1041 size_t* nway, 1042 be_t be) 1043 { 1044 const addr_t tag = m_z[ad]; 1045 const size_t set = m_y[ad]; 1046 const size_t word = m_x[ad]; 1047 1048 for ( size_t way = 0; way < m_ways; way++ ) 1049 { 1050 if ( (tag == cache_tag(way, set)) and 1051 (cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) ) 1052 { 1053 data_t mask = be2mask(be); 1054 data_t prev = cache_data(way, set, word); 1055 cache_data(way, set, word) = (mask & dt) | (~mask & prev); 1056 cache_set_lru(way, set); 1057 *nway = way; 1058 return true; 1059 } 1060 } 1061 return false; 1062 } 1063 874 1064 875 }; 1065 876 -
branches/RWT/lib/generic_cache_tsar/metadata/generic_cache.sd
r297 r771 4 4 __version__ = "$Revision: 917 $" 5 5 6 Module('caba:generic_cache_tsar', 7 classname = 'soclib::GenericCache', 8 header_files = ['../include/generic_cache.h',], 9 tmpl_parameters = [ 10 parameter.Type('addr_t'), 11 ], 12 uses = [Uses('common:mapping_table'), 13 Uses('common:address_masking_table', 14 data_t = parameter.Reference('addr_t')),], 6 Module('caba:generic_cache_tsar_rwt', 7 classname = 'soclib::GenericCache', 8 header_files = ['../include/generic_cache.h',], 9 tmpl_parameters = [ 10 parameter.Type('addr_t'), 11 ], 12 uses = [ 13 Uses('common:mapping_table'), 14 Uses('common:address_masking_table', 15 data_t = parameter.Reference('addr_t')), 16 ], 15 17 )
Note: See TracChangeset
for help on using the changeset viewer.