Otawa  0.10
otawa::hard::Cache Class Reference

This class contains the configuration of a level of cache of processor. More...

#include <otawa/hard/Cache.h>

Classes

struct  info_t
 

Public Types

enum  replace_policy_t {
  NONE = 0, OTHER = 1, LRU = 2, RANDOM = 3,
  FIFO = 4, PLRU = 5
}
 
enum  write_policy_t { WRITE_THROUGH = 0, WRITE_BACK = 1 }
 
typedef enum
otawa::hard::Cache::replace_policy_t 
replace_policy_t
 
typedef enum
otawa::hard::Cache::write_policy_t 
write_policity_t
 
typedef struct
otawa::hard::Cache::info_t 
info_t
 
typedef t::uint32 block_t
 
typedef t::uint32 set_t
 
typedef t::uint32 tag_t
 
typedef t::uint32 offset_t
 

Public Member Functions

 Cache (void)
 
 Cache (const Cache &cache, const Cache *next=0)
 Build a cache by cloning an existing cache and setting it in new cache configuration. More...
 
virtual ~Cache (void)
 
const CachenextLevel (void) const
 Get the next level of cache. More...
 
ot::size cacheSize (void) const
 Get the cache size. More...
 
ot::size blockSize (void) const
 Get the block size. More...
 
int wayCount (void) const
 Get the count of ways for associatives caches. More...
 
int setCount (void) const
 
int blockCount (void) const
 
replace_policy_t replacementPolicy (void) const
 Get the replacement policy. More...
 
write_policy_t writePolicy (void) const
 Get the write policy. More...
 
bool doesWriteAllocate (void) const
 Set the behaviour about write allocation. More...
 
int missPenalty (void) const
 Return the time penaly of a missed access to memory. More...
 
int writeBufferSize (void) const
 Get the write buffer size of this cache (0 for no write buffer). More...
 
int readPortSize (void) const
 Get the read port size of this cache (default to 1, must be non-null). More...
 
int writePortSize (void) const
 Get the write port size of this cache (default to 1 for data cache). More...
 
int blockBits (void) const
 Required bits count for a byte address in the block. More...
 
int setBits (void) const
 
int tagBits (void) const
 Required bits count in the tag part of the address. More...
 
int wayBits (void) const
 Get the number of bits to count the ways in set associative cache. More...
 
ot::mask blockMask (void) const
 Mask for selecting the address of a byte in a block in a memory address. More...
 
ot::mask setMask (void) const
 
ot::mask tagMask (void) const
 Mask for selecting the tag in a memory address. More...
 
offset_t offset (Address addr) const
 Compute the offset of the accessed byte in the block from the memory address. More...
 
set_t set (Address addr) const
 
tag_t tag (Address addr) const
 Compute the tag from the memory address. More...
 
block_t block (Address addr) const
 Return the bits used for identifying uniquely a block, that is, tag and line number. More...
 
Address round (Address addr) const
 Round the given address to the address of the container cache block. More...
 
void setAccessTime (int access_time)
 Set the access time. More...
 
void setMissPenalty (int miss_penalty)
 Set the miss penaly time. More...
 
void setBlockBits (int block_bits)
 
void setRowBits (int set_bits)
 Set the row count as a number of bits. More...
 
void setWayBits (int way_bits)
 Set the way count as a number of bits. More...
 
void setReplacePolicy (replace_policy_t replace)
 Set the replace policy of the cache. More...
 
void setWritePolicy (write_policy_t write)
 Set the write policy of the cache. More...
 
void setAllocate (bool allocate)
 Set the allocation state. More...
 
void setWriteBufferSize (int write_buffer_size)
 Set the write buffer size (0 for no write buffer). More...
 
void setReadPortSize (int read_port_size)
 Set the read port size (at least 1). More...
 
void setWritePortSize (int write_port_size)
 Set the write port size (at least 1). More...
 
int rowBits (void) const
 Required bits count for a row index. More...
 
ot::mask lineMask (void) const
 Mask for selecting the line number in a memory address. More...
 
ot::mask rowMask (void) const
 
ot::mask line (const Address &addr) const
 Compute the line number from the memory address. More...
 
int rowCount (void) const
 Get the count of rows. More...
 

Private Member Functions

 SERIALIZABLE (Cache, field("access_time", _info.access_time, 1)&field("miss_penalty", _info.miss_penalty, 10)&field("block_bits", _info.block_bits, 4)&field("row_bits", _info.row_bits, 12)&field("way_bits", _info.way_bits, 0)&field("allocate", _info.allocate, false)&field("next", _next,(const Cache *) 0)&field("replace", _info.replace, LRU)&field("write_buffer_size", _info.write_buffer_size, 0)&field("read_port_size", _info.read_port_size, 1)&field("write_port_size", _info.write_port_size, 1)&field("write", _info.write, WRITE_THROUGH))
 

Private Attributes

info_t _info
 
const Cache_next
 

Detailed Description

This class contains the configuration of a level of cache of processor.

