Daniel Carvalho has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/23946 )

Change subject: mem-ruby: Use lookup function in cache
......................................................................

mem-ruby: Use lookup function in cache

There is a function to perform lookups; there is no need to replicate
its code everywhere.

Change-Id: I1290594615d282722cd91071be8ef3c372414e4e
Signed-off-by: Daniel R. Carvalho <oda...@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23946
Reviewed-by: John Alsop <johnathan.al...@amd.com>
Reviewed-by: Jason Lowe-Power <power...@gmail.com>
Maintainer: Jason Lowe-Power <power...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/mem/ruby/structures/CacheMemory.cc
1 file changed, 19 insertions(+), 36 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
  John Alsop: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/mem/ruby/structures/CacheMemory.cc b/src/mem/ruby/structures/CacheMemory.cc
index 08004ac..efdd77d 100644
--- a/src/mem/ruby/structures/CacheMemory.cc
+++ b/src/mem/ruby/structures/CacheMemory.cc
@@ -173,15 +173,12 @@
 CacheMemory::tryCacheAccess(Addr address, RubyRequestType type,
                             DataBlock*& data_ptr)
 {
-    assert(address == makeLineAddress(address));
     DPRINTF(RubyCache, "address: %#x\n", address);
-    int64_t cacheSet = addressToCacheSet(address);
-    int loc = findTagInSet(cacheSet, address);
-    if (loc != -1) {
+    AbstractCacheEntry* entry = lookup(address);
+    if (entry != nullptr) {
         // Do we even have a tag match?
-        AbstractCacheEntry* entry = m_cache[cacheSet][loc];
         m_replacementPolicy_ptr->touch(entry->replacementData);
-        m_cache[cacheSet][loc]->setLastAccess(curTick());
+        entry->setLastAccess(curTick());
         data_ptr = &(entry->getDataBlk());

         if (entry->m_Permission == AccessPermission_Read_Write) {
@@ -201,20 +198,15 @@
 CacheMemory::testCacheAccess(Addr address, RubyRequestType type,
                              DataBlock*& data_ptr)
 {
-    assert(address == makeLineAddress(address));
     DPRINTF(RubyCache, "address: %#x\n", address);
-    int64_t cacheSet = addressToCacheSet(address);
-    int loc = findTagInSet(cacheSet, address);
-
-    if (loc != -1) {
+    AbstractCacheEntry* entry = lookup(address);
+    if (entry != nullptr) {
         // Do we even have a tag match?
-        AbstractCacheEntry* entry = m_cache[cacheSet][loc];
         m_replacementPolicy_ptr->touch(entry->replacementData);
-        m_cache[cacheSet][loc]->setLastAccess(curTick());
+        entry->setLastAccess(curTick());
         data_ptr = &(entry->getDataBlk());

-        return m_cache[cacheSet][loc]->m_Permission !=
-            AccessPermission_NotPresent;
+        return entry->m_Permission != AccessPermission_NotPresent;
     }

     data_ptr = NULL;
@@ -225,11 +217,8 @@
 bool
 CacheMemory::isTagPresent(Addr address) const
 {
-    assert(address == makeLineAddress(address));
-    int64_t cacheSet = addressToCacheSet(address);
-    int loc = findTagInSet(cacheSet, address);
-
-    if (loc == -1) {
+    const AbstractCacheEntry* const entry = lookup(address);
+    if (entry == nullptr) {
         // We didn't find the tag
         DPRINTF(RubyCache, "No tag match for address: %#x\n", address);
         return false;
@@ -476,34 +465,28 @@
 CacheMemory::setLocked(Addr address, int context)
 {
DPRINTF(RubyCache, "Setting Lock for addr: %#x to %d\n", address, context);
-    assert(address == makeLineAddress(address));
-    int64_t cacheSet = addressToCacheSet(address);
-    int loc = findTagInSet(cacheSet, address);
-    assert(loc != -1);
-    m_cache[cacheSet][loc]->setLocked(context);
+    AbstractCacheEntry* entry = lookup(address);
+    assert(entry != nullptr);
+    entry->setLocked(context);
 }

 void
 CacheMemory::clearLocked(Addr address)
 {
     DPRINTF(RubyCache, "Clear Lock for addr: %#x\n", address);
-    assert(address == makeLineAddress(address));
-    int64_t cacheSet = addressToCacheSet(address);
-    int loc = findTagInSet(cacheSet, address);
-    assert(loc != -1);
-    m_cache[cacheSet][loc]->clearLocked();
+    AbstractCacheEntry* entry = lookup(address);
+    assert(entry != nullptr);
+    entry->clearLocked();
 }

 bool
 CacheMemory::isLocked(Addr address, int context)
 {
-    assert(address == makeLineAddress(address));
-    int64_t cacheSet = addressToCacheSet(address);
-    int loc = findTagInSet(cacheSet, address);
-    assert(loc != -1);
+    AbstractCacheEntry* entry = lookup(address);
+    assert(entry != nullptr);
     DPRINTF(RubyCache, "Testing Lock for addr: %#llx cur %d con %d\n",
-            address, m_cache[cacheSet][loc]->m_locked, context);
-    return m_cache[cacheSet][loc]->isLocked(context);
+            address, entry->m_locked, context);
+    return entry->isLocked(context);
 }

 void

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/23946
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I1290594615d282722cd91071be8ef3c372414e4e
Gerrit-Change-Number: 23946
Gerrit-PatchSet: 3
Gerrit-Owner: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: John Alsop <johnathan.al...@amd.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to