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/TypeDefines.hh"
38 const int ADDRESS_WIDTH = 64; // address width in bytes
41 typedef Address PhysAddress;
42 typedef Address VirtAddress;
52 Address(physical_address_t address)
56 Address(const Address& obj);
57 Address& operator=(const Address& obj);
59 void setAddress(physical_address_t address) { m_address = address; }
60 physical_address_t getAddress() const {return m_address;}
61 // selects bits inclusive
62 physical_address_t bitSelect(int small, int big) const;
63 physical_address_t bitRemove(int small, int big) const;
64 physical_address_t maskLowOrderBits(int number) const;
65 physical_address_t maskHighOrderBits(int number) const;
66 physical_address_t shiftLowOrderBits(int number) const;
68 physical_address_t getLineAddress() const;
69 physical_address_t getOffset() const;
70 void makeLineAddress();
71 void makeNextStrideAddress(int stride);
73 int getBankSetNum() const;
74 int getBankSetDist() const;
76 Index memoryModuleIndex() const;
78 void print(std::ostream& out) const;
79 void output(std::ostream& out) const;
80 void input(std::istream& in);
85 // first, zero out the offset bits
87 m_address |= (physical_address_t) offset;
91 physical_address_t m_address;
95 line_address(const Address& addr)
98 temp.makeLineAddress();
103 operator<(const Address& obj1, const Address& obj2)
105 return obj1.getAddress() < obj2.getAddress();
109 operator<<(std::ostream& out, const Address& obj)
117 operator==(const Address& obj1, const Address& obj2)
119 return (obj1.getAddress() == obj2.getAddress());
123 operator!=(const Address& obj1, const Address& obj2)
125 return (obj1.getAddress() != obj2.getAddress());
128 // rips bits inclusive
129 inline physical_address_t
130 Address::bitSelect(int small, int big) const
132 physical_address_t mask;
133 assert((unsigned)big >= (unsigned)small);
135 if (big >= ADDRESS_WIDTH - 1) {
136 return (m_address >> small);
138 mask = ~((physical_address_t)~0 << (big + 1));
139 // FIXME - this is slow to manipulate a 64-bit number using 32-bits
140 physical_address_t partial = (m_address & mask);
141 return (partial >> small);
145 // removes bits inclusive
146 inline physical_address_t
147 Address::bitRemove(int small, int big) const
149 physical_address_t mask;
150 assert((unsigned)big >= (unsigned)small);
152 if (small >= ADDRESS_WIDTH - 1) {
154 } else if (big >= ADDRESS_WIDTH - 1) {
155 mask = (physical_address_t)~0 >> small;
156 return (m_address & mask);
157 } else if (small == 0) {
158 mask = (physical_address_t)~0 << big;
159 return (m_address & mask);
161 mask = ~((physical_address_t)~0 << small);
162 physical_address_t lower_bits = m_address & mask;
163 mask = (physical_address_t)~0 << (big + 1);
164 physical_address_t higher_bits = m_address & mask;
166 // Shift the valid high bits over the removed section
167 higher_bits = higher_bits >> (big - small + 1);
168 return (higher_bits | lower_bits);
172 inline physical_address_t
173 Address::maskLowOrderBits(int number) const
175 physical_address_t mask;
177 if (number >= ADDRESS_WIDTH - 1) {
180 mask = (physical_address_t)~0 << number;
182 return (m_address & mask);
185 inline physical_address_t
186 Address::maskHighOrderBits(int number) const
188 physical_address_t mask;
190 if (number >= ADDRESS_WIDTH - 1) {
193 mask = (physical_address_t)~0 >> number;
195 return (m_address & mask);
198 inline physical_address_t
199 Address::shiftLowOrderBits(int number) const
201 return (m_address >> number);
205 namespace __hash_namespace {
206 template <> struct hash<Address>
209 operator()(const Address &s) const
211 return (size_t)s.getAddress();
214 } // namespace __hash_namespace
217 template <> struct equal_to<Address>
220 operator()(const Address& s1, const Address& s2) const
227 #endif // __MEM_RUBY_COMMON_ADDRESS_HH__