| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * $Id: gfx-sqr-mktab.c,v 1.2 2004/04/08 01:36:15 mdw Exp $ |
| 4 | * |
| 5 | * Build table for squaring of binary polynomials |
| 6 | * |
| 7 | * (c) 2000 Straylight/Edgeware |
| 8 | */ |
| 9 | |
| 10 | /*----- Licensing notice --------------------------------------------------* |
| 11 | * |
| 12 | * This file is part of Catacomb. |
| 13 | * |
| 14 | * Catacomb is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU Library General Public License as |
| 16 | * published by the Free Software Foundation; either version 2 of the |
| 17 | * License, or (at your option) any later version. |
| 18 | * |
| 19 | * Catacomb is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU Library General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU Library General Public |
| 25 | * License along with Catacomb; if not, write to the Free |
| 26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 27 | * MA 02111-1307, USA. |
| 28 | */ |
| 29 | |
| 30 | /*----- Header files ------------------------------------------------------*/ |
| 31 | |
| 32 | #include <stdio.h> |
| 33 | #include <stdlib.h> |
| 34 | |
| 35 | #include <mLib/bits.h> |
| 36 | |
| 37 | /*----- Main code ---------------------------------------------------------*/ |
| 38 | |
| 39 | static void mktab(uint16 *t) |
| 40 | { |
| 41 | unsigned i, j, x; |
| 42 | |
| 43 | for (i = 0; i < 256; i++) { |
| 44 | x = 0; |
| 45 | for (j = 0; j < 8; j++) { |
| 46 | if (i & (1 << j)) |
| 47 | x |= 1 << (2 * j); |
| 48 | } |
| 49 | t[i] = x; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | int main(void) |
| 54 | { |
| 55 | uint16 t[256]; |
| 56 | unsigned i; |
| 57 | |
| 58 | mktab(t); |
| 59 | fputs("\ |
| 60 | /* -*-c-*-\n\ |
| 61 | *\n\ |
| 62 | * Bit spacing table for binary polynomial squaring\n\ |
| 63 | */\n\ |
| 64 | \n\ |
| 65 | #ifndef GFX_SQR_TAB_H\n\ |
| 66 | #define GFX_SQR_TAB_H\n\ |
| 67 | \n\ |
| 68 | #define GFX_SQRTAB { \\\n\ |
| 69 | ", stdout); |
| 70 | |
| 71 | for (i = 0; i < 256; i++) { |
| 72 | printf("0x%04x", t[i]); |
| 73 | if (i == 255) |
| 74 | puts(" \\\n}\n"); |
| 75 | else if (i % 8 == 7) |
| 76 | fputs(", \\\n ", stdout); |
| 77 | else |
| 78 | fputs(", ", stdout); |
| 79 | } |
| 80 | |
| 81 | fputs("#endif\n", stdout); |
| 82 | |
| 83 | if (fclose(stdout)) { |
| 84 | fprintf(stderr, "error writing data\n"); |
| 85 | exit(EXIT_FAILURE); |
| 86 | } |
| 87 | |
| 88 | return (0); |
| 89 | } |
| 90 | |
| 91 | /*----- That's all, folks -------------------------------------------------*/ |