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