1 /* Generate data for fpioconst.c.
2 Copyright (C) 2012-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
29 FILE *out32 = fopen ("fpioconst-32", "w");
32 FILE *out64 = fopen ("fpioconst-64", "w");
35 FILE *outtable = fopen ("fpioconst-table", "w");
40 for (int i = 0; i <= 14; i++)
43 mpz_ui_pow_ui (p, 10, j - 1);
44 int exp_m = mpz_sizeinbase (p, 2);
45 mpz_ui_pow_ui (p, 10, j);
46 int exp_p = mpz_sizeinbase (p, 2);
47 int size32 = 2 + (exp_p + 31) / 32;
48 int size64 = 1 + (exp_p + 63) / 64;
49 uint32_t data32[size32];
50 uint64_t data64[size64];
51 memset (data32, 0, sizeof data32);
52 memset (data64, 0, sizeof data64);
53 mpz_export (data32 + 2, NULL, -1, 4, 0, 0, p);
54 mpz_export (data64 + 1, NULL, -1, 8, 0, 0, p);
57 fprintf (out32, "#define TENS_P%d_IDX\t0\n", i);
58 fprintf (out64, "#define TENS_P%d_IDX\t0\n", i);
62 fprintf (out32, "#define TENS_P%d_IDX\t"
63 "(TENS_P%d_IDX + TENS_P%d_SIZE)\n",
65 fprintf (out64, "#define TENS_P%d_IDX\t"
66 "(TENS_P%d_IDX + TENS_P%d_SIZE)\n",
69 fprintf (out32, "#define TENS_P%d_SIZE\t%d\n", i, size32);
70 fprintf (out64, "#define TENS_P%d_SIZE\t%d\n", i, size64);
71 for (int k = 0; k < size32; k++)
74 fprintf (out32, " [TENS_P%d_IDX] = ", i);
76 fprintf (out32, "\n ");
79 fprintf (out32, "0x%08"PRIx32",", data32[k]);
81 for (int k = 0; k < size64; k++)
84 fprintf (out64, " [TENS_P%d_IDX] = ", i);
86 fprintf (out64, "\n ");
89 fprintf (out64, "0x%016"PRIx64"ull,", data64[k]);
91 fprintf (out32, "\n\n");
92 fprintf (out64, "\n\n");
93 const char *t = (i >= 10 ? "\t" : "\t\t");
95 fprintf (outtable, " { TENS_P%d_IDX, TENS_P%d_SIZE,%s%d,\t },\n",
98 fprintf (outtable, " { TENS_P%d_IDX, TENS_P%d_SIZE,%s%d,\t%5d },\n",
99 i, i, t, exp_p, exp_m);
101 if (fclose (out32) != 0)
103 if (fclose (out64) != 0)
105 if (fclose (outtable) != 0)