Address.hh (8485:7a9a7f2a3d46) Address.hh (8608:02d7ac5fb855)
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
29#ifndef __MEM_RUBY_COMMON_ADDRESS_HH__
30#define __MEM_RUBY_COMMON_ADDRESS_HH__
31
32#include <cassert>
33#include <iomanip>
34
35#include "base/hashmap.hh"
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
29#ifndef __MEM_RUBY_COMMON_ADDRESS_HH__
30#define __MEM_RUBY_COMMON_ADDRESS_HH__
31
32#include <cassert>
33#include <iomanip>
34
35#include "base/hashmap.hh"
36#include "mem/ruby/common/Global.hh"
37#include "mem/ruby/system/NodeID.hh"
36#include "mem/ruby/common/TypeDefines.hh"
38
39const int ADDRESS_WIDTH = 64; // address width in bytes
40
41class Address;
42typedef Address PhysAddress;
43typedef Address VirtAddress;
44
45class Address
46{
47 public:
48 Address()
49 : m_address(0)
50 { }
51
52 explicit
53 Address(physical_address_t address)
54 : m_address(address)
55 { }
56
57 Address(const Address& obj);
58 Address& operator=(const Address& obj);
59
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;
68
69 physical_address_t getLineAddress() const;
70 physical_address_t getOffset() const;
71 void makeLineAddress();
72 void makeNextStrideAddress(int stride);
73
74 int getBankSetNum() const;
75 int getBankSetDist() const;
76
77 Index memoryModuleIndex() const;
78
79 void print(std::ostream& out) const;
80 void output(std::ostream& out) const;
81 void input(std::istream& in);
82
83 void
84 setOffset(int offset)
85 {
86 // first, zero out the offset bits
87 makeLineAddress();
88 m_address |= (physical_address_t) offset;
89 }
90
91 private:
92 physical_address_t m_address;
93};
94
95inline Address
96line_address(const Address& addr)
97{
98 Address temp(addr);
99 temp.makeLineAddress();
100 return temp;
101}
102
103inline bool
104operator<(const Address& obj1, const Address& obj2)
105{
106 return obj1.getAddress() < obj2.getAddress();
107}
108
109inline std::ostream&
110operator<<(std::ostream& out, const Address& obj)
111{
112 obj.print(out);
113 out << std::flush;
114 return out;
115}
116
117inline bool
118operator==(const Address& obj1, const Address& obj2)
119{
120 return (obj1.getAddress() == obj2.getAddress());
121}
122
123inline bool
124operator!=(const Address& obj1, const Address& obj2)
125{
126 return (obj1.getAddress() != obj2.getAddress());
127}
128
129// rips bits inclusive
130inline physical_address_t
131Address::bitSelect(int small, int big) const
132{
133 physical_address_t mask;
134 assert((unsigned)big >= (unsigned)small);
135
136 if (big >= ADDRESS_WIDTH - 1) {
137 return (m_address >> small);
138 } else {
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);
143 }
144}
145
146// removes bits inclusive
147inline physical_address_t
148Address::bitRemove(int small, int big) const
149{
150 physical_address_t mask;
151 assert((unsigned)big >= (unsigned)small);
152
153 if (small >= ADDRESS_WIDTH - 1) {
154 return m_address;
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);
161 } else {
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;
166
167 // Shift the valid high bits over the removed section
168 higher_bits = higher_bits >> (big - small + 1);
169 return (higher_bits | lower_bits);
170 }
171}
172
173inline physical_address_t
174Address::maskLowOrderBits(int number) const
175{
176 physical_address_t mask;
177
178 if (number >= ADDRESS_WIDTH - 1) {
179 mask = ~0;
180 } else {
181 mask = (physical_address_t)~0 << number;
182 }
183 return (m_address & mask);
184}
185
186inline physical_address_t
187Address::maskHighOrderBits(int number) const
188{
189 physical_address_t mask;
190
191 if (number >= ADDRESS_WIDTH - 1) {
192 mask = ~0;
193 } else {
194 mask = (physical_address_t)~0 >> number;
195 }
196 return (m_address & mask);
197}
198
199inline physical_address_t
200Address::shiftLowOrderBits(int number) const
201{
202 return (m_address >> number);
203}
204
205class Address;
206namespace __hash_namespace {
207template <> struct hash<Address>
208{
209 size_t
210 operator()(const Address &s) const
211 {
212 return (size_t)s.getAddress();
213 }
214};
215} // namespace __hash_namespace
216
217namespace std {
218template <> struct equal_to<Address>
219{
220 bool
221 operator()(const Address& s1, const Address& s2) const
222 {
223 return s1 == s2;
224 }
225};
226} // namespace std
227
228#endif // __MEM_RUBY_COMMON_ADDRESS_HH__
37
38const int ADDRESS_WIDTH = 64; // address width in bytes
39
40class Address;
41typedef Address PhysAddress;
42typedef Address VirtAddress;
43
44class Address
45{
46 public:
47 Address()
48 : m_address(0)
49 { }
50
51 explicit
52 Address(physical_address_t address)
53 : m_address(address)
54 { }
55
56 Address(const Address& obj);
57 Address& operator=(const Address& obj);
58
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;
67
68 physical_address_t getLineAddress() const;
69 physical_address_t getOffset() const;
70 void makeLineAddress();
71 void makeNextStrideAddress(int stride);
72
73 int getBankSetNum() const;
74 int getBankSetDist() const;
75
76 Index memoryModuleIndex() const;
77
78 void print(std::ostream& out) const;
79 void output(std::ostream& out) const;
80 void input(std::istream& in);
81
82 void
83 setOffset(int offset)
84 {
85 // first, zero out the offset bits
86 makeLineAddress();
87 m_address |= (physical_address_t) offset;
88 }
89
90 private:
91 physical_address_t m_address;
92};
93
94inline Address
95line_address(const Address& addr)
96{
97 Address temp(addr);
98 temp.makeLineAddress();
99 return temp;
100}
101
102inline bool
103operator<(const Address& obj1, const Address& obj2)
104{
105 return obj1.getAddress() < obj2.getAddress();
106}
107
108inline std::ostream&
109operator<<(std::ostream& out, const Address& obj)
110{
111 obj.print(out);
112 out << std::flush;
113 return out;
114}
115
116inline bool
117operator==(const Address& obj1, const Address& obj2)
118{
119 return (obj1.getAddress() == obj2.getAddress());
120}
121
122inline bool
123operator!=(const Address& obj1, const Address& obj2)
124{
125 return (obj1.getAddress() != obj2.getAddress());
126}
127
128// rips bits inclusive
129inline physical_address_t
130Address::bitSelect(int small, int big) const
131{
132 physical_address_t mask;
133 assert((unsigned)big >= (unsigned)small);
134
135 if (big >= ADDRESS_WIDTH - 1) {
136 return (m_address >> small);
137 } else {
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);
142 }
143}
144
145// removes bits inclusive
146inline physical_address_t
147Address::bitRemove(int small, int big) const
148{
149 physical_address_t mask;
150 assert((unsigned)big >= (unsigned)small);
151
152 if (small >= ADDRESS_WIDTH - 1) {
153 return m_address;
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);
160 } else {
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;
165
166 // Shift the valid high bits over the removed section
167 higher_bits = higher_bits >> (big - small + 1);
168 return (higher_bits | lower_bits);
169 }
170}
171
172inline physical_address_t
173Address::maskLowOrderBits(int number) const
174{
175 physical_address_t mask;
176
177 if (number >= ADDRESS_WIDTH - 1) {
178 mask = ~0;
179 } else {
180 mask = (physical_address_t)~0 << number;
181 }
182 return (m_address & mask);
183}
184
185inline physical_address_t
186Address::maskHighOrderBits(int number) const
187{
188 physical_address_t mask;
189
190 if (number >= ADDRESS_WIDTH - 1) {
191 mask = ~0;
192 } else {
193 mask = (physical_address_t)~0 >> number;
194 }
195 return (m_address & mask);
196}
197
198inline physical_address_t
199Address::shiftLowOrderBits(int number) const
200{
201 return (m_address >> number);
202}
203
204class Address;
205namespace __hash_namespace {
206template <> struct hash<Address>
207{
208 size_t
209 operator()(const Address &s) const
210 {
211 return (size_t)s.getAddress();
212 }
213};
214} // namespace __hash_namespace
215
216namespace std {
217template <> struct equal_to<Address>
218{
219 bool
220 operator()(const Address& s1, const Address& s2) const
221 {
222 return s1 == s2;
223 }
224};
225} // namespace std
226
227#endif // __MEM_RUBY_COMMON_ADDRESS_HH__