Replacing the x86 crc32q Assembly Instruction
There are two ways to use the CRC32 instruction: directly using (inline) assembly code or using compiler intrinsics.
crc32 is used to calculate the 32-bit CRC code of a character string. After the character string to be calculated is input, the 32-bit CRC polynomial code is output.
- Code on x86:
static inline uint32_t SSE4_crc32_u64(uint32_t crc, uint64_t v) { uint64_t result = crc; __asm__("crc32q %1, %0" : "+r"(result) : "rm"(v)); return result; } - Alternative for Kunpeng processors:
static inline uint32_t SSE4_crc32_u64(uint32_t crc, uint64_t alue) { __asm__ __volatile__("crc32cx %w[c], %w[c], %x[v]":[c]"+r"(crc):[v]"r"(value)); return crc; }
After the modification, add the -march=armv8-a+crc compilation option.
Parent topic: Source Code Modification Cases