-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API Implementation]: Expose general purpose Crc32 APIs (#61558)
* Expose Crc32 Implementation and implement Crc32 software fallback * Fix signature of BitOperation Crc32 methods * Implement common test cases * Add X64 Intrinsic support for Crc32(uint crc, ulong data) * Add documentation comments * Remove Hwintrinsic doc-comment * Rename Crc32 to Crc32C * Remove unnessecary heap allocation * Fix software fallback using table-based-CRC * Usage of uint32_t __crc32ch (uint32_t a, uint32_t b) * Remove Crc.Sse42 implementation for Crc32C(uint crc, ulong data) There is no implementation which returns `uint32_t`. See https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#techs=MMX,SSE,SSE2,SSE3,SSSE3,SSE4_1,SSE4_2,AVX,AVX2,FMA,AVX_VNNI,AVX_512,KNC,AMX,SVML,Other&text=crc * Add SSE 4.2 x64 implementation with byte truncation for Crc32C(uint crc, ulong data) * Replace Unsafe.As with unchecked-uint cast * Usage of WriteUnaligned instead of As Co-authored-by: Günther Foidl <gue@korporal.at> * Usage of WriteUnaligned instead of As Co-authored-by: Günther Foidl <gue@korporal.at> * Usage of WriteUnaligned instead of As Co-authored-by: Günther Foidl <gue@korporal.at> * Usage of explicit types * Fix Software-Fallback Table to Castalogni equivalent * Fix test signature * Remove mask for software fallback * reuse reflected table generator * Fix test data * Usage of CRC Table Generator instead of constant values * Fix solution file * Revert "Usage of CRC Table Generator instead of constant values" This reverts commit d44a215. * Fix solution file * Make Crc32ReflectedTable static Co-authored-by: kasperk81 <83082615+kasperk81@users.noreply.github.com> * Fix wrong intrinsic for Arm64/BitOperations.Crc32C(uint crc, ulong data) * Reduce amount of stackalloc statements and replace them with MemoryMarshal.CreateReadOnlySpan * Loop unwinding and performance optimization * Remove unnessecary cast Co-authored-by: Clinton Ingram <clinton.ingram@outlook.com> * Use MemoryMarshal.GetArrayDataReference instead of direct array access * Remove unnessecary newlines * Update src/libraries/System.Private.CoreLib/src/System/Numerics/BitOperations.cs Co-authored-by: kasperk81 <83082615+kasperk81@users.noreply.github.com> * Add x64 SSE check Co-authored-by: kasperk81 <83082615+kasperk81@users.noreply.github.com> * Move Crc32 Software into own class * Remove IsSupported check * Fix parameter naming * Fix fallback implementation method naming * Improve documentation * Move bswap into Crc32Fallback class * Implement efficient usage of SSE x86/x64 Co-authored-by: Clinton Ingram <clinton.ingram@outlook.com> * Style Changes for BitOperations.cs * Remove unnessecary `bswap` of a single byte * Fix doc comments * fix doc * Fix * Merge remote-tracking branch 'upstream/main' into issue-2036 * Apply suggestions Co-authored-by: Günther Foidl <gue@korporal.at> Co-authored-by: kasperk81 <83082615+kasperk81@users.noreply.github.com> Co-authored-by: Clinton Ingram <clinton.ingram@outlook.com>
- Loading branch information
1 parent
23697bb
commit 56bbc7c
Showing
7 changed files
with
256 additions
and
28 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/libraries/Common/src/System/Numerics/Crc32ReflectedTable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Numerics | ||
{ | ||
internal static class Crc32ReflectedTable | ||
{ | ||
internal static uint[] Generate(uint reflectedPolynomial) | ||
{ | ||
uint[] table = new uint[256]; | ||
|
||
for (int i = 0; i < 256; i++) | ||
{ | ||
uint val = (uint)i; | ||
|
||
for (int j = 0; j < 8; j++) | ||
{ | ||
if ((val & 0b0000_0001) == 0) | ||
{ | ||
val >>= 1; | ||
} | ||
else | ||
{ | ||
val = (val >> 1) ^ reflectedPolynomial; | ||
} | ||
} | ||
|
||
table[i] = val; | ||
} | ||
|
||
return table; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters