@@ -141,48 +141,45 @@ LookupResult MappingInfoTy::lookupMapping(HDTTMapAccessorTy &HDTTMap,
141
141
if (HDTTMap->empty ())
142
142
return LR;
143
143
144
+ // HDTTMap is std::set, ordered by HstPtrBegin.
145
+ // Upper is the first element whose HstPtrBegin > HP.
144
146
auto Upper = HDTTMap->upper_bound (HP);
145
147
146
148
if (Size == 0 ) {
147
- // specification v5.1 Pointer Initialization for Device Data Environments
148
- // upper_bound satisfies
149
- // std::prev(upper)->HDTT.HstPtrBegin <= hp < upper->HDTT.HstPtrBegin
149
+ // HP satisfies
150
+ // std::prev(Upper)->HDTT.HstPtrBegin <= HP < Upper->HDTT.HstPtrBegin
150
151
if (Upper != HDTTMap->begin ()) {
151
152
LR.TPR .setEntry (std::prev (Upper)->HDTT , OwnedTPR);
152
- // the left side of extended address range is satisfied.
153
- // hp >= LR.TPR.getEntry()->HstPtrBegin || hp >=
154
- // LR.TPR.getEntry()->HstPtrBase
155
- LR.Flags .IsContained = HP < LR.TPR .getEntry ()->HstPtrEnd ||
156
- HP < LR.TPR .getEntry ()->HstPtrBase ;
153
+ // We know that HP >= LR.TPR.getEntry()->HstPtrBegin
154
+ LR.Flags .IsContained = HP < LR.TPR .getEntry ()->HstPtrEnd ;
157
155
}
158
156
159
157
if (!LR.Flags .IsContained && Upper != HDTTMap->end ()) {
160
158
LR.TPR .setEntry (Upper->HDTT , OwnedTPR);
161
- // the right side of extended address range is satisfied.
162
- // hp < LR.TPR.getEntry()->HstPtrEnd || hp < LR.TPR.getEntry()->HstPtrBase
159
+ // This is a special case: HP is not really contained in the mapped
160
+ // address range, but it's contained in the extended address range,
161
+ // which suffices to get the mapping of the base pointer.
162
+ // We know that HP < LR.TPR.getEntry()->HstPtrBegin
163
163
LR.Flags .IsContained = HP >= LR.TPR .getEntry ()->HstPtrBase ;
164
164
}
165
165
} else {
166
- // check the left bin
167
166
if (Upper != HDTTMap->begin ()) {
168
167
LR.TPR .setEntry (std::prev (Upper)->HDTT , OwnedTPR);
169
- // Is it contained?
170
- LR.Flags .IsContained = HP >= LR.TPR .getEntry ()->HstPtrBegin &&
171
- HP < LR.TPR .getEntry ()->HstPtrEnd &&
168
+ // We know that HP >= LR.TPR.getEntry()->HstPtrBegin
169
+ LR.Flags .IsContained = HP < LR.TPR .getEntry ()->HstPtrEnd &&
172
170
(HP + Size) <= LR.TPR .getEntry ()->HstPtrEnd ;
173
- // Does it extend beyond the mapped region ?
171
+ // Does it extend beyond the mapped address range ?
174
172
LR.Flags .ExtendsAfter = HP < LR.TPR .getEntry ()->HstPtrEnd &&
175
173
(HP + Size) > LR.TPR .getEntry ()->HstPtrEnd ;
176
174
}
177
175
178
- // check the right bin
179
176
if (!(LR.Flags .IsContained || LR.Flags .ExtendsAfter ) &&
180
177
Upper != HDTTMap->end ()) {
181
178
LR.TPR .setEntry (Upper->HDTT , OwnedTPR);
182
- // Does it extend into an already mapped region ?
183
- LR. Flags . ExtendsBefore = HP < LR.TPR .getEntry ()->HstPtrBegin &&
184
- (HP + Size) > LR.TPR .getEntry ()->HstPtrBegin ;
185
- // Does it extend beyond the mapped region ?
179
+ // Does it extend into an already mapped address range ?
180
+ // We know that HP < LR.TPR.getEntry()->HstPtrBegin
181
+ LR. Flags . ExtendsBefore = (HP + Size) > LR.TPR .getEntry ()->HstPtrBegin ;
182
+ // Does it extend beyond the mapped address range ?
186
183
LR.Flags .ExtendsAfter = HP < LR.TPR .getEntry ()->HstPtrEnd &&
187
184
(HP + Size) > LR.TPR .getEntry ()->HstPtrEnd ;
188
185
}
0 commit comments