Created
April 5, 2020 15:19
-
-
Save Drawaes/114eed38b52c5c8cac963886b8f30ca0 to your computer and use it in GitHub Desktop.
CalcCRC
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
var remainder = outputSpan.Length; | |
ref var pointer = ref MemoryMarshal.GetReference(span); | |
var currentCrc = (uint)0; | |
while(remainder >= 4) | |
{ | |
var uintValue = Unsafe.As<byte, uint>(ref pointer); | |
currentCrc = System.Runtime.Intrinsics.X86.Sse42.Crc32(currentCrc, uintValue); | |
pointer = Unsafe.Add(ref pointer, 4); | |
remainder -= 4; | |
} | |
while(remainder > 0) | |
{ | |
currentCrc = System.Runtime.Intrinsics.X86.Sse42.Crc32(currentCrc, pointer); | |
pointer = Unsafe.Add(ref pointer, 1); | |
remainder -= 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If i'm correct, to compute a CRC32C, currentCrc should be initialized with ~0U and set to ~currentCrc at the end