From 9f85fdadd043312af6699d71401e035d3fd73668 Mon Sep 17 00:00:00 2001 From: Eduard Sergeev Date: Thu, 7 Jul 2022 21:13:51 +1000 Subject: [PATCH 1/4] Add hardware accelerated implementations - Force.Crc32.Intrinsics.Crc32Algorithm - CRC32 (supported by ARM) - Force.Crc32.Intrinsics.Crc32CAlgorithm - CRC32A (supported by Intel and ARM) --- Crc32.NET/Crc32.NET.Core.csproj | 6 +- Crc32.NET/Intrinsics/Crc32Algorithm.cs | 112 ++++++++++++++++++ Crc32.NET/Intrinsics/Crc32CAlgorithm.cs | 149 ++++++++++++++++++++++++ Crc32.NET/Intrinsics/Platform.cs | 19 +++ 4 files changed, 283 insertions(+), 3 deletions(-) create mode 100644 Crc32.NET/Intrinsics/Crc32Algorithm.cs create mode 100644 Crc32.NET/Intrinsics/Crc32CAlgorithm.cs create mode 100644 Crc32.NET/Intrinsics/Platform.cs diff --git a/Crc32.NET/Crc32.NET.Core.csproj b/Crc32.NET/Crc32.NET.Core.csproj index cec1661..54842b5 100644 --- a/Crc32.NET/Crc32.NET.Core.csproj +++ b/Crc32.NET/Crc32.NET.Core.csproj @@ -1,7 +1,7 @@  - 1.2.1 - netstandard1.3;netstandard2.0;net20 + 1.3.0 + netstandard1.3;netstandard2.0;net20;net5.0;net6.0 true Crc32.NET - - $(DefineConstants);NETCORE;;NETCORE13 - - - $(DefineConstants);NETCORE;NETCORE20 - - - $(DefineConstants);COREVERSION - diff --git a/Crc32.NET.Tests/Crc32Implementations/Crc32C_Standard.cs b/Crc32.NET.Tests/Crc32Implementations/Crc32C_Standard.cs index 5920265..a57cd4a 100644 --- a/Crc32.NET.Tests/Crc32Implementations/Crc32C_Standard.cs +++ b/Crc32.NET.Tests/Crc32Implementations/Crc32C_Standard.cs @@ -1,5 +1,4 @@ -#if !NETFRAMEWORK -namespace Force.Crc32.Tests.Crc32Implementations +namespace Force.Crc32.Tests.Crc32Implementations { public class Crc32C_Standard : CrcCalculator { @@ -15,4 +14,3 @@ public override uint Calculate(byte[] data) } } } -#endif diff --git a/Crc32.NET.Tests/Crc32Implementations/Crc32_Crc32Algorithm.cs b/Crc32.NET.Tests/Crc32Implementations/Crc32_Crc32Algorithm.cs index 04f95b3..cdc31f2 100644 --- a/Crc32.NET.Tests/Crc32Implementations/Crc32_Crc32Algorithm.cs +++ b/Crc32.NET.Tests/Crc32Implementations/Crc32_Crc32Algorithm.cs @@ -1,5 +1,4 @@ -#if NETFRAMEWORK -using Crc = Crc32.Crc32Algorithm; +using Crc = Crc32.Crc32Algorithm; namespace Force.Crc32.Tests.Crc32Implementations { @@ -15,4 +14,3 @@ public override uint Calculate(byte[] data) } } } -#endif diff --git a/Crc32.NET.Tests/Crc32Implementations/K4os_Hash_Crc.cs b/Crc32.NET.Tests/Crc32Implementations/K4os_Hash_Crc.cs index 62870d8..72abf4b 100644 --- a/Crc32.NET.Tests/Crc32Implementations/K4os_Hash_Crc.cs +++ b/Crc32.NET.Tests/Crc32Implementations/K4os_Hash_Crc.cs @@ -1,5 +1,4 @@ -#if COREVERSION -namespace Force.Crc32.Tests.Crc32Implementations +namespace Force.Crc32.Tests.Crc32Implementations { public class K4os_Hash_Crc : CrcCalculator { @@ -13,4 +12,3 @@ public override uint Calculate(byte[] data) } } } -#endif \ No newline at end of file diff --git a/Crc32.NET.Tests/PerformanceTest.cs b/Crc32.NET.Tests/PerformanceTest.cs index fb1b6d1..3ab0459 100644 --- a/Crc32.NET.Tests/PerformanceTest.cs +++ b/Crc32.NET.Tests/PerformanceTest.cs @@ -21,12 +21,6 @@ public void ThroughputKlinkby_Checksum() Calculate(new Klinkby_Checkum_Crc32()); } - [Test] - public void ThroughputCrc32_By_dariogriffo() - { - Calculate(new Crc32_Crc32Algorithm()); - } - [Test] public void ThroughputCrc32_By_Data_HashFunction_Crc() { @@ -44,14 +38,25 @@ public void ThroughputCrc32C_Crc32C() { Calculate(new Crc32C_Crc32CAlgorithm()); } -#else +#endif [Test] public void ThroughputCrc32C_Standard() { Calculate(new Crc32C_Standard()); } -#endif - + + [Test] + public void ThroughputCrc32_By_dariogriffo() + { + Calculate(new Crc32_Crc32Algorithm()); + } + + [Test] + public void ThroughputCrc32C_By_K4os_Hash_Crc() + { + Calculate(new K4os_Hash_Crc()); + } + [Test] public void ThroughputCrc32_By_Me() { @@ -86,14 +91,6 @@ public void ThroughputCrc32_By_Me_Intrinsics() } #endif -#if COREVERSION && NETFRAMEWORK13 - [Test] - public void ThroughputCrc32C_By_K4os_Hash_Crc() - { - Calculate(new K4os_Hash_Crc()); - } -#endif - private void Calculate(CrcCalculator implementation, int size = 65536) { if(!implementation.IsSupported) diff --git a/Crc32.NET.Tests/Program.cs b/Crc32.NET.Tests/Program.cs index 2d47edb..7f9354b 100644 --- a/Crc32.NET.Tests/Program.cs +++ b/Crc32.NET.Tests/Program.cs @@ -6,16 +6,14 @@ public static void Main() { var pt = new PerformanceTest(); #if NETFRAMEWORK - pt.ThroughputCrc32_By_dariogriffo(); pt.ThroughputCHCrc32_By_tanglebones(); pt.ThroughputKlinkby_Checksum(); pt.ThroughputCrc32_By_Data_HashFunction_Crc(); pt.ThroughputCrc32_By_Me(); pt.ThroughputCrc32_By_Dexiom(); -#if COREVERSION - pt.ThroughputCrc32C_By_K4os_Hash_Crc(); #endif -#else + pt.ThroughputCrc32_By_dariogriffo(); + pt.ThroughputCrc32C_By_K4os_Hash_Crc(); pt.ThroughputCrc32C_Standard(); pt.ThroughputCrc32C_By_Me(); pt.ThroughputCrc32_By_Me(); @@ -24,7 +22,6 @@ public static void Main() #endif #if NET5_0_OR_GREATER pt.ThroughputCrc32_By_Me_Intrinsics(); -#endif #endif } } From dd80c05de0f4f24a6fc2bc614027501d23df94d8 Mon Sep 17 00:00:00 2001 From: Eduard Sergeev Date: Mon, 28 Aug 2023 08:39:40 +1000 Subject: [PATCH 4/4] Update .NET `TargetFrameworks` Use latest supported .NET frameworks: - .NET 6 - .NET 7 --- Crc32.NET.Tests/Crc32.NET.Tests.Core.csproj | 2 +- Crc32.NET/Crc32.NET.Core.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Crc32.NET.Tests/Crc32.NET.Tests.Core.csproj b/Crc32.NET.Tests/Crc32.NET.Tests.Core.csproj index c029d85..9642f6b 100644 --- a/Crc32.NET.Tests/Crc32.NET.Tests.Core.csproj +++ b/Crc32.NET.Tests/Crc32.NET.Tests.Core.csproj @@ -1,6 +1,6 @@  - net461;net5.0;net6.0 + net6.0;net7.0 portable Crc32.NET.Tests Exe diff --git a/Crc32.NET/Crc32.NET.Core.csproj b/Crc32.NET/Crc32.NET.Core.csproj index d189354..6faefad 100644 --- a/Crc32.NET/Crc32.NET.Core.csproj +++ b/Crc32.NET/Crc32.NET.Core.csproj @@ -1,7 +1,7 @@  1.3.0 - netstandard1.3;netstandard2.0;net20;net5.0;net6.0 + net6.0;net7.0 true Crc32.NET