Rate This Document
Findability
Accuracy
Completeness
Readability

Replacing the x86 crc32l 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_u32(uint32_t crc, uint32_t v) { 
    __asm__("crc32l %1, %0" : "+r"(crc) : "rm"(v)); 
    return crc; 
    }
  • Alternative for Kunpeng processors:
    static inline uint32_t SSE4_crc32_u32(uint32_t crc, uint32_t value) { 
    __asm__ __volatile__("crc32cw %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value)); 
    return crc; 
    }

After the modification, add the -march=armv8-a+crc compilation option.