Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Avx2 helpers #85275

Merged
merged 12 commits into from
Apr 25, 2023
24 changes: 12 additions & 12 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,21 +292,21 @@
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>cb54ca21431ee8d96f91abfbc42237bcb001f9d1</Sha>
</Dependency>
<Dependency Name="optimization.windows_nt-x64.MIBC.Runtime" Version="1.0.0-prerelease.23175.4">
<Dependency Name="optimization.windows_nt-x64.MIBC.Runtime" Version="1.0.0-prerelease.23220.15">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>
<Sha>103c1eaca9ad80cdd1746abfb97c7f3c9d0b0f3b</Sha>
<Sha>f9ae5c9fda841a26d8eaaa07151ac2618725da87</Sha>
</Dependency>
<Dependency Name="optimization.windows_nt-x86.MIBC.Runtime" Version="1.0.0-prerelease.23175.4">
<Dependency Name="optimization.windows_nt-x86.MIBC.Runtime" Version="1.0.0-prerelease.23220.15">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>
<Sha>103c1eaca9ad80cdd1746abfb97c7f3c9d0b0f3b</Sha>
<Sha>f9ae5c9fda841a26d8eaaa07151ac2618725da87</Sha>
</Dependency>
<Dependency Name="optimization.linux-x64.MIBC.Runtime" Version="1.0.0-prerelease.23175.4">
<Dependency Name="optimization.linux-x64.MIBC.Runtime" Version="1.0.0-prerelease.23220.15">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>
<Sha>103c1eaca9ad80cdd1746abfb97c7f3c9d0b0f3b</Sha>
<Sha>f9ae5c9fda841a26d8eaaa07151ac2618725da87</Sha>
</Dependency>
<Dependency Name="optimization.PGO.CoreCLR" Version="1.0.0-prerelease.23175.4">
<Dependency Name="optimization.PGO.CoreCLR" Version="1.0.0-prerelease.23220.15">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>
<Sha>103c1eaca9ad80cdd1746abfb97c7f3c9d0b0f3b</Sha>
<Sha>f9ae5c9fda841a26d8eaaa07151ac2618725da87</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.HotReload.Utils.Generator.BuildTool" Version="1.1.0-alpha.0.23179.3">
<Uri>https://github.com/dotnet/hotreload-utils</Uri>
Expand Down Expand Up @@ -340,13 +340,13 @@
<Uri>https://github.com/dotnet/sdk</Uri>
<Sha>2fd62c3936f5336b836f6b12df170aa0e90da767</Sha>
</Dependency>
<Dependency Name="optimization.windows_nt-arm64.MIBC.Runtime" Version="1.0.0-prerelease.23175.4">
<Dependency Name="optimization.windows_nt-arm64.MIBC.Runtime" Version="1.0.0-prerelease.23220.15">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>
<Sha>103c1eaca9ad80cdd1746abfb97c7f3c9d0b0f3b</Sha>
<Sha>f9ae5c9fda841a26d8eaaa07151ac2618725da87</Sha>
</Dependency>
<Dependency Name="optimization.linux-arm64.MIBC.Runtime" Version="1.0.0-prerelease.23175.4">
<Dependency Name="optimization.linux-arm64.MIBC.Runtime" Version="1.0.0-prerelease.23220.15">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>
<Sha>103c1eaca9ad80cdd1746abfb97c7f3c9d0b0f3b</Sha>
<Sha>f9ae5c9fda841a26d8eaaa07151ac2618725da87</Sha>
</Dependency>
</ToolsetDependencies>
</Dependencies>
12 changes: 6 additions & 6 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@
<SystemWindowsExtensionsTestDataVersion>8.0.0-beta.23179.4</SystemWindowsExtensionsTestDataVersion>
<MicrosoftDotNetCilStripSourcesVersion>8.0.0-beta.23179.4</MicrosoftDotNetCilStripSourcesVersion>
<!-- dotnet-optimization dependencies -->
<optimizationwindows_ntx64MIBCRuntimeVersion>1.0.0-prerelease.23175.4</optimizationwindows_ntx64MIBCRuntimeVersion>
<optimizationwindows_ntx86MIBCRuntimeVersion>1.0.0-prerelease.23175.4</optimizationwindows_ntx86MIBCRuntimeVersion>
<optimizationwindows_ntarm64MIBCRuntimeVersion>1.0.0-prerelease.23175.4</optimizationwindows_ntarm64MIBCRuntimeVersion>
<optimizationlinuxx64MIBCRuntimeVersion>1.0.0-prerelease.23175.4</optimizationlinuxx64MIBCRuntimeVersion>
<optimizationlinuxarm64MIBCRuntimeVersion>1.0.0-prerelease.23175.4</optimizationlinuxarm64MIBCRuntimeVersion>
<optimizationPGOCoreCLRVersion>1.0.0-prerelease.23175.4</optimizationPGOCoreCLRVersion>
<optimizationwindows_ntx64MIBCRuntimeVersion>1.0.0-prerelease.23220.15</optimizationwindows_ntx64MIBCRuntimeVersion>
<optimizationwindows_ntx86MIBCRuntimeVersion>1.0.0-prerelease.23220.15</optimizationwindows_ntx86MIBCRuntimeVersion>
<optimizationwindows_ntarm64MIBCRuntimeVersion>1.0.0-prerelease.23220.15</optimizationwindows_ntarm64MIBCRuntimeVersion>
<optimizationlinuxx64MIBCRuntimeVersion>1.0.0-prerelease.23220.15</optimizationlinuxx64MIBCRuntimeVersion>
<optimizationlinuxarm64MIBCRuntimeVersion>1.0.0-prerelease.23220.15</optimizationlinuxarm64MIBCRuntimeVersion>
<optimizationPGOCoreCLRVersion>1.0.0-prerelease.23220.15</optimizationPGOCoreCLRVersion>
<!-- Not auto-updated. -->
<MicrosoftDiaSymReaderNativeVersion>16.11.23-beta1.23063.1</MicrosoftDiaSymReaderNativeVersion>
<SystemCommandLineVersion>2.0.0-beta4.22564.1</SystemCommandLineVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\SatelliteContractVersionAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\UltimateResourceFallbackLocation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\AmbiguousImplementationException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\BypassReadyToRunAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AccessedThroughPropertyAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncIteratorMethodBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncIteratorStateMachineAttribute.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
Expand Down Expand Up @@ -350,6 +351,7 @@ public static unsafe OperationStatus DecodeFromUtf8InPlace(Span<byte> buffer, ou
}
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe void Avx2Decode(ref byte* srcBytes, ref byte* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, byte* destStart)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
Expand Down Expand Up @@ -225,6 +226,7 @@ public static unsafe OperationStatus EncodeToUtf8InPlace(Span<byte> buffer, int
}
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe void Avx2Encode(ref byte* srcBytes, ref byte* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, byte* destStart)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Numerics;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
Expand Down Expand Up @@ -869,6 +870,7 @@ private static Vector128<byte> IndexOfAnyLookupCore(Vector128<byte> source, Vect
return result;
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector256<byte> IndexOfAnyLookup<TNegator, TOptimizations>(Vector256<short> source0, Vector256<short> source1, Vector256<byte> bitmapLookup)
where TNegator : struct, INegator
Expand All @@ -889,6 +891,7 @@ private static Vector256<byte> IndexOfAnyLookup<TNegator, TOptimizations>(Vector
return TNegator.NegateIfNeeded(result);
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector256<byte> IndexOfAnyLookupCore(Vector256<byte> source, Vector256<byte> bitmapLookup)
{
Expand Down Expand Up @@ -922,6 +925,7 @@ private static Vector128<byte> IndexOfAnyLookup<TNegator>(Vector128<byte> source
return TNegator.NegateIfNeeded(result);
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector256<byte> IndexOfAnyLookup<TNegator>(Vector256<byte> source, Vector256<byte> bitmapLookup0, Vector256<byte> bitmapLookup1)
where TNegator : struct, INegator
Expand Down Expand Up @@ -992,6 +996,7 @@ private static unsafe int ComputeLastIndexOverlapped<T, TNegator>(ref T searchSp
return offsetInVector - Vector128<short>.Count + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref secondVector) / (nuint)sizeof(T));
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe int ComputeFirstIndex<T, TNegator>(ref T searchSpace, ref T current, Vector256<byte> result)
where TNegator : struct, INegator
Expand All @@ -1007,6 +1012,7 @@ private static unsafe int ComputeFirstIndex<T, TNegator>(ref T searchSpace, ref
return offsetInVector + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref current) / (nuint)sizeof(T));
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe int ComputeFirstIndexOverlapped<T, TNegator>(ref T searchSpace, ref T current0, ref T current1, Vector256<byte> result)
where TNegator : struct, INegator
Expand All @@ -1028,6 +1034,7 @@ private static unsafe int ComputeFirstIndexOverlapped<T, TNegator>(ref T searchS
return offsetInVector + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref current0) / (nuint)sizeof(T));
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe int ComputeLastIndex<T, TNegator>(ref T searchSpace, ref T current, Vector256<byte> result)
where TNegator : struct, INegator
Expand All @@ -1043,6 +1050,7 @@ private static unsafe int ComputeLastIndex<T, TNegator>(ref T searchSpace, ref T
return offsetInVector + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref current) / (nuint)sizeof(T));
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe int ComputeLastIndexOverlapped<T, TNegator>(ref T searchSpace, ref T secondVector, Vector256<byte> result)
where TNegator : struct, INegator
Expand All @@ -1064,6 +1072,7 @@ private static unsafe int ComputeLastIndexOverlapped<T, TNegator>(ref T searchSp
return offsetInVector - Vector256<short>.Count + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref secondVector) / (nuint)sizeof(T));
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector256<byte> FixUpPackedVector256Result(Vector256<byte> result)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics;
using System.Numerics;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
Expand Down Expand Up @@ -104,6 +105,7 @@ ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(values)),
(short)ch,
values.Length);

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector256<byte> ContainsMask32CharsAvx2(Vector256<byte> charMapLower, Vector256<byte> charMapUpper, ref char searchSpace)
{
Expand All @@ -124,6 +126,7 @@ private static Vector256<byte> ContainsMask32CharsAvx2(Vector256<byte> charMapLo
return resultLower & resultUpper;
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector256<byte> IsCharBitSetAvx2(Vector256<byte> charMapLower, Vector256<byte> charMapUpper, Vector256<byte> values)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Runtime
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false)]
internal sealed class BypassReadyToRunAttribute : Attribute
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Buffers.Binary;
using System.Diagnostics;
using System.Numerics;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
Expand Down Expand Up @@ -784,6 +785,7 @@ private static int IndexOfAnyInRange<TNegator>(ref short searchSpace, short lowI
return -1;
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector256<byte> PackSources(Vector256<short> source0, Vector256<short> source1)
{
Expand Down Expand Up @@ -824,6 +826,7 @@ private static int ComputeFirstIndex(ref short searchSpace, ref short current, V
return index + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref current) / sizeof(short));
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int ComputeFirstIndex(ref short searchSpace, ref short current, Vector256<byte> equals)
{
Expand All @@ -846,6 +849,7 @@ private static int ComputeFirstIndexOverlapped(ref short searchSpace, ref short
return offsetInVector + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref current0) / sizeof(short));
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int ComputeFirstIndexOverlapped(ref short searchSpace, ref short current0, ref short current1, Vector256<byte> equals)
{
Expand All @@ -860,6 +864,7 @@ private static int ComputeFirstIndexOverlapped(ref short searchSpace, ref short
return offsetInVector + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref current0) / sizeof(short));
}

[BypassReadyToRun]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector256<byte> FixUpPackedVector256Result(Vector256<byte> result)
{
Expand Down