All of lore.kernel.org
 help / color / mirror / Atom feed
From: rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org
Subject: [patch v2 01/37] add slice by 8 algorithm to crc32.c
Date: Sun, 24 Jul 2011 14:43:01 -0500	[thread overview]
Message-ID: <20110724201228.154338911@systemfabricworks.com> (raw)
In-Reply-To: 20110724194300.421253331@systemfabricworks.com

[-- Attachment #1: slice-by-8-for-crc32.diff --]
[-- Type: text/plain, Size: 17837 bytes --]

Added support for slice by 8 to existing crc32 algorithm. Also
modified gen_crc32table.c to only produce table entries that are
actually used. The parameters CRC_LE_BITS and CRC_BE_BITS determine
the number of bits in the input array that are processed during each
step. Generally the more bits the faster the algorithm is but the
more table data required.

Using an x86_64 Opteron machine running at 2100MHz the following table
was collected with a pre-warmed cache by computing the crc 1000 times
on a buffer of 4096 bytes.

	BITS	Size	LE Cycles/byte	BE Cycles/byte
	----------------------------------------------
	1	873	41.65		34.60
	2	1097	25.43		29.61
	4	1057	13.29		15.28
	8	2913	7.13		8.19
	32	9684	2.80		2.82
	64	18178	1.53		1.53

	BITS is the value of CRC_LE_BITS or CRC_BE_BITS. The old
	default was 8 which actually selected the 32 bit algorithm. In
	this version the value 8 is used to select the standard
	8 bit algorithm and two new values: 32 and 64 are introduced
	to select the slice by 4 and slice by 8 algorithms respectively.

	Where Size is the size of crc32.o's text segment which includes
	code and table data when both LE and BE versions are set to BITS.

The current version of crc32.c by default uses the slice by 4 algorithm
which requires about 2.8 cycles per byte. The slice by 8 algorithm is
roughly 2X faster and enables packet processing at over 1GB/sec on a typical
2-3GHz system.

Signed-off-by: Bob Pearson <rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>

---
 lib/crc32.c          |  372 +++++++++++++++++++++++++++++++++++----------------
 lib/crc32defs.h      |   16 +-
 lib/gen_crc32table.c |   59 +++++---
 3 files changed, 310 insertions(+), 137 deletions(-)

Index: infiniband/lib/crc32.c
===================================================================
--- infiniband.orig/lib/crc32.c
+++ infiniband/lib/crc32.c
@@ -1,4 +1,8 @@
 /*
+ * July 20, 2011 Bob Pearson <rpearson at systemfabricworks.com>
+ * added slice by 8 algorithm to the existing conventional and
+ * slice by 4 algorithms.
+ *
  * Oct 15, 2000 Matt Domsch <Matt_Domsch-8PEkshWhKlo@public.gmane.org>
  * Nicer crc32 functions/docs submitted by linux-gpGsJRJZ3PDowKkBSvOlow@public.gmane.org  Thanks!
  * Code was from the public domain, copyright abandoned.  Code was
@@ -19,7 +23,6 @@
  * This source code is licensed under the GNU General Public License,
  * Version 2.  See the file COPYING for more details.
  */
-
 #include <linux/crc32.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -28,14 +31,15 @@
 #include <linux/init.h>
 #include <asm/atomic.h>
 #include "crc32defs.h"
-#if CRC_LE_BITS == 8
-# define tole(x) __constant_cpu_to_le32(x)
+
+#if CRC_LE_BITS > 8
+# define tole(x) (__force u32) __constant_cpu_to_le32(x)
 #else
 # define tole(x) (x)
 #endif
 
-#if CRC_BE_BITS == 8
-# define tobe(x) __constant_cpu_to_be32(x)
+#if CRC_BE_BITS > 8
+# define tobe(x) (__force u32) __constant_cpu_to_be32(x)
 #else
 # define tobe(x) (x)
 #endif
@@ -45,54 +49,228 @@ MODULE_AUTHOR("Matt Domsch <Matt_Domsch@
 MODULE_DESCRIPTION("Ethernet CRC32 calculations");
 MODULE_LICENSE("GPL");
 
-#if CRC_LE_BITS == 8 || CRC_BE_BITS == 8
+#if CRC_LE_BITS > 8
+static inline u32 crc32_le_body(u32 crc, u8 const *buf, size_t len)
+{
+	const u8 *p8;
+	const u32 *p32;
+	int init_bytes, end_bytes;
+	size_t words;
+	int i;
+	u32 q;
+	u8 i0, i1, i2, i3;
+
+	crc = (__force u32) __cpu_to_le32(crc);
+
+#if CRC_LE_BITS == 64
+	p8 = buf;
+	p32 = (u32 *)(((uintptr_t)p8 + 7) & ~7);
+
+	init_bytes = (uintptr_t)p32 - (uintptr_t)p8;
+	if (init_bytes > len)
+		init_bytes = len;
+	words = (len - init_bytes) >> 3;
+	end_bytes = (len - init_bytes) & 7;
+#else
+	p8 = buf;
+	p32 = (u32 *)(((uintptr_t)p8 + 3) & ~3);
+
+	init_bytes = (uintptr_t)p32 - (uintptr_t)p8;
+	if (init_bytes > len)
+		init_bytes = len;
+	words = (len - init_bytes) >> 2;
+	end_bytes = (len - init_bytes) & 3;
+#endif
+
+	for (i = 0; i < init_bytes; i++) {
+#ifdef __LITTLE_ENDIAN
+		i0 = *p8++ ^ crc;
+		crc = t0_le[i0] ^ (crc >> 8);
+#else
+		i0 = *p8++ ^ (crc >> 24);
+		crc = t0_le[i0] ^ (crc << 8);
+#endif
+	}
+
+	for (i = 0; i < words; i++) {
+#ifdef __LITTLE_ENDIAN
+#  if CRC_LE_BITS == 64
+		/* slice by 8 algorithm */
+		q = *p32++ ^ crc;
+		i3 = q;
+		i2 = q >> 8;
+		i1 = q >> 16;
+		i0 = q >> 24;
+		crc = t7_le[i3] ^ t6_le[i2] ^ t5_le[i1] ^ t4_le[i0];
+
+		q = *p32++;
+		i3 = q;
+		i2 = q >> 8;
+		i1 = q >> 16;
+		i0 = q >> 24;
+		crc ^= t3_le[i3] ^ t2_le[i2] ^ t1_le[i1] ^ t0_le[i0];
+#  else
+		/* slice by 4 algorithm */
+		q = *p32++ ^ crc;
+		i3 = q;
+		i2 = q >> 8;
+		i1 = q >> 16;
+		i0 = q >> 24;
+		crc = t3_le[i3] ^ t2_le[i2] ^ t1_le[i1] ^ t0_le[i0];
+#  endif
+#else
+#  if CRC_LE_BITS == 64
+		q = *p32++ ^ crc;
+		i3 = q >> 24;
+		i2 = q >> 16;
+		i1 = q >> 8;
+		i0 = q;
+		crc = t7_le[i3] ^ t6_le[i2] ^ t5_le[i1] ^ t4_le[i0];
+
+		q = *p32++;
+		i3 = q >> 24;
+		i2 = q >> 16;
+		i1 = q >> 8;
+		i0 = q;
+		crc ^= t3_le[i3] ^ t2_le[i2] ^ t1_le[i1] ^ t0_le[i0];
+#  else
+		q = *p32++ ^ crc;
+		i3 = q >> 24;
+		i2 = q >> 16;
+		i1 = q >> 8;
+		i0 = q;
+		crc = t3_le[i3] ^ t2_le[i2] ^ t1_le[i1] ^ t0_le[i0];
+#  endif
+#endif
+	}
+
+	p8 = (u8 *)p32;
+
+	for (i = 0; i < end_bytes; i++) {
+#ifdef __LITTLE_ENDIAN
+		i0 = *p8++ ^ crc;
+		crc = t0_le[i0] ^ (crc >> 8);
+#else
+		i0 = *p8++ ^ (crc >> 24);
+		crc = t0_le[i0] ^ (crc << 8);
+#endif
+	}
+
+	return __le32_to_cpu((__force __le32)crc);
+}
+#endif
 
-static inline u32
-crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256])
+#if CRC_BE_BITS > 8
+static inline u32 crc32_be_body(u32 crc, u8 const *buf, size_t len)
 {
-# ifdef __LITTLE_ENDIAN
-#  define DO_CRC(x) crc = tab[0][(crc ^ (x)) & 255] ^ (crc >> 8)
-#  define DO_CRC4 crc = tab[3][(crc) & 255] ^ \
-		tab[2][(crc >> 8) & 255] ^ \
-		tab[1][(crc >> 16) & 255] ^ \
-		tab[0][(crc >> 24) & 255]
-# else
-#  define DO_CRC(x) crc = tab[0][((crc >> 24) ^ (x)) & 255] ^ (crc << 8)
-#  define DO_CRC4 crc = tab[0][(crc) & 255] ^ \
-		tab[1][(crc >> 8) & 255] ^ \
-		tab[2][(crc >> 16) & 255] ^ \
-		tab[3][(crc >> 24) & 255]
-# endif
-	const u32 *b;
-	size_t    rem_len;
+	const u8 *p8;
+	const u32 *p32;
+	int init_bytes, end_bytes;
+	size_t words;
+	int i;
+	u32 q;
+	u8 i0, i1, i2, i3;
+
+	crc = (__force u32) __cpu_to_be32(crc);
+
+#if CRC_LE_BITS == 64
+	p8 = buf;
+	p32 = (u32 *)(((uintptr_t)p8 + 7) & ~7);
+
+	init_bytes = (uintptr_t)p32 - (uintptr_t)p8;
+	if (init_bytes > len)
+		init_bytes = len;
+	words = (len - init_bytes) >> 3;
+	end_bytes = (len - init_bytes) & 7;
+#else
+	p8 = buf;
+	p32 = (u32 *)(((uintptr_t)p8 + 3) & ~3);
+
+	init_bytes = (uintptr_t)p32 - (uintptr_t)p8;
+	if (init_bytes > len)
+		init_bytes = len;
+	words = (len - init_bytes) >> 2;
+	end_bytes = (len - init_bytes) & 3;
+#endif
+
+	for (i = 0; i < init_bytes; i++) {
+#ifdef __LITTLE_ENDIAN
+		i0 = *p8++ ^ crc;
+		crc = t0_be[i0] ^ (crc >> 8);
+#else
+		i0 = *p8++ ^ (crc >> 24);
+		crc = t0_be[i0] ^ (crc << 8);
+#endif
+	}
 
-	/* Align it */
-	if (unlikely((long)buf & 3 && len)) {
-		do {
-			DO_CRC(*buf++);
-		} while ((--len) && ((long)buf)&3);
-	}
-	rem_len = len & 3;
-	/* load data 32 bits wide, xor data 32 bits wide. */
-	len = len >> 2;
-	b = (const u32 *)buf;
-	for (--b; len; --len) {
-		crc ^= *++b; /* use pre increment for speed */
-		DO_CRC4;
-	}
-	len = rem_len;
-	/* And the last few bytes */
-	if (len) {
-		u8 *p = (u8 *)(b + 1) - 1;
-		do {
-			DO_CRC(*++p); /* use pre increment for speed */
-		} while (--len);
+	for (i = 0; i < words; i++) {
+#ifdef __LITTLE_ENDIAN
+#  if CRC_LE_BITS == 64
+		/* slice by 8 algorithm */
+		q = *p32++ ^ crc;
+		i3 = q;
+		i2 = q >> 8;
+		i1 = q >> 16;
+		i0 = q >> 24;
+		crc = t7_be[i3] ^ t6_be[i2] ^ t5_be[i1] ^ t4_be[i0];
+
+		q = *p32++;
+		i3 = q;
+		i2 = q >> 8;
+		i1 = q >> 16;
+		i0 = q >> 24;
+		crc ^= t3_be[i3] ^ t2_be[i2] ^ t1_be[i1] ^ t0_be[i0];
+#  else
+		/* slice by 4 algorithm */
+		q = *p32++ ^ crc;
+		i3 = q;
+		i2 = q >> 8;
+		i1 = q >> 16;
+		i0 = q >> 24;
+		crc = t3_be[i3] ^ t2_be[i2] ^ t1_be[i1] ^ t0_be[i0];
+#  endif
+#else
+#  if CRC_LE_BITS == 64
+		q = *p32++ ^ crc;
+		i3 = q >> 24;
+		i2 = q >> 16;
+		i1 = q >> 8;
+		i0 = q;
+		crc = t7_be[i3] ^ t6_be[i2] ^ t5_be[i1] ^ t4_be[i0];
+
+		q = *p32++;
+		i3 = q >> 24;
+		i2 = q >> 16;
+		i1 = q >> 8;
+		i0 = q;
+		crc ^= t3_be[i3] ^ t2_be[i2] ^ t1_be[i1] ^ t0_be[i0];
+#  else
+		q = *p32++ ^ crc;
+		i3 = q >> 24;
+		i2 = q >> 16;
+		i1 = q >> 8;
+		i0 = q;
+		crc = t3_be[i3] ^ t2_be[i2] ^ t1_be[i1] ^ t0_be[i0];
+#  endif
+#endif
 	}
-	return crc;
-#undef DO_CRC
-#undef DO_CRC4
+
+	p8 = (u8 *)p32;
+
+	for (i = 0; i < end_bytes; i++) {
+#ifdef __LITTLE_ENDIAN
+		i0 = *p8++ ^ crc;
+		crc = t0_be[i0] ^ (crc >> 8);
+#else
+		i0 = *p8++ ^ (crc >> 24);
+		crc = t0_be[i0] ^ (crc << 8);
+#endif
+	}
+
+	return __be32_to_cpu((__force __be32)crc);
 }
 #endif
+
 /**
  * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32
  * @crc: seed value for computation.  ~0 for Ethernet, sometimes 0 for
@@ -100,53 +278,40 @@ crc32_body(u32 crc, unsigned char const 
  * @p: pointer to buffer over which CRC is run
  * @len: length of buffer @p
  */
-u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len);
-
-#if CRC_LE_BITS == 1
-/*
- * In fact, the table-based code will work in this case, but it can be
- * simplified by inlining the table in ?: form.
- */
-
 u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
 {
+#if CRC_LE_BITS == 1
 	int i;
 	while (len--) {
 		crc ^= *p++;
 		for (i = 0; i < 8; i++)
 			crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
 	}
-	return crc;
-}
-#else				/* Table-based approach */
-
-u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
-{
-# if CRC_LE_BITS == 8
-	const u32      (*tab)[] = crc32table_le;
-
-	crc = __cpu_to_le32(crc);
-	crc = crc32_body(crc, p, len, tab);
-	return __le32_to_cpu(crc);
+# elif CRC_LE_BITS == 2
+	while (len--) {
+		crc ^= *p++;
+		crc = (crc >> 2) ^ t0_le[crc & 0x03];
+		crc = (crc >> 2) ^ t0_le[crc & 0x03];
+		crc = (crc >> 2) ^ t0_le[crc & 0x03];
+		crc = (crc >> 2) ^ t0_le[crc & 0x03];
+	}
 # elif CRC_LE_BITS == 4
 	while (len--) {
 		crc ^= *p++;
-		crc = (crc >> 4) ^ crc32table_le[crc & 15];
-		crc = (crc >> 4) ^ crc32table_le[crc & 15];
+		crc = (crc >> 4) ^ t0_le[crc & 0x0f];
+		crc = (crc >> 4) ^ t0_le[crc & 0x0f];
 	}
-	return crc;
-# elif CRC_LE_BITS == 2
+# elif CRC_LE_BITS == 8
 	while (len--) {
 		crc ^= *p++;
-		crc = (crc >> 2) ^ crc32table_le[crc & 3];
-		crc = (crc >> 2) ^ crc32table_le[crc & 3];
-		crc = (crc >> 2) ^ crc32table_le[crc & 3];
-		crc = (crc >> 2) ^ crc32table_le[crc & 3];
+		crc = (crc >> 8) ^ t0_le[crc & 0xff];
 	}
-	return crc;
+# else
+	crc = crc32_le_body(crc, p, len);
 # endif
+	return crc;
 }
