gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
addr_range.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 2014 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2002-2005 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  * Authors: Nathan Binkert
41  * Steve Reinhardt
42  * Andreas Hansson
43  */
44 
45 #ifndef __BASE_ADDR_RANGE_HH__
46 #define __BASE_ADDR_RANGE_HH__
47 
48 #include <list>
49 #include <vector>
50 
51 #include "base/bitfield.hh"
52 #include "base/cprintf.hh"
53 #include "base/misc.hh"
54 #include "base/types.hh"
55 
72 class AddrRange
73 {
74 
75  private:
76 
81 
83  uint8_t intlvHighBit;
84 
87  uint8_t xorHighBit;
88 
90  uint8_t intlvBits;
91 
94  uint8_t intlvMatch;
95 
96  public:
97 
99  : _start(1), _end(0), intlvHighBit(0), xorHighBit(0), intlvBits(0),
100  intlvMatch(0)
101  {}
102 
103  AddrRange(Addr _start, Addr _end, uint8_t _intlv_high_bit,
104  uint8_t _xor_high_bit, uint8_t _intlv_bits,
105  uint8_t _intlv_match)
106  : _start(_start), _end(_end), intlvHighBit(_intlv_high_bit),
107  xorHighBit(_xor_high_bit), intlvBits(_intlv_bits),
108  intlvMatch(_intlv_match)
109  {
110  // sanity checks
112  "Match value %d does not fit in %d interleaving bits\n",
114 
115  // ignore the XOR bits if not interleaving
116  if (intlvBits && xorHighBit) {
117  if (xorHighBit == intlvHighBit) {
118  fatal("XOR and interleave high bit must be different\n");
119  } else if (xorHighBit > intlvHighBit) {
121  fatal("XOR and interleave high bit must be at least "
122  "%d bits apart\n", intlvBits);
123  } else {
124  if ((intlvHighBit - xorHighBit) < intlvBits) {
125  fatal("Interleave and XOR high bit must be at least "
126  "%d bits apart\n", intlvBits);
127  }
128  }
129  }
130  }
131 
133  : _start(_start), _end(_end), intlvHighBit(0), xorHighBit(0),
134  intlvBits(0), intlvMatch(0)
135  {}
136 
144  : _start(1), _end(0), intlvHighBit(0), xorHighBit(0), intlvBits(0),
145  intlvMatch(0)
146  {
147  if (!ranges.empty()) {
148  // get the values from the first one and check the others
149  _start = ranges.front()._start;
150  _end = ranges.front()._end;
151  intlvHighBit = ranges.front().intlvHighBit;
152  xorHighBit = ranges.front().xorHighBit;
153  intlvBits = ranges.front().intlvBits;
154 
155  if (ranges.size() != (ULL(1) << intlvBits))
156  fatal("Got %d ranges spanning %d interleaving bits\n",
157  ranges.size(), intlvBits);
158 
159  uint8_t match = 0;
160  for (const auto& r : ranges) {
161  if (!mergesWith(r))
162  fatal("Can only merge ranges with the same start, end "
163  "and interleaving bits\n");
164 
165  if (r.intlvMatch != match)
166  fatal("Expected interleave match %d but got %d when "
167  "merging\n", match, r.intlvMatch);
168  ++match;
169  }
170 
171  // our range is complete and we can turn this into a
172  // non-interleaved range
173  intlvHighBit = 0;
174  xorHighBit = 0;
175  intlvBits = 0;
176  }
177  }
178 
184  bool interleaved() const { return intlvBits != 0; }
185 
189  bool hashed() const { return interleaved() && xorHighBit != 0; }
190 
196  uint64_t granularity() const
197  {
198  return ULL(1) << (intlvHighBit - intlvBits + 1);
199  }
200 
207  uint32_t stripes() const { return ULL(1) << intlvBits; }
208 
214  Addr size() const
215  {
216  return (_end - _start + 1) >> intlvBits;
217  }
218 
222  bool valid() const { return _start <= _end; }
223 
227  Addr start() const { return _start; }
228 
232  Addr end() const { return _end; }
233 
239  std::string to_string() const
240  {
241  if (interleaved()) {
242  if (hashed()) {
243  return csprintf("[%#llx : %#llx], [%d : %d] XOR [%d : %d] = %d",
244  _start, _end,
247  intlvMatch);
248  } else {
249  return csprintf("[%#llx : %#llx], [%d : %d] = %d",
250  _start, _end,
252  intlvMatch);
253  }
254  } else {
255  return csprintf("[%#llx : %#llx]", _start, _end);
256  }
257  }
258 
267  bool mergesWith(const AddrRange& r) const
268  {
269  return r._start == _start && r._end == _end &&
270  r.intlvHighBit == intlvHighBit &&
271  r.xorHighBit == xorHighBit &&
272  r.intlvBits == intlvBits;
273  }
274 
283  bool intersects(const AddrRange& r) const
284  {
285  if (_start > r._end || _end < r._start)
286  // start with the simple case of no overlap at all,
287  // applicable even if we have interleaved ranges
288  return false;
289  else if (!interleaved() && !r.interleaved())
290  // if neither range is interleaved, we are done
291  return true;
292 
293  // now it gets complicated, focus on the cases we care about
294  if (r.size() == 1)
295  // keep it simple and check if the address is within
296  // this range
297  return contains(r.start());
298  else if (mergesWith(r))
299  // restrict the check to ranges that belong to the
300  // same chunk
301  return intlvMatch == r.intlvMatch;
302  else
303  panic("Cannot test intersection of %s and %s\n",
304  to_string(), r.to_string());
305  }
306 
315  bool isSubset(const AddrRange& r) const
316  {
317  if (interleaved())
318  panic("Cannot test subset of interleaved range %s\n", to_string());
319  return _start >= r._start && _end <= r._end;
320  }
321 
328  bool contains(const Addr& a) const
329  {
330  // check if the address is in the range and if there is either
331  // no interleaving, or with interleaving also if the selected
332  // bits from the address match the interleaving value
333  bool in_range = a >= _start && a <= _end;
334  if (!interleaved()) {
335  return in_range;
336  } else if (in_range) {
337  if (!hashed()) {
338  return bits(a, intlvHighBit, intlvHighBit - intlvBits + 1) ==
339  intlvMatch;
340  } else {
341  return (bits(a, intlvHighBit, intlvHighBit - intlvBits + 1) ^
342  bits(a, xorHighBit, xorHighBit - intlvBits + 1)) ==
343  intlvMatch;
344  }
345  }
346  return false;
347  }
348 
356  bool operator<(const AddrRange& r) const
357  {
358  if (_start != r._start)
359  return _start < r._start;
360  else
361  // for now assume that the end is also the same, and that
362  // we are looking at the same interleaving bits
363  return intlvMatch < r.intlvMatch;
364  }
365 
366  bool operator==(const AddrRange& r) const
367  {
368  if (_start != r._start) return false;
369  if (_end != r._end) return false;
370  if (intlvBits != r.intlvBits) return false;
371  if (intlvBits != 0) {
372  if (intlvHighBit != r.intlvHighBit) return false;
373  if (intlvMatch != r.intlvMatch) return false;
374  }
375  return true;
376  }
377 
378  bool operator!=(const AddrRange& r) const
379  {
380  return !(*this == r);
381  }
382 };
383 
388 
389 inline AddrRange
390 RangeEx(Addr start, Addr end)
391 { return AddrRange(start, end - 1); }
392 
393 inline AddrRange
394 RangeIn(Addr start, Addr end)
395 { return AddrRange(start, end); }
396 
397 inline AddrRange
399 { return AddrRange(start, start + size - 1); }
400 
401 #endif // __BASE_ADDR_RANGE_HH__
bool intersects(const AddrRange &r) const
Determine if another range intersects this one, i.e.
Definition: addr_range.hh:283
AddrRange RangeSize(Addr start, Addr size)
Definition: addr_range.hh:398
uint64_t granularity() const
Determing the interleaving granularity of the range.
Definition: addr_range.hh:196
bool hashed() const
Determine if the range interleaving is hashed or not.
Definition: addr_range.hh:189
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:227
bool interleaved() const
Determine if the range is interleaved or not.
Definition: addr_range.hh:184
#define panic(...)
Definition: misc.hh:153
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition: addr_range.hh:387
bool mergesWith(const AddrRange &r) const
Determine if another range merges with the current one, i.e.
Definition: addr_range.hh:267
Bitfield< 8 > a
Definition: miscregs.hh:1377
uint8_t intlvMatch
The value to compare the slice addr[high:(high - bits + 1)] with.
Definition: addr_range.hh:94
bool contains(const Addr &a) const
Determine if the range contains an address.
Definition: addr_range.hh:328
uint8_t xorHighBit
The high bit of the slice used to XOR hash the value we match against, set to 0 to disable...
Definition: addr_range.hh:87
bool operator<(const AddrRange &r) const
Less-than operator used to turn an STL map into a binary search tree of non-overlapping address range...
Definition: addr_range.hh:356
Addr _start
Private fields for the start and end of the range Both _start and _end are part of the range...
Definition: addr_range.hh:79
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:72
AddrRange(const std::vector< AddrRange > &ranges)
Create an address range by merging a collection of interleaved ranges.
Definition: addr_range.hh:143
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
bool valid() const
Determine if the range is valid.
Definition: addr_range.hh:222
uint32_t stripes() const
Determine the number of interleaved address stripes this range is part of.
Definition: addr_range.hh:207
std::string to_string() const
Get a string representation of the range.
Definition: addr_range.hh:239
#define fatal(...)
Definition: misc.hh:163
Addr _end
Definition: addr_range.hh:80
AddrRange RangeIn(Addr start, Addr end)
Definition: addr_range.hh:394
bool isSubset(const AddrRange &r) const
Determine if this range is a subset of another range, i.e.
Definition: addr_range.hh:315
uint8_t intlvHighBit
The high bit of the slice that is used for interleaving.
Definition: addr_range.hh:83
AddrRange(Addr _start, Addr _end)
Definition: addr_range.hh:132
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
#define ULL(N)
uint64_t constant
Definition: types.hh:50
uint8_t intlvBits
The number of bits used for interleaving, set to 0 to disable.
Definition: addr_range.hh:90
AddrRange RangeEx(Addr start, Addr end)
Definition: addr_range.hh:390
Addr end() const
Get the end address of the range.
Definition: addr_range.hh:232
int size()
Definition: pagetable.hh:146
AddrRange(Addr _start, Addr _end, uint8_t _intlv_high_bit, uint8_t _xor_high_bit, uint8_t _intlv_bits, uint8_t _intlv_match)
Definition: addr_range.hh:103
fatal_if(p->js_features.size() > 16,"Too many job slot feature registers specified (%i)\n", p->js_features.size())
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
Definition: bitfield.hh:67
bool operator==(const AddrRange &r) const
Definition: addr_range.hh:366
Addr size() const
Get the size of the address range.
Definition: addr_range.hh:214
bool operator!=(const AddrRange &r) const
Definition: addr_range.hh:378

Generated on Fri Jun 9 2017 13:03:40 for gem5 by doxygen 1.8.6