summaryrefslogtreecommitdiff
path: root/crc
diff options
context:
space:
mode:
authorJens Axboe <jens.axboe@oracle.com>2008-08-04 15:35:26 +0200
committerJens Axboe <jens.axboe@oracle.com>2008-08-04 15:35:26 +0200
commit3845591fadea480177223e28c9d1c03642d34f0e (patch)
treeedbf632fa5f111ba29f43adbb11b72e2c09958c3 /crc
parentc48c0be79173897824d8f439c39374f2588931dc (diff)
downloadfio-3845591fadea480177223e28c9d1c03642d34f0e.tar.gz
fio-3845591fadea480177223e28c9d1c03642d34f0e.tar.bz2
Add intel hardware assisted crc32c support
Not tested, since I don't have the hardware. Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'crc')
-rw-r--r--crc/crc32c-intel.c66
-rw-r--r--crc/crc32c.h1
2 files changed, 67 insertions, 0 deletions
diff --git a/crc/crc32c-intel.c b/crc/crc32c-intel.c
new file mode 100644
index 00000000..c0abe73a
--- /dev/null
+++ b/crc/crc32c-intel.c
@@ -0,0 +1,66 @@
+#include <inttypes.h>
+
+/*
+ * Based on a posting to lkml by Austin Zhang <austin.zhang@intel.com>
+ *
+ * Using hardware provided CRC32 instruction to accelerate the CRC32 disposal.
+ * CRC32C polynomial:0x1EDC6F41(BE)/0x82F63B78(LE)
+ * CRC32 is a new instruction in Intel SSE4.2, the reference can be found at:
+ * http://www.intel.com/products/processor/manuals/
+ * Intel(R) 64 and IA-32 Architectures Software Developer's Manual
+ * Volume 2A: Instruction Set Reference, A-M
+ */
+
+#if BITS_PER_LONG == 64
+#define REX_PRE "0x48, "
+#define SCALE_F 8
+#else
+#define REX_PRE
+#define SCALE_F 4
+#endif
+
+uint32_t crc32c_intel_le_hw_byte(uint32_t crc, unsigned char const *data,
+ unsigned long length)
+{
+ while (length--) {
+ __asm__ __volatile__(
+ ".byte 0xf2, 0xf, 0x38, 0xf0, 0xf1"
+ :"=S"(crc)
+ :"0"(crc), "c"(*data)
+ );
+ data++;
+ }
+
+ return crc;
+}
+
+/*
+ * Steps through buffer one byte at at time, calculates reflected
+ * crc using table.
+ */
+uint32_t crc32c_intel(unsigned char const *data, unsigned long length)
+{
+ unsigned int iquotient = length / SCALE_F;
+ unsigned int iremainder = length % SCALE_F;
+#if BITS_PER_LONG == 64
+ uint64_t *ptmp = (uint64_t *) data;
+#else
+ uint32_t *ptmp = (uint32_t *) data;
+#endif
+ uint32_t crc = ~0;
+
+ while (iquotient--) {
+ __asm__ __volatile__(
+ ".byte 0xf2, " REX_PRE "0xf, 0x38, 0xf1, 0xf1;"
+ :"=S"(crc)
+ :"0"(crc), "c"(*ptmp)
+ );
+ ptmp++;
+ }
+
+ if (iremainder)
+ crc = crc32c_intel_le_hw_byte(crc, (unsigned char *)ptmp,
+ iremainder);
+
+ return crc;
+}
diff --git a/crc/crc32c.h b/crc/crc32c.h
index 1498db91..cf171369 100644
--- a/crc/crc32c.h
+++ b/crc/crc32c.h
@@ -19,5 +19,6 @@
#define CRC32C_H
extern uint32_t crc32c(unsigned char const *, unsigned long);
+extern uint32_t crc32c_intel(unsigned char const *, unsigned long);
#endif