-#endif
+EXPORT_SYMBOL(crc32_le);
 
 /**
  * crc32_be() - Calculate bitwise big-endian Ethernet AUTODIN II CRC32
@@ -155,57 +320,40 @@ u32 __pure crc32_le(u32 crc, unsigned ch
  * @p: pointer to buffer over which CRC is run
  * @len: length of buffer @p
  */
-u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len);
-
-#if CRC_BE_BITS == 1
-/*
- * In fact, the table-based code will work in this case, but it can be
- * simplified by inlining the table in ?: form.
- */
-
 u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
 {
+#if CRC_BE_BITS == 1
 	int i;
 	while (len--) {
 		crc ^= *p++ << 24;
 		for (i = 0; i < 8; i++)
-			crc =
-			    (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE :
-					  0);
+			crc = (crc << 1) ^
+			      ((crc & 0x80000000) ? CRCPOLY_BE : 0);
+	}
+# elif CRC_BE_BITS == 2
+	while (len--) {
+		crc ^= *p++ << 24;
+		crc = (crc << 2) ^ t0_be[crc >> 30];
+		crc = (crc << 2) ^ t0_be[crc >> 30];
+		crc = (crc << 2) ^ t0_be[crc >> 30];
+		crc = (crc << 2) ^ t0_be[crc >> 30];
 	}
-	return crc;
-}
-
-#else				/* Table-based approach */
-u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
-{
-# if CRC_BE_BITS == 8
-	const u32      (*tab)[] = crc32table_be;
-
-	crc = __cpu_to_be32(crc);
-	crc = crc32_body(crc, p, len, tab);
-	return __be32_to_cpu(crc);
 # elif CRC_BE_BITS == 4
 	while (len--) {
 		crc ^= *p++ << 24;
-		crc = (crc << 4) ^ crc32table_be[crc >> 28];
-		crc = (crc << 4) ^ crc32table_be[crc >> 28];
+		crc = (crc << 4) ^ t0_be[crc >> 28];
+		crc = (crc << 4) ^ t0_be[crc >> 28];
 	}
-	return crc;
-# elif CRC_BE_BITS == 2
+# elif CRC_BE_BITS == 8
 	while (len--) {
 		crc ^= *p++ << 24;
-		crc = (crc << 2) ^ crc32table_be[crc >> 30];
-		crc = (crc << 2) ^ crc32table_be[crc >> 30];
-		crc = (crc << 2) ^ crc32table_be[crc >> 30];
-		crc = (crc << 2) ^ crc32table_be[crc >> 30];
+		crc = (crc << 8) ^ t0_be[crc >> 24];
 	}
-	return crc;
+# else
+	crc = crc32_be_body(crc, p, len);
 # endif
+	return crc;
 }
