Deleted Added
sdiff udiff text old ( 10481:59fb5779ec6e ) new ( 10676:f6c168692b20 )
full compact
1/*
2 * Copyright (c) 2012 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

--- 37 unchanged lines hidden (view full) ---

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
56class AddrRange
57{
58
59 private:
60
61 /// Private fields for the start and end of the range
62 /// Both _start and _end are part of the range.
63 Addr _start;
64 Addr _end;
65
66 /// The high bit of the slice that is used for interleaving
67 uint8_t intlvHighBit;
68
69 /// The number of bits used for interleaving, set to 0 to disable
70 uint8_t intlvBits;
71
72 /// The value to compare the slice addr[high:(high - bits + 1)]
73 /// with.
74 uint8_t intlvMatch;
75
76 public:
77
78 AddrRange()
79 : _start(1), _end(0), intlvHighBit(0), intlvBits(0), intlvMatch(0)
80 {}
81
82 AddrRange(Addr _start, Addr _end, uint8_t _intlv_high_bit,
83 uint8_t _intlv_bits, uint8_t _intlv_match)
84 : _start(_start), _end(_end), intlvHighBit(_intlv_high_bit),
85 intlvBits(_intlv_bits), intlvMatch(_intlv_match)
86 {}
87
88 AddrRange(Addr _start, Addr _end)
89 : _start(_start), _end(_end), intlvHighBit(0), intlvBits(0),
90 intlvMatch(0)
91 {}
92
93 /**
94 * Create an address range by merging a collection of interleaved
95 * ranges.
96 *
97 * @param ranges Interleaved ranges to be merged
98 */
99 AddrRange(const std::vector<AddrRange>& ranges)
100 : _start(1), _end(0), intlvHighBit(0), intlvBits(0), intlvMatch(0)
101 {
102 if (!ranges.empty()) {
103 // get the values from the first one and check the others
104 _start = ranges.front()._start;
105 _end = ranges.front()._end;
106 intlvHighBit = ranges.front().intlvHighBit;
107 intlvBits = ranges.front().intlvBits;
108
109 if (ranges.size() != (ULL(1) << intlvBits))
110 fatal("Got %d ranges spanning %d interleaving bits\n",
111 ranges.size(), intlvBits);
112
113 uint8_t match = 0;
114 for (std::vector<AddrRange>::const_iterator r = ranges.begin();
115 r != ranges.end(); ++r) {
116 if (!mergesWith(*r))
117 fatal("Can only merge ranges with the same start, end "
118 "and interleaving bits\n");
119
120 if (r->intlvMatch != match)
121 fatal("Expected interleave match %d but got %d when "
122 "merging\n", match, r->intlvMatch);
123 ++match;
124 }
125
126 // our range is complete and we can turn this into a
127 // non-interleaved range
128 intlvHighBit = 0;
129 intlvBits = 0;
130 }
131 }
132
133 /**
134 * Determine if the range is interleaved or not.
135 *
136 * @return true if interleaved
137 */
138 bool interleaved() const { return intlvBits != 0; }
139
140 /**
141 * Determing the interleaving granularity of the range.
142 *
143 * @return The size of the regions created by the interleaving bits
144 */
145 uint64_t granularity() const
146 {
147 return ULL(1) << (intlvHighBit - intlvBits + 1);
148 }

--- 28 unchanged lines hidden (view full) ---

177
178 /**
179 * Get a string representation of the range. This could
180 * alternatively be implemented as a operator<<, but at the moment
181 * that seems like overkill.
182 */
183 std::string to_string() const
184 {
185 if (interleaved())
186 return csprintf("[%#llx : %#llx], [%d : %d] = %d", _start, _end,
187 intlvHighBit, intlvHighBit - intlvBits + 1,
188 intlvMatch);
189 else
190 return csprintf("[%#llx : %#llx]", _start, _end);
191 }
192
193 /**
194 * Determine if another range merges with the current one, i.e. if
195 * they are part of the same contigous range and have the same
196 * interleaving bits.
197 *
198 * @param r Range to evaluate merging with
199 * @return true if the two ranges would merge
200 */
201 bool mergesWith(const AddrRange& r) const
202 {
203 return r._start == _start && r._end == _end &&
204 r.intlvHighBit == intlvHighBit &&
205 r.intlvBits == intlvBits;
206 }
207
208 /**
209 * Determine if another range intersects this one, i.e. if there
210 * is an address that is both in this range and the other
211 * range. No check is made to ensure either range is valid.
212 *

--- 45 unchanged lines hidden (view full) ---

258 * @param a Address to compare with
259 * @return true if the address is in the range
260 */
261 bool contains(const Addr& a) const
262 {
263 // check if the address is in the range and if there is either
264 // no interleaving, or with interleaving also if the selected
265 // bits from the address match the interleaving value
266 return a >= _start && a <= _end &&
267 (!interleaved() ||
268 (bits(a, intlvHighBit, intlvHighBit - intlvBits + 1) ==
269 intlvMatch));
270 }
271
272/**
273 * Keep the operators away from SWIG.
274 */
275#ifndef SWIG
276
277 /**

--- 37 unchanged lines hidden ---