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