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.
29 #include "base/intmath.hh"
30 #include "base/str.hh"
31 #include "mem/ruby/filters/BlockBloomFilter.hh"
32 #include "mem/ruby/system/System.hh"
36 BlockBloomFilter::BlockBloomFilter(string str
)
43 split_first(str
, head
, tail
, '_');
47 m_filter_size
= atoi(head
.c_str());
48 m_filter_size_bits
= floorLog2(m_filter_size
);
50 m_filter
.resize(m_filter_size
);
55 BlockBloomFilter::~BlockBloomFilter()
60 BlockBloomFilter::clear()
62 for (int i
= 0; i
< m_filter_size
; i
++) {
68 BlockBloomFilter::increment(const Address
& addr
)
74 BlockBloomFilter::decrement(const Address
& addr
)
80 BlockBloomFilter::merge(AbstractBloomFilter
* other_filter
)
86 BlockBloomFilter::set(const Address
& addr
)
88 int i
= get_index(addr
);
93 BlockBloomFilter::unset(const Address
& addr
)
95 int i
= get_index(addr
);
100 BlockBloomFilter::isSet(const Address
& addr
)
102 int i
= get_index(addr
);
103 return (m_filter
[i
]);
107 BlockBloomFilter::getCount(const Address
& addr
)
109 return m_filter
[get_index(addr
)];
113 BlockBloomFilter::getTotalCount()
117 for (int i
= 0; i
< m_filter_size
; i
++) {
126 BlockBloomFilter::getIndex(const Address
& addr
)
128 return get_index(addr
);
132 BlockBloomFilter::print(ostream
& out
) const
137 BlockBloomFilter::readBit(const int index
)
139 return m_filter
[index
];
143 BlockBloomFilter::writeBit(const int index
, const int value
)
145 m_filter
[index
] = value
;
149 BlockBloomFilter::get_index(const Address
& addr
)
151 // Pull out some bit field ==> B1
152 // Pull out additional bits, not the same as B1 ==> B2
153 // XOR B1 and B2 to get hash index
154 physical_address_t block_bits
=
155 addr
.bitSelect(RubySystem::getBlockSizeBits(),
156 2 * RubySystem::getBlockSizeBits() - 1);
158 physical_address_t other_bits
=
159 addr
.bitSelect(2 * RubySystem::getBlockSizeBits() + offset
,
160 2 * RubySystem::getBlockSizeBits() + offset
+
161 m_filter_size_bits
- 1);
162 int index
= block_bits
^ other_bits
;
163 assert(index
< m_filter_size
);