diff --git a/Crc32.NET.Tests/BytePatternsTest.cs b/Crc32.NET.Tests/BytePatternsTest.cs
index 02bb874..4651136 100644
--- a/Crc32.NET.Tests/BytePatternsTest.cs
+++ b/Crc32.NET.Tests/BytePatternsTest.cs
@@ -1,4 +1,4 @@
-#if !NETCORE
+#if NETFRAMEWORK
using System;
using System.Linq;
using Force.Crc32.Tests.Crc32Implementations;
@@ -91,4 +91,4 @@ private void TestByteSequence(byte[] data)
}
}
-#endif
\ No newline at end of file
+#endif
diff --git a/Crc32.NET.Tests/Crc32.NET.Tests.Core.csproj b/Crc32.NET.Tests/Crc32.NET.Tests.Core.csproj
index abd6655..9642f6b 100644
--- a/Crc32.NET.Tests/Crc32.NET.Tests.Core.csproj
+++ b/Crc32.NET.Tests/Crc32.NET.Tests.Core.csproj
@@ -1,6 +1,6 @@
- netcoreapp1.0;netcoreapp2.0;net461
+ net6.0;net7.0
portable
Crc32.NET.Tests
Exe
@@ -13,34 +13,22 @@
-
-
-
+
+
+
+
-
-
-
-
-
+
+
-
-
-
-
+
+
+
+
-
-
- $(DefineConstants);NETCORE;;NETCORE13
-
-
- $(DefineConstants);NETCORE;NETCORE20
-
-
- $(DefineConstants);COREVERSION
-
-
\ No newline at end of file
+
diff --git a/Crc32.NET.Tests/Crc32Implementations/CH_Crc32_Crc.cs b/Crc32.NET.Tests/Crc32Implementations/CH_Crc32_Crc.cs
index 6699a19..c7eae41 100644
--- a/Crc32.NET.Tests/Crc32Implementations/CH_Crc32_Crc.cs
+++ b/Crc32.NET.Tests/Crc32Implementations/CH_Crc32_Crc.cs
@@ -1,4 +1,4 @@
-#if !NETCORE
+#if NETFRAMEWORK
namespace Force.Crc32.Tests.Crc32Implementations
{
@@ -14,4 +14,4 @@ public override uint Calculate(byte[] data)
}
}
}
-#endif
\ No newline at end of file
+#endif
diff --git a/Crc32.NET.Tests/Crc32Implementations/Crc32C_Crc32CAlgorithm.cs b/Crc32.NET.Tests/Crc32Implementations/Crc32C_Crc32CAlgorithm.cs
index 175ef8b..e522985 100644
--- a/Crc32.NET.Tests/Crc32Implementations/Crc32C_Crc32CAlgorithm.cs
+++ b/Crc32.NET.Tests/Crc32Implementations/Crc32C_Crc32CAlgorithm.cs
@@ -1,4 +1,4 @@
-#if !NETCORE
+#if NETFRAMEWORK
namespace Force.Crc32.Tests.Crc32Implementations
{
public class Crc32C_Crc32CAlgorithm : CrcCalculator
@@ -13,4 +13,4 @@ public override uint Calculate(byte[] data)
}
}
}
-#endif
\ No newline at end of file
+#endif
diff --git a/Crc32.NET.Tests/Crc32Implementations/Crc32C_Standard.cs b/Crc32.NET.Tests/Crc32Implementations/Crc32C_Standard.cs
index e9226f7..a57cd4a 100644
--- a/Crc32.NET.Tests/Crc32Implementations/Crc32C_Standard.cs
+++ b/Crc32.NET.Tests/Crc32Implementations/Crc32C_Standard.cs
@@ -1,5 +1,4 @@
-#if NETCORE
-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
\ No newline at end of file
diff --git a/Crc32.NET.Tests/Crc32Implementations/Crc32_Crc32Algorithm.cs b/Crc32.NET.Tests/Crc32Implementations/Crc32_Crc32Algorithm.cs
index a034074..cdc31f2 100644
--- a/Crc32.NET.Tests/Crc32Implementations/Crc32_Crc32Algorithm.cs
+++ b/Crc32.NET.Tests/Crc32Implementations/Crc32_Crc32Algorithm.cs
@@ -1,5 +1,4 @@
-#if !NETCORE
-using Crc = Crc32.Crc32Algorithm;
+using Crc = Crc32.Crc32Algorithm;
namespace Force.Crc32.Tests.Crc32Implementations
{
@@ -15,4 +14,3 @@ public override uint Calculate(byte[] data)
}
}
}
-#endif
\ No newline at end of file
diff --git a/Crc32.NET.Tests/Crc32Implementations/CrcCalculator.cs b/Crc32.NET.Tests/Crc32Implementations/CrcCalculator.cs
index dad7ab5..9e7a301 100644
--- a/Crc32.NET.Tests/Crc32Implementations/CrcCalculator.cs
+++ b/Crc32.NET.Tests/Crc32Implementations/CrcCalculator.cs
@@ -2,13 +2,16 @@
{
public abstract class CrcCalculator
{
- protected CrcCalculator(string name)
+ protected CrcCalculator(string name, bool isSupported = true)
{
Name = name;
+ IsSupported = isSupported;
}
public string Name { get; private set; }
+ public bool IsSupported { get; private set; }
+
public abstract uint Calculate(byte[] data);
}
}
diff --git a/Crc32.NET.Tests/Crc32Implementations/Dexiom_Quick_Crc32.cs b/Crc32.NET.Tests/Crc32Implementations/Dexiom_Quick_Crc32.cs
index 62512b1..77e28f3 100644
--- a/Crc32.NET.Tests/Crc32Implementations/Dexiom_Quick_Crc32.cs
+++ b/Crc32.NET.Tests/Crc32Implementations/Dexiom_Quick_Crc32.cs
@@ -1,4 +1,4 @@
-#if !NETCORE
+#if NETFRAMEWORK
namespace Force.Crc32.Tests.Crc32Implementations
{
public class Dexiom_Quick_Crc32 : CrcCalculator
@@ -14,4 +14,4 @@ public override uint Calculate(byte[] data)
}
}
}
-#endif
\ No newline at end of file
+#endif
diff --git a/Crc32.NET.Tests/Crc32Implementations/Force_Intrinsics_Crc32_Crc32Algorithm.cs b/Crc32.NET.Tests/Crc32Implementations/Force_Intrinsics_Crc32_Crc32Algorithm.cs
new file mode 100644
index 0000000..9aa37f9
--- /dev/null
+++ b/Crc32.NET.Tests/Crc32Implementations/Force_Intrinsics_Crc32_Crc32Algorithm.cs
@@ -0,0 +1,17 @@
+namespace Force.Crc32.Tests.Crc32Implementations
+{
+ using Algorithm = Force.Crc32.Intrinsics.Crc32Algorithm;
+
+ public class Force_Intrinsics_Crc32_Crc32Algorithm : CrcCalculator
+ {
+ public Force_Intrinsics_Crc32_Crc32Algorithm()
+ : base("Force.Crc32.Intrinsics.Crc32Algorithm", Algorithm.IsSupported)
+ {
+ }
+
+ public override uint Calculate(byte[] data)
+ {
+ return Algorithm.Compute(data);
+ }
+ }
+}
diff --git a/Crc32.NET.Tests/Crc32Implementations/Force_Intrinsics_Crc32_Crc32CAlgorithm.cs b/Crc32.NET.Tests/Crc32Implementations/Force_Intrinsics_Crc32_Crc32CAlgorithm.cs
new file mode 100644
index 0000000..0dc0111
--- /dev/null
+++ b/Crc32.NET.Tests/Crc32Implementations/Force_Intrinsics_Crc32_Crc32CAlgorithm.cs
@@ -0,0 +1,17 @@
+namespace Force.Crc32.Tests.Crc32Implementations
+{
+ using Algorithm = Force.Crc32.Intrinsics.Crc32CAlgorithm;
+
+ public class Force_Intrinsics_Crc32_Crc32CAlgorithm : CrcCalculator
+ {
+ public Force_Intrinsics_Crc32_Crc32CAlgorithm()
+ : base("Force.Crc32.Intrinsics.Crc32CAlgorithm", Algorithm.IsSupported)
+ {
+ }
+
+ public override uint Calculate(byte[] data)
+ {
+ return Algorithm.Compute(data);
+ }
+ }
+}
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/Crc32Implementations/Klinkby_Checkum_Crc32.cs b/Crc32.NET.Tests/Crc32Implementations/Klinkby_Checkum_Crc32.cs
index d846ec2..ccd2d8c 100644
--- a/Crc32.NET.Tests/Crc32Implementations/Klinkby_Checkum_Crc32.cs
+++ b/Crc32.NET.Tests/Crc32Implementations/Klinkby_Checkum_Crc32.cs
@@ -1,4 +1,4 @@
-#if !NETCORE
+#if NETFRAMEWORK
namespace Force.Crc32.Tests.Crc32Implementations
{
public class Klinkby_Checkum_Crc32 : CrcCalculator
@@ -13,4 +13,4 @@ public override uint Calculate(byte[] data)
}
}
}
-#endif
\ No newline at end of file
+#endif
diff --git a/Crc32.NET.Tests/Crc32Implementations/System_Data_HashFunction_CRC.cs b/Crc32.NET.Tests/Crc32Implementations/System_Data_HashFunction_CRC.cs
index fd1bb48..37f2fc7 100644
--- a/Crc32.NET.Tests/Crc32Implementations/System_Data_HashFunction_CRC.cs
+++ b/Crc32.NET.Tests/Crc32Implementations/System_Data_HashFunction_CRC.cs
@@ -1,4 +1,4 @@
-#if !NETCORE
+#if NETFRAMEWORK
using System;
using System.Data.HashFunction;
@@ -19,4 +19,4 @@ public override uint Calculate(byte[] data)
private readonly CRC _crc;
}
}
-#endif
\ No newline at end of file
+#endif
diff --git a/Crc32.NET.Tests/ImplementationCTest.cs b/Crc32.NET.Tests/ImplementationCTest.cs
index 90735de..15eef0e 100644
--- a/Crc32.NET.Tests/ImplementationCTest.cs
+++ b/Crc32.NET.Tests/ImplementationCTest.cs
@@ -4,16 +4,16 @@
using NUnit.Framework;
-#if !NETCORE
+#if NETFRAMEWORK
using E = Crc32C.Crc32CAlgorithm;
#endif
+
namespace Force.Crc32.Tests
{
[TestFixture]
public class ImplementationCTest
{
-#if !NETCORE
[TestCase("Hello", 3)]
[TestCase("Nazdar", 0)]
[TestCase("Ahoj", 1)]
@@ -23,11 +23,20 @@ public void ResultConsistency(string text, int offset)
{
var bytes = Encoding.ASCII.GetBytes(text);
+#if NETFRAMEWORK
var crc1 = E.Compute(bytes.Skip(offset).ToArray());
var crc2 = Crc32CAlgorithm.Append(0, bytes, offset, bytes.Length - offset);
Assert.That(crc2, Is.EqualTo(crc1));
- }
+#elif NETCOREAPP3_0_OR_GREATER
+ if(Intrinsics.Crc32CAlgorithm.IsSupported)
+ {
+ var crc32C = new Ralph.Crc32C.Crc32C();
+ crc32C.Update(bytes, offset, bytes.Length - offset);
+ var crc3 = Intrinsics.Crc32CAlgorithm.Compute(bytes, offset, bytes.Length - offset);
+ Assert.That(crc3, Is.EqualTo(crc32C.GetIntValue()));
+ }
#endif
+ }
[Test]
public void ResultConsistency2()
@@ -36,7 +45,19 @@ public void ResultConsistency2()
Assert.That(Crc32CAlgorithm.Compute(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }), Is.EqualTo(0xB219DB69));
}
-#if !NETCORE
+#if NETCOREAPP3_0_OR_GREATER
+ [Test]
+ public void ResultConsistencyIntrinsics()
+ {
+ if(Intrinsics.Crc32CAlgorithm.IsSupported)
+ {
+ Assert.That(Intrinsics.Crc32CAlgorithm.Compute(new byte[] { 1 }), Is.EqualTo(0xA016D052));
+ Assert.That(Intrinsics.Crc32CAlgorithm.Compute(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }), Is.EqualTo(0xB219DB69));
+ }
+ }
+#endif
+
+#if NETFRAMEWORK
[Test]
public void ResultConsistencyAsHashAlgorithm()
{
diff --git a/Crc32.NET.Tests/ImplementationTest.cs b/Crc32.NET.Tests/ImplementationTest.cs
index 7bfe6da..e42a400 100644
--- a/Crc32.NET.Tests/ImplementationTest.cs
+++ b/Crc32.NET.Tests/ImplementationTest.cs
@@ -4,7 +4,7 @@
using NUnit.Framework;
-#if !NETCORE
+#if NETFRAMEWORK
using E = Crc32.Crc32Algorithm;
#endif
@@ -15,7 +15,6 @@ namespace Force.Crc32.Tests
public class ImplementationTest
{
-#if !NETCORE
[TestCase("Hello", 3)]
[TestCase("Nazdar", 0)]
[TestCase("Ahoj", 1)]
@@ -25,11 +24,20 @@ public void ResultConsistency(string text, int offset)
{
var bytes = Encoding.ASCII.GetBytes(text);
+#if NETFRAMEWORK
var crc1 = E.Compute(bytes.Skip(offset).ToArray());
var crc2 = Crc32Algorithm.Append(0, bytes, offset, bytes.Length - offset);
Assert.That(crc2, Is.EqualTo(crc1));
- }
#endif
+#if NET5_0_OR_GREATER
+ if(Intrinsics.Crc32Algorithm.IsSupported)
+ {
+ var crc1 = K4os.Hash.Crc.Crc32.DigestOf(bytes, offset, bytes.Length - offset);
+ var crc2 = Intrinsics.Crc32Algorithm.Compute(bytes, offset, bytes.Length - offset);
+ Assert.That(crc2, Is.EqualTo(crc1));
+ }
+#endif
+ }
[Test]
public void ResultConsistency2()
@@ -38,7 +46,20 @@ public void ResultConsistency2()
Assert.That(Crc32Algorithm.Compute(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }), Is.EqualTo(622876539));
}
-#if !NETCORE
+#if NET5_0_OR_GREATER
+ [Test]
+ public void ResultConsistencyIntrinsics()
+ {
+ if(Intrinsics.Crc32Algorithm.IsSupported)
+ {
+ Assert.That(Intrinsics.Crc32Algorithm.Compute(new byte[] { 1 }), Is.EqualTo(2768625435));
+ Assert.That(Intrinsics.Crc32Algorithm.Compute(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }), Is.EqualTo(622876539));
+ }
+ }
+#endif
+
+
+#if NETFRAMEWORK
[Test]
public void ResultConsistencyAsHashAlgorithm()
{
diff --git a/Crc32.NET.Tests/PerformanceTest.cs b/Crc32.NET.Tests/PerformanceTest.cs
index 5b96338..3ab0459 100644
--- a/Crc32.NET.Tests/PerformanceTest.cs
+++ b/Crc32.NET.Tests/PerformanceTest.cs
@@ -8,7 +8,7 @@ namespace Force.Crc32.Tests
[TestFixture]
public class PerformanceTest
{
-#if !NETCORE
+#if NETFRAMEWORK
[Test]
public void ThroughputCHCrc32_By_tanglebones()
{
@@ -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()
{
@@ -70,16 +75,29 @@ public void ThroughputCrc32C_By_Me()
Calculate(new Force_Crc32_Crc32CAlgorithm());
}
-#if COREVERSION && !NETCORE13
+#if NETCOREAPP3_0_OR_GREATER
[Test]
- public void ThroughputCrc32C_By_K4os_Hash_Crc()
+ public void ThroughputCrc32C_By_Me_Intrinsics()
{
- Calculate(new K4os_Hash_Crc());
+ Calculate(new Force_Intrinsics_Crc32_Crc32CAlgorithm());
+ }
+#endif
+
+#if NET5_0_OR_GREATER
+ [Test]
+ public void ThroughputCrc32_By_Me_Intrinsics()
+ {
+ Calculate(new Force_Intrinsics_Crc32_Crc32Algorithm());
}
#endif
private void Calculate(CrcCalculator implementation, int size = 65536)
{
+ if(!implementation.IsSupported)
+ {
+ return;
+ }
+
var data = new byte[size];
var random = new Random();
random.NextBytes(data);
diff --git a/Crc32.NET.Tests/Program.cs b/Crc32.NET.Tests/Program.cs
index 3538919..7f9354b 100644
--- a/Crc32.NET.Tests/Program.cs
+++ b/Crc32.NET.Tests/Program.cs
@@ -5,22 +5,24 @@ public static class Program
public static void Main()
{
var pt = new PerformanceTest();
-#if !NETCORE
- pt.ThroughputCrc32_By_dariogriffo();
+#if NETFRAMEWORK
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();
+#if NETCOREAPP3_0_OR_GREATER
+ pt.ThroughputCrc32C_By_Me_Intrinsics();
+#endif
+#if NET5_0_OR_GREATER
+ pt.ThroughputCrc32_By_Me_Intrinsics();
#endif
-
}
}
}
diff --git a/Crc32.NET/Crc32.NET.Core.csproj b/Crc32.NET/Crc32.NET.Core.csproj
index cec1661..6faefad 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
+ net6.0;net7.0
true
Crc32.NET