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/MultiGrainBloomFilter.hh"
32 #include "mem/ruby/system/System.hh"
36 MultiGrainBloomFilter::MultiGrainBloomFilter(string str
)
42 split_first(str
, head
, tail
, '_');
45 // head contains size of 1st bloom filter, tail contains size of
48 m_filter_size
= atoi(head
.c_str());
49 m_filter_size_bits
= floorLog2(m_filter_size
);
51 m_page_filter_size
= atoi(tail
.c_str());
52 m_page_filter_size_bits
= floorLog2(m_page_filter_size
);
54 m_filter
.resize(m_filter_size
);
55 m_page_filter
.resize(m_page_filter_size
);
59 MultiGrainBloomFilter::~MultiGrainBloomFilter()
64 MultiGrainBloomFilter::clear()
66 for (int i
= 0; i
< m_filter_size
; i
++) {
69 for(int i
=0; i
< m_page_filter_size
; ++i
){
75 MultiGrainBloomFilter::increment(Addr addr
)
82 MultiGrainBloomFilter::decrement(Addr addr
)
88 MultiGrainBloomFilter::merge(AbstractBloomFilter
*other_filter
)
94 MultiGrainBloomFilter::set(Addr addr
)
96 int i
= get_block_index(addr
);
97 assert(i
< m_filter_size
);
98 assert(get_page_index(addr
) < m_page_filter_size
);
100 m_page_filter
[i
] = 1;
105 MultiGrainBloomFilter::unset(Addr addr
)
111 MultiGrainBloomFilter::isSet(Addr addr
)
113 int i
= get_block_index(addr
);
114 assert(i
< m_filter_size
);
115 assert(get_page_index(addr
) < m_page_filter_size
);
116 // we have to have both indices set
117 return (m_filter
[i
] && m_page_filter
[i
]);
121 MultiGrainBloomFilter::getCount(Addr addr
)
128 MultiGrainBloomFilter::getTotalCount()
132 for (int i
= 0; i
< m_filter_size
; i
++) {
133 count
+= m_filter
[i
];
136 for(int i
=0; i
< m_page_filter_size
; ++i
) {
137 count
+= m_page_filter
[i
] = 0;
144 MultiGrainBloomFilter::getIndex(Addr addr
)
151 MultiGrainBloomFilter::readBit(const int index
)
158 MultiGrainBloomFilter::writeBit(const int index
, const int value
)
164 MultiGrainBloomFilter::print(ostream
& out
) const
169 MultiGrainBloomFilter::get_block_index(Addr addr
)
171 // grap a chunk of bits after byte offset
172 return bitSelect(addr
, RubySystem::getBlockSizeBits(),
173 RubySystem::getBlockSizeBits() +
174 m_filter_size_bits
- 1);
178 MultiGrainBloomFilter::get_page_index(Addr addr
)
180 int bits
= RubySystem::getBlockSizeBits() + m_filter_size_bits
- 1;
182 // grap a chunk of bits after first chunk
183 return bitSelect(addr
, bits
, bits
+ m_page_filter_size_bits
- 1);