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
| 1/* 2 * Copyright (c) 1999 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
|
30/* 31 * $Id$ 32 */
| 29#ifndef __MEM_RUBY_COMMON_ADDRESS_HH__ 30#define __MEM_RUBY_COMMON_ADDRESS_HH__
|
33
| 31
|
34#ifndef ADDRESS_H 35#define ADDRESS_H 36
| |
37#include <iomanip> 38 39#include "base/hashmap.hh" 40#include "mem/ruby/common/Global.hh"
| 32#include <iomanip> 33 34#include "base/hashmap.hh" 35#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"
| 36#include "mem/ruby/system/MachineID.hh"
|
| 37#include "mem/ruby/system/NodeID.hh" 38#include "mem/ruby/system/System.hh"
|
44 45const int ADDRESS_WIDTH = 64; // address width in bytes 46 47class Address; 48typedef Address PhysAddress; 49typedef Address VirtAddress; 50
| 39 40const int ADDRESS_WIDTH = 64; // address width in bytes 41 42class Address; 43typedef Address PhysAddress; 44typedef Address VirtAddress; 45
|
51class Address { 52public: 53 // Constructors 54 Address() { m_address = 0; } 55 explicit Address(physical_address_t address) { m_address = address; }
| 46class Address 47{ 48 public: 49 Address() 50 : m_address(0) 51 { }
|
56
| 52
|
57 Address(const Address& obj); 58 Address& operator=(const Address& obj);
| 53 explicit 54 Address(physical_address_t address) 55 : m_address(address) 56 { }
|
59
| 57
|
60 // Destructor 61 // ~Address();
| 58 Address(const Address& obj); 59 Address& operator=(const Address& obj);
|
62
| 60
|
63 // Public Methods
| 61 void setAddress(physical_address_t address) { m_address = address; } 62 physical_address_t getAddress() const {return m_address;} 63 // selects bits inclusive 64 physical_address_t bitSelect(int small, int big) const; 65 physical_address_t bitRemove(int small, int big) const; 66 physical_address_t maskLowOrderBits(int number) const; 67 physical_address_t maskHighOrderBits(int number) const; 68 physical_address_t shiftLowOrderBits(int number) const;
|
64
| 69
|
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 bitRemove(int small, int big) const; 70 physical_address_t maskLowOrderBits(int number) const; 71 physical_address_t maskHighOrderBits(int number) const; 72 physical_address_t shiftLowOrderBits(int number) const; 73 physical_address_t getLineAddress() const 74 { return bitSelect(RubySystem::getBlockSizeBits(), ADDRESS_WIDTH); } 75 physical_address_t getOffset() const 76 { return bitSelect(0, RubySystem::getBlockSizeBits()-1); }
| 70 physical_address_t 71 getLineAddress() const 72 { 73 return bitSelect(RubySystem::getBlockSizeBits(), ADDRESS_WIDTH); 74 }
|
77
| 75
|
78 void makeLineAddress() { m_address = maskLowOrderBits(RubySystem::getBlockSizeBits()); } 79 // returns the next stride address based on line address 80 void makeNextStrideAddress( int stride) { 81 m_address = maskLowOrderBits(RubySystem::getBlockSizeBits()) 82 + RubySystem::getBlockSizeBytes()*stride; 83 } 84 int getBankSetNum() const; 85 int getBankSetDist() const;
| 76 physical_address_t 77 getOffset() const 78 { 79 return bitSelect(0, RubySystem::getBlockSizeBits() - 1); 80 }
|
86
| 81
|
87 Index memoryModuleIndex() const;
| 82 void 83 makeLineAddress() 84 { 85 m_address = maskLowOrderBits(RubySystem::getBlockSizeBits()); 86 }
|
88
| 87
|
89 void print(ostream& out) const; 90 void output(ostream& out) const; 91 void input(istream& in);
| 88 // returns the next stride address based on line address 89 void 90 makeNextStrideAddress(int stride) 91 { 92 m_address = maskLowOrderBits(RubySystem::getBlockSizeBits()) 93 + RubySystem::getBlockSizeBytes()*stride; 94 }
|
92
| 95
|
93 void setOffset( int offset ){ 94 // first, zero out the offset bits 95 makeLineAddress(); 96 m_address |= (physical_address_t) offset; 97 }
| 96 int getBankSetNum() const; 97 int getBankSetDist() const;
|
98
| 98
|
99private: 100 // Private Methods
| 99 Index memoryModuleIndex() const;
|
101
| 100
|
102 // Private copy constructor and assignment operator 103 // Address(const Address& obj); 104 // Address& operator=(const Address& obj);
| 101 void print(ostream& out) const; 102 void output(ostream& out) const; 103 void input(istream& in);
|
105
| 104
|
106 // Data Members (m_ prefix) 107 physical_address_t m_address;
| 105 void 106 setOffset(int offset) 107 { 108 // first, zero out the offset bits 109 makeLineAddress(); 110 m_address |= (physical_address_t) offset; 111 } 112 113 private: 114 physical_address_t m_address;
|
108}; 109
| 115}; 116
|
110inline 111Address line_address(const Address& addr) { Address temp(addr); temp.makeLineAddress(); return temp; }
| 117inline Address 118line_address(const Address& addr) 119{ 120 Address temp(addr); 121 temp.makeLineAddress(); 122 return temp; 123}
|
112
| 124
|
113// Output operator declaration 114ostream& operator<<(ostream& out, const Address& obj); 115// comparison operator declaration 116bool operator==(const Address& obj1, const Address& obj2); 117bool operator!=(const Address& obj1, const Address& obj2); 118bool operator<(const Address& obj1, const Address& obj2); 119/* Address& operator=(const physical_address_t address); */ 120 121inline 122bool operator<(const Address& obj1, const Address& obj2)
| 125inline bool 126operator<(const Address& obj1, const Address& obj2)
|
123{
| 127{
|
124 return obj1.getAddress() < obj2.getAddress();
| 128 return obj1.getAddress() < obj2.getAddress();
|
125} 126
| 129} 130
|
127// ******************* Definitions ******************* 128 129// Output operator definition 130inline 131ostream& operator<<(ostream& out, const Address& obj)
| 131inline ostream& 132operator<<(ostream& out, const Address& obj)
|
132{
| 133{
|
133 obj.print(out); 134 out << flush; 135 return out;
| 134 obj.print(out); 135 out << flush; 136 return out;
|
136} 137
| 137} 138
|
138inline 139bool operator==(const Address& obj1, const Address& obj2)
| 139inline bool 140operator==(const Address& obj1, const Address& obj2)
|
140{
| 141{
|
141 return (obj1.getAddress() == obj2.getAddress());
| 142 return (obj1.getAddress() == obj2.getAddress());
|
142} 143
| 143} 144
|
144inline 145bool operator!=(const Address& obj1, const Address& obj2)
| 145inline bool 146operator!=(const Address& obj1, const Address& obj2)
|
146{
| 147{
|
147 return (obj1.getAddress() != obj2.getAddress());
| 148 return (obj1.getAddress() != obj2.getAddress());
|
148} 149
| 149} 150
|
150inline 151physical_address_t Address::bitSelect(int small, int big) const // rips bits inclusive
| 151// rips bits inclusive 152inline physical_address_t 153Address::bitSelect(int small, int big) const
|
152{
| 154{
|
153 physical_address_t mask; 154 assert((unsigned)big >= (unsigned)small);
| 155 physical_address_t mask; 156 assert((unsigned)big >= (unsigned)small);
|
155
| 157
|
156 if (big >= ADDRESS_WIDTH - 1) { 157 return (m_address >> small); 158 } else { 159 mask = ~((physical_address_t)~0 << (big + 1)); 160 // FIXME - this is slow to manipulate a 64-bit number using 32-bits 161 physical_address_t partial = (m_address & mask); 162 return (partial >> small); 163 }
| 158 if (big >= ADDRESS_WIDTH - 1) { 159 return (m_address >> small); 160 } else { 161 mask = ~((physical_address_t)~0 << (big + 1)); 162 // FIXME - this is slow to manipulate a 64-bit number using 32-bits 163 physical_address_t partial = (m_address & mask); 164 return (partial >> small); 165 }
|
164} 165 166// removes bits inclusive
| 166} 167 168// removes bits inclusive
|
167inline 168physical_address_t Address::bitRemove(int small, int big) const
| 169inline physical_address_t 170Address::bitRemove(int small, int big) const
|
169{ 170 physical_address_t mask; 171 assert((unsigned)big >= (unsigned)small); 172 173 if (small >= ADDRESS_WIDTH - 1) { 174 return m_address; 175 } else if (big >= ADDRESS_WIDTH - 1) { 176 mask = (physical_address_t)~0 >> small; 177 return (m_address & mask); 178 } else if (small == 0) { 179 mask = (physical_address_t)~0 << big; 180 return (m_address & mask); 181 } else { 182 mask = ~((physical_address_t)~0 << small); 183 physical_address_t lower_bits = m_address & mask; 184 mask = (physical_address_t)~0 << (big + 1); 185 physical_address_t higher_bits = m_address & mask; 186
| 171{ 172 physical_address_t mask; 173 assert((unsigned)big >= (unsigned)small); 174 175 if (small >= ADDRESS_WIDTH - 1) { 176 return m_address; 177 } else if (big >= ADDRESS_WIDTH - 1) { 178 mask = (physical_address_t)~0 >> small; 179 return (m_address & mask); 180 } else if (small == 0) { 181 mask = (physical_address_t)~0 << big; 182 return (m_address & mask); 183 } else { 184 mask = ~((physical_address_t)~0 << small); 185 physical_address_t lower_bits = m_address & mask; 186 mask = (physical_address_t)~0 << (big + 1); 187 physical_address_t higher_bits = m_address & mask; 188
|
187 //
| |
188 // Shift the valid high bits over the removed section
| 189 // Shift the valid high bits over the removed section
|
189 //
| |
190 higher_bits = higher_bits >> (big - small); 191 return (higher_bits | lower_bits); 192 } 193} 194
| 190 higher_bits = higher_bits >> (big - small); 191 return (higher_bits | lower_bits); 192 } 193} 194
|
195inline 196physical_address_t Address::maskLowOrderBits(int number) const
| 195inline physical_address_t 196Address::maskLowOrderBits(int number) const
|
197{ 198 physical_address_t mask; 199 200 if (number >= ADDRESS_WIDTH - 1) {
| 197{ 198 physical_address_t mask; 199 200 if (number >= ADDRESS_WIDTH - 1) {
|
201 mask = ~0;
| 201 mask = ~0;
|
202 } else {
| 202 } else {
|
203 mask = (physical_address_t)~0 << number;
| 203 mask = (physical_address_t)~0 << number;
|
204 } 205 return (m_address & mask); 206} 207
| 204 } 205 return (m_address & mask); 206} 207
|
208inline 209physical_address_t Address::maskHighOrderBits(int number) const
| 208inline physical_address_t 209Address::maskHighOrderBits(int number) const
|
210{
| 210{
|
211 physical_address_t mask;
| 211 physical_address_t mask;
|
212
| 212
|
213 if (number >= ADDRESS_WIDTH - 1) { 214 mask = ~0; 215 } else { 216 mask = (physical_address_t)~0 >> number; 217 } 218 return (m_address & mask);
| 213 if (number >= ADDRESS_WIDTH - 1) { 214 mask = ~0; 215 } else { 216 mask = (physical_address_t)~0 >> number; 217 } 218 return (m_address & mask);
|
219} 220
| 219} 220
|
221inline 222physical_address_t Address::shiftLowOrderBits(int number) const
| 221inline physical_address_t 222Address::shiftLowOrderBits(int number) const
|
223{
| 223{
|
224 return (m_address >> number);
| 224 return (m_address >> number);
|
225} 226
| 225} 226
|
227inline 228integer_t Address::memoryModuleIndex() const
| 227inline integer_t 228Address::memoryModuleIndex() const
|
229{
| 229{
|
230 integer_t index = bitSelect(RubySystem::getBlockSizeBits()+RubySystem::getMemorySizeBits(), ADDRESS_WIDTH); 231 assert (index >= 0); 232 return index;
| 230 integer_t index = 231 bitSelect(RubySystem::getBlockSizeBits() + 232 RubySystem::getMemorySizeBits(), ADDRESS_WIDTH); 233 assert (index >= 0); 234 return index;
|
233
| 235
|
234 // Index indexHighPortion = address.bitSelect(MEMORY_SIZE_BITS-1, PAGE_SIZE_BITS+NUMBER_OF_MEMORY_MODULE_BITS); 235 // Index indexLowPortion = address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS-1);
| 236 // Index indexHighPortion = 237 // address.bitSelect(MEMORY_SIZE_BITS - 1, 238 // PAGE_SIZE_BITS + NUMBER_OF_MEMORY_MODULE_BITS); 239 // Index indexLowPortion = 240 // address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS - 1); 241 // 242 // Index index = indexLowPortion | 243 // (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));
|
236
| 244
|
237 //Index index = indexLowPortion | (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));
| 245 /* 246 Round-robin mapping of addresses, at page size granularity
|
238
| 247
|
239 /* 240 Round-robin mapping of addresses, at page size granularity 241
| |
242ADDRESS_WIDTH MEMORY_SIZE_BITS PAGE_SIZE_BITS DATA_BLOCK_BITS 243 | | | | 244 \ / \ / \ / \ / 0 245 ----------------------------------------------------------------------- 246 | unused |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| | 247 | |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| | 248 ----------------------------------------------------------------------- 249 indexHighPortion indexLowPortion 250 <-------> 251 NUMBER_OF_MEMORY_MODULE_BITS
| 248ADDRESS_WIDTH MEMORY_SIZE_BITS PAGE_SIZE_BITS DATA_BLOCK_BITS 249 | | | | 250 \ / \ / \ / \ / 0 251 ----------------------------------------------------------------------- 252 | unused |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| | 253 | |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| | 254 ----------------------------------------------------------------------- 255 indexHighPortion indexLowPortion 256 <-------> 257 NUMBER_OF_MEMORY_MODULE_BITS
|
252 */
| 258 */
|
253} 254
| 259} 260
|
255inline 256void Address::print(ostream& out) const
| 261inline void 262Address::print(ostream& out) const
|
257{ 258 using namespace std;
| 263{ 264 using namespace std;
|
259 out << "[" << hex << "0x" << m_address << "," << " line 0x" << maskLowOrderBits(RubySystem::getBlockSizeBits()) << dec << "]" << flush;
| 265 out << "[" << hex << "0x" << m_address << "," << " line 0x" 266 << maskLowOrderBits(RubySystem::getBlockSizeBits()) << dec << "]" 267 << flush;
|
260} 261 262class Address; 263namespace __hash_namespace {
| 268} 269 270class Address; 271namespace __hash_namespace {
|
264 template <> struct hash<Address> 265 { 266 size_t operator()(const Address &s) const { return (size_t) s.getAddress(); } 267 }; 268}
| 272template <> struct hash 273{ 274 size_t 275 operator()(const Address &s) const 276 { 277 return (size_t)s.getAddress(); 278 } 279}; 280/* namespace __hash_namespace */ } 281
|
269namespace std {
| 282namespace std {
|
270 template <> struct equal_to<Address> 271 { 272 bool operator()(const Address& s1, const Address& s2) const { return s1 == s2; } 273 }; 274}
| 283template <> struct equal_to 284{ 285 bool 286 operator()(const Address& s1, const Address& s2) const 287 { 288 return s1 == s2; 289 } 290}; 291/* namespace std */ }
|
275
| 292
|
276#endif //ADDRESS_H 277
| 293#endif // __MEM_RUBY_COMMON_ADDRESS_HH__
|
| |