Address.hh (6712:b95abe00dd9d) Address.hh (7002:48a19d52d939)
1
2/*
3 * Copyright (c) 1999 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/*
31 * $Id$
32 */
33
34#ifndef ADDRESS_H
35#define ADDRESS_H
36
37#include <iomanip>
1
2/*
3 * Copyright (c) 1999 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/*
31 * $Id$
32 */
33
34#ifndef ADDRESS_H
35#define ADDRESS_H
36
37#include <iomanip>
38
39#include "base/hashmap.hh"
38#include "mem/ruby/common/Global.hh"
39#include "mem/ruby/system/System.hh"
40#include "mem/ruby/system/NodeID.hh"
41#include "mem/ruby/system/MachineID.hh"
42
43const int ADDRESS_WIDTH = 64; // address width in bytes
44
45class Address;
46typedef Address PhysAddress;
47typedef Address VirtAddress;
48
49class Address {
50public:
51 // Constructors
52 Address() { m_address = 0; }
53 explicit Address(physical_address_t address) { m_address = address; }
54
55 Address(const Address& obj);
56 Address& operator=(const Address& obj);
57
58 // Destructor
59 // ~Address();
60
61 // Public Methods
62
63 void setAddress(physical_address_t address) { m_address = address; }
64 physical_address_t getAddress() const {return m_address;}
65 // selects bits inclusive
66 physical_address_t bitSelect(int small, int big) const;
67 physical_address_t maskLowOrderBits(int number) const;
68 physical_address_t maskHighOrderBits(int number) const;
69 physical_address_t shiftLowOrderBits(int number) const;
70 physical_address_t getLineAddress() const
71 { return bitSelect(RubySystem::getBlockSizeBits(), ADDRESS_WIDTH); }
72 physical_address_t getOffset() const
73 { return bitSelect(0, RubySystem::getBlockSizeBits()-1); }
74
75 void makeLineAddress() { m_address = maskLowOrderBits(RubySystem::getBlockSizeBits()); }
76 // returns the next stride address based on line address
77 void makeNextStrideAddress( int stride) {
78 m_address = maskLowOrderBits(RubySystem::getBlockSizeBits())
79 + RubySystem::getBlockSizeBytes()*stride;
80 }
81 int getBankSetNum() const;
82 int getBankSetDist() const;
83
84 Index memoryModuleIndex() const;
85
86 void print(ostream& out) const;
87 void output(ostream& out) const;
88 void input(istream& in);
89
90 void setOffset( int offset ){
91 // first, zero out the offset bits
92 makeLineAddress();
93 m_address |= (physical_address_t) offset;
94 }
95
96private:
97 // Private Methods
98
99 // Private copy constructor and assignment operator
100 // Address(const Address& obj);
101 // Address& operator=(const Address& obj);
102
103 // Data Members (m_ prefix)
104 physical_address_t m_address;
105};
106
107inline
108Address line_address(const Address& addr) { Address temp(addr); temp.makeLineAddress(); return temp; }
109
110// Output operator declaration
111ostream& operator<<(ostream& out, const Address& obj);
112// comparison operator declaration
113bool operator==(const Address& obj1, const Address& obj2);
114bool operator!=(const Address& obj1, const Address& obj2);
115bool operator<(const Address& obj1, const Address& obj2);
116/* Address& operator=(const physical_address_t address); */
117
118inline
119bool operator<(const Address& obj1, const Address& obj2)
120{
121 return obj1.getAddress() < obj2.getAddress();
122}
123
124// ******************* Definitions *******************
125
126// Output operator definition
127inline
128ostream& operator<<(ostream& out, const Address& obj)
129{
130 obj.print(out);
131 out << flush;
132 return out;
133}
134
135inline
136bool operator==(const Address& obj1, const Address& obj2)
137{
138 return (obj1.getAddress() == obj2.getAddress());
139}
140
141inline
142bool operator!=(const Address& obj1, const Address& obj2)
143{
144 return (obj1.getAddress() != obj2.getAddress());
145}
146
147inline
148physical_address_t Address::bitSelect(int small, int big) const // rips bits inclusive
149{
150 physical_address_t mask;
151 assert((unsigned)big >= (unsigned)small);
152
153 if (big >= ADDRESS_WIDTH - 1) {
154 return (m_address >> small);
155 } else {
156 mask = ~((physical_address_t)~0 << (big + 1));
157 // FIXME - this is slow to manipulate a 64-bit number using 32-bits
158 physical_address_t partial = (m_address & mask);
159 return (partial >> small);
160 }
161}
162
163inline
164physical_address_t Address::maskLowOrderBits(int number) const
165{
166 physical_address_t mask;
167
168 if (number >= ADDRESS_WIDTH - 1) {
169 mask = ~0;
170 } else {
171 mask = (physical_address_t)~0 << number;
172 }
173 return (m_address & mask);
174}
175
176inline
177physical_address_t Address::maskHighOrderBits(int number) const
178{
179 physical_address_t mask;
180
181 if (number >= ADDRESS_WIDTH - 1) {
182 mask = ~0;
183 } else {
184 mask = (physical_address_t)~0 >> number;
185 }
186 return (m_address & mask);
187}
188
189inline
190physical_address_t Address::shiftLowOrderBits(int number) const
191{
192 return (m_address >> number);
193}
194
195inline
196integer_t Address::memoryModuleIndex() const
197{
198 integer_t index = bitSelect(RubySystem::getBlockSizeBits()+RubySystem::getMemorySizeBits(), ADDRESS_WIDTH);
199 assert (index >= 0);
200 return index;
201
202 // Index indexHighPortion = address.bitSelect(MEMORY_SIZE_BITS-1, PAGE_SIZE_BITS+NUMBER_OF_MEMORY_MODULE_BITS);
203 // Index indexLowPortion = address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS-1);
204
205 //Index index = indexLowPortion | (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));
206
207 /*
208 Round-robin mapping of addresses, at page size granularity
209
210ADDRESS_WIDTH MEMORY_SIZE_BITS PAGE_SIZE_BITS DATA_BLOCK_BITS
211 | | | |
212 \ / \ / \ / \ / 0
213 -----------------------------------------------------------------------
214 | unused |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
215 | |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
216 -----------------------------------------------------------------------
217 indexHighPortion indexLowPortion
218 <------->
219 NUMBER_OF_MEMORY_MODULE_BITS
220 */
221}
222
223inline
224void Address::print(ostream& out) const
225{
40#include "mem/ruby/common/Global.hh"
41#include "mem/ruby/system/System.hh"
42#include "mem/ruby/system/NodeID.hh"
43#include "mem/ruby/system/MachineID.hh"
44
45const int ADDRESS_WIDTH = 64; // address width in bytes
46
47class Address;
48typedef Address PhysAddress;
49typedef Address VirtAddress;
50
51class Address {
52public:
53 // Constructors
54 Address() { m_address = 0; }
55 explicit Address(physical_address_t address) { m_address = address; }
56
57 Address(const Address& obj);
58 Address& operator=(const Address& obj);
59
60 // Destructor
61 // ~Address();
62
63 // Public Methods
64
65 void setAddress(physical_address_t address) { m_address = address; }
66 physical_address_t getAddress() const {return m_address;}
67 // selects bits inclusive
68 physical_address_t bitSelect(int small, int big) const;
69 physical_address_t maskLowOrderBits(int number) const;
70 physical_address_t maskHighOrderBits(int number) const;
71 physical_address_t shiftLowOrderBits(int number) const;
72 physical_address_t getLineAddress() const
73 { return bitSelect(RubySystem::getBlockSizeBits(), ADDRESS_WIDTH); }
74 physical_address_t getOffset() const
75 { return bitSelect(0, RubySystem::getBlockSizeBits()-1); }
76
77 void makeLineAddress() { m_address = maskLowOrderBits(RubySystem::getBlockSizeBits()); }
78 // returns the next stride address based on line address
79 void makeNextStrideAddress( int stride) {
80 m_address = maskLowOrderBits(RubySystem::getBlockSizeBits())
81 + RubySystem::getBlockSizeBytes()*stride;
82 }
83 int getBankSetNum() const;
84 int getBankSetDist() const;
85
86 Index memoryModuleIndex() const;
87
88 void print(ostream& out) const;
89 void output(ostream& out) const;
90 void input(istream& in);
91
92 void setOffset( int offset ){
93 // first, zero out the offset bits
94 makeLineAddress();
95 m_address |= (physical_address_t) offset;
96 }
97
98private:
99 // Private Methods
100
101 // Private copy constructor and assignment operator
102 // Address(const Address& obj);
103 // Address& operator=(const Address& obj);
104
105 // Data Members (m_ prefix)
106 physical_address_t m_address;
107};
108
109inline
110Address line_address(const Address& addr) { Address temp(addr); temp.makeLineAddress(); return temp; }
111
112// Output operator declaration
113ostream& operator<<(ostream& out, const Address& obj);
114// comparison operator declaration
115bool operator==(const Address& obj1, const Address& obj2);
116bool operator!=(const Address& obj1, const Address& obj2);
117bool operator<(const Address& obj1, const Address& obj2);
118/* Address& operator=(const physical_address_t address); */
119
120inline
121bool operator<(const Address& obj1, const Address& obj2)
122{
123 return obj1.getAddress() < obj2.getAddress();
124}
125
126// ******************* Definitions *******************
127
128// Output operator definition
129inline
130ostream& operator<<(ostream& out, const Address& obj)
131{
132 obj.print(out);
133 out << flush;
134 return out;
135}
136
137inline
138bool operator==(const Address& obj1, const Address& obj2)
139{
140 return (obj1.getAddress() == obj2.getAddress());
141}
142
143inline
144bool operator!=(const Address& obj1, const Address& obj2)
145{
146 return (obj1.getAddress() != obj2.getAddress());
147}
148
149inline
150physical_address_t Address::bitSelect(int small, int big) const // rips bits inclusive
151{
152 physical_address_t mask;
153 assert((unsigned)big >= (unsigned)small);
154
155 if (big >= ADDRESS_WIDTH - 1) {
156 return (m_address >> small);
157 } else {
158 mask = ~((physical_address_t)~0 << (big + 1));
159 // FIXME - this is slow to manipulate a 64-bit number using 32-bits
160 physical_address_t partial = (m_address & mask);
161 return (partial >> small);
162 }
163}
164
165inline
166physical_address_t Address::maskLowOrderBits(int number) const
167{
168 physical_address_t mask;
169
170 if (number >= ADDRESS_WIDTH - 1) {
171 mask = ~0;
172 } else {
173 mask = (physical_address_t)~0 << number;
174 }
175 return (m_address & mask);
176}
177
178inline
179physical_address_t Address::maskHighOrderBits(int number) const
180{
181 physical_address_t mask;
182
183 if (number >= ADDRESS_WIDTH - 1) {
184 mask = ~0;
185 } else {
186 mask = (physical_address_t)~0 >> number;
187 }
188 return (m_address & mask);
189}
190
191inline
192physical_address_t Address::shiftLowOrderBits(int number) const
193{
194 return (m_address >> number);
195}
196
197inline
198integer_t Address::memoryModuleIndex() const
199{
200 integer_t index = bitSelect(RubySystem::getBlockSizeBits()+RubySystem::getMemorySizeBits(), ADDRESS_WIDTH);
201 assert (index >= 0);
202 return index;
203
204 // Index indexHighPortion = address.bitSelect(MEMORY_SIZE_BITS-1, PAGE_SIZE_BITS+NUMBER_OF_MEMORY_MODULE_BITS);
205 // Index indexLowPortion = address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS-1);
206
207 //Index index = indexLowPortion | (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));
208
209 /*
210 Round-robin mapping of addresses, at page size granularity
211
212ADDRESS_WIDTH MEMORY_SIZE_BITS PAGE_SIZE_BITS DATA_BLOCK_BITS
213 | | | |
214 \ / \ / \ / \ / 0
215 -----------------------------------------------------------------------
216 | unused |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
217 | |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
218 -----------------------------------------------------------------------
219 indexHighPortion indexLowPortion
220 <------->
221 NUMBER_OF_MEMORY_MODULE_BITS
222 */
223}
224
225inline
226void Address::print(ostream& out) const
227{
226 out << "[" << hex << "0x" << m_address << "," << " line 0x" << maskLowOrderBits(RubySystem::getBlockSizeBits()) << dec << "]" << flush;
228 using namespace std;
229 out << "[" << hex << "0x" << m_address << "," << " line 0x" << maskLowOrderBits(RubySystem::getBlockSizeBits()) << dec << "]" << flush;
227}
228
229class Address;
230}
231
232class Address;
230namespace __gnu_cxx {
233namespace __hash_namespace {
231 template <> struct hash<Address>
232 {
233 size_t operator()(const Address &s) const { return (size_t) s.getAddress(); }
234 };
235}
236namespace std {
237 template <> struct equal_to<Address>
238 {
239 bool operator()(const Address& s1, const Address& s2) const { return s1 == s2; }
240 };
241}
242
243#endif //ADDRESS_H
244
234 template <> struct hash<Address>
235 {
236 size_t operator()(const Address &s) const { return (size_t) s.getAddress(); }
237 };
238}
239namespace std {
240 template <> struct equal_to<Address>
241 {
242 bool operator()(const Address& s1, const Address& s2) const { return s1 == s2; }
243 };
244}
245
246#endif //ADDRESS_H
247