diff -r 1ef98c3d2ebf -r 492253ed13c8 src/mem/cache/prefetch/base.hh --- a/src/mem/cache/prefetch/base.hh Tue Oct 20 18:50:31 2015 +0100 +++ b/src/mem/cache/prefetch/base.hh Wed Nov 04 10:56:39 2015 +0000 @@ -68,6 +68,9 @@ /** The block size of the parent cache. */ unsigned blkSize; + /** log_2(block size of the parent cache). */ + unsigned lBlkSize; + /** System we belong to */ System* system; @@ -102,6 +105,17 @@ /** Determine if addresses are on the same page */ bool samePage(Addr a, Addr b) const; + /** Determine the address of the block in which a lays */ + Addr blockAddress(Addr a) const; + /** Determine the address of a at block granularity */ + Addr blockIndex(Addr a) const; + /** Determine the address of the page in which a lays */ + Addr pageAddress(Addr a) const; + /** Determine the page-offset of a */ + Addr pageOffset(Addr a) const; + /** Build the address of the i-th block inside the page */ + Addr pageIthBlockAddress(Addr page, uint32_t i) const; + Stats::Scalar pfIssued; diff -r 1ef98c3d2ebf -r 492253ed13c8 src/mem/cache/prefetch/base.cc --- a/src/mem/cache/prefetch/base.cc Tue Oct 20 18:50:31 2015 +0100 +++ b/src/mem/cache/prefetch/base.cc Wed Nov 04 10:56:39 2015 +0000 @@ -48,13 +48,14 @@ #include +#include "base/intmath.hh" #include "mem/cache/prefetch/base.hh" #include "mem/cache/base.hh" #include "sim/system.hh" BasePrefetcher::BasePrefetcher(const BasePrefetcherParams *p) - : ClockedObject(p), cache(nullptr), blkSize(0), system(p->sys), - onMiss(p->on_miss), onRead(p->on_read), + : ClockedObject(p), cache(nullptr), blkSize(0), lBlkSize(0), + system(p->sys), onMiss(p->on_miss), onRead(p->on_read), onWrite(p->on_write), onData(p->on_data), onInst(p->on_inst), masterId(system->getMasterId(name())), pageBytes(system->getPageBytes()) @@ -67,6 +68,7 @@ assert(!cache); cache = _cache; blkSize = cache->getBlockSize(); + lBlkSize = floorLog2(blkSize); } void @@ -76,6 +78,7 @@ .name(name() + ".num_hwpf_issued") .desc("number of hwpf issued") ; + } bool @@ -127,4 +130,32 @@ return roundDown(a, pageBytes) == roundDown(b, pageBytes); } +Addr +BasePrefetcher::blockAddress(Addr a) const +{ + return a & ~(blkSize-1); +} +Addr +BasePrefetcher::blockIndex(Addr a) const +{ + return a >> lBlkSize; +} + +Addr +BasePrefetcher::pageAddress(Addr a) const +{ + return roundDown(a, pageBytes); +} + +Addr +BasePrefetcher::pageOffset(Addr a) const +{ + return a & (pageBytes - 1); +} + +Addr +BasePrefetcher::pageIthBlockAddress(Addr page, uint32_t blockIndex) const +{ + return page + (blockIndex << lBlkSize); +}