2 * Copyright (c) 1999 Mark D. Hill and David A. Wood
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.
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.
29 #ifndef __MEM_RUBY_COMMON_ADDRESS_HH__
30 #define __MEM_RUBY_COMMON_ADDRESS_HH__
35 #include "base/hashmap.hh"
36 #include "mem/ruby/common/Global.hh"
37 #include "mem/ruby/system/NodeID.hh"
39 const int ADDRESS_WIDTH = 64; // address width in bytes
42 typedef Address PhysAddress;
43 typedef Address VirtAddress;
53 Address(physical_address_t address)
57 Address(const Address& obj);
58 Address& operator=(const Address& obj);
60 void setAddress(physical_address_t address) { m_address = address; }
61 physical_address_t getAddress() const {return m_address;}
62 // selects bits inclusive
63 physical_address_t bitSelect(int small, int big) const;
64 physical_address_t bitRemove(int small, int big) const;
65 physical_address_t maskLowOrderBits(int number) const;
66 physical_address_t maskHighOrderBits(int number) const;
67 physical_address_t shiftLowOrderBits(int number) const;
69 physical_address_t getLineAddress() const;
70 physical_address_t getOffset() const;
71 void makeLineAddress();
72 void makeNextStrideAddress(int stride);
74 int getBankSetNum() const;
75 int getBankSetDist() const;
77 Index memoryModuleIndex() const;
79 void print(std::ostream& out) const;
80 void output(std::ostream& out) const;
81 void input(std::istream& in);
86 // first, zero out the offset bits
88 m_address |= (physical_address_t) offset;
92 physical_address_t m_address;
96 line_address(const Address& addr)
99 temp.makeLineAddress();
104 operator<(const Address& obj1, const Address& obj2)
106 return obj1.getAddress() < obj2.getAddress();
110 operator<<(std::ostream& out, const Address& obj)
118 operator==(const Address& obj1, const Address& obj2)
120 return (obj1.getAddress() == obj2.getAddress());
124 operator!=(const Address& obj1, const Address& obj2)
126 return (obj1.getAddress() != obj2.getAddress());
129 // rips bits inclusive
130 inline physical_address_t
131 Address::bitSelect(int small, int big) const
133 physical_address_t mask;
134 assert((unsigned)big >= (unsigned)small);
136 if (big >= ADDRESS_WIDTH - 1) {
137 return (m_address >> small);
139 mask = ~((physical_address_t)~0 << (big + 1));
140 // FIXME - this is slow to manipulate a 64-bit number using 32-bits
141 physical_address_t partial = (m_address & mask);
142 return (partial >> small);
146 // removes bits inclusive
147 inline physical_address_t
148 Address::bitRemove(int small, int big) const
150 physical_address_t mask;
151 assert((unsigned)big >= (unsigned)small);
153 if (small >= ADDRESS_WIDTH - 1) {
155 } else if (big >= ADDRESS_WIDTH - 1) {
156 mask = (physical_address_t)~0 >> small;
157 return (m_address & mask);
158 } else if (small == 0) {
159 mask = (physical_address_t)~0 << big;
160 return (m_address & mask);
162 mask = ~((physical_address_t)~0 << small);
163 physical_address_t lower_bits = m_address & mask;
164 mask = (physical_address_t)~0 << (big + 1);
165 physical_address_t higher_bits = m_address & mask;
167 // Shift the valid high bits over the removed section
168 higher_bits = higher_bits >> (big - small + 1);
169 return (higher_bits | lower_bits);
173 inline physical_address_t
174 Address::maskLowOrderBits(int number) const
176 physical_address_t mask;
178 if (number >= ADDRESS_WIDTH - 1) {
181 mask = (physical_address_t)~0 << number;
183 return (m_address & mask);
186 inline physical_address_t
187 Address::maskHighOrderBits(int number) const
189 physical_address_t mask;
191 if (number >= ADDRESS_WIDTH - 1) {
194 mask = (physical_address_t)~0 >> number;
196 return (m_address & mask);
199 inline physical_address_t
200 Address::shiftLowOrderBits(int number) const
202 return (m_address >> number);
206 namespace __hash_namespace {
207 template <> struct hash<Address>
210 operator()(const Address &s) const
212 return (size_t)s.getAddress();
215 } // namespace __hash_namespace
218 template <> struct equal_to<Address>
221 operator()(const Address& s1, const Address& s2) const
228 #endif // __MEM_RUBY_COMMON_ADDRESS_HH__