-#endif
-
-EXPORT_SYMBOL(crc32_le);
 EXPORT_SYMBOL(crc32_be);
 
 /*
Index: infiniband/lib/crc32defs.h
===================================================================
--- infiniband.orig/lib/crc32defs.h
+++ infiniband/lib/crc32defs.h
@@ -6,27 +6,29 @@
 #define CRCPOLY_LE 0xedb88320
 #define CRCPOLY_BE 0x04c11db7
 
-/* How many bits at a time to use.  Requires a table of 4<<CRC_xx_BITS bytes. */
+/* How many bits at a time to use.  Valid values are 1, 2, 4, 8, 32 and 64. */
 /* For less performance-sensitive, use 4 */
 #ifndef CRC_LE_BITS 
-# define CRC_LE_BITS 8
+# define CRC_LE_BITS 64
 #endif
 #ifndef CRC_BE_BITS
-# define CRC_BE_BITS 8
+# define CRC_BE_BITS 64
 #endif
 
 /*
  * Little-endian CRC computation.  Used with serial bit streams sent
  * lsbit-first.  Be sure to use cpu_to_le32() to append the computed CRC.
  */
-#if CRC_LE_BITS > 8 || CRC_LE_BITS < 1 || CRC_LE_BITS & CRC_LE_BITS-1
-# error CRC_LE_BITS must be a power of 2 between 1 and 8
+#if CRC_LE_BITS > 64 || CRC_LE_BITS < 1 || CRC_LE_BITS == 16 || \
+	CRC_LE_BITS & CRC_LE_BITS-1
+# error "CRC_LE_BITS must be one of {1, 2, 4, 8, 32, 64}"
 #endif
 
 /*
  * Big-endian CRC computation.  Used with serial bit streams sent
  * msbit-first.  Be sure to use cpu_to_be32() to append the computed CRC.
  */
