11 * Based on a posting to lkml by Austin Zhang <austin.zhang@intel.com>
13 * Using hardware provided CRC32 instruction to accelerate the CRC32 disposal.
14 * CRC32C polynomial:0x1EDC6F41(BE)/0x82F63B78(LE)
15 * CRC32 is a new instruction in Intel SSE4.2, the reference can be found at:
16 * http://www.intel.com/products/processor/manuals/
17 * Intel(R) 64 and IA-32 Architectures Software Developer's Manual
18 * Volume 2A: Instruction Set Reference, A-M
23 #if BITS_PER_LONG == 64
24 #define REX_PRE "0x48, "
31 uint32_t crc32c_intel_le_hw_byte(uint32_t crc, unsigned char const *data,
36 ".byte 0xf2, 0xf, 0x38, 0xf0, 0xf1"
47 * Steps through buffer one byte at at time, calculates reflected
50 uint32_t crc32c_intel(unsigned char const *data, unsigned long length)
52 unsigned int iquotient = length / SCALE_F;
53 unsigned int iremainder = length % SCALE_F;
54 #if BITS_PER_LONG == 64
55 uint64_t *ptmp = (uint64_t *) data;
57 uint32_t *ptmp = (uint32_t *) data;
63 ".byte 0xf2, " REX_PRE "0xf, 0x38, 0xf1, 0xf1;"
71 crc = crc32c_intel_le_hw_byte(crc, (unsigned char *)ptmp,
77 static void sig_ill(int sig)
81 static void crc32c_test(void)
83 unsigned char buf[4] = { 1, 2, 3, 4 };
87 * Check if hw accelerated crc32c is available
89 memset(&act, 0, sizeof(act));
90 act.sa_handler = sig_ill;
91 act.sa_flags = SA_RESETHAND;
92 sigaction(SIGILL, &act, NULL);
94 (void) crc32c_intel(buf, sizeof(buf));
97 int crc32c_intel_works(void)
106 return !WIFSIGNALED(status);
110 #endif /* ARCH_HAVE_SSE */