Skip to content
Open
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
8 changes: 3 additions & 5 deletions src/libraries/System.IO.Hashing/src/System.IO.Hashing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ System.IO.Hashing.XxHash32</PackageDescription>
<ItemGroup>
<Compile Include="System\IO\Hashing\Adler32.cs" />
<Compile Include="System\IO\Hashing\Crc32.cs" />
<Compile Include="System\IO\Hashing\Crc32.Table.cs" />
<Compile Include="System\IO\Hashing\Crc32ParameterSet.cs" />
<Compile Include="System\IO\Hashing\Crc32ParameterSet.Table.cs" />
<Compile Include="System\IO\Hashing\Crc32ParameterSet.WellKnown.cs" />
<Compile Include="System\IO\Hashing\Crc64.cs" />
<Compile Include="System\IO\Hashing\Crc64.Table.cs" />
<Compile Include="System\IO\Hashing\Crc64ParameterSet.cs" />
<Compile Include="System\IO\Hashing\Crc64ParameterSet.Table.cs" />
<Compile Include="System\IO\Hashing\Crc64ParameterSet.WellKnown.cs" />
Expand All @@ -35,9 +33,9 @@ System.IO.Hashing.XxHash32</PackageDescription>
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Compile Include="System\IO\Hashing\Crc32.Arm.cs" />
<Compile Include="System\IO\Hashing\Crc32.Vectorized.cs" />
<Compile Include="System\IO\Hashing\Crc64.Vectorized.cs" />
<Compile Include="System\IO\Hashing\Crc32ParameterSet.Vectorized.cs" />
<Compile Include="System\IO\Hashing\Crc64ParameterSet.Vectorized.cs" />
<Compile Include="System\IO\Hashing\CrcPolynomialHelper.cs" />
<Compile Include="System\IO\Hashing\VectorHelper.cs" />
<Compile Include="System\ThrowHelper.cs" />
</ItemGroup>
Expand Down
69 changes: 0 additions & 69 deletions src/libraries/System.IO.Hashing/src/System/IO/Hashing/Crc32.Arm.cs

This file was deleted.

This file was deleted.

This file was deleted.

44 changes: 3 additions & 41 deletions src/libraries/System.IO.Hashing/src/System/IO/Hashing/Crc32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace System.IO.Hashing
/// the Little Endian representation of <c>0x2144DF1C</c>.
/// </para>
/// </remarks>
public sealed partial class Crc32 : NonCryptographicHashAlgorithm
public sealed class Crc32 : NonCryptographicHashAlgorithm
{
private const int Size = sizeof(uint);

Expand Down Expand Up @@ -292,7 +292,8 @@ public static uint HashToUInt32(ReadOnlySpan<byte> source)
// Rather than go through Crc32ParameterSet.Crc32 to end up in the optimized Update method here,
// just call the Update method directly.
// ITU-T V.42 / IEEE 802.3 uses a final XOR of 0xFFFFFFFF, so accelerate that as ~.
return ~Update(Crc32ParameterSet.Crc32.InitialValue, source);
Crc32ParameterSet parameterSet = Crc32ParameterSet.Crc32;
return ~parameterSet.Update(parameterSet.InitialValue, source);
}

/// <summary>Computes the CRC-32 hash of the provided data, using specified parameters.</summary>
Expand All @@ -310,44 +311,5 @@ public static uint HashToUInt32(Crc32ParameterSet parameterSet, ReadOnlySpan<byt
uint crc = parameterSet.Update(parameterSet.InitialValue, source);
return parameterSet.Finalize(crc);
}

internal static uint Update(uint crc, ReadOnlySpan<byte> source)
{
#if NET
if (CanBeVectorized(source))
{
return UpdateVectorized(crc, source);
}
#endif

return UpdateScalar(crc, source);
}

private static uint UpdateScalar(uint crc, ReadOnlySpan<byte> source)
{
#if NET
// Use ARM intrinsics for CRC if available. This is used for the trailing bytes on the vectorized path
// and is the primary method if the vectorized path is unavailable.
if (System.Runtime.Intrinsics.Arm.Crc32.Arm64.IsSupported)
{
return UpdateScalarArm64(crc, source);
}

if (System.Runtime.Intrinsics.Arm.Crc32.IsSupported)
{
return UpdateScalarArm32(crc, source);
}
#endif

ReadOnlySpan<uint> crcLookup = CrcLookup;
for (int i = 0; i < source.Length; i++)
{
byte idx = (byte)crc;
idx ^= source[i];
crc = crcLookup[idx] ^ (crc >> 8);
}

return crc;
}
}
}
Loading
Loading