-#if CRC_BE_BITS > 8 || CRC_BE_BITS < 1 || CRC_BE_BITS & CRC_BE_BITS-1
-# error CRC_BE_BITS must be a power of 2 between 1 and 8
+#if CRC_BE_BITS > 64 || CRC_BE_BITS < 1 || CRC_BE_BITS == 16 || \
+	CRC_BE_BITS & CRC_BE_BITS-1
+# error "CRC_BE_BITS must be one of {1, 2, 4, 8, 32, 64}"
 #endif
Index: infiniband/lib/gen_crc32table.c
===================================================================
--- infiniband.orig/lib/gen_crc32table.c
+++ infiniband/lib/gen_crc32table.c
@@ -4,11 +4,20 @@
 
 #define ENTRIES_PER_LINE 4
 
+#if CRC_LE_BITS <= 8
 #define LE_TABLE_SIZE (1 << CRC_LE_BITS)
+#else
+#define LE_TABLE_SIZE 256
+#endif
+
+#if CRC_BE_BITS <= 8
 #define BE_TABLE_SIZE (1 << CRC_BE_BITS)
+#else
+#define BE_TABLE_SIZE 256
+#endif
 
-static uint32_t crc32table_le[4][LE_TABLE_SIZE];
-static uint32_t crc32table_be[4][BE_TABLE_SIZE];
+static uint32_t crc32table_le[8][256];
+static uint32_t crc32table_be[8][256];
 
 /**
  * crc32init_le() - allocate and initialize LE table data
@@ -24,14 +33,14 @@ static void crc32init_le(void)
 
 	crc32table_le[0][0] = 0;
 
-	for (i = 1 << (CRC_LE_BITS - 1); i; i >>= 1) {
+	for (i = LE_TABLE_SIZE >> 1; i; i >>= 1) {
 		crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
 		for (j = 0; j < LE_TABLE_SIZE; j += 2 * i)
 			crc32table_le[0][i + j] = crc ^ crc32table_le[0][j];
 	}
 	for (i = 0; i < LE_TABLE_SIZE; i++) {
 		crc = crc32table_le[0][i];
-		for (j = 1; j < 4; j++) {
+		for (j = 1; j < 8; j++) {
 			crc = crc32table_le[0][crc & 0xff] ^ (crc >> 8);
 			crc32table_le[j][i] = crc;
 		}
@@ -55,44 +64,58 @@ static void crc32init_be(void)
 	}
 	for (i = 0; i < BE_TABLE_SIZE; i++) {
 		crc = crc32table_be[0][i];
-		for (j = 1; j < 4; j++) {
+		for (j = 1; j < 8; j++) {
 			crc = crc32table_be[0][(crc >> 24) & 0xff] ^ (crc << 8);
 			crc32table_be[j][i] = crc;
 		}
 	}
 }
 
-static void output_table(uint32_t table[4][256], int len, char *trans)
+static void output_table(uint32_t table[8][256], int len, char trans)
 {
 	int i, j;
 
-	for (j = 0 ; j < 4; j++) {
-		printf("{");
+	for (j = 0 ; j < 8; j++) {
+		printf("static const u32 t%d_%ce[] = {", j, trans);
 		for (i = 0; i < len - 1; i++) {
-			if (i % ENTRIES_PER_LINE == 0)
+			if ((i % ENTRIES_PER_LINE) == 0)
 				printf("\n");
-			printf("%s(0x%8.8xL), ", trans, table[j][i]);
+			printf("to%ce(0x%8.8xL),", trans, table[j][i]);
+			if ((i % ENTRIES_PER_LINE) != (ENTRIES_PER_LINE - 1))
+				printf(" ");
+		}
+		printf("to%ce(0x%8.8xL)};\n\n", trans, table[j][len - 1]);
+
+		if (trans == 'l') {
+			if ((j+1)*8 >= CRC_LE_BITS)
+				break;
+		} else {
+			if ((j+1)*8 >= CRC_BE_BITS)
+				break;
 		}
-		printf("%s(0x%8.8xL)},\n", trans, table[j][len - 1]);
 	}
 }
 
 int main(int argc, char** argv)
 {
-	printf("/* this file is generated - do not edit */\n\n");
+	printf("/*\n");
+	printf(" * crc32table.h - CRC32 tables\n");
+	printf(" *    this file is generated - do not edit\n");
+	printf(" *	# gen_crc32table > crc32table.h\n");
+	printf(" *    with\n");
+	printf(" *	CRC_LE_BITS = %d\n", CRC_LE_BITS);
+	printf(" *	CRC_BE_BITS = %d\n", CRC_BE_BITS);
+	printf(" */\n");
+	printf("\n");
 
 	if (CRC_LE_BITS > 1) {
 		crc32init_le();
-		printf("static const u32 crc32table_le[4][256] = {");
-		output_table(crc32table_le, LE_TABLE_SIZE, "tole");
-		printf("};\n");
+		output_table(crc32table_le, LE_TABLE_SIZE, 'l');
 	}
 
 	if (CRC_BE_BITS > 1) {
 		crc32init_be();
-		printf("static const u32 crc32table_be[4][256] = {");
-		output_table(crc32table_be, BE_TABLE_SIZE, "tobe");
-		printf("};\n");
+		output_table(crc32table_be, BE_TABLE_SIZE, 'b');
 	}
 
 	return 0;


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2011-07-24 19:43 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-24 19:43 [patch v2 00/37] add rxe (soft RoCE) rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5 [this message]
     [not found]   ` <20110724201228.154338911-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-05 18:39     ` [patch v2 01/37] add slice by 8 algorithm to crc32.c Bart Van Assche
     [not found]       ` <CAO+b5-rFs79znwVcG42Px2i351vhiz9hFyCJV5qg77of8Y6P5Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-05 19:24         ` Bob Pearson
