From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755326Ab1HJWoq (ORCPT ); Wed, 10 Aug 2011 18:44:46 -0400 Received: from cdptpa-bc-oedgelb.mail.rr.com ([75.180.133.32]:48738 "EHLO cdptpa-bc-oedgelb.mail.rr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751651Ab1HJWoo (ORCPT ); Wed, 10 Aug 2011 18:44:44 -0400 Authentication-Results: cdptpa-bc-oedgelb.mail.rr.com smtp.user=rpearson@systemfabricworks.com; auth=pass (PLAIN) X-Authority-Analysis: v=1.1 cv=40Z/dbZBr1wgzPkGSf8y7qdCkiWp+M7NvixVUiz+qMg= c=1 sm=0 a=869cbtyjxWwA:10 a=tulel7SS7DYA:10 a=ozIaqLvjkoIA:10 a=8nJEP1OIZ-IA:10 a=DCwX0kaxZCiV3mmbfDr8nQ==:17 a=YORvzBCaAAAA:8 a=uIhRfg8bZ1sTBjkDpCsA:9 a=Dmq1lhRy0yOysvdakeUA:7 a=wPNLvfGTeEIA:10 a=VV2__AUApEoA:10 a=DCwX0kaxZCiV3mmbfDr8nQ==:117 X-Cloudmark-Score: 0 X-Originating-IP: 67.79.195.91 Message-ID: <4E4309DA.8080203@systemfabricworks.com> Date: Wed, 10 Aug 2011 17:44:42 -0500 From: Bob Pearson User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 MIME-Version: 1.0 To: linux-kernel@vger.kernel.org, joakim.tjernlund@transmode.se, akpm@linux-foundation.org, linux@horizon.com, fzago@systemfabricworks.com Subject: [patch v5 6/8] crc32-add-real-8-bit.diff References: <20110810222018.281901163@systemfabricworks.com> In-Reply-To: <20110810222018.281901163@systemfabricworks.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org crc32.c encodes an algorithm that processes 32 bits at a time with the value BITS = 8 and leaves out the most common 8 bit algorithm for computing the crc. This patch reencodes the 32 bit algorithm with the value 32 and adds back the 'standard' 8 bit algorithm. Signed-off-by: Bob Pearson --- lib/crc32.c | 17 ++++++++++++++--- lib/crc32defs.h | 18 ++++++++++-------- lib/gen_crc32table.c | 15 ++++++++++++--- 3 files changed, 36 insertions(+), 14 deletions(-) Index: infiniband/lib/crc32.c =================================================================== --- infiniband.orig/lib/crc32.c +++ infiniband/lib/crc32.c @@ -25,13 +25,13 @@ #include #include "crc32defs.h" -#if CRC_LE_BITS == 8 +#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 +#if CRC_BE_BITS > 8 # define tobe(x) (__force u32) __constant_cpu_to_be32(x) #else # define tobe(x) (x) @@ -43,7 +43,7 @@ MODULE_AUTHOR("Matt Domsch 8 || CRC_BE_BITS > 8 static inline u32 crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256]) @@ -124,6 +124,12 @@ u32 __pure crc32_le(u32 crc, unsigned ch crc = (crc >> 4) ^ crc32table_le[0][crc & 15]; } # elif CRC_LE_BITS == 8 + /* aka Sarwate algorithm */ + while (len--) { + crc ^= *p++; + crc = (crc >> 8) ^ crc32table_le[0][crc & 255]; + } +# else const u32 (*tab)[] = crc32table_le; crc = (__force u32) __cpu_to_le32(crc); @@ -167,6 +173,11 @@ u32 __pure crc32_be(u32 crc, unsigned ch crc = (crc << 4) ^ crc32table_be[0][crc >> 28]; } # elif CRC_BE_BITS == 8 + while (len--) { + crc ^= *p++ << 24; + crc = (crc << 8) ^ crc32table_be[0][crc >> 24]; + } +# else const u32 (*tab)[] = crc32table_be; crc = (__force u32) __cpu_to_be32(crc); 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< 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 > 32 || 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}" #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 > 32 || 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}" #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[4][256]; +static uint32_t crc32table_be[4][256]; /** * crc32init_le() - allocate and initialize LE table data @@ -24,7 +33,7 @@ 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];