2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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.
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.
31 #include "base/intmath.hh"
32 #include "base/str.hh"
33 #include "mem/ruby/filters/MultiBitSelBloomFilter.hh"
37 MultiBitSelBloomFilter::MultiBitSelBloomFilter(string str
)
40 tokenize(items
, str
, '_');
41 assert(items
.size() == 4);
43 // head contains filter size, tail contains bit offset from block number
44 m_filter_size
= atoi(items
[0].c_str());
45 m_num_hashes
= atoi(items
[1].c_str());
46 m_skip_bits
= atoi(items
[2].c_str());
48 if (items
[3] == "Regular") {
50 } else if (items
[3] == "Parallel") {
53 panic("ERROR: Incorrect config string for MultiBitSel Bloom! :%s",
57 m_filter_size_bits
= floorLog2(m_filter_size
);
59 m_par_filter_size
= m_filter_size
/ m_num_hashes
;
60 m_par_filter_size_bits
= floorLog2(m_par_filter_size
);
62 m_filter
.resize(m_filter_size
);
66 MultiBitSelBloomFilter::~MultiBitSelBloomFilter()
71 MultiBitSelBloomFilter::clear()
73 for (int i
= 0; i
< m_filter_size
; i
++) {
79 MultiBitSelBloomFilter::increment(Addr addr
)
86 MultiBitSelBloomFilter::decrement(Addr addr
)
92 MultiBitSelBloomFilter::merge(AbstractBloomFilter
*other_filter
)
94 // assumes both filters are the same size!
95 MultiBitSelBloomFilter
* temp
= (MultiBitSelBloomFilter
*) other_filter
;
96 for(int i
= 0; i
< m_filter_size
; ++i
){
97 m_filter
[i
] |= (*temp
)[i
];
102 MultiBitSelBloomFilter::set(Addr addr
)
104 for (int i
= 0; i
< m_num_hashes
; i
++) {
105 int idx
= get_index(addr
, i
);
111 MultiBitSelBloomFilter::unset(Addr addr
)
113 cout
<< "ERROR: Unset should never be called in a Bloom filter";
118 MultiBitSelBloomFilter::isSet(Addr addr
)
122 for (int i
=0; i
< m_num_hashes
; i
++) {
123 int idx
= get_index(addr
, i
);
124 res
= res
&& m_filter
[idx
];
130 MultiBitSelBloomFilter::getCount(Addr addr
)
132 return isSet(addr
)? 1: 0;
136 MultiBitSelBloomFilter::getIndex(Addr addr
)
142 MultiBitSelBloomFilter::readBit(const int index
)
148 MultiBitSelBloomFilter::writeBit(const int index
, const int value
)
153 MultiBitSelBloomFilter::getTotalCount()
157 for (int i
= 0; i
< m_filter_size
; i
++) {
158 count
+= m_filter
[i
];
164 MultiBitSelBloomFilter::print(ostream
& out
) const
169 MultiBitSelBloomFilter::get_index(Addr addr
, int i
)
171 // m_skip_bits is used to perform BitSelect after skipping some
172 // bits. Used to simulate BitSel hashing on larger than cache-line
174 uint64 x
= (makeLineAddress(addr
) >> m_skip_bits
);
175 int y
= hash_bitsel(x
, i
, m_num_hashes
, 30, m_filter_size_bits
);
176 //36-bit addresses, 6-bit cache lines
179 return (y
% m_par_filter_size
) + i
*m_par_filter_size
;
181 return y
% m_filter_size
;
186 MultiBitSelBloomFilter::hash_bitsel(uint64 value
, int index
, int jump
,
187 int maxBits
, int numBits
)
193 for (i
= 0; i
< numBits
; i
++) {
194 bit
= (index
+ jump
*i
) % maxBits
;
195 if (value
& (mask
<< bit
)) result
+= mask
<< i
;