Skip to content

Commit

Permalink
Add NET 8.0 target to Microsoft.Bcl.Memory package (#104648)
Browse files Browse the repository at this point in the history
* Add NET 8.0 target to Microsoft.Bcl.Memory package

* Apply suggestions from code review

Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>

* Update src/libraries/Microsoft.Bcl.Memory/tests/Microsoft.Bcl.Memory.Tests.csproj

---------

Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>
  • Loading branch information
buyaa-n and ViktorHofer authored Jul 11, 2024
1 parent ca0011a commit 4dd997d
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;$(NetFrameworkMinimum);$(NetCoreAppCurrent)</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;$(NetFrameworkMinimum);$(NetCoreAppMinimum);$(NetCoreAppCurrent)</TargetFrameworks>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))">
<Compile Include="Microsoft.Bcl.Memory.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))">
<Compile Include="Microsoft.Bcl.Memory.Forwards.cs" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;$(NetFrameworkMinimum);$(NetCoreAppCurrent)</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;$(NetFrameworkMinimum);$(NetCoreAppMinimum);$(NetCoreAppCurrent)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPackable>true</IsPackable>
<DefineConstants>MICROSOFT_BCL_MEMORY;$(DefineConstants)</DefineConstants>
Expand All @@ -22,10 +22,10 @@

<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<OmitResources Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp'">true</OmitResources>
<OmitResources Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))">true</OmitResources>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))">
<Compile Include="..\ref\Microsoft.Bcl.Memory.Forwards.cs" />
</ItemGroup>

Expand All @@ -34,7 +34,7 @@
<Compile Include="..\ref\Microsoft.Bcl.Memory.Forwards.netstandard21.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))">
<Compile Include="..\..\System.Private.CoreLib\src\System\Buffers\Text\Base64Helper\Base64Helper.cs">
<Link>System\Buffers\Text\Base64Helper\Base64Helper.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetFrameworkMinimum);$(NetCoreAppCurrent);</TargetFrameworks>
<TargetFrameworks>$(NetFrameworkMinimum);$(NetCoreAppCurrent)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down Expand Up @@ -39,7 +39,7 @@
</Compile>
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<ItemGroup>
<ProjectReference Include="..\src\Microsoft.Bcl.Memory.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ internal static unsafe OperationStatus DecodeFrom<TBase64Decoder, T>(TBase64Deco
}
}

#if NET9_0_OR_GREATER
end = srcMax - 66;
if (AdvSimd.Arm64.IsSupported && (end >= src))
{
Expand All @@ -81,6 +82,7 @@ internal static unsafe OperationStatus DecodeFrom<TBase64Decoder, T>(TBase64Deco
goto DoneExit;
}
}
#endif

end = srcMax - 24;
if ((Ssse3.IsSupported || AdvSimd.Arm64.IsSupported) && BitConverter.IsLittleEndian && (end >= src))
Expand Down Expand Up @@ -641,8 +643,10 @@ private static OperationStatus DecodeWithWhiteSpaceFromUtf8InPlace<TBase64Decode

