@@ -216,13 +216,17 @@ class __accessor_iterator {
216
216
// . X X X .
217
217
// . . . . .
218
218
//
219
- // _MStaticOffset stores a number of elements in _full_ rows (and in _full_
220
- // slices in case of 3-dimensional buffers) before the first accessible
221
- // element. For the example above, _MStaticOffset would be equal to 5, because
222
- // there is only one full row before the first accessible element. "Static" in
223
- // the name highlights that this is a constant element in an equation which
224
- // calculates an absoulte offset to an accessor's buffer, it doesn't depend
225
- // on the current state of the iterator.
219
+ // _MStaticOffset stores a number of elements which precede the first
220
+ // accessible element, calculated as if the buffer was linearized.
221
+ // For the example above, _MStaticOffset would be equal to 6, because
222
+ // there is one full row before the first accessible element and a one more on
223
+ // the second line. "Static" in the name highlights that this is a constant
224
+ // element in an equation which calculates an absoulte offset to an accessor's
225
+ // buffer, it doesn't depend on the current state of the iterator.
226
+ //
227
+ // NOTE: _MStaticOffset is set to 0 in 1D case even if the accessor was
228
+ // created with offset: it is done to further optimize 1D case by
229
+ // incorporating that offset into _MLinearId right away.
226
230
//
227
231
// _MPerRowOffset stores a number of _inaccessible_ elements in each
228
232
// _accessible_ row. For the example above it would be equal to 2 (leftmost
@@ -278,9 +282,6 @@ class __accessor_iterator {
278
282
_AbsoluteId += _MPerRowOffset * (_Remaining / _MRowSize);
279
283
_Remaining %= _MRowSize;
280
284
281
- // And finally, there could be inaccessible elements on the current row
282
- _AbsoluteId += _MAccessorPtr->get_offset ()[_Dimensions - 1 ];
283
-
284
285
return _AbsoluteId;
285
286
}
286
287
@@ -314,8 +315,11 @@ class __accessor_iterator {
314
315
_AccessRange[_XIndex] * _AccessRange[_YIndex] - _MSliceSize;
315
316
}
316
317
if constexpr (_Dimensions > 1 ) {
318
+ // Elements in fully inaccessible rows
317
319
_MStaticOffset +=
318
320
_AccessRange[_XIndex] * _MAccessorPtr->get_offset ()[_YIndex];
321
+ // Elements from the first accessible row
322
+ _MStaticOffset += _MAccessorPtr->get_offset ()[_XIndex];
319
323
_MPerRowOffset = _AccessRange[_XIndex] - _MRowSize;
320
324
}
321
325
}
0 commit comments