gem5  v22.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/compiler.hh"
36 #include "base/intmath.hh"
37 #include "base/sat_counter.hh"
38 #include "base/types.hh"
39 #include "params/BloomFilterBase.hh"
40 #include "sim/sim_object.hh"
41 
42 namespace gem5
43 {
44 
45 GEM5_DEPRECATED_NAMESPACE(BloomFilter, bloom_filter);
46 namespace bloom_filter
47 {
48 
49 class Base : public SimObject
50 {
51  protected:
53  const unsigned offsetBits;
54 
57 
59  const int sizeBits;
60 
62  const int setThreshold;
63 
64  public:
68  Base(const BloomFilterBaseParams &p)
69  : SimObject(p), offsetBits(p.offset_bits),
70  filter(p.size, SatCounter8(p.num_bits)),
71  sizeBits(floorLog2(p.size)), setThreshold(p.threshold)
72  {
73  clear();
74  }
75  virtual ~Base() {};
76 
80  virtual void clear()
81  {
82  for (auto& entry : filter) {
83  entry.reset();
84  }
85  }
86 
93  virtual void
94  merge(const Base* other)
95  {
96  assert(filter.size() == other->filter.size());
97  for (int i = 0; i < filter.size(); ++i){
98  filter[i] += other->filter[i];
99  }
100  }
101 
108  virtual void set(Addr addr) = 0;
109 
117  virtual void unset(Addr addr) {};
118 
126  virtual bool
127  isSet(Addr addr) const
128  {
129  return getCount(addr) >= setThreshold;
130  }
131 
138  virtual int getCount(Addr addr) const { return 0; }
139 
145  virtual int getTotalCount() const
146  {
147  int count = 0;
148  for (const auto& entry : filter) {
149  count += entry;
150  }
151  return count;
152  }
153 };
154 
155 } // namespace bloom_filter
156 } // namespace gem5
157 
158 #endif // __BASE_FILTERS_BASE_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
virtual bool isSet(Addr addr) const
Check if the corresponding filter entries of an address should be considered as set.
Definition: base.hh:127
std::vector< SatCounter8 > filter
The filter itself.
Definition: base.hh:56
const int setThreshold
Threshold at which a filter entry starts being considered as set.
Definition: base.hh:62
virtual void unset(Addr addr)
Perform the filter specific function to clear the corresponding entries (can be multiple) of an addre...
Definition: base.hh:117
virtual int getTotalCount() const
Get the total value stored in the filter entries.
Definition: base.hh:145
virtual void clear()
Clear the filter by resetting all values.
Definition: base.hh:80
const int sizeBits
Number of bits needed to represent the size of the filter.
Definition: base.hh:59
const unsigned offsetBits
Number of LSB bits to ignore from the the addresses.
Definition: base.hh:53
virtual void set(Addr addr)=0
Perform the filter specific function to set the corresponding entries (can be multiple) of an address...
Base(const BloomFilterBaseParams &p)
Create and clear the filter.
Definition: base.hh:68
virtual int getCount(Addr addr) const
Get the value stored in the corresponding filter entry of an address.
Definition: base.hh:138
virtual void merge(const Base *other)
Merges the contents of both filters into this' (Bloom Filter union).
Definition: base.hh:94
STL vector class.
Definition: stl.hh:37
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition: intmath.hh:59
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)

Generated on Wed Dec 21 2022 10:22:28 for gem5 by doxygen 1.9.1