Skip to content

Commit a1affb9

Browse files
committed
Add comments explaining ARM64 vs x86 SIMD mask differences
1 parent 9ec33c7 commit a1affb9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Ramstack.Globbing/Internal/PathHelper.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,29 @@ public PathSegmentIterator() =>
339339
var offset = BitOperations.TrailingZeroCount(_mask);
340340
if (AdvSimd.IsSupported)
341341
{
342+
//
343+
// On ARM, ExtractMostSignificantBits returns a mask where each bit
344+
// represents one vector element (1 bit per ushort), so offset
345+
// directly corresponds to the element index
346+
//
342347
_last = (int)(_position + (nint)(uint)offset);
348+
343349
//
344-
// Clear the bits for the current separator to process the next position in the mask
350+
// Clear the bits for the current separator
345351
//
346352
_mask &= ~(1u << offset);
347353
}
348354
else
349355
{
356+
//
357+
// On x86, MoveMask (and ExtractMostSignificantBits on byte-based vectors)
358+
// returns a mask where each bit represents one byte (2 bits per ushort),
359+
// so we need to divide offset by 2 to get the actual element index
360+
//
350361
_last = (int)(_position + (nint)((uint)offset >> 1));
362+
351363
//
352-
// Clear the bits for the current separator to process the next position in the mask
364+
// Clear the bits for the current separator
353365
//
354366
_mask &= ~(0b_11u << offset);
355367
}

0 commit comments

Comments
 (0)