2011-07-24 19:43 ` [patch v2 02/37] add opcodes to ib_pack.h rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201228.204265835-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-15  9:13     ` Bart Van Assche
     [not found]       ` <CAO+b5-pb3p0n5MZYNSJicAdUfZ4PtMNG5vdzDOiZNQwLnB3Wcw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-15 16:15         ` Bob Pearson
2011-08-20 14:47           ` Bart Van Assche
     [not found]             ` <CAO+b5-qV9uxs=V_uHbVZ_3sm1LqkQUB0em=K=nrRxUvFQYWo5A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-22 18:08               ` Bart Van Assche
     [not found]                 ` <CAO+b5-pKPuhsrQV6igqo78y_1+gZ=09GxHoABOVnLxX3myFYZA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-09-01  3:15                   ` Bob Pearson
2011-09-01 17:29                     ` Jason Gunthorpe
2011-09-01 17:51                     ` Bart Van Assche
2011-09-01  3:38         ` Bob Pearson
2011-07-24 19:43 ` [patch v2 03/37] add rxe_hdr.h rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 04/37] add rxe_opcode.h rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 05/37] add rxe_opcode.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 06/37] add rxe_param.h rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201228.415281967-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-20 15:27     ` Bart Van Assche
     [not found]       ` <CAO+b5-q5ohgttDAc45MSKrSUdUVOfR3xHMSY99JtfX_MetSw8Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-09-01  3:50         ` Bob Pearson
