gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BulkBloomFilter.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 <cassert>
32 
33 #include "base/intmath.hh"
34 #include "base/str.hh"
36 
37 using namespace std;
38 
40 {
41  m_filter_size = size;
42  m_filter_size_bits = floorLog2(m_filter_size);
43  // split the filter bits in half, c0 and c1
44  m_sector_bits = m_filter_size_bits - 1;
45 
46  m_temp_filter.resize(m_filter_size);
47  m_filter.resize(m_filter_size);
48  clear();
49 
50  // clear temp filter
51  for (int i = 0; i < m_filter_size; ++i) {
52  m_temp_filter[i] = 0;
53  }
54 }
55 
57 {
58 }
59 
60 void
62 {
63  for (int i = 0; i < m_filter_size; i++) {
64  m_filter[i] = 0;
65  }
66 }
67 
68 void
70 {
71  // Not used
72 }
73 
74 void
76 {
77  // Not used
78 }
79 
80 void
82 {
83  // TODO
84 }
85 
86 void
88 {
89  // c0 contains the cache index bits
90  int set_bits = m_sector_bits;
91  int block_bits = RubySystem::getBlockSizeBits();
92  int c0 = bitSelect(addr, block_bits, block_bits + set_bits - 1);
93  // c1 contains the lower m_sector_bits permuted bits
94  //Address permuted_bits = permute(addr);
95  //int c1 = permuted_bits.bitSelect(0, set_bits-1);
96  int c1 = bitSelect(addr, block_bits+set_bits, (block_bits+2*set_bits) - 1);
97  //assert(c0 < (m_filter_size/2));
98  //assert(c0 + (m_filter_size/2) < m_filter_size);
99  //assert(c1 < (m_filter_size/2));
100  // set v0 bit
101  m_filter[c0 + (m_filter_size/2)] = 1;
102  // set v1 bit
103  m_filter[c1] = 1;
104 }
105 
106 void
108 {
109  // not used
110 }
111 
112 bool
114 {
115  // c0 contains the cache index bits
116  int set_bits = m_sector_bits;
117  int block_bits = RubySystem::getBlockSizeBits();
118  int c0 = bitSelect(addr, block_bits, block_bits + set_bits - 1);
119  // c1 contains the lower 10 permuted bits
120  //Address permuted_bits = permute(addr);
121  //int c1 = permuted_bits.bitSelect(0, set_bits-1);
122  int c1 = bitSelect(addr, block_bits+set_bits, (block_bits+2*set_bits) - 1);
123  //assert(c0 < (m_filter_size/2));
124  //assert(c0 + (m_filter_size/2) < m_filter_size);
125  //assert(c1 < (m_filter_size/2));
126  // set v0 bit
127  m_temp_filter[c0 + (m_filter_size/2)] = 1;
128  // set v1 bit
129  m_temp_filter[c1] = 1;
130 
131  // perform filter intersection. If any c part is 0, no possibility
132  // of address being in signature. get first c intersection part
133  bool zero = false;
134  for (int i = 0; i < m_filter_size/2; ++i){
135  // get intersection of signatures
136  m_temp_filter[i] = m_temp_filter[i] && m_filter[i];
137  zero = zero || m_temp_filter[i];
138  }
139  zero = !zero;
140  if (zero) {
141  // one section is zero, no possiblility of address in signature
142  // reset bits we just set
143  m_temp_filter[c0 + (m_filter_size / 2)] = 0;
144  m_temp_filter[c1] = 0;
145  return false;
146  }
147 
148  // check second section
149  zero = false;
150  for (int i = m_filter_size / 2; i < m_filter_size; ++i) {
151  // get intersection of signatures
152  m_temp_filter[i] = m_temp_filter[i] && m_filter[i];
153  zero = zero || m_temp_filter[i];
154  }
155  zero = !zero;
156  if (zero) {
157  // one section is zero, no possiblility of address in signature
158  m_temp_filter[c0 + (m_filter_size / 2)] = 0;
159  m_temp_filter[c1] = 0;
160  return false;
161  }
162  // one section has at least one bit set
163  m_temp_filter[c0 + (m_filter_size / 2)] = 0;
164  m_temp_filter[c1] = 0;
165  return true;
166 }
167 
168 int
170 {
171  // not used
172  return 0;
173 }
174 
175 int
177 {
178  int count = 0;
179  for (int i = 0; i < m_filter_size; i++) {
180  if (m_filter[i]) {
181  count++;
182  }
183  }
184  return count;
185 }
186 
187 int
189 {
190  return get_index(addr);
191 }
192 
193 int
195 {
196  return 0;
197  // TODO
198 }
199 
200 void
201 BulkBloomFilter::writeBit(const int index, const int value)
202 {
203  // TODO
204 }
205 
206 void
207 BulkBloomFilter::print(ostream& out) const
208 {
209 }
210 
211 int
213 {
216  m_filter_size_bits - 1);
217 }
218 
219 Addr
221 {
222  // permutes the original address bits according to Table 5
223  int block_offset = RubySystem::getBlockSizeBits();
224  Addr part1 = bitSelect(addr, block_offset, block_offset + 6),
225  part2 = bitSelect(addr, block_offset + 9, block_offset + 9),
226  part3 = bitSelect(addr, block_offset + 11, block_offset + 11),
227  part4 = bitSelect(addr, block_offset + 17, block_offset + 17),
228  part5 = bitSelect(addr, block_offset + 7, block_offset + 8),
229  part6 = bitSelect(addr, block_offset + 10, block_offset + 10),
230  part7 = bitSelect(addr, block_offset + 12, block_offset + 12),
231  part8 = bitSelect(addr, block_offset + 13, block_offset + 13),
232  part9 = bitSelect(addr, block_offset + 15, block_offset + 16),
233  part10 = bitSelect(addr, block_offset + 18, block_offset + 20),
234  part11 = bitSelect(addr, block_offset + 14, block_offset + 14);
235 
236  Addr result =
237  (part1 << 14) | (part2 << 13) | (part3 << 12) | (part4 << 11) |
238  (part5 << 9) | (part6 << 8) | (part7 << 7) | (part8 << 6) |
239  (part9 << 4) | (part10 << 1) | (part11);
240 
241  // assume 32 bit addresses (both virtual and physical)
242  // select the remaining high-order 11 bits
243  Addr remaining_bits =
244  bitSelect(addr, block_offset + 21, 31) << 21;
245  result = result | remaining_bits;
246 
247  return result;
248 }
count
Definition: misc.hh:704
Bitfield< 30, 0 > index
Addr bitSelect(Addr addr, unsigned int small, unsigned int big)
Definition: Address.cc:34
Bitfield< 7 > i
Definition: miscregs.hh:1378
ip6_addr_t addr
Definition: inet.hh:335
bool isSet(Addr addr)
BulkBloomFilter(int size)
int get_index(Addr addr)
void writeBit(const int index, const int value)
void decrement(Addr addr)
Addr permute(Addr addr)
void set(Addr addr)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
int readBit(const int index)
int getCount(Addr addr)
int floorLog2(unsigned x)
Definition: intmath.hh:100
int size()
Definition: pagetable.hh:146
void unset(Addr addr)
void increment(Addr addr)
void print(std::ostream &out) const
static uint32_t getBlockSizeBits()
Definition: RubySystem.hh:75
void merge(AbstractBloomFilter *other_filter)
int getIndex(Addr addr)

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