#if NET
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET9_0_OR_GREATER
[CompExactlyDependsOn(typeof(Avx512BW))]
[CompExactlyDependsOn(typeof(Avx512Vbmi))]
#endif
private static unsafe void Avx512Decode<TBase64Decoder, T>(TBase64Decoder decoder, ref T* srcBytes, ref byte* destBytes, T* srcEnd, int sourceLength, int destLength, T* srcStart, byte* destStart)
where TBase64Decoder : IBase64Decoder<T>
where T : unmanaged
Expand Down Expand Up @@ -709,7 +713,9 @@ private static unsafe void Avx512Decode<TBase64Decoder, T>(TBase64Decoder decode
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET9_0_OR_GREATER
[CompExactlyDependsOn(typeof(Avx2))]
#endif
private static unsafe void Avx2Decode<TBase64Decoder, T>(TBase64Decoder decoder, ref T* srcBytes, ref byte* destBytes, T* srcEnd, int sourceLength, int destLength, T* srcStart, byte* destStart)
where TBase64Decoder : IBase64Decoder<T>
where T : unmanaged
Expand Down Expand Up @@ -813,8 +819,10 @@ private static unsafe void Avx2Decode<TBase64Decoder, T>(TBase64Decoder decoder,
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET9_0_OR_GREATER
[CompExactlyDependsOn(typeof(Ssse3))]
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
#endif
internal static Vector128<byte> SimdShuffle(Vector128<byte> left, Vector128<byte> right, Vector128<byte> mask8F)
{
Debug.Assert((Ssse3.IsSupported || AdvSimd.Arm64.IsSupported) && BitConverter.IsLittleEndian);
Expand All @@ -824,9 +832,14 @@ internal static Vector128<byte> SimdShuffle(Vector128<byte> left, Vector128<byte
right &= mask8F;
}

#if NET9_0_OR_GREATER
return Vector128.ShuffleUnsafe(left, right);
#else
return Base64Helper.ShuffleUnsafe(left, right);
#endif
}

#if NET9_0_OR_GREATER
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
private static unsafe void AdvSimdDecode<TBase64Decoder, T>(TBase64Decoder decoder, ref T* srcBytes, ref byte* destBytes, T* srcEnd, int sourceLength, int destLength, T* srcStart, byte* destStart)
Expand Down Expand Up @@ -966,10 +979,13 @@ private static unsafe void AdvSimdDecode<TBase64Decoder, T>(TBase64Decoder decod
srcBytes = src;
destBytes = dest;
}
#endif

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET9_0_OR_GREATER
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
[CompExactlyDependsOn(typeof(Ssse3))]
#endif
private static unsafe void Vector128Decode<TBase64Decoder, T>(TBase64Decoder decoder, ref T* srcBytes, ref byte* destBytes, T* srcEnd, int sourceLength, int destLength, T* srcStart, byte* destStart)
where TBase64Decoder : IBase64Decoder<T>
where T : unmanaged
Expand Down Expand Up @@ -1249,8 +1265,10 @@ internal static bool IsWhiteSpace(int value)

#if NET
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET9_0_OR_GREATER
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
[CompExactlyDependsOn(typeof(Ssse3))]
#endif
public bool TryDecode128Core(
Vector128<byte> str,
Vector128<byte> hiNibbles,
Expand Down Expand Up @@ -1284,7 +1302,9 @@ public bool TryDecode128Core(
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET9_0_OR_GREATER
[CompExactlyDependsOn(typeof(Avx2))]
#endif
public bool TryDecode256Core(
Vector256<sbyte> str,
Vector256<sbyte> hiNibbles,
Expand Down Expand Up @@ -1322,7 +1342,9 @@ public unsafe bool TryLoadVector512(byte* src, byte* srcStart, int sourceLength,
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET9_0_OR_GREATER
[CompExactlyDependsOn(typeof(Avx2))]
#endif
public unsafe bool TryLoadAvxVector256(byte* src, byte* srcStart, int sourceLength, out Vector256<sbyte> str)
{
AssertRead<Vector256<sbyte>>(src, srcStart, sourceLength);
Expand All @@ -1338,6 +1360,7 @@ public unsafe bool TryLoadVector128(byte* src, byte* srcStart, int sourceLength,
return true;
}

#if NET9_0_OR_GREATER
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
public unsafe bool TryLoadArmVector128x4(byte* src, byte* srcStart, int sourceLength,
Expand All @@ -1348,7 +1371,8 @@ public unsafe bool TryLoadArmVector128x4(byte* src, byte* srcStart, int sourceLe

return true;
}
#endif
#endif // NET9_0_OR_GREATER
#endif // NET

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe int DecodeFourElements(byte* source, ref sbyte decodingMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ internal static unsafe OperationStatus EncodeTo<TBase64Encoder, T>(TBase64Encode
goto DoneExit;
}

#if NET9_0_OR_GREATER
end = srcMax - 48;
if (AdvSimd.Arm64.IsSupported && (end >= src))
{
Expand All @@ -66,6 +67,7 @@ internal static unsafe OperationStatus EncodeTo<TBase64Encoder, T>(TBase64Encode
if (src == srcEnd)
goto DoneExit;
}
#endif

end = srcMax - 16;
if ((Ssse3.IsSupported || AdvSimd.Arm64.IsSupported) && BitConverter.IsLittleEndian && (end >= src))
Expand Down Expand Up @@ -130,8 +132,10 @@ internal static unsafe OperationStatus EncodeTo<TBase64Encoder, T>(TBase64Encode

#if NET
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET9_0_OR_GREATER
[CompExactlyDependsOn(typeof(Avx512BW))]
[CompExactlyDependsOn(typeof(Avx512Vbmi))]
#endif
private static unsafe void Avx512Encode<TBase64Encoder, T>(TBase64Encoder encoder, ref byte* srcBytes, ref T* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, T* destStart)
where TBase64Encoder : IBase64Encoder<T>
where T : unmanaged
Expand Down Expand Up @@ -205,7 +209,9 @@ private static unsafe void Avx512Encode<TBase64Encoder, T>(TBase64Encoder encode
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET9_0_OR_GREATER
[CompExactlyDependsOn(typeof(Avx2))]
#endif
private static unsafe void Avx2Encode<TBase64Encoder, T>(TBase64Encoder encoder, ref byte* srcBytes, ref T* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, T* destStart)
where TBase64Encoder : IBase64Encoder<T>
where T : unmanaged
Expand Down Expand Up @@ -376,6 +382,7 @@ private static unsafe void Avx2Encode<TBase64Encoder, T>(TBase64Encoder encoder,
destBytes = dest;
}

#if NET9_0_OR_GREATER // Part of the Arm APIs used here added in .NET 9
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
private static unsafe void AdvSimdEncode<TBase64Encoder, T>(TBase64Encoder encoder, ref byte* srcBytes, ref T* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, T* destStart)
Expand Down Expand Up @@ -434,10 +441,13 @@ private static unsafe void AdvSimdEncode<TBase64Encoder, T>(TBase64Encoder encod
srcBytes = src;
destBytes = dest;
}
#endif

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET9_0_OR_GREATER
[CompExactlyDependsOn(typeof(Ssse3))]
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
#endif
private static unsafe void Vector128Encode<TBase64Encoder, T>(TBase64Encoder encoder, ref byte* srcBytes, ref T* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, T* destStart)
where TBase64Encoder : IBase64Encoder<T>
where T : unmanaged
Expand Down Expand Up @@ -712,7 +722,9 @@ public unsafe void StoreVector512ToDestination(byte* dest, byte* destStart, int
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET9_0_OR_GREATER
[CompExactlyDependsOn(typeof(Avx2))]
#endif
public unsafe void StoreVector256ToDestination(byte* dest, byte* destStart, int destLength, Vector256<byte> str)
{
AssertWrite<Vector256<sbyte>>(dest, destStart, destLength);
Expand All @@ -726,6 +738,7 @@ public unsafe void StoreVector128ToDestination(byte* dest, byte* destStart, int
str.Store(dest);
}

#if NET9_0_OR_GREATER
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
public unsafe void StoreArmVector128x4ToDestination(byte* dest, byte* destStart, int destLength,
Expand All @@ -734,7 +747,8 @@ public unsafe void StoreArmVector128x4ToDestination(byte* dest, byte* destStart,
AssertWrite<Vector128<byte>>(dest, destStart, destLength);
AdvSimd.Arm64.StoreVectorAndZip(dest, (res1, res2, res3, res4));
}
#endif
#endif // NET9_0_OR_GREATER
#endif // NET

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void EncodeThreeAndWrite(byte* threeBytes, byte* destination, ref byte encodingMap)
Expand Down
Loading

0 comments on commit 4dd997d

Please sign in to comment.