2011-07-24 19:43 ` [patch v2 07/37] add rxe.h rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 08/37] add rxe_loc.h rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 09/37] add rxe_mmap.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 10/37] add rxe_queue.h rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 11/37] add rxe_queue.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 12/37] add rxe_verbs.h rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201228.710989476-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-15 12:32     ` Bart Van Assche
     [not found]       ` <CAO+b5-okTDAJ6iOTv_JKXeGttt0MFM+na-FRaNwJMFqHktKHJQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-09-01  4:32         ` Bob Pearson
2011-08-15 12:59     ` Bart Van Assche
     [not found]       ` <CAO+b5-qQBWeyFacCU3tx92jG2zw1=YZJRRX5SbQ57Ztx+zxuew-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-09-01  4:35         ` Bob Pearson
2011-07-24 19:43 ` [patch v2 13/37] add rxe_verbs.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201228.761358826-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-15 13:24     ` Bart Van Assche
     [not found]       ` <CAO+b5-r3UtgnyfhyaodHQTj_xB5d2MQkZ8kRbrpZ1hF_0W1ONw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-09-01  5:20         ` Bob Pearson
2011-09-01 10:33           ` Bart Van Assche
2011-09-01 11:02           ` Bart Van Assche
2011-08-15 14:33     ` Bart Van Assche
     [not found]       ` <CAO+b5-pRQXn08aVOPxeQBzrYXAV+3zD+HZdCCmPTTwBCCzY=ag-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-15 14:45         ` Greg KH
     [not found]           ` <20110815144503.GA12014-l3A5Bk7waGM@public.gmane.org>
2011-08-15 14:58             ` Bart Van Assche
     [not found]               ` <CAO+b5-rsofKNdcjCjBdj1fH7i3DpbHhFajhk0QfNK4DE7nj_SQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-15 15:07                 ` Greg KH
     [not found]                   ` <20110815150726.GA12490-l3A5Bk7waGM@public.gmane.org>
2011-08-15 16:02                     ` Bart Van Assche
     [not found]                       ` <CAO+b5-ocwYv2_A8PfVUh1yp0CFNYasjTJNQ0F6bj-+wT8npavA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-15 16:13                         ` Greg KH
