mem-ruby: Fix maskLowOrderBits
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Sat, 7 Sep 2019 09:45:25 +0000 (11:45 +0200)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Mon, 30 Sep 2019 20:58:46 +0000 (20:58 +0000)
The function was wrong when number = 63. Also, use the more reliable
src/base/bitfield.hh's mbits when posible.

maskLowOrderBits has only been kept because SLICC does not accept
a templated function.

Change-Id: I8dd680da02ceb9e614e2f9cbf8f1ac52cead8d45
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21084
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Anthony Gutierrez <anthony.gutierrez@amd.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/mem/ruby/common/Address.cc
src/mem/ruby/profiler/AddressProfiler.cc
src/mem/ruby/structures/Prefetcher.cc

index 1afefc236d6300bdda15f4b3288244ca6e0c3dd3..5c89d31ccb5a1cb1bb46b154a2e1aba408e2f384 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "mem/ruby/common/Address.hh"
 
+#include "base/bitfield.hh"
 #include "mem/ruby/system/RubySystem.hh"
 
 Addr
@@ -48,14 +49,7 @@ bitSelect(Addr addr, unsigned int small, unsigned int big)
 Addr
 maskLowOrderBits(Addr addr, unsigned int number)
 {
-  Addr mask;
-
-  if (number >= ADDRESS_WIDTH - 1) {
-      mask = ~0;
-  } else {
-      mask = (Addr)~0 << number;
-  }
-  return (addr & mask);
+    return mbits<Addr>(addr, 63, number);
 }
 
 Addr
@@ -67,15 +61,14 @@ getOffset(Addr addr)
 Addr
 makeLineAddress(Addr addr)
 {
-    return maskLowOrderBits(addr, RubySystem::getBlockSizeBits());
+    return mbits<Addr>(addr, 63, RubySystem::getBlockSizeBits());
 }
 
 // returns the next stride address based on line address
 Addr
 makeNextStrideAddress(Addr addr, int stride)
 {
-    return maskLowOrderBits(addr, RubySystem::getBlockSizeBits())
-        + RubySystem::getBlockSizeBytes() * stride;
+    return makeLineAddress(addr) + RubySystem::getBlockSizeBytes() * stride;
 }
 
 std::string
@@ -83,7 +76,6 @@ printAddress(Addr addr)
 {
     std::stringstream out;
     out << "[" << std::hex << "0x" << addr << "," << " line 0x"
-       << maskLowOrderBits(addr, RubySystem::getBlockSizeBits())
-       << std::dec << "]";
+       << makeLineAddress(addr) << std::dec << "]";
     return out.str();
 }
index acdc860232c3708ea8f89eaf2f6ef02f777e60c6..9d96de707ea41a0fb6bd98be159233e8cfb50339 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <vector>
 
+#include "base/bitfield.hh"
 #include "base/stl_helpers.hh"
 #include "mem/ruby/profiler/Profiler.hh"
 #include "mem/ruby/protocol/RubyRequest.hh"
@@ -298,7 +299,7 @@ AddressProfiler::addTraceSample(Addr data_addr, Addr pc_addr,
         // record macro data address trace info
 
         // 6 for datablock, 4 to make it 16x more coarse
-        Addr macro_addr = maskLowOrderBits(data_addr, 10);
+        Addr macro_addr = mbits<Addr>(data_addr, 63, 10);
         lookupTraceForAddress(macro_addr, m_macroBlockAccessTrace).
             update(type, access_mode, id, sharing_miss);
 
index df8fdfcba7386d5eb3301f6aa2c1e803f322988a..70b30352ea73abaff086e7effaee39d3be0e7759 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "mem/ruby/structures/Prefetcher.hh"
 
+#include "base/bitfield.hh"
 #include "debug/RubyPrefetcher.hh"
 #include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh"
 #include "mem/ruby/system/RubySystem.hh"
@@ -475,5 +476,5 @@ Prefetcher::print(std::ostream& out) const
 Addr
 Prefetcher::pageAddress(Addr addr) const
 {
-    return maskLowOrderBits(addr, m_page_shift);
+    return mbits<Addr>(addr, 63, m_page_shift);
 }