It may represents direct-mapped or associative cache (with any associatvity level) using bits as block/line boundaries. Supported management policies (when they apply) are only LRU, FIFO, RANDOM and PLRU. Once built, a cache object is viewed as a read-only database.

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
NONE 
OTHER 
LRU 
RANDOM 
FIFO 
PLRU 
Enumerator
WRITE_THROUGH 
WRITE_BACK 

Constructor & Destructor Documentation

otawa::hard::Cache::Cache ( void  )
otawa::hard::Cache::Cache ( const Cache cache,
const Cache next = 0 
)

Build a cache by cloning an existing cache and setting it in new cache configuration.

Parameters
nextNext level of cache (null if there is no more cache).
otawa::hard::Cache::~Cache ( void  )
virtual

Member Function Documentation

mask_t otawa::hard::Cache::block ( Address  addr) const
inline

Return the bits used for identifying uniquely a block, that is, tag and line number.

Parameters
addrAddress to take block from.
Returns
Block part of the address.

References blockBits(), and otawa::Address::offset().

Referenced by otawa::ccg::LBlockBuilder::addLBlock(), otawa::LBlockBuilder::addLBlock(), otawa::dcache::CLPBlockBuilder::processBB(), and otawa::ccg::Builder::processLBlockSet().

int otawa::hard::Cache::blockCount ( void  ) const
inline
mask_t otawa::hard::Cache::blockMask ( void  ) const
inline

Mask for selecting the address of a byte in a block in a memory address.

Returns
Byte address mask in the block.

References blockSize().

Referenced by otawa::ccg::LBlockBuilder::addLBlock(), otawa::LBlockBuilder::addLBlock(), offset(), otawa::ccg::LBlockBuilder::processBB(), otawa::LBlockBuilder::processBB(), otawa::dcache::BlockBuilder::processBB(), and tagMask().

size_t otawa::hard::Cache::blockSize ( void  ) const
inline
size_t otawa::hard::Cache::cacheSize ( void  ) const
inline

Get the cache size.

Returns
Cache size in bytes.

References blockBits(), rowBits(), and wayBits().

Referenced by otawa::dcache::BlockBuilder::processBB().

bool otawa::hard::Cache::doesWriteAllocate ( void  ) const
inline

Set the behaviour about write allocation.

Returns
Write-allocate if true, No-write-allocate else.

References _info, and otawa::hard::Cache::info_t::allocate.

mask_t otawa::hard::Cache::line ( const Address addr) const
inline

Compute the line number from the memory address.

Parameters
addrMemory address to compute from.
Returns
Line number.

References blockBits(), lineMask(), and otawa::Address::offset().

Referenced by otawa::sim::AbstractCacheDriver::access(), otawa::ets::ACSComputation::initialization(), otawa::dcache::BlockBuilder::processBB(), and otawa::FirstLastBuilder::processCFG().

mask_t otawa::hard::Cache::lineMask ( void  ) const
inline

Mask for selecting the line number in a memory address.

Returns
Line number bits.

References blockBits(), and rowCount().

Referenced by line(), set(), and tagMask().

Cache * otawa::hard::Cache::nextLevel ( void  ) const
inline

Get the next level of cache.

Returns
Next cache level or null if there is no more cache.

References _next.

Referenced by otawa::hard::CacheConfiguration::cacheName().

mask_t otawa::hard::Cache::offset ( Address  addr) const
inline

Compute the offset of the accessed byte in the block from the memory address.

Parameters
addrMemory address to compute from.
Returns
Accessed byte offset in the block.

References blockMask(), and otawa::Address::offset().

Referenced by otawa::ipet::TrivialInstCacheManager::processBB(), and otawa::dcache::CLPBlockBuilder::processBB().

int otawa::hard::Cache::readPortSize ( void  ) const
inline

Get the read port size of this cache (default to 1, must be non-null).

Returns
Read port size.

References _info, and otawa::hard::Cache::info_t::read_port_size.

Cache::replace_policy_t otawa::hard::Cache::replacementPolicy ( void  ) const
inline
Address otawa::hard::Cache::round ( Address  addr) const
inline

Round the given address to the address of the container cache block.

Parameters
addrAddress to round.
Returns
Round address.

References blockSize(), otawa::Address::isNull(), otawa::Address::offset(), and otawa::Address::page().

Referenced by otawa::ccg::LBlockBuilder::addLBlock(), otawa::LBlockBuilder::addLBlock(), and otawa::dcache::CLPBlockBuilder::processBB().

int otawa::hard::Cache::rowBits ( void  ) const
inline

Required bits count for a row index.

Returns
Line index bits.

References _info, and otawa::hard::Cache::info_t::row_bits.

Referenced by cacheSize(), rowCount(), setCount(), tag(), and tagBits().

ot::mask otawa::hard::Cache::rowMask ( void  ) const
inline

References blockBits(), and rowCount().