2011-08-15 16:31     ` Bart Van Assche
2011-07-24 19:43 ` [patch v2 14/37] add rxe_pool.h rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 15/37] add rxe_pool.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 16/37] add rxe_task.h rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 17/37] add rxe_task.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 18/37] add rxe_av.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 19/37] add rxe_srq.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 20/37] add rxe_cq.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.112267527-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-20 15:53     ` Bart Van Assche
2011-07-24 19:43 ` [patch v2 21/37] add rxe_qp.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.163423781-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-15 16:13     ` Bart Van Assche
     [not found]       ` <CAO+b5-opA-W4Lp69NzS=9MLEv1V7jWhHPo=bayKhaR-kPgTQTQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-15 16:58         ` Jason Gunthorpe
2011-07-24 19:43 ` [patch v2 22/37] add rxe_mr.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 23/37] add rxe_mcast.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.264963653-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-20 16:13     ` Bart Van Assche
2011-07-24 19:43 ` [patch v2 24/37] add rxe_recv.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 25/37] add rxe_comp.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 26/37] add rxe_req.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.415319539-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-10 18:44     ` Bart Van Assche
2011-07-24 19:43 ` [patch v2 27/37] add rxe_resp.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.464927217-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-20 16:26     ` Bart Van Assche
2011-07-24 19:43 ` [patch v2 28/37] add rxe_arbiter.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.515453123-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-10 18:46     ` Bart Van Assche
     [not found]       ` <CAO+b5-p=++ofCDj4ZB_PS9LiT5bcHsJiYDW8EL_2OrrzqjZmhg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-10 19:12         ` Bob Pearson
2011-07-24 19:43 ` [patch v2 29/37] add rxe_dma.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.565188525-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-20 15:32     ` Bart Van Assche
2011-07-24 19:43 ` [patch v2 30/37] add rxe_icrc.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 31/37] add rxe.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.666252623-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-20 15:12     ` Bart Van Assche
2011-07-24 19:43 ` [patch v2 32/37] add rxe_net.h rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.715886208-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-07  8:51     ` Bart Van Assche
2011-07-24 19:43 ` [patch v2 33/37] add rxe_net.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.765038738-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-05 18:47     ` Bart Van Assche
     [not found]       ` <CAO+b5-pk-X7aGgg12ND17OLcqcLU6qyiV+vf22anh9bYsXUUzw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-05 19:17         ` Bob Pearson
2011-08-06  8:02         ` Bart Van Assche
2011-07-24 19:43 ` [patch v2 34/37] add rxe_net_sysfs.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.815123934-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-07  9:27     ` Bart Van Assche
2011-07-24 19:43 ` [patch v2 35/37] add rxe_sample.c rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.865806162-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-07  8:08     ` Bart Van Assche
2011-07-24 19:43 ` [patch v2 36/37] add Makefile rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
2011-07-24 19:43 ` [patch v2 37/37] add Kconfig rpearson-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5
     [not found]   ` <20110724201229.966262587-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2011-08-05 18:44     ` Bart Van Assche
     [not found]       ` <CAO+b5-oFKiAhTkCntAo5_mMCtdg1vb1eM_mTi-8E-T_atHa_3w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-05 19:19         ` Bob Pearson
2011-08-06 18:44           ` Bart Van Assche
     [not found] ` <20110724194300.421253331-klaOcWyJdxkshyMvu7JE4pqQE7yCjDx5@public.gmane.org>
2012-09-05 10:36   ` [patch v2 00/37] add rxe (soft RoCE) Stefan (metze) Metzmacher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110724201228.154338911@systemfabricworks.com \
    --to=rpearson-klaocwyjdxkshymvu7je4pqqe7ycjdx5@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.