Program to create slice by 8 tables for the CRC32 calculation.

Signed-off-by: Bob Pearson <[email protected]>

---
 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 <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <byteswap.h>
+
+#define _GNU_SOURCE
+#include <getopt.h>
+
+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;
+}

-- 

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to