Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ public static nint Count<T>(ref T r0, nint length, T value)
return CountSimd(ref r1, length, target);
}

#if NET6_0_OR_GREATER
if (typeof(T) == typeof(nint) ||
typeof(T) == typeof(nuint))
{
ref nint r1 = ref Unsafe.As<T, nint>(ref r0);
nint target = Unsafe.As<T, nint>(ref value);

return CountSimd(ref r1, length, target);
}
#endif

return CountSequential(ref r0, length, value);
}

Expand Down Expand Up @@ -229,7 +240,11 @@ private static nint CountSimd<T>(ref T r0, nint length, T value)
offset += Vector<T>.Count;
}

#if NET6_0_OR_GREATER
result += CastToNativeInt(Vector.Sum(partials));
#else
result += CastToNativeInt(Vector.Dot(partials, Vector<T>.One));
#endif
length -= offset - initialOffset;
}
while (length >= Vector<T>.Count);
Expand Down Expand Up @@ -320,6 +335,13 @@ private static unsafe nint GetUpperBound<T>()
return (nint)(void*)long.MaxValue;
}

#if NET6_0_OR_GREATER
if (typeof(T) == typeof(nint))
{
return nint.MaxValue;
}
#endif

throw null!;
}

Expand Down Expand Up @@ -353,6 +375,13 @@ private static nint CastToNativeInt<T>(T value)
return (nint)(ulong)(long)(object)value;
}

#if NET6_0_OR_GREATER
if (typeof(T) == typeof(nint))
{
return (nint)(object)value;
}
#endif

throw null!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.Runtime.InteropServices;
using CommunityToolkit.HighPerformance;
using CommunityToolkit.HighPerformance.UnitTests.Buffers.Internals;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -49,6 +48,15 @@ public void Test_ReadOnlySpanExtensions_RandomCount64()
TestForType(Math.PI, CreateRandomData);
}

#if NET6_0_OR_GREATER
[TestMethod]
public void Test_ReadOnlySpanExtensions_RandomCountPtr()
{
TestForType(nint.MaxValue / 2, CreateRandomData);
TestForType(nuint.MaxValue / 2, CreateRandomData);
}
#endif

[TestMethod]
public void Test_ReadOnlySpanExtensions_RandomCountManaged()
{
Expand Down Expand Up @@ -148,6 +156,15 @@ public void Test_ReadOnlySpanExtensions_FilledCount64()
TestForType((ulong)47128480128401, (count, _) => CreateFilledData(count, (ulong)47128480128401));
}

#if NET6_0_OR_GREATER
[TestMethod]
public void Test_ReadOnlySpanExtensions_FilledCountPtr()
{
TestForType((nint)37438941, (count, _) => CreateFilledData(count, (nint)37438941));
TestForType((nuint)37438941, (count, _) => CreateFilledData(count, (nuint)37438941));
}
#endif

/// <summary>
/// Performs a test for a specified type.
/// </summary>
Expand Down