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__
36 #include "base/hashmap.hh"
37 #include "mem/ruby/common/TypeDefines.hh"
39 const uint32_t 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(unsigned int small, unsigned int big) const;
64 physical_address_t bitRemove(unsigned int small, unsigned int big) const;
65 physical_address_t maskLowOrderBits(unsigned int number) const;
66 physical_address_t maskHighOrderBits(unsigned int number) const;
67 physical_address_t shiftLowOrderBits(unsigned int number) const;
69 physical_address_t getLineAddress() const;
70 physical_address_t getOffset() const;
71 void makeLineAddress();
72 void makeNextStrideAddress(int stride);
74 int64 memoryModuleIndex() const;
76 void print(std::ostream& out) const;
77 void output(std::ostream& out) const;
78 void input(std::istream& in);
83 // first, zero out the offset bits
85 m_address |= (physical_address_t) offset;
89 physical_address_t m_address;
93 line_address(const Address& addr)
96 temp.makeLineAddress();
101 operator<(const Address& obj1, const Address& obj2)
103 return obj1.getAddress() < obj2.getAddress();
107 operator<<(std::ostream& out, const Address& obj)
115 operator==(const Address& obj1, const Address& obj2)
117 return (obj1.getAddress() == obj2.getAddress());
121 operator!=(const Address& obj1, const Address& obj2)
123 return (obj1.getAddress() != obj2.getAddress());
126 // rips bits inclusive
127 inline physical_address_t
128 Address::bitSelect(unsigned int small, unsigned int big) const
130 physical_address_t mask;
131 assert(big >= small);
133 if (big >= ADDRESS_WIDTH - 1) {
134 return (m_address >> small);
136 mask = ~((physical_address_t)~0 << (big + 1));
137 // FIXME - this is slow to manipulate a 64-bit number using 32-bits
138 physical_address_t partial = (m_address & mask);
139 return (partial >> small);
143 // removes bits inclusive
144 inline physical_address_t
145 Address::bitRemove(unsigned int small, unsigned int big) const
147 physical_address_t mask;
148 assert(big >= small);
150 if (small >= ADDRESS_WIDTH - 1) {
152 } else if (big >= ADDRESS_WIDTH - 1) {
153 mask = (physical_address_t)~0 >> small;
154 return (m_address & mask);
155 } else if (small == 0) {
156 mask = (physical_address_t)~0 << big;
157 return (m_address & mask);
159 mask = ~((physical_address_t)~0 << small);
160 physical_address_t lower_bits = m_address & mask;
161 mask = (physical_address_t)~0 << (big + 1);
162 physical_address_t higher_bits = m_address & mask;
164 // Shift the valid high bits over the removed section
165 higher_bits = higher_bits >> (big - small + 1);
166 return (higher_bits | lower_bits);
170 inline physical_address_t
171 Address::maskLowOrderBits(unsigned int number) const
173 physical_address_t mask;
175 if (number >= ADDRESS_WIDTH - 1) {
178 mask = (physical_address_t)~0 << number;
180 return (m_address & mask);
183 inline physical_address_t
184 Address::maskHighOrderBits(unsigned int number) const
186 physical_address_t mask;
188 if (number >= ADDRESS_WIDTH - 1) {
191 mask = (physical_address_t)~0 >> number;
193 return (m_address & mask);
196 inline physical_address_t
197 Address::shiftLowOrderBits(unsigned int number) const
199 return (m_address >> number);
202 Address next_stride_address(const Address& addr, int stride);
204 __hash_namespace_begin
205 template <> struct hash<Address>
208 operator()(const Address &s) const
210 return (size_t)s.getAddress();
216 template <> struct equal_to<Address>
219 operator()(const Address& s1, const Address& s2) const
226 #endif // __MEM_RUBY_COMMON_ADDRESS_HH__