From patchwork Fri Jul 1 13:18:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Pearson X-Patchwork-Id: 938852 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p61LTcRw014702 for ; Fri, 1 Jul 2011 21:51:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757456Ab1GAVON (ORCPT ); Fri, 1 Jul 2011 17:14:13 -0400 Received: from cdptpa-bc-oedgelb.mail.rr.com ([75.180.133.32]:58949 "EHLO cdptpa-bc-oedgelb.mail.rr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757417Ab1GAVON (ORCPT ); Fri, 1 Jul 2011 17:14:13 -0400 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 01 Jul 2011 21:51:08 +0000 (UTC) X-Greylist: delayed 300 seconds by postgrey-1.27 at vger.kernel.org; Fri, 01 Jul 2011 17:13:31 EDT Received: from cdptpa-bc-oedgelb.mail.rr.com ([10.127.134.102]) by cdptpa-bc-qmta01.mail.rr.com with ESMTP id <20110701211004618.BKSY4947@cdptpa-bc-qmta01.mail.rr.com> for ; Fri, 1 Jul 2011 21:10:04 +0000 Authentication-Results: cdptpa-bc-oedgelb.mail.rr.com smtp.user=fzago@systemfabricworks.com; auth=pass (PLAIN) X-Authority-Analysis: v=1.1 cv=QcSFu2tMqX8VyBnwf4xZriMeG3TVj1s8v1Rcea0EwGI= c=1 sm=0 a=hAzdGUM1iB0A:10 a=TsdQ8M87TTYA:10 a=ozIaqLvjkoIA:10 a=DCwX0kaxZCiV3mmbfDr8nQ==:17 a=YORvzBCaAAAA:8 a=bC7xisPkAAAA:8 a=qdjOWkR39E1vlyNJKRUA:9 a=jirmo7QvXj5AkEQ6WGQA:7 a=QLxd5cu_Zb8A:10 a=VV2__AUApEoA:10 a=DCwX0kaxZCiV3mmbfDr8nQ==:117 X-Cloudmark-Score: 0 X-Originating-IP: 67.79.195.91 Received: from [67.79.195.91] ([67.79.195.91:36999] helo=[10.0.2.91]) by cdptpa-bc-oedge01.mail.rr.com (envelope-from ) (ecelerity 2.2.3.46 r()) with ESMTPA id 25/2C-18213-6673E0E4; Fri, 01 Jul 2011 21:08:55 +0000 Message-Id: <20110701132202.438736882@systemfabricworks.com> References: <20110701131821.928693424@systemfabricworks.com> User-Agent: quilt/0.46-1 Date: Fri, 01 Jul 2011 08:18:57 -0500 From: rpearson@systemfabricworks.com To: linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [patch 36/44] gen_sb8tables.c Content-Disposition: inline; filename=patch36 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Program to create slice by 8 tables for the CRC32 calculation. Signed-off-by: Bob Pearson --- drivers/infiniband/hw/rxe/gen_sb8tables.c | 242 ++++++++++++++++++++++++++++++ 1 file changed, 242 insertions(+) Index: infiniband/drivers/infiniband/hw/rxe/gen_sb8tables.c =================================================================== --- /dev/null +++ infiniband/drivers/infiniband/hw/rxe/gen_sb8tables.c @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2009-2011 Mellanox Technologies Ltd. All rights reserved. + * Copyright (c) 2009-2011 System Fabric Works, Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#define _GNU_SOURCE +#include + +static int flip; +static int swap; +static int swip; +static int flop; + +static uint32_t poly = 0xedb88320; /* crc32 */ + +static uint32_t t[256]; + +static int reverse[] = { 7, 6, 5, 4, 3, 2, 1, 0}; + +static uint8_t flip8(uint8_t x) +{ + uint8_t y = 0; + int i; + + for (i = 0; i < 8; i++) { + if (x & (1 << i)) + y |= 1 << reverse[i]; + } + + return y; +} + +static uint32_t flip32(uint32_t x) +{ + uint32_t y; + uint8_t *p = (uint8_t *)&x; + uint8_t *q = (uint8_t *)&y; + int i; + + for (i = 0; i < 4; i++) + q[i] = flip8(p[i]); + + return y; +} + +static void compute(int n) +{ + uint64_t rem; + uint64_t p, m; + int i; + int j; + int k; + uint32_t ply = poly; + + if (flop) + ply = flip32(ply); + if (swip) + ply = bswap_32(ply); + + for (i = 0; i < 256; i++) { + if (flip) + rem = flip8(i); + else + rem = i; + rem <<= 32; + + for (k = 0; k <= n; k++) { + for (j = 7; j >= 0; j--) { + m = 1ULL << (32 + j); + + if (rem & m) { + p = ((1ULL << 32) + ply) << j; + rem ^= p; + } + } + + rem <<= 8; + } + + rem >>= 8; + + if (flip) { + if (swap) + t[i] = bswap_32(flip32(rem)); + else + t[i] = flip32(rem); + } else { + if (swap) + t[i] = bswap_32(rem); + else + t[i] = rem; + } + } +} + +static void print_table(char *name) +{ + int i; + + printf("\nstatic u32 %s[] = {\n", name); + for (i = 0; i < 256; i++) { + printf("0x%08x,", t[i]); + if ((i % 4) == 3) + printf("\n"); + else + printf(" "); + } + printf("};\n"); +} + +static void usage(void) +{ + printf("usage:\n"); +} + +static int arg_process(int argc, char *argv[]) +{ + int c; + char *opt_string = "sfFShp:"; + struct option opt_long[] = { + {"help", 0, 0, 'h'}, + {"poly", 1, 0, 'p'}, + {"flip", 0, 0, 'f'}, + {"swap", 0, 0, 's'}, + {"swip", 0, 0, 'S'}, + {"flop", 0, 0, 'F'}, + }; + + while (1) { + c = getopt_long(argc, argv, opt_string, opt_long, NULL); + + if (c == -1) + break; + + switch (c) { + case 'h': + usage(); + return 1; + + case 'p': + poly = strtoul(optarg, NULL, 0); + break; + + case 'f': + flip = 1; + break; + + case 'F': + flop = 1; + break; + + case 's': + swap = 1; + break; + + case 'S': + swip = 1; + break; + + default: + return 1; + } + } + + if (optind < argc) + return 1; + + return 0; +} + +int main(int argc, char *argv[]) +{ + if (arg_process(argc, argv)) { + usage(); + return 0; + } + + printf("/*\n"); + printf(" * Slice by 8 tables for CRC polynomial = 0x%08x\n", poly); + printf(" * This file is automatically generated\n"); + printf(" */\n"); + + compute(0); + print_table("t32"); + + compute(1); + print_table("t40"); + + compute(2); + print_table("t48"); + + compute(3); + print_table("t56"); + + compute(4); + print_table("t64"); + + compute(5); + print_table("t72"); + + compute(6); + print_table("t80"); + + compute(7); + print_table("t88"); + + return 0; +}