Changeset 814 for branches/RWT/lib


Ignore:
Timestamp:
Sep 24, 2014, 3:48:50 PM (10 years ago)
Author:
devigne
Message:

RWT commit : Cosmetic (Remove trailing whitespace)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/RWT/lib/generic_cache_tsar/include/generic_cache.h

    r771 r814  
    3838// Hit if ( (matching tag) and (state == VALID).
    3939// The replacement policy is pseudo-LRU. The victim selection process cannot
    40 // fail if the ZOMBI state is not used. 
     40// fail if the ZOMBI state is not used.
    4141// But it can fail if all ways are in ZOMBI state.
    4242/////////////////////////////////////////////////////////////////////////////////
     
    4949// Constructor parameters are :
    5050// - std::string    &name
    51 // - size_t         nways   : number of associativity levels 
     51// - size_t         nways   : number of associativity levels
    5252// - size_t         nsets   : number of sets
    5353// - size_t         nwords  : number of words in a cache line
     
    5858/////////////////////////////////////////////////////////////////////////////////
    5959// Template parameter is :
    60 // - addr_t : address format to access the cache 
     60// - addr_t : address format to access the cache
    6161/////////////////////////////////////////////////////////////////////////////////
    6262
     
    7171#include <cstring>
    7272
    73 namespace soclib { 
     73namespace soclib {
    7474
    7575enum cache_slot_state_e
     
    8383//////////////////////////
    8484template<typename addr_t>
    85 class GenericCache 
     85class GenericCache
    8686//////////////////////////
    8787{
     
    9494    bool             *r_lru ;
    9595
    96     size_t           m_ways;   
    97     size_t           m_sets;   
     96    size_t           m_ways;
     97    size_t           m_sets;
    9898    size_t           m_words;
    9999
     
    119119        return r_lru[(way*m_sets)+set];
    120120    }
    121    
     121
    122122    //////////////////////////////////////////////
    123123    inline int &cache_state(size_t way, size_t set)
     
    126126    }
    127127
    128    
     128
    129129    /////////////////////////////////////////////////
    130130    inline void cache_set_lru(size_t way, size_t set)
    131131    {
    132             size_t way2;
     132        size_t way2;
    133133
    134134        cache_lru(way, set) = true;
    135135
    136             for (way2 = 0; way2 < m_ways; way2++)
    137         {
    138                 if (cache_lru(way2, set) == false) return;
    139             }
    140             // all lines are new -> they all become old
    141             for (way2 = 0; way2 < m_ways; way2++)
    142         {
    143                 cache_lru(way2, set) = false;
    144             }
     136        for (way2 = 0; way2 < m_ways; way2++)
     137        {
     138            if (cache_lru(way2, set) == false) return;
     139        }
     140        // all lines are new -> they all become old
     141        for (way2 = 0; way2 < m_ways; way2++)
     142        {
     143            cache_lru(way2, set) = false;
     144        }
    145145    }
    146146
     
    160160    //////////////////////////////////////////
    161161    GenericCache(const std::string &name,
    162                     size_t            nways, 
    163                     size_t            nsets, 
     162                    size_t            nways,
     163                    size_t            nsets,
    164164                    size_t            nwords)
    165165        : m_ways(nways),
     
    190190          << "- nsets  = " << nsets << std::endl
    191191          << "- nwords = " << nwords << std::endl
    192           << " m_x: " << m_x 
     192          << " m_x: " << m_x
    193193          << " m_y: " << m_y
    194194          << " m_z: " << m_z
     
    224224        return cache_state(way,set);
    225225    }
    226    
     226
    227227    /////////////////////////////////////////////////////////////////////
    228228    // Read a single 32 bits word.
    229     // returns true if (matching tag) and (state == VALID) 
    230     // Both data & directory are accessed. 
     229    // returns true if (matching tag) and (state == VALID)
     230    // Both data & directory are accessed.
    231231    /////////////////////////////////////////////////////////////////////
    232     inline bool read(addr_t  ad, 
     232    inline bool read(addr_t  ad,
    233233                     data_t* dt)
    234234    {
     
    237237        const size_t word = m_x[ad];
    238238
    239         for (size_t way = 0; way < m_ways; way++) 
    240         {
    241             if ((tag == cache_tag(way, set)) 
     239        for (size_t way = 0; way < m_ways; way++)
     240        {
     241            if ((tag == cache_tag(way, set))
    242242                   && ((cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) or (cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC)) )
    243243            {
     
    252252    ////////////////////////////////////////////////////////////////////
    253253    // Read a single 32 bits word.
    254     // returns true if (matching tag) and (state == VALID) 
    255     // Both data & directory are accessed. 
     254    // returns true if (matching tag) and (state == VALID)
     255    // Both data & directory are accessed.
    256256    // The selected way, set and word index are returned in case of hit.
    257257    /////////////////////////////////////////////////////////////////////
    258     inline bool read(addr_t ad, 
     258    inline bool read(addr_t ad,
    259259                     data_t* dt,
    260260                     size_t* selway,
    261261                     size_t* selset,
    262                      size_t* selword) 
     262                     size_t* selword)
    263263    {
    264264        const addr_t tag  = m_z[ad];
     
    266266        const size_t word = m_x[ad];
    267267
    268         for (size_t way = 0; way < m_ways; way++) 
     268        for (size_t way = 0; way < m_ways; way++)
    269269        {
    270270            if ((tag == cache_tag(way, set)) and
     
    286286    // Both data and directory are accessed.
    287287    // returns the access status in the state argument:
    288     // - VALID : (matching tag) and (state == VALID) 
    289     // - ZOMBI : (matching tag) and (state == ZOMBI) 
     288    // - VALID : (matching tag) and (state == VALID)
     289    // - ZOMBI : (matching tag) and (state == ZOMBI)
    290290    // - MISS  : no matching tag or EMPTY state
    291     // If VALID or ZOMBI, the data, the way, set and word index are 
     291    // If VALID or ZOMBI, the data, the way, set and word index are
    292292    // returned in the other arguments.
    293293    ////////////////////////////////////////////////////////////////////
     
    297297                     size_t* selset,
    298298                     size_t* selword,
    299                      int*    state) 
     299                     int*    state)
    300300    {
    301301        const addr_t tag  = m_z[ad];
     
    303303        const size_t word = m_x[ad];
    304304
    305         // default return values 
     305        // default return values
    306306        *state   = CACHE_SLOT_STATE_EMPTY;
    307307        *selway  = 0;
     
    310310        *dt      = 0;
    311311
    312         for (size_t way = 0; way < m_ways; way++) 
     312        for (size_t way = 0; way < m_ways; way++)
    313313        {
    314314            if (tag == cache_tag(way, set))  // matching tag
     
    343343        }
    344344    }
    345              
     345
    346346    ////////////////////////////////////////////////////////////////////
    347347    // Read a single 32 bits word, without LRU update.
    348     // returns true if (matching tag) and (state == VALID) 
    349     // Both data & directory are accessed. 
     348    // returns true if (matching tag) and (state == VALID)
     349    // Both data & directory are accessed.
    350350    // The selected way, set and word index are returned in case of hit.
    351351    /////////////////////////////////////////////////////////////////////
    352     inline bool read_neutral(addr_t  ad, 
     352    inline bool read_neutral(addr_t  ad,
    353353                             data_t* dt,
    354354                             size_t* selway,
    355355                             size_t* selset,
    356                              size_t* selword) 
     356                             size_t* selword)
    357357    {
    358358        const addr_t tag  = m_z[ad];
     
    360360        const size_t word = m_x[ad];
    361361
    362         for (size_t way = 0; way < m_ways; way++) 
    363         {
    364             if ((tag == cache_tag(way, set)) 
     362        for (size_t way = 0; way < m_ways; way++)
     363        {
     364            if ((tag == cache_tag(way, set))
    365365                   && ((cache_state(way, set) == CACHE_SLOT_STATE_VALID_CC) or (cache_state(way, set) == CACHE_SLOT_STATE_VALID_NCC) ))
    366366            {
     
    377377    /////////////////////////////////////////////////////////////////////////////
    378378    // Read one or two 32 bits word.
    379     // Both data & directory are accessed. 
    380     // Hit if (matching tag) and (valid == true) and (zombi == false) 
     379    // Both data & directory are accessed.
     380    // Hit if (matching tag) and (valid == true) and (zombi == false)
    381381    // If the addressed word is not the last in the cache line,
    382382    // two successive words are returned.
     
    384384    // This function is used by the cc_vcache to get a 64 bits page table entry.
    385385    /////////////////////////////////////////////////////////////////////////////
    386     inline bool read( addr_t  ad, 
    387                       data_t* dt, 
     386    inline bool read( addr_t  ad,
     387                      data_t* dt,
    388388                      data_t* dt_next,
    389389                      size_t* selway,
     
    395395        const size_t word = m_x[ad];
    396396
    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))) 
     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)))
    401401            {
    402402                *dt = cache_data(way, set, word);
    403                 if (word + 1 < m_words) 
     403                if (word + 1 < m_words)
    404404                {
    405405                    *dt_next = cache_data(way, set, word + 1);
     
    419419    // Both data and directory are accessed.
    420420    // returns the access status in the state argument:
    421     // - VALID : (matching tag) and (state == VALID) 
    422     // - ZOMBI : (matching tag) and (state == ZOMBI) 
     421    // - VALID : (matching tag) and (state == VALID)
     422    // - ZOMBI : (matching tag) and (state == ZOMBI)
    423423    // - MISS  : no matching tag or EMPTY state
    424     // If VALID or ZOMBI, the data, the way, set and word index are 
     424    // If VALID or ZOMBI, the data, the way, set and word index are
    425425    // returned in the other arguments.
    426426    ////////////////////////////////////////////////////////////////////
     
    431431                     size_t* selset,
    432432                     size_t* selword,
    433                      int*    state) 
     433                     int*    state)
    434434    {
    435435        const addr_t tag  = m_z[ad];
     
    437437        const size_t word = m_x[ad];
    438438
    439         // default return values 
     439        // default return values
    440440        *state   = CACHE_SLOT_STATE_EMPTY;
    441441        *selway  = 0;
     
    444444        *dt      = 0;
    445445
    446         for (size_t way = 0; way < m_ways; way++) 
     446        for (size_t way = 0; way < m_ways; way++)
    447447        {
    448448            if (tag == cache_tag(way, set))  // matching tag
     
    456456                    *selword = word;
    457457                    *dt      = cache_data(way, set, word);
    458                     if (word + 1 < m_words) 
     458                    if (word + 1 < m_words)
    459459                    {
    460460                        *dt_next = cache_data(way, set, word+1);
     
    470470                    *selword = word;
    471471                    *dt      = cache_data(way, set, word);
    472                     if (word + 1 < m_words) 
     472                    if (word + 1 < m_words)
    473473                    {
    474474                        *dt_next = cache_data(way, set, word + 1);
     
    490490    ///////////////////////////////////////////////////////////////////////////////
    491491    // Checks the cache state for a given address.
    492     // Only the directory is accessed. 
    493     // returns true if (matching tag) and (state == VALID) 
     492    // Only the directory is accessed.
     493    // returns true if (matching tag) and (state == VALID)
    494494    // The selected way, set and first word index are returned in case of hit.
    495495    // This function can be used when we need to access the directory
    496496    // while we write in the data part with a different address in the same cycle.
    497497    ///////////////////////////////////////////////////////////////////////////////
    498     inline bool hit(addr_t  ad, 
     498    inline bool hit(addr_t  ad,
    499499                    size_t* selway,
    500500                    size_t* selset,
     
    505505        const size_t word = m_x[ad];
    506506
    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))) 
     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)))
    511511            {
    512512                *selway  = way;
     
    519519        return false;
    520520    }
    521  
     521
    522522    ///////////////////////////////////////////////////////////////////////////////
    523523    // Checks the cache state for a given address, when the ZOMBI state is used.
    524     // Only the directory is accessed. 
     524    // Only the directory is accessed.
    525525    // Returns the access status in the state argument:
    526     // - VALID if (matching tag) and (state == VALID) 
    527     // - ZOMBI if (matching tag) and (state == ZOMBI) 
     526    // - VALID if (matching tag) and (state == VALID)
     527    // - ZOMBI if (matching tag) and (state == ZOMBI)
    528528    // - EMPTY if no match or (state == EMPTY)
    529529    // The selected way, set and first word index are returned if not empty.
     
    531531    // while we write in the data part with a different address in the same cycle.
    532532    ///////////////////////////////////////////////////////////////////////////////
    533     inline void read_dir(addr_t  ad, 
     533    inline void read_dir(addr_t  ad,
    534534                         int*    state,
    535535                         size_t* way,
     
    540540        const size_t ad_set  = m_y[ad];
    541541        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)) 
     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))
    546546            {
    547547                *state = cache_state(_way, ad_set);
     
    552552            }
    553553        }
    554        
     554
    555555        // return value if not (VALID or ZOMBI)
    556556        *state = CACHE_SLOT_STATE_EMPTY;
     
    559559    ///////////////////////////////////////////////////////////////////////////////
    560560    // Checks the cache state for a slot (set,way), when the ZOMBI state is used.
    561     // Only the directory is accessed. 
     561    // Only the directory is accessed.
    562562    // Returns the access status and the tag value in the state and tag argument.
    563563    ///////////////////////////////////////////////////////////////////////////////
     
    581581    // It does not use the directory and cannot miss.
    582582    //////////////////////////////////////////////////////////////////
    583     inline void write(size_t way, 
    584                       size_t set, 
    585                       size_t word, 
     583    inline void write(size_t way,
     584                      size_t set,
     585                      size_t word,
    586586                      data_t data)
    587587    {
     
    594594    // It does not use the directory and cannot miss.
    595595    ////////////////////////////////////////////////////////////////////////////
    596     inline void write(size_t way, 
    597                       size_t set, 
    598                       size_t word, 
    599                       data_t data, 
     596    inline void write(size_t way,
     597                      size_t set,
     598                      size_t word,
     599                      data_t data,
    600600                      be_t   be)
    601601    {
     
    610610    // It returns true if the line was valid, and returns the line index.
    611611    //////////////////////////////////////////////////////////////////////////
    612     inline bool inval(size_t  way, 
    613                       size_t  set, 
     612    inline bool inval(size_t  way,
     613                      size_t  set,
    614614                      addr_t* nline)
    615615    {
     
    626626    // This function selects a victim slot in an associative set.
    627627    // It cannot fail, as a slot in ZOMBI state is considered EMPTY.
    628     // - we search first an EMPTY slot 
     628    // - we search first an EMPTY slot
    629629    // - if no EMPTY slot, we search an OLD slot, using lru
    630     // It returns the line index (Z + Y fields), the selected slot way and set, 
     630    // It returns the line index (Z + Y fields), the selected slot way and set,
    631631    // and a Boolean indicating that a cleanup is requested.
    632632    //////////////////////////////////////////////////////////////////////////////////
    633     inline bool victim_select(addr_t  ad, 
    634                               addr_t* victim, 
    635                               size_t* way, 
     633    inline bool victim_select(addr_t  ad,
     634                              addr_t* victim,
     635                              size_t* way,
    636636                              size_t* set)
    637637    {
     
    642642        *way = 0;
    643643
    644         // Search first empty slot 
     644        // Search first empty slot
    645645        for (size_t _way = 0 ; _way < m_ways && !found ; _way++)
    646646        {
     
    653653        }
    654654
    655         // If no empty slot, search first  old slot (lru == false) 
     655        // If no empty slot, search first  old slot (lru == false)
    656656        if (!found)
    657         { 
     657        {
    658658            for (size_t _way = 0 ; _way < m_ways && !found ; _way++)
    659659            {
     
    678678    // - if no empty slot, we search an OLD slot not in ZOMBI state,
    679679    // - if not found, we take the first not ZOMBI slot.
    680     // It returns the line index (Z + Y fields), the selected slot way and set, 
     680    // It returns the line index (Z + Y fields), the selected slot way and set,
    681681    // and two Boolean indicating success and a required cleanup.
    682682    //////////////////////////////////////////////////////////////////////////////////
    683     inline void read_select(addr_t  ad, 
    684                             addr_t* victim, 
    685                             size_t* way, 
     683    inline void read_select(addr_t  ad,
     684                            addr_t* victim,
     685                            size_t* way,
    686686                            size_t* set,
    687687                            bool*   found,
     
    692692        *found = false;
    693693
    694         // Search first empty slot 
     694        // Search first empty slot
    695695        for (size_t _way = 0 ; _way < m_ways && !(*found) ; _way++)
    696696        {
     
    704704            }
    705705        }
    706        
    707         // Search first not zombi old slot 
     706
     707        // Search first not zombi old slot
    708708        for (size_t _way = 0 ; _way < m_ways && !(*found) ; _way++)
    709709        {
    710             if (not cache_lru(_way, _set) and 
     710            if (not cache_lru(_way, _set) and
    711711                 (cache_state(_way, _set) != CACHE_SLOT_STATE_ZOMBI))
    712712            {
     
    722722        for (size_t _way = 0 ; _way < m_ways && !(*found) ; _way++)
    723723        {
    724             if (cache_state(_way, _set) != CACHE_SLOT_STATE_ZOMBI) 
     724            if (cache_state(_way, _set) != CACHE_SLOT_STATE_ZOMBI)
    725725            {
    726726                *found   = true;
     
    742742    // identified by the way & set.
    743743    //////////////////////////////////////////////////////////////////
    744     inline void victim_update_tag(addr_t ad, 
    745                                   size_t way, 
     744    inline void victim_update_tag(addr_t ad,
     745                                  size_t way,
    746746                                  size_t set)
    747747    {
     
    757757    // identified by the way & set, when using the ZOMBI state.
    758758    //////////////////////////////////////////////////////////////////
    759     inline void write_dir(addr_t ad, 
    760                           size_t way, 
     759    inline void write_dir(addr_t ad,
     760                          size_t way,
    761761                          size_t set,
    762762                          int    state)
     
    787787    // It does not affect the tag
    788788    //////////////////////////////////////////////////////////////////
    789     inline void write_dir(size_t way, 
     789    inline void write_dir(size_t way,
    790790                          size_t set,
    791791                          int    state)
     
    813813    // Both DATA and DIRECTORY are written
    814814    ///////////////////////////////////////////////////////////////////
    815     inline void update(addr_t  ad, 
    816                        size_t  way, 
    817                        size_t  set, 
     815    inline void update(addr_t  ad,
     816                       size_t  way,
     817                       size_t  set,
    818818                       data_t* buf)
    819819    {
     
    823823        cache_state(way, set) = CACHE_SLOT_STATE_VALID_CC;
    824824        cache_set_lru(way, set);
    825         for (size_t word = 0 ; word < m_words ; word++) 
     825        for (size_t word = 0 ; word < m_words ; word++)
    826826        {
    827827            cache_data(way, set, word) = buf[word] ;
     
    832832    void fileTrace(FILE* file)
    833833    {
    834         for (size_t nway = 0 ; nway < m_ways ; nway++) 
    835         {
    836             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++)
    837837            {
    838838                fprintf(file, "%d / ", (int)cache_state(nway, nset));
    839839                fprintf(file, "way %d / ", (int)nway);
    840840                fprintf(file, "set %d / ", (int)nset);
    841                 fprintf(file, "@ = %08zX / ", 
     841                fprintf(file, "@ = %08zX / ",
    842842                        ((cache_tag(nway, nset) * m_sets + nset) * m_words * 4));
    843                 for (size_t nword = m_words ; nword > 0 ; nword--) 
     843                for (size_t nword = m_words ; nword > 0 ; nword--)
    844844                {
    845845                    unsigned int data = cache_data(nway, nset, nword - 1);
     
    854854    inline void printTrace()
    855855    {
    856         for (size_t way = 0; way < m_ways ; way++) 
     856        for (size_t way = 0; way < m_ways ; way++)
    857857        {
    858858            for (size_t set = 0 ; set < m_sets ; set++)
    859859            {
    860860                addr_t addr = (((addr_t)cache_tag(way,set))*m_words*m_sets+m_words*set)*4;
    861                 std::cout << std::dec << cache_state(way, set) 
    862                           << " | way " << way 
    863                           << " | set " << set 
     861                std::cout << std::dec << cache_state(way, set)
     862                          << " | way " << way
     863                          << " | set " << set
    864864                          << std::hex << " | @ " << addr;
    865865
     
    872872        }
    873873    }
    874    
     874
    875875};
    876876
Note: See TracChangeset for help on using the changeset viewer.