chiark / gitweb /
First glimmerings of binary polynomial arithmetic.
[catacomb] / gfx-sqr-mktab.c
1 /* -*-c-*-
2  *
3  * $Id: gfx-sqr-mktab.c,v 1.1 2000/10/08 15:49:37 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 /*----- Revision history --------------------------------------------------* 
31  *
32  * $Log: gfx-sqr-mktab.c,v $
33  * Revision 1.1  2000/10/08 15:49:37  mdw
34  * First glimmerings of binary polynomial arithmetic.
35  *
36  */
37
38 /*----- Header files ------------------------------------------------------*/
39
40 #include <stdio.h>
41 #include <stdlib.h>
42
43 #include <mLib/bits.h>
44
45 /*----- Main code ---------------------------------------------------------*/
46
47 static void mktab(uint16 *t)
48 {
49   unsigned i, j, x;
50
51   for (i = 0; i < 256; i++) {
52     x = 0;
53     for (j = 0; j < 8; j++) {
54       if (i & (1 << j))
55         x |= 1 << (2 * j);
56     }
57     t[i] = x;
58   }
59 }
60
61 int main(void)
62 {
63   uint16 t[256];
64   unsigned i;
65
66   mktab(t);
67 fputs("\
68 /* -*-c-*-\n\
69  *\n\
70  * Bit spacing table for binary polynomial squaring\n\
71  */\n\
72 \n\
73 #ifndef GFX_SQR_TAB_H\n\
74 #define GFX_SQR_TAB_H\n\
75 \n\
76 #define GFX_SQRTAB {                                                    \\\n\
77   ", stdout);
78
79   for (i = 0; i < 256; i++) {
80     printf("0x%04x", t[i]);
81     if (i == 255)
82       puts("    \\\n}\n");
83     else if (i % 8 == 7)
84       fputs(",  \\\n  ", stdout);
85     else
86       fputs(", ", stdout);
87   }
88
89   fputs("#endif\n", stdout);
90
91   if (fclose(stdout)) {
92     fprintf(stderr, "error writing data\n");
93     exit(EXIT_FAILURE);
94   }
95
96   return (0);
97 }
98
99 /*----- That's all, folks -------------------------------------------------*/