gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
42namespace gem5
43{
44
45namespace bloom_filter
46{
47
48class Base : public SimObject
49{
50 protected:
52 const unsigned offsetBits;
53
56
58 const int sizeBits;
59
61 const int setThreshold;
62
63 public:
67 Base(const BloomFilterBaseParams &p)
68 : SimObject(p), offsetBits(p.offset_bits),
69 filter(p.size, SatCounter8(p.num_bits)),
70 sizeBits(floorLog2(p.size)), setThreshold(p.threshold)
71 {
72 clear();
73 }
74 virtual ~Base() {};
75
79 virtual void clear()
80 {
81 for (auto& entry : filter) {
82 entry.reset();
83 }
84 }
85
92 virtual void
93 merge(const Base* other)
94 {
95 assert(filter.size() == other->filter.size());
96 for (int i = 0; i < filter.size(); ++i){
97 filter[i] += other->filter[i];
98 }
99 }
100
107 virtual void set(Addr addr) = 0;
108
116 virtual void unset(Addr addr) {};
117
125 virtual bool
127 {
128 return getCount(addr) >= setThreshold;
129 }
130
137 virtual int getCount(Addr addr) const { return 0; }
138
144 virtual int getTotalCount() const
145 {
146 int count = 0;
147 for (const auto& entry : filter) {
148 count += entry;
149 }
150 return count;
151 }
152};
153
154} // namespace bloom_filter
155} // namespace gem5
156
157#endif // __BASE_FILTERS_BASE_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Abstract superclass for simulation objects.
virtual bool isSet(Addr addr) const
Check if the corresponding filter entries of an address should be considered as set.
Definition base.hh:126
std::vector< SatCounter8 > filter
The filter itself.
Definition base.hh:55
const int setThreshold
Threshold at which a filter entry starts being considered as set.
Definition base.hh:61
virtual void unset(Addr addr)
Perform the filter specific function to clear the corresponding entries (can be multiple) of an addre...
Definition base.hh:116
virtual int getTotalCount() const
Get the total value stored in the filter entries.
Definition base.hh:144
virtual void clear()
Clear the filter by resetting all values.
Definition base.hh:79
const int sizeBits
Number of bits needed to represent the size of the filter.
Definition base.hh:58
const unsigned offsetBits
Number of LSB bits to ignore from the the addresses.
Definition base.hh:52
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:67
virtual int getCount(Addr addr) const
Get the value stored in the corresponding filter entry of an address.
Definition base.hh:137
virtual void merge(const Base *other)
Merges the contents of both filters into this' (Bloom Filter union).
Definition base.hh:93
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< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0