ruby: get rid of Vector and use STL
[gem5.git] / src / mem / ruby / filters / MultiGrainBloomFilter.cc
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
29 #include "base/intmath.hh"
30 #include "base/str.hh"
31 #include "mem/gems_common/Map.hh"
32 #include "mem/ruby/common/Address.hh"
33 #include "mem/ruby/filters/MultiGrainBloomFilter.hh"
34
35 using namespace std;
36
37 MultiGrainBloomFilter::MultiGrainBloomFilter(string str)
38 {
39 string head, tail;
40 #ifndef NDEBUG
41 bool success =
42 #endif
43 split_first(str, head, tail, '_');
44 assert(success);
45
46 // head contains size of 1st bloom filter, tail contains size of
47 // 2nd bloom filter
48
49 m_filter_size = atoi(head.c_str());
50 m_filter_size_bits = floorLog2(m_filter_size);
51
52 m_page_filter_size = atoi(tail.c_str());
53 m_page_filter_size_bits = floorLog2(m_page_filter_size);
54
55 m_filter.resize(m_filter_size);
56 m_page_filter.resize(m_page_filter_size);
57 clear();
58 }
59
60 MultiGrainBloomFilter::~MultiGrainBloomFilter()
61 {
62 }
63
64 void
65 MultiGrainBloomFilter::clear()
66 {
67 for (int i = 0; i < m_filter_size; i++) {
68 m_filter[i] = 0;
69 }
70 for(int i=0; i < m_page_filter_size; ++i){
71 m_page_filter[i] = 0;
72 }
73 }
74
75 void
76 MultiGrainBloomFilter::increment(const Address& addr)
77 {
78 // Not used
79 }
80
81
82 void
83 MultiGrainBloomFilter::decrement(const Address& addr)
84 {
85 // Not used
86 }
87
88 void
89 MultiGrainBloomFilter::merge(AbstractBloomFilter *other_filter)
90 {
91 // TODO
92 }
93
94 void
95 MultiGrainBloomFilter::set(const Address& addr)
96 {
97 int i = get_block_index(addr);
98 assert(i < m_filter_size);
99 assert(get_page_index(addr) < m_page_filter_size);
100 m_filter[i] = 1;
101 m_page_filter[i] = 1;
102
103 }
104
105 void
106 MultiGrainBloomFilter::unset(const Address& addr)
107 {
108 // not used
109 }
110
111 bool
112 MultiGrainBloomFilter::isSet(const Address& addr)
113 {
114 int i = get_block_index(addr);
115 assert(i < m_filter_size);
116 assert(get_page_index(addr) < m_page_filter_size);
117 // we have to have both indices set
118 return (m_filter[i] && m_page_filter[i]);
119 }
120
121 int
122 MultiGrainBloomFilter::getCount(const Address& addr)
123 {
124 // not used
125 return 0;
126 }
127
128 int
129 MultiGrainBloomFilter::getTotalCount()
130 {
131 int count = 0;
132
133 for (int i = 0; i < m_filter_size; i++) {
134 count += m_filter[i];
135 }
136
137 for(int i=0; i < m_page_filter_size; ++i) {
138 count += m_page_filter[i] = 0;
139 }
140
141 return count;
142 }
143
144 int
145 MultiGrainBloomFilter::getIndex(const Address& addr)
146 {
147 return 0;
148 // TODO
149 }
150
151 int
152 MultiGrainBloomFilter::readBit(const int index)
153 {
154 return 0;
155 // TODO
156 }
157
158 void
159 MultiGrainBloomFilter::writeBit(const int index, const int value)
160 {
161 // TODO
162 }
163
164 void
165 MultiGrainBloomFilter::print(ostream& out) const
166 {
167 }
168
169 int
170 MultiGrainBloomFilter::get_block_index(const Address& addr)
171 {
172 // grap a chunk of bits after byte offset
173 return addr.bitSelect(RubySystem::getBlockSizeBits(),
174 RubySystem::getBlockSizeBits() +
175 m_filter_size_bits - 1);
176 }
177
178 int
179 MultiGrainBloomFilter::get_page_index(const Address & addr)
180 {
181 int bits = RubySystem::getBlockSizeBits() + m_filter_size_bits - 1;
182
183 // grap a chunk of bits after first chunk
184 return addr.bitSelect(bits, bits + m_page_filter_size_bits - 1);
185 }
186
187
188
189