Skip to content

Commit fcb8d94

Browse files
authored
Merge pull request #32 from rameel/backport-advsimd
Backport ExtractMostSignificantBits
2 parents 3759e5a + 4890190 commit fcb8d94

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

Ramstack.Globbing.Tests/Ramstack.Globbing.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
3+
<TargetFramework>net6.0</TargetFramework>
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<LangVersion>preview</LangVersion>

Ramstack.Globbing.Tests/SimdConfigurationTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public void VerifySimdConfiguration()
1515
Assert.That(Sse2.IsSupported, Is.False);
1616
Assert.That(Sse41.IsSupported, Is.False);
1717
Assert.That(Avx2.IsSupported, Is.False);
18+
Assert.That(AdvSimd.Arm64.IsSupported, Is.False);
1819
Assert.That(AdvSimd.IsSupported, Is.False);
1920
}
2021

Ramstack.Globbing/Internal/PathHelper.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public PathSegmentIterator() =>
334334

335335
while ((int)_position < length)
336336
{
337-
if ((Avx2.IsSupported || Sse2.IsSupported || AdvSimd.IsSupported) && _mask != 0)
337+
if ((Avx2.IsSupported || Sse2.IsSupported || AdvSimd.Arm64.IsSupported) && _mask != 0)
338338
{
339339
var offset = BitOperations.TrailingZeroCount(_mask);
340340
if (AdvSimd.IsSupported)
@@ -446,8 +446,7 @@ public PathSegmentIterator() =>
446446
if (_mask == 0)
447447
_position += Vector128<ushort>.Count;
448448
}
449-
#if NET7_0_OR_GREATER
450-
else if (AdvSimd.IsSupported && (int)_position + Vector128<ushort>.Count <= length)
449+
else if (AdvSimd.Arm64.IsSupported && (int)_position + Vector128<ushort>.Count <= length)
451450
{
452451
var chunk = LoadVector128(ref source, _position);
453452
var backslashMask = CreateBackslash128Bitmask(flags);
@@ -466,15 +465,24 @@ public PathSegmentIterator() =>
466465
// This avoids reloading SIMD registers and repeating comparisons
467466
// on the same chunk of data.
468467
//
469-
_mask = comparison.ExtractMostSignificantBits();
468+
_mask = ExtractMostSignificantBits(comparison);
470469

471470
//
472471
// Advance position to the next chunk when no separators found
473472
//
474473
if (_mask == 0)
475474
_position += Vector128<ushort>.Count;
475+
476+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
477+
static uint ExtractMostSignificantBits(Vector128<ushort> v)
478+
{
479+
var sum = AdvSimd.Arm64.AddAcross(
480+
AdvSimd.ShiftLogical(
481+
AdvSimd.And(v, Vector128.Create((ushort)0x8000)),
482+
Vector128.Create((short)-15, -14, -13, -12, -11, -10, -9, -8)));
483+
return sum.ToScalar();
484+
}
476485
}
477-
#endif
478486
else
479487
{
480488
for (; (int)_position < length; _position++)

Ramstack.Globbing/Ramstack.Globbing.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
3+
<TargetFramework>net6.0</TargetFramework>
44
<Description>Fast and zero-allocation .NET globbing library for matching file paths using glob patterns.</Description>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>

0 commit comments

Comments
 (0)