mirror of
https://github.com/tezc/sc.git
synced 2025-01-14 06:43:04 +08:00
CRC32c function
-
Same code from : https://stackoverflow.com/a/17646775
-
Fixed some alignment issues, replaced asm code with compiler intrinsics
-
Just copy sc_crc32.h and sc_crc32.c to your project.
-
Compile time switch to hardware version if supported (crc32c instruction on x64), fallback to software version if not available
-
See CmakeLists.txt, it just checks "-msse4.2" flag. Stackoverflow answer has runtime dispatch between hardware and software versions if you'd like that.
-
This is Crc32c algorithm, not Crc32
-
A faster version might be possible with 'PCLMULQDQ' instruction as explained here
## Cmake
## Only use hardware version in 64 bit architectures.
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
check_c_compiler_flag(-msse4.2 HAVE_CRC32_HARDWARE)
if (${HAVE_CRC32_HARDWARE})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2 -DSC_HAVE_CRC32_HARDWARE")
endif ()
endif()