mem-cache: ambiguous use of abs function
authorRyan Gambord <gambordr@oregonstate.edu>
Thu, 4 Apr 2019 16:25:07 +0000 (12:25 -0400)
committerRyan Gambord <gambordr@oregonstate.edu>
Fri, 5 Apr 2019 18:10:04 +0000 (18:10 +0000)
std::abs doesn't accept unsigned long long, generating the error:

error: call to 'abs' is ambiguous

Use instead a compare-and-subtract idiom.

Also, Changed return type of distanceFromTrigger from unsigned int to Addr to
prevent overflow problems.

Change-Id: Ia7752c1c7a838f98e8c7ed6ade9f586f31bbcf7d
Signed-off-by: Ryan Gambord <gambordr@oregonstate.edu>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/17788
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>

src/mem/cache/prefetch/pif.cc
src/mem/cache/prefetch/pif.hh

index 04064d4970a78ab1d3c08deb454ec71ec80a9300..c8cc109fd1a605ab84b6ae8831e230413bbddb17 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "mem/cache/prefetch/pif.hh"
 
-#include <cmath>
 #include <utility>
 
 #include "debug/HWPrefetch.hh"
@@ -59,20 +58,22 @@ PIFPrefetcher::CompactorEntry::CompactorEntry(Addr addr,
     succ.resize(succ_size, false);
 }
 
-unsigned int
+Addr
 PIFPrefetcher::CompactorEntry::distanceFromTrigger(Addr target,
-        unsigned int log_blk_size) const {
+        unsigned int log_blk_size) const
+{
     const Addr target_blk = target >> log_blk_size;
     const Addr trigger_blk = trigger >> log_blk_size;
 
-    return std::abs(target_blk - trigger_blk);
+    return target_blk > trigger_blk ?
+              target_blk - trigger_blk : trigger_blk - target_blk;
 }
 
 bool
 PIFPrefetcher::CompactorEntry::inSameSpatialRegion(Addr pc,
         unsigned int log_blk_size, bool update)
 {
-    unsigned int blk_distance = distanceFromTrigger(pc, log_blk_size);
+    Addr blk_distance = distanceFromTrigger(pc, log_blk_size);
 
     bool hit = (pc > trigger) ?
         (succ.size() >= blk_distance) : (prec.size() >= blk_distance);
@@ -90,7 +91,7 @@ bool
 PIFPrefetcher::CompactorEntry::hasAddress(Addr target,
                                           unsigned int log_blk_size) const
 {
-    unsigned int blk_distance = distanceFromTrigger(target, log_blk_size);
+    Addr blk_distance = distanceFromTrigger(target, log_blk_size);
     bool hit = false;
     if (target > trigger) {
         hit = blk_distance <= succ.size() && succ[blk_distance - 1];
index 6516b2c6aa0f786372635fab348cdcd6c48690a5..abff4fafb94a36047336e5473eff091e52e4579f 100644 (file)
@@ -116,8 +116,8 @@ class PIFPrefetcher : public QueuedPrefetcher
              * @param log_blk_distance log_2(block size of the cache)
              * @result distance in cache blocks from the address to the trigger
              */
-            unsigned int distanceFromTrigger(Addr addr,
-                                             unsigned int log_blk_size) const;
+            Addr distanceFromTrigger(Addr addr,
+                                     unsigned int log_blk_size) const;
         };
 
         CompactorEntry spatialCompactor;