From: Bob Pearson <rpearson@systemfabricworks.com>
To: linux-kernel@vger.kernel.org, joakim.tjernlund@transmode.se,
akpm@linux-foundation.org, linux@horizon.com,
fzago@systemfabricworks.com
Subject: [patch v5 4/8] crc32-misc-cleanup.diff
Date: Wed, 10 Aug 2011 17:44:22 -0500 [thread overview]
Message-ID: <4E4309C6.2070203@systemfabricworks.com> (raw)
In-Reply-To: <20110810222018.281901163@systemfabricworks.com>
Misc cleanup of lib/crc32.c
- removed unnecessary header files. If it passes sparse without
it I took it out.
- straightened out some convoluted ifdef's
- code incorrectly referenced 2D crc32table_le table as
crc32table_l(b)e[x] instead of crc32table_l(b)e[0][x] for
BITS = 2 & 4. This failed sparse.
- a few trivial whitespace changes
Signed-off-by: Bob Pearson <rpearson@systemfabricworks.com>
---
lib/crc32.c | 104 ++++++++++++++++++++----------------------------------------
1 file changed, 36 insertions(+), 68 deletions(-)
Index: infiniband/lib/crc32.c
===================================================================
--- infiniband.orig/lib/crc32.c
+++ infiniband/lib/crc32.c
@@ -21,13 +21,10 @@
*/
#include <linux/crc32.h>
-#include <linux/kernel.h>
#include <linux/module.h>
-#include <linux/compiler.h>
#include <linux/types.h>
-#include <linux/init.h>
-#include <asm/atomic.h>
#include "crc32defs.h"
+
#if CRC_LE_BITS == 8
# define tole(x) __constant_cpu_to_le32(x)
#else
@@ -39,6 +36,7 @@
#else
# define tobe(x) (x)
#endif
+
#include "crc32table.h"
MODULE_AUTHOR("Matt Domsch <Matt_Domsch@dell.com>");
@@ -94,6 +92,7 @@ crc32_body(u32 crc, unsigned char const #undef DO_CRC4
}
#endif
+
/**
* crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32
* @crc: seed value for computation. ~0 for Ethernet, sometimes 0 for
@@ -101,53 +100,39 @@ 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 == 4
+# elif CRC_LE_BITS == 2
while (len--) {
crc ^= *p++;
- crc = (crc >> 4) ^ crc32table_le[crc & 15];
- crc = (crc >> 4) ^ crc32table_le[crc & 15];
+ crc = (crc >> 2) ^ crc32table_le[0][crc & 3];
+ crc = (crc >> 2) ^ crc32table_le[0][crc & 3];
+ crc = (crc >> 2) ^ crc32table_le[0][crc & 3];
+ crc = (crc >> 2) ^ crc32table_le[0][crc & 3];
}
- return crc;
-# elif CRC_LE_BITS == 2
+# elif CRC_LE_BITS == 4
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 >> 4) ^ crc32table_le[0][crc & 15];
+ crc = (crc >> 4) ^ crc32table_le[0][crc & 15];
}
+# elif CRC_LE_BITS == 8
+ const u32 (*tab)[] = crc32table_le;
+
+ crc = __cpu_to_le32(crc);
+ crc = crc32_body(crc, p, len, tab);
+ crc = __le32_to_cpu(crc);
+#endif
return crc;
-# endif
}
-#endif
+EXPORT_SYMBOL(crc32_le);
/**
* crc32_be() - Calculate bitwise big-endian Ethernet AUTODIN II CRC32
@@ -156,16 +141,9 @@ 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;
@@ -174,39 +152,29 @@ u32 __pure crc32_be(u32 crc, unsigned ch
(crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE :
0);
}
- 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
+# elif CRC_BE_BITS == 2
while (len--) {
crc ^= *p++ << 24;
- crc = (crc << 4) ^ crc32table_be[crc >> 28];
- crc = (crc << 4) ^ crc32table_be[crc >> 28];
+ crc = (crc << 2) ^ crc32table_be[0][crc >> 30];
+ crc = (crc << 2) ^ crc32table_be[0][crc >> 30];
+ crc = (crc << 2) ^ crc32table_be[0][crc >> 30];
+ crc = (crc << 2) ^ crc32table_be[0][crc >> 30];
}
- return crc;
-# elif CRC_BE_BITS == 2
+# elif CRC_BE_BITS == 4
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 << 4) ^ crc32table_be[0][crc >> 28];
+ crc = (crc << 4) ^ crc32table_be[0][crc >> 28];
}
- return crc;
+# elif CRC_BE_BITS == 8
+ const u32 (*tab)[] = crc32table_be;
+
+ crc = __cpu_to_be32(crc);
+ crc = crc32_body(crc, p, len, tab);
+ crc = __be32_to_cpu(crc);
# endif
+ return crc;
}
-#endif
-
-EXPORT_SYMBOL(crc32_le);
EXPORT_SYMBOL(crc32_be);
#ifdef CONFIG_CRC32_SELFTEST
next prev parent reply other threads:[~2011-08-10 22:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20110810222018.281901163@systemfabricworks.com>
2011-08-10 22:43 ` [patch v5 1/8] crc32-add-pointer-to-tab.diff Bob Pearson
2011-08-10 22:43 ` [patch v5 2/8] crc32-move-to-documentation.diff Bob Pearson
2011-08-10 22:44 ` [patch v5 3/8] crc32-replace-self-test.diff Bob Pearson
2011-08-10 22:44 ` Bob Pearson [this message]
2011-08-10 22:44 ` [patch v5 5/8] crc32-fix-check-endian-warnings.diff Bob Pearson
2011-08-10 22:44 ` [patch v5 6/8] crc32-add-real-8-bit.diff Bob Pearson
2011-08-10 22:44 ` [patch v5 7/8] crc32-add-slicing-by-8.diff Bob Pearson
2011-08-11 13:46 ` Joakim Tjernlund
2011-08-11 15:34 ` George Spelvin
2011-09-07 10:39 ` Joakim Tjernlund
2011-08-10 22:45 ` [patch v5 8/8] crc32-final-cleanup.diff Bob Pearson
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=4E4309C6.2070203@systemfabricworks.com \
--to=rpearson@systemfabricworks.com \
--cc=akpm@linux-foundation.org \
--cc=fzago@systemfabricworks.com \
--cc=joakim.tjernlund@transmode.se \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@horizon.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox