Uses the crc32q Intel instruction in x64 platforms.

This commit is contained in:
Andrea Mazzoleni 2013-08-20 20:33:22 +02:00
parent 28bdd0f7b7
commit 6a4879caad
2 changed files with 15 additions and 1 deletions

View file

@ -177,7 +177,7 @@ void speed(void)
}
} SPEED_STOP
printf("CRC intel-crc32l %"PRIu64" [MB/s]\n", ds / dt);
printf("CRC intel-crc32 %"PRIu64" [MB/s]\n", ds / dt);
}
#endif
SPEED_START {

14
util.c
View file

@ -1093,13 +1093,27 @@ uint32_t crc32c_gen(uint32_t crc, const unsigned char* ptr, unsigned size)
uint32_t crc32c_x86(uint32_t crc, const unsigned char* ptr, unsigned size)
{
#if defined(__x86_64__)
uint64_t crc64;
#endif
crc ^= CRC_IV;
#if defined(__x86_64__)
crc64 = crc;
while (size >= 8) {
asm volatile ("crc32q %1, %0\n" : "+r" (crc64) : "rm" (*(uint64_t*)ptr));
ptr += 8;
size -= 8;
}
crc = crc64;
#else
while (size >= 4) {
asm volatile ("crc32l %1, %0\n" : "+r" (crc) : "rm" (*(uint32_t*)ptr));
ptr += 4;
size -= 4;
}
#endif
while (size) {
asm volatile ("crc32b %1, %0\n" : "+r" (crc) : "rm" (*ptr));