Skip to content

Cache model

Pavel Kryukov edited this page May 3, 2017 · 6 revisions

CacheTagArray class

Class CacheTagArray implements the concepts of a real tag array in a CPU cache. As you know, the cache tag array (unlike cache data array) does not stores any real data (bytes of instructions, variables, arrays, etc). It is only responsible for generation hit signal, i.e. it can say whether a particular block is contained by the cache or not, but cannot provide the block data itself.

Implementation provides at least these interfaces:

class CacheTagArray
{
   
public:
    /**
     * Constructor params:
     *
     * 1) size_in_bytes is a number of data bytes that can be stored in the cache,
     *    i.e. if the block size is 16 Bytes then the number of data blocks in the cache is size_in_bytes/16.
     *
     * 2) ways is a number of associative ways in a set, i.e. how many blocks are referred by the same index.
     *
     * 3) block_size_in_bytes is a number of Bytes in a data block
     *
     * 4) addr_size_in_bit is a number of bits in the physical address.
     */
    CacheTagArray( uint32 size_in_bytes,
                   uint32 ways,
                   uint32 block_size_in_bytes, 
                   uint32 addr_size_in_bits);
    /**
     * Return true and way if the byte with the given address is stored in the cache,
     * otherwise, return false.
     *
     * Note that his method updates the LRU information.
     */
    std::pair<bool, uint32> read( uint64 addr);

    /**
     * Return true if the byte with the given address is stored in the cache,
     * otherwise, return false.
     *
     * Note that his method updates the LRU information.
     */
    std::pair<bool, uint32> read_no_lru( uint64 addr) const;
    
    /**
     * Mark that the block containing the byte with the given address
     * is stored in the cache.
     *
     * Note: in order to put the given address inside the tags it is needed
     * to select a way where it will be written in.
     * This selection is being done according to LRU (Least Recently Used)
     * policy.
     *
     * Returns # of updated way
     */
    uint32 write( uint64 addr);
};

You are free to add as many additional methods and classes as you want, but you cannot change these interfaces.

Clone this wiki locally