otawa::hard::Cache::SERIALIZABLE ( Cache  ,
field("access_time", _info.access_time, 1)&field("miss_penalty", _info.miss_penalty, 10)&field("block_bits", _info.block_bits, 4)&field("row_bits", _info.row_bits, 12)&field("way_bits", _info.way_bits, 0)&field("allocate", _info.allocate, false)&field("next", _next,(const Cache *) 0)&field("replace", _info.replace, LRU)&field("write_buffer_size", _info.write_buffer_size, 0)&field("read_port_size", _info.read_port_size, 1)&field("write_port_size", _info.write_port_size, 1)&field("write", _info.write, WRITE_THROUGH  
)
private
void otawa::hard::Cache::setAccessTime ( int  access_time)

Set the access time.

Parameters
access_timeAccess time in processor cycles.

References _info, and otawa::hard::Cache::info_t::access_time.

void otawa::hard::Cache::setAllocate ( bool  allocate)

Set the allocation state.

If true, the write operation also allocate a block. If false, no allocation arise.

Parameters
allocateAllocate state.

References _info, and otawa::hard::Cache::info_t::allocate.

int otawa::hard::Cache::setBits ( void  ) const
inline
void otawa::hard::Cache::setBlockBits ( int  block_bits)
int otawa::hard::Cache::setCount ( void  ) const
inline

References rowBits().

Referenced by otawa::dcache::BlockAccess::inSet().

ot::mask otawa::hard::Cache::setMask ( void  ) const
inline

References blockBits(), and rowCount().

void otawa::hard::Cache::setMissPenalty ( int  miss_penalty)

Set the miss penaly time.

Parameters
miss_penalyMiss penalty time in processor cycles.

References _info, and otawa::hard::Cache::info_t::miss_penalty.

void otawa::hard::Cache::setReadPortSize ( int  read_port_size)

Set the read port size (at least 1).

Parameters
read_port_sizeRead port size.

References _info, and otawa::hard::Cache::info_t::read_port_size.

void otawa::hard::Cache::setReplacePolicy ( replace_policy_t  replace)

Set the replace policy of the cache.

Parameters
replaceReplace policy, one of OTHER, LRU, RANDOM, FIFO, PLRU.

References _info, OTHER, PLRU, and otawa::hard::Cache::info_t::replace.

void otawa::hard::Cache::setRowBits ( int  row_bits)

Set the row count as a number of bits.

The actual row count is 1 << row_bits.

Parameters
row_bitsRow count in bits.

References _info, and otawa::hard::Cache::info_t::row_bits.

void otawa::hard::Cache::setWayBits ( int  way_bits)

Set the way count as a number of bits.

The actual way count is 1 << way_bits.

Parameters
way_bitsWay count in bits.

References _info, and otawa::hard::Cache::info_t::way_bits.

void otawa::hard::Cache::setWriteBufferSize ( int  write_buffer_size)

Set the write buffer size (0 for no write buffer).

Parameters
write_buffer_sizeWrite buffer size.

References _info, and otawa::hard::Cache::info_t::write_buffer_size.

void otawa::hard::Cache::setWritePolicy ( write_policy_t  write)

Set the write policy of the cache.

Parameters
writeWrite policy, one of WRITE_THROUGH or WRITE_BACK.

References _info, otawa::hard::Cache::info_t::write, WRITE_BACK, and WRITE_THROUGH.

void otawa::hard::Cache::setWritePortSize ( int  write_port_size)

Set the write port size (at least 1).

Parameters
read_write_sizeWrite port size.

References _info, and otawa::hard::Cache::info_t::write_port_size.

mask_t otawa::hard::Cache::tag ( Address  addr) const
inline

Compute the tag from the memory address.

Parameters
addrMemory address to compute from.
Returns
Tag.

References blockBits(), otawa::Address::offset(), and rowBits().

Referenced by otawa::sim::AbstractCacheDriver::access(), and otawa::dcache::BlockAccess::inSet().

int otawa::hard::Cache::tagBits ( void  ) const
inline

Required bits count in the tag part of the address.

Returns
Tag bits.

References blockBits(), and rowBits().

mask_t otawa::hard::Cache::tagMask ( void  ) const
inline

Mask for selecting the tag in a memory address.

Returns
Tag selection mask.

References blockMask(), and lineMask().

int otawa::hard::Cache::wayBits ( void  ) const
inline

Get the number of bits to count the ways in set associative cache.

This value is 1 for direct-mapped cache.

Returns
Way count bits.

References _info, and otawa::hard::Cache::info_t::way_bits.

Referenced by cacheSize(), and wayCount().

int otawa::hard::Cache::writeBufferSize ( void  ) const
inline

Get the write buffer size of this cache (0 for no write buffer).

Returns
Write buffer size.

References _info, and otawa::hard::Cache::info_t::write_buffer_size.

Cache::write_policy_t otawa::hard::Cache::writePolicy ( void  ) const
inline

Get the write policy.

Returns
Write policy.

References _info, and otawa::hard::Cache::info_t::write.

int otawa::hard::Cache::writePortSize ( void  ) const
inline

Get the write port size of this cache (default to 1 for data cache).

Returns
Write port size.

References _info, and otawa::hard::Cache::info_t::write_port_size.

Member Data Documentation

const Cache* otawa::hard::Cache::_next
private

Referenced by nextLevel().


The documentation for this class was generated from the following files: