Last active
September 26, 2022 16:54
-
-
Save israellot/c4c29ee56039d53e16e66a3f6b1faffb to your computer and use it in GitHub Desktop.
Expert Checksum
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; | |
while (z < limit) | |
{ | |
sum += BinaryPrimitives.ReverseEndianness(*(uint*)(ptr + z)); | |
sum += BinaryPrimitives.ReverseEndianness(*(uint*)(ptr + z + 4)); | |
sum += BinaryPrimitives.ReverseEndianness(*(uint*)(ptr + z + 8)); | |
sum += BinaryPrimitives.ReverseEndianness(*(uint*)(ptr + z + 12)); | |
sum += BinaryPrimitives.ReverseEndianness(*(uint*)(ptr + z + 16)); | |
sum += BinaryPrimitives.ReverseEndianness(*(uint*)(ptr + z + 20)); | |
sum += BinaryPrimitives.ReverseEndianness(*(uint*)(ptr + z + 24)); | |
sum += BinaryPrimitives.ReverseEndianness(*(uint*)(ptr + z + 28)); | |
z += 32; | |
} | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment