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 the N-byte buffer. If the | |
// buffer is not a multiple of 4 bytes length, compute the sum that would | |
// have occurred if the buffer was padded with zeros to the next multiple | |
// of four bytes. | |
public static uint Checksum(ReadOnlySpan<byte> arr) | |
{ | |
if (arr.Length == 0) return 0; | |
uint sum0 = 0, sum1 = 0, sum2 = 0, sum = 0, N = (uint)arr.Length; | |
int z = 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 class CrcBenchmark | |
{ | |
public byte[]? SourceBytes { get; set; } | |
[Params(1_000_000)] | |
public int Length { get; set; } | |
[GlobalSetup] | |
public void Setup() | |
{ |
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 static uint ChecksumPro(ReadOnlySpan<byte> arr) | |
{ | |
if (arr.Length == 0) return 0; | |
uint sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0; | |
int z = 0; | |
int rem = arr.Length % 16; | |
var limit = arr.Length - rem; |
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 ChecksumSenior(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; | |
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 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
//while (z < limit) | |
// { | |
// sum0 += (uint)(ptr[z + 0] + ptr[z + 4] + ptr[z + 8] + ptr[z + 12] | |
//PRO | |
G_M000_IG06: | |
cmp r11d, ecx | |
jae G_M000_IG17 | |
mov ebx, r11d | |
movzx rbx, byte ptr [rdx+rbx] |
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 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
G_M000_IG06: ;; offset=007BH | |
mov r15d, r11d | |
mov r12, qword ptr [rdx+r15] | |
mov r13, qword ptr [rdx+r15+08H] | |
mov rdi, qword ptr [rdx+r15+10H] | |
mov r15, qword ptr [rdx+r15+18H] | |
mov rcx, 0xFF00FF00FF00FF | |
and rcx, r12 | |
add rsi, rcx | |
mov rcx, 0xFF00FF00FF00FF |
OlderNewer