Last active
September 27, 2022 15:54
-
-
Save israellot/fcaec47dce9988c9eb2949c73d4d1994 to your computer and use it in GitHub Desktop.
Senior 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 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; | |
while (z < limit) | |
{ | |
sum0 += (uint)(ptr[z + 0] + ptr[z + 4] + ptr[z + 8] + ptr[z + 12] | |
+ ptr[z + 16] + ptr[z + 20] + ptr[z + 24] + ptr[z + 28]); | |
sum1 += (uint)(ptr[z + 1] + ptr[z + 5] + ptr[z + 9] + ptr[z + 13] | |
+ ptr[z + 17] + ptr[z + 21] + ptr[z + 25] + ptr[z + 29]); | |
sum2 += (uint)(ptr[z + 2] + ptr[z + 6] + ptr[z + 10] + ptr[z + 14] | |
+ ptr[z + 18] + ptr[z + 22] + ptr[z + 26] + ptr[z + 30]); | |
sum3 += (uint)(ptr[z + 3] + ptr[z + 7] + ptr[z + 11] + ptr[z + 15] | |
+ ptr[z + 19] + ptr[z + 23] + ptr[z + 27] + ptr[z + 31]); | |
z += 32; | |
} | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment