Skip to content

Instantly share code, notes, and snippets.

@DvdKhl
Created October 24, 2016 20:15
Show Gist options
  • Save DvdKhl/cf1f1730cf00245afab17049a27a7814 to your computer and use it in GitHub Desktop.
Save DvdKhl/cf1f1730cf00245afab17049a27a7814 to your computer and use it in GitHub Desktop.
#include "AVD3NativeLibApi.h"
void* CRC32Create() {
uint8_t *b = (uint8_t*)malloc(4);
memset(b, 0xFF, 4);
return b;
}
void CRC32Transform(void* handle, uint8_t *b, int32_t length) {
uint64_t state64 = *(uint32_t*)handle;
uint64_t* words = (uint64_t*)b;
uint64_t* wordEnd = words + (length >> 3);
while (words != wordEnd) {
state64 = _mm_crc32_u64(state64, *(words++));
}
uint32_t state32 = (uint32_t)state64;
b = (uint8_t*)wordEnd;
uint8_t *bEnd = b + (length & 7);
while (b != bEnd) {
state32 = _mm_crc32_u8(state32, *(b++));
}
*(uint32_t*)handle = state32;
}
void CRC32Final(void* handle, uint8_t *b) {
*((int32_t*)b) = *(int32_t*)handle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment