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