gem5  v20.1.0.0
base.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Inria
3  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef __BASE_FILTERS_BASE_HH__
31 #define __BASE_FILTERS_BASE_HH__
32 
33 #include <vector>
34 
35 #include "base/intmath.hh"
36 #include "base/sat_counter.hh"
37 #include "base/types.hh"
38 #include "params/BloomFilterBase.hh"
39 #include "sim/sim_object.hh"
40 
41 namespace BloomFilter {
42 
43 class Base : public SimObject
44 {
45  protected:
47  const unsigned offsetBits;
48 
51 
53  const int sizeBits;
54 
56  const int setThreshold;
57 
58  public:
62  Base(const BloomFilterBaseParams* p)
63  : SimObject(p), offsetBits(p->offset_bits),
64  filter(p->size, SatCounter(p->num_bits)),
65  sizeBits(floorLog2(p->size)), setThreshold(p->threshold)
66  {
67  clear();
68  }
69  virtual ~Base() {};
70 
74  virtual void clear()
75  {
76  for (auto& entry : filter) {
77  entry.reset();
78  }
79  }
80 
87  virtual void
88  merge(const Base* other)
89  {
90  assert(filter.size() == other->filter.size());
91  for (int i = 0; i < filter.size(); ++i){
92  filter[i] += other->filter[i];
93  }
94  }
95 
102  virtual void set(Addr addr) = 0;
103 
111  virtual void unset(Addr addr) {};
112 
120  virtual bool
121  isSet(Addr addr) const
122  {
123  return getCount(addr) >= setThreshold;
124  }
125 
132  virtual int getCount(Addr addr) const { return 0; }
133 
139  virtual int getTotalCount() const
140  {
141  int count = 0;
142  for (const auto& entry : filter) {
143  count += entry;
144  }
145  return count;
146  }
147 };
148 
149 } // namespace BloomFilter
150 
151 #endif // __BASE_FILTERS_BASE_HH__
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
BloomFilter::Base::sizeBits
const int sizeBits
Number of bits needed to represent the size of the filter.
Definition: base.hh:53
BloomFilter::Base::merge
virtual void merge(const Base *other)
Merges the contents of both filters into this' (Bloom Filter union).
Definition: base.hh:88
std::vector< SatCounter >
X86ISA::count
count
Definition: misc.hh:703
floorLog2
std::enable_if< std::is_integral< T >::value, int >::type floorLog2(T x)
Definition: intmath.hh:63
sat_counter.hh
BloomFilter::Base::Base
Base(const BloomFilterBaseParams *p)
Create and clear the filter.
Definition: base.hh:62
BloomFilter::Base::clear
virtual void clear()
Clear the filter by resetting all values.
Definition: base.hh:74
BloomFilter::Base::set
virtual void set(Addr addr)=0
Perform the filter specific function to set the corresponding entries (can be multiple) of an address...
BloomFilter::Base::offsetBits
const unsigned offsetBits
Number of LSB bits to ignore from the the addresses.
Definition: base.hh:47
BloomFilter::Base::filter
std::vector< SatCounter > filter
The filter itself.
Definition: base.hh:50
sim_object.hh
BloomFilter::Base::unset
virtual void unset(Addr addr)
Perform the filter specific function to clear the corresponding entries (can be multiple) of an addre...
Definition: base.hh:111
BloomFilter::Base
Definition: base.hh:43
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
BloomFilter::Base::getCount
virtual int getCount(Addr addr) const
Get the value stored in the corresponding filter entry of an address.
Definition: base.hh:132
SatCounter
Implements an n bit saturating counter and provides methods to increment, decrement,...
Definition: sat_counter.hh:54
BloomFilter::Base::isSet
virtual bool isSet(Addr addr) const
Check if the corresponding filter entries of an address should be considered as set.
Definition: base.hh:121
BloomFilter::Base::setThreshold
const int setThreshold
Threshold at which a filter entry starts being considered as set.
Definition: base.hh:56
types.hh
BloomFilter
Definition: base.hh:41
addr
ip6_addr_t addr
Definition: inet.hh:423
BloomFilter::Base::getTotalCount
virtual int getTotalCount() const
Get the total value stored in the filter entries.
Definition: base.hh:139
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
intmath.hh
BloomFilter::Base::~Base
virtual ~Base()
Definition: base.hh:69
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17