mem-ruby: Finish implementing BloomFilter merge
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Fri, 10 May 2019 07:13:10 +0000 (09:13 +0200)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Wed, 28 Aug 2019 22:18:37 +0000 (22:18 +0000)
Not all Bloom Filters had their union functionality implemented.
This change adds them.

Change-Id: I86af18d3c5eabd0da8280b57a88789b3af803c04
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18872
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>

src/mem/ruby/filters/AbstractBloomFilter.hh
src/mem/ruby/filters/H3BloomFilter.cc
src/mem/ruby/filters/H3BloomFilter.hh
src/mem/ruby/filters/LSB_CountingBloomFilter.cc
src/mem/ruby/filters/LSB_CountingBloomFilter.hh
src/mem/ruby/filters/MultiBitSelBloomFilter.cc
src/mem/ruby/filters/MultiBitSelBloomFilter.hh

index 6a62d0ab1c9fc506c7da9a37e89e84ed68b654a7..a9826968accbf7dcff7342b34a90d78e1af2e8c1 100644 (file)
@@ -76,8 +76,20 @@ class AbstractBloomFilter : public SimObject
         }
     }
 
-    /** Merges the contents of both filters into this'. */
-    virtual void merge(const AbstractBloomFilter* other) {}
+    /**
+     * Merges the contents of both filters into this' (Bloom Filter union).
+     * Both must have the same number of entries.
+     *
+     * @param other The other bloom filter to merge with.
+     */
+    virtual void
+    merge(const AbstractBloomFilter* other)
+    {
+        assert(filter.size() == other->filter.size());
+        for (int i = 0; i < filter.size(); ++i){
+            filter[i] |= other->filter[i];
+        }
+    }
 
     /**
      * Perform the filter specific function to set the corresponding
index 4e4f95d52018b0df7b3b651bb6769713ca55c0dd..37af607e9e298d2f3547b5ed5964d2727271c1e3 100644 (file)
@@ -367,16 +367,6 @@ H3BloomFilter::~H3BloomFilter()
 {
 }
 
-void
-H3BloomFilter::merge(const AbstractBloomFilter *other)
-{
-    auto* cast_other = static_cast<const H3BloomFilter*>(other);
-    assert(filter.size() == cast_other->filter.size());
-    for (int i = 0; i < filter.size(); ++i){
-        filter[i] |= cast_other->filter[i];
-    }
-}
-
 void
 H3BloomFilter::set(Addr addr)
 {
index 62a8ec1a117fd8ad8ac800f33af538a9588c8617..6a36692b0a150739a8ef1020363013e3e8e8eecb 100644 (file)
@@ -43,7 +43,6 @@ class H3BloomFilter : public AbstractBloomFilter
     H3BloomFilter(const H3BloomFilterParams* p);
     ~H3BloomFilter();
 
-    void merge(const AbstractBloomFilter* other) override;
     void set(Addr addr) override;
     int getCount(Addr addr) const override;
 
index b999a2cb0a4d1b54f8e1caafaecd6a3e837bebcc..d45850d998fa7f7994e5768aca418f378682abd4 100644 (file)
@@ -41,6 +41,20 @@ LSB_CountingBloomFilter::~LSB_CountingBloomFilter()
 {
 }
 
+void
+LSB_CountingBloomFilter::merge(const AbstractBloomFilter* other)
+{
+    auto* cast_other = static_cast<const LSB_CountingBloomFilter*>(other);
+    assert(filter.size() == cast_other->filter.size());
+    for (int i = 0; i < filter.size(); ++i){
+        if (filter[i] < maxValue - cast_other->filter[i]) {
+            filter[i] += cast_other->filter[i];
+        } else {
+            filter[i] = maxValue;
+        }
+    }
+}
+
 void
 LSB_CountingBloomFilter::set(Addr addr)
 {
index 4bc0441dafce817f5e7f89fb934e95de3a81b87e..410f22d22a66b91c97a84e26ef1ba080ffabb0ed 100644 (file)
@@ -39,6 +39,7 @@ class LSB_CountingBloomFilter : public AbstractBloomFilter
     LSB_CountingBloomFilter(const LSB_CountingBloomFilterParams* p);
     ~LSB_CountingBloomFilter();
 
+    void merge(const AbstractBloomFilter* other) override;
     void set(Addr addr) override;
     void unset(Addr addr) override;
 
index 007de8e8bbb2ddc7bb6d4c93910f936bcb4566ab..65428e0b8edf5e7c615867c2d1a6e2230652f1f4 100644 (file)
@@ -46,16 +46,6 @@ MultiBitSelBloomFilter::~MultiBitSelBloomFilter()
 {
 }
 
-void
-MultiBitSelBloomFilter::merge(const AbstractBloomFilter *other)
-{
-    auto cast_other = static_cast<const MultiBitSelBloomFilter*>(other);
-    assert(filter.size() == cast_other->filter.size());
-    for (int i = 0; i < filter.size(); ++i){
-        filter[i] |= cast_other->filter[i];
-    }
-}
-
 void
 MultiBitSelBloomFilter::set(Addr addr)
 {
index 501483dac908769163ba801fe9d52b1ad12ee67b..42ba94c4e54bd5c887e068897ec1424a19a8da07 100644 (file)
@@ -39,7 +39,6 @@ class MultiBitSelBloomFilter : public AbstractBloomFilter
     MultiBitSelBloomFilter(const MultiBitSelBloomFilterParams* p);
     ~MultiBitSelBloomFilter();
 
-    void merge(const AbstractBloomFilter* other) override;
     void set(Addr addr) override;
     int getCount(Addr addr) const override;