gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiBitSelBloomFilter.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
30 
31 #include <vector>
32 
33 #include "base/intmath.hh"
34 #include "base/str.hh"
35 
36 using namespace std;
37 
39 {
40  vector<string> items;
41  tokenize(items, str, '_');
42  assert(items.size() == 4);
43 
44  // head contains filter size, tail contains bit offset from block number
45  m_filter_size = atoi(items[0].c_str());
46  m_num_hashes = atoi(items[1].c_str());
47  m_skip_bits = atoi(items[2].c_str());
48 
49  if (items[3] == "Regular") {
50  isParallel = false;
51  } else if (items[3] == "Parallel") {
52  isParallel = true;
53  } else {
54  panic("ERROR: Incorrect config string for MultiBitSel Bloom! :%s",
55  str);
56  }
57 
58  m_filter_size_bits = floorLog2(m_filter_size);
59 
60  m_par_filter_size = m_filter_size / m_num_hashes;
61  m_par_filter_size_bits = floorLog2(m_par_filter_size);
62 
63  m_filter.resize(m_filter_size);
64  clear();
65 }
66 
68 {
69 }
70 
71 void
73 {
74  for (int i = 0; i < m_filter_size; i++) {
75  m_filter[i] = 0;
76  }
77 }
78 
79 void
81 {
82  // Not used
83 }
84 
85 
86 void
88 {
89  // Not used
90 }
91 
92 void
94 {
95  // assumes both filters are the same size!
96  MultiBitSelBloomFilter * temp = (MultiBitSelBloomFilter*) other_filter;
97  for (int i = 0; i < m_filter_size; ++i){
98  m_filter[i] |= (*temp)[i];
99  }
100 }
101 
102 void
104 {
105  for (int i = 0; i < m_num_hashes; i++) {
106  int idx = get_index(addr, i);
107  m_filter[idx] = 1;
108  }
109 }
110 
111 void
113 {
114  cout << "ERROR: Unset should never be called in a Bloom filter";
115  assert(0);
116 }
117 
118 bool
120 {
121  bool res = true;
122 
123  for (int i=0; i < m_num_hashes; i++) {
124  int idx = get_index(addr, i);
125  res = res && m_filter[idx];
126  }
127  return res;
128 }
129 
130 int
132 {
133  return isSet(addr)? 1: 0;
134 }
135 
136 int
138 {
139  return 0;
140 }
141 
142 int
144 {
145  return 0;
146 }
147 
148 void
149 MultiBitSelBloomFilter::writeBit(const int index, const int value)
150 {
151 }
152 
153 int
155 {
156  int count = 0;
157 
158  for (int i = 0; i < m_filter_size; i++) {
159  count += m_filter[i];
160  }
161  return count;
162 }
163 
164 void
165 MultiBitSelBloomFilter::print(ostream& out) const
166 {
167 }
168 
169 int
171 {
172  // m_skip_bits is used to perform BitSelect after skipping some
173  // bits. Used to simulate BitSel hashing on larger than cache-line
174  // granularities
175  uint64_t x = (makeLineAddress(addr) >> m_skip_bits);
176  int y = hash_bitsel(x, i, m_num_hashes, 30, m_filter_size_bits);
177  //36-bit addresses, 6-bit cache lines
178 
179  if (isParallel) {
180  return (y % m_par_filter_size) + i*m_par_filter_size;
181  } else {
182  return y % m_filter_size;
183  }
184 }
185 
186 int
187 MultiBitSelBloomFilter::hash_bitsel(uint64_t value, int index, int jump,
188  int maxBits, int numBits)
189 {
190  uint64_t mask = 1;
191  int result = 0;
192  int bit, i;
193 
194  for (i = 0; i < numBits; i++) {
195  bit = (index + jump*i) % maxBits;
196  if (value & (mask << bit)) result += mask << i;
197  }
198  return result;
199 }
count
Definition: misc.hh:704
Bitfield< 30, 0 > index
Bitfield< 7 > i
Definition: miscregs.hh:1378
#define panic(...)
Definition: misc.hh:153
ip6_addr_t addr
Definition: inet.hh:335
int hash_bitsel(uint64_t value, int index, int jump, int maxBits, int numBits)
void print(std::ostream &out) const
MultiBitSelBloomFilter(std::string config)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Addr makeLineAddress(Addr addr)
Definition: Address.cc:112
int floorLog2(unsigned x)
Definition: intmath.hh:100
void tokenize(vector< string > &v, const string &s, char token, bool ignore)
Definition: str.cc:69
Bitfield< 3, 0 > mask
Definition: types.hh:64
void writeBit(const int index, const int value)
Bitfield< 1 > x
Definition: types.hh:105
int get_index(Addr addr, int hashNumber)
void merge(AbstractBloomFilter *other_filter)
int readBit(const int index)

Generated on Fri Jun 9 2017 13:03:49 for gem5 by doxygen 1.8.6