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
public static unsafe uint ChecksumExpertAvx2(ReadOnlySpan<byte> arr) | |
{ | |
ref byte refSpan = ref MemoryMarshal.GetReference<byte>(arr); | |
var z = 0; | |
uint sum = 0; | |
var vectorSum = Avx2.Xor(Vector256<byte>.Zero, Vector256<byte>.Zero).AsUInt32(); | |
var mask = Vector256.Create((byte)3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, (byte)3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12); |
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
public unsafe static uint ChecksumHacker(ReadOnlySpan<byte> arr) | |
{ | |
if (arr.Length == 0) return 0; | |
fixed (byte* ptr = arr) | |
{ | |
uint sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0; | |
uint z = 0; | |
ulong tmp0 = 0, tmp1 = 0; |
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
public static unsafe uint ChecksumExpert(ReadOnlySpan<byte> arr) | |
{ | |
if (arr.Length == 0) return 0; | |
fixed (byte* ptr = arr) | |
{ | |
uint sum = 0; | |
int z = 0; | |
var limit = arr.Length - 32; |
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
public static unsafe uint ChecksumExpertAvx(ReadOnlySpan<byte> arr) | |
{ | |
ref byte refSpan = ref MemoryMarshal.GetReference<byte>(arr); | |
uint z = 0; | |
uint sum = 0; | |
var vectorSum = Avx.Xor(Vector128<byte>.Zero, Vector128<byte>.Zero).AsUInt32(); | |
var mask = Vector128.Create((byte)3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12); |
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
public static unsafe uint Checksum(ReadOnlySpan<byte> arr) | |
{ | |
if (arr.Length == 0) return 0; | |
fixed (byte* ptr = arr) | |
{ | |
uint sum = 0; | |
int z = 0; | |
var limit = arr.Length - 4; |
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
// Compute a 32-bit big-endian checksum on arr | |
public static uint Checksum(ReadOnlySpan<byte> arr) | |
{ | |
if (arr.Length == 0) return 0; | |
uint sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0; | |
for(var i = 0; i<arr.Length; i++) | |
{ | |
switch (i % 4) |
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
public unsafe static uint ChecksumHackerExpanded(ReadOnlySpan<byte> arr) | |
{ | |
if (arr.Length == 0) return 0; | |
fixed (byte* ptr = arr) | |
{ | |
uint sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0; | |
uint z = 0; | |
int rem = arr.Length % 32; |
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
public unsafe static uint ChecksumExpert(ReadOnlySpan<byte> arr) | |
{ | |
if (arr.Length == 0) return 0; | |
fixed (byte* ptr = arr) | |
{ | |
uint sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0; | |
uint z = 0; | |
int rem = arr.Length % 32; |
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
public static unsafe int PointerAccessInt(byte* ptr,int x,int y) | |
{ | |
return ptr[x]& ptr[x+y]; | |
} | |
public static unsafe int PointerAccessUInt(byte* ptr,uint x,uint y) | |
{ | |
return ptr[x]& ptr[x+y]; | |
} |
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
public class CrcBenchmark | |
{ | |
public byte[]? SourceBytes { get; set; } | |
[Params(1_000_000)] | |
public int Length { get; set; } | |
[GlobalSetup] | |
public void Setup() | |
{ |