ruby: change advance_stage for flit_d
[gem5.git] / src / mem / ruby / filters / BlockBloomFilter.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/BlockBloomFilter.hh"
32 #include "mem/ruby/system/System.hh"
33
34 using namespace std;
35
36 BlockBloomFilter::BlockBloomFilter(string str)
37 {
38 string head, tail;
39
40 #ifndef NDEBUG
41 bool success =
42 #endif
43 split_first(str, head, tail, '_');
44
45 assert(success);
46
47 m_filter_size = atoi(head.c_str());
48 m_filter_size_bits = floorLog2(m_filter_size);
49
50 m_filter.resize(m_filter_size);
51
52 clear();
53 }
54
55 BlockBloomFilter::~BlockBloomFilter()
56 {
57 }
58
59 void
60 BlockBloomFilter::clear()
61 {
62 for (int i = 0; i < m_filter_size; i++) {
63 m_filter[i] = 0;
64 }
65 }
66
67 void
68 BlockBloomFilter::increment(const Address& addr)
69 {
70 // Not used
71 }
72
73 void
74 BlockBloomFilter::decrement(const Address& addr)
75 {
76 // Not used
77 }
78
79 void
80 BlockBloomFilter::merge(AbstractBloomFilter * other_filter)
81 {
82 // TODO
83 }
84
85 void
86 BlockBloomFilter::set(const Address& addr)
87 {
88 int i = get_index(addr);
89 m_filter[i] = 1;
90 }
91
92 void
93 BlockBloomFilter::unset(const Address& addr)
94 {
95 int i = get_index(addr);
96 m_filter[i] = 0;
97 }
98
99 bool
100 BlockBloomFilter::isSet(const Address& addr)
101 {
102 int i = get_index(addr);
103 return (m_filter[i]);
104 }
105
106 int
107 BlockBloomFilter::getCount(const Address& addr)
108 {
109 return m_filter[get_index(addr)];
110 }
111
112 int
113 BlockBloomFilter::getTotalCount()
114 {
115 int count = 0;
116
117 for (int i = 0; i < m_filter_size; i++) {
118 if (m_filter[i]) {
119 count++;
120 }
121 }
122 return count;
123 }
124
125 int
126 BlockBloomFilter::getIndex(const Address& addr)
127 {
128 return get_index(addr);
129 }
130
131 void
132 BlockBloomFilter::print(ostream& out) const
133 {
134 }
135
136 int
137 BlockBloomFilter::readBit(const int index)
138 {
139 return m_filter[index];
140 }
141
142 void
143 BlockBloomFilter::writeBit(const int index, const int value)
144 {
145 m_filter[index] = value;
146 }
147
148 int
149 BlockBloomFilter::get_index(const Address& addr)
150 {
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);
157 int offset = 5;
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);
164 return index;
165 }
166
167