1
// Copyright (C) 2000 - 2002 Hewlett-Packard Company
3
// This program is free software; you can redistribute it and/or modify it
4
// under the term of the GNU Lesser General Public License as published by the
5
// Free Software Foundation; either version 2 of the License, or (at your
6
// option) any later version.
8
// This program is distributed in the hope that it will be useful, but WITHOUT
9
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13
// You should have received a copy of the GNU Lesser General Public License
14
// along with this program; if not, write to the Free Software Foundation,
15
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
// @(#) $Revision: 4.37 $ $Source: /judy/src/JudyCommon/JudyTables.c $
21
#include <unistd.h> // unavailable on win_*.
27
#if (! (JUDY1 || JUDYL))
28
Error: One of -DJUDY1 or -DJUDYL must be specified.
31
#define TERMINATOR 999 // terminator for Alloc tables
33
#define BPW sizeof(Word_t) // define bytes per word
41
// Definitions come from header files Judy1.h and JudyL.h:
43
int AllocSizes[] = ALLOCSIZES;
45
#define ROUNDUP(BYTES,BPW,OFFSETW) \
46
((((BYTES) + (BPW) - 1) / (BPW)) + (OFFSETW))
49
// ****************************************************************************
52
// Note: "const" is required for newer compilers.
54
FUNCTION void GenTable(
55
const char * TableName, // name of table string
56
const char * TableSize, // dimentioned size string
57
int IndexBytes, // bytes per Index
58
int LeafSize, // number elements in object
59
int ValueBytes, // bytes per Value
60
int OffsetWords) // 1 for JAP_LEAF
62
int * PAllocSizes = AllocSizes;
71
int Words [1000] = { 0 };
72
int Offset[1000] = { 0 };
75
MaxWords = ROUNDUP((IndexBytes + ValueBytes) * LeafSize, BPW, OffsetWords);
80
// Walk through all number of Indexes in table:
82
for (Index = 1; /* null */; ++Index)
85
// Calculate byte required for next size:
87
BytesOfIndex = IndexBytes * Index;
88
BytesOfObject = (IndexBytes + ValueBytes) * Index;
90
// Round up and calculate words required for next size:
92
OWord = ROUNDUP(BytesOfObject, BPW, OffsetWords);
93
IWord = ROUNDUP(BytesOfIndex, BPW, OffsetWords);
95
// Root-level leaves of population of 1 and 2 do not have the 1 word offset:
97
#if (LOW_POP && JUDYL)
100
OWord -= OffsetWords;
101
IWord -= OffsetWords;
103
#endif // (LOW_POP && JUDYL)
105
// Save minimum value of offset:
107
Offset[Index] = IWord;
109
// Round up to next available size of words:
111
while (OWord > *PAllocSizes) PAllocSizes++;
113
if (Index == LeafSize)
115
CurWord = Words[Index] = OWord;
118
// end of available sizes ?
120
if (*PAllocSizes == TERMINATOR)
122
fprintf(stderr, "BUG, in %sPopToWords, sizes not big enough for object\n", TableName);
126
// Save words required and last word:
128
if (*PAllocSizes < MaxWords) { CurWord = Words[Index] = *PAllocSizes; }
129
else { CurWord = Words[Index] = MaxWords; }
133
LastWords = TERMINATOR;
135
// Round up to largest size in each group of malloc sizes:
137
for (ii = LeafSize; ii > 0; ii--)
139
if (LastWords > (Words[ii] - ii)) LastWords = Offset[ii];
140
else Offset[ii] = LastWords;
143
// Print the PopToWords[] table:
145
printf("\n//\tobject uses %d words\n", CurWord);
146
printf("//\t%s = %d\n", TableSize, LeafSize);
148
printf("const uint8_t\n");
149
printf("%sPopToWords[%s + 1] =\n", TableName, TableSize);
152
for (ii = 1; ii <= LeafSize; ii++)
155
// 8 columns per line, starting with 1:
157
if ((ii % 8) == 1) printf("\n\t");
159
printf("%2d", Words[ii]);
161
// If not last number place comma:
163
if (ii != LeafSize) printf(", ");
167
// Print the Offset table if needed:
169
if (! ValueBytes) return;
171
printf("const uint8_t\n");
172
printf("%sOffset[%s + 1] =\n", TableName, TableSize);
176
for (ii = 1; ii <= LeafSize; ii++)
178
if ((ii % 8) == 1) printf("\n\t");
180
printf("%2d", Offset[ii]);
182
if (ii != LeafSize) printf(", ");
189
// ****************************************************************************
196
printf("// @(#) From generation tool: $Revision: 4.37 $ $Source: /judy/src/JudyCommon/JudyTables.c $\n");
200
// ================================ Judy1 =================================
203
printf("#include \"Judy1.h\"\n");
204
printf("#include \"config.h\"\n");
206
printf("// Leave the malloc() sizes readable in the binary (via "
208
printf("const char * Judy1MallocSizes = \"Judy1MallocSizes =");
210
for (ii = 0; AllocSizes[ii] != TERMINATOR; ii++)
211
printf(" %d,", AllocSizes[ii]);
214
printf(" Leaf1 = %d\";\n\n", cJ1_LEAF1_MAXPOP1);
216
printf("\";\n\n"); // no Leaf1 in this case.
219
// ================================ 32 bit ================================
222
GenTable("__j1_BranchBJP","cJU_BITSPERSUBEXPB", 8, cJU_BITSPERSUBEXPB,0,0);
224
GenTable("__j1_Leaf1", "cJ1_LEAF1_MAXPOP1", 1, cJ1_LEAF1_MAXPOP1, 0, 0);
225
GenTable("__j1_Leaf2", "cJ1_LEAF2_MAXPOP1", 2, cJ1_LEAF2_MAXPOP1, 0, 0);
226
GenTable("__j1_Leaf3", "cJ1_LEAF3_MAXPOP1", 3, cJ1_LEAF3_MAXPOP1, 0, 0);
227
GenTable("__j1_LeafW", "cJ1_JAPLEAF_MAXPOP1",4, cJ1_JAPLEAF_MAXPOP1, 0, 1);
231
// ================================ 64 bit ================================
233
GenTable("__j1_BranchBJP","cJU_BITSPERSUBEXPB",16, cJU_BITSPERSUBEXPB,0,0);
235
GenTable("__j1_Leaf2", "cJ1_LEAF2_MAXPOP1", 2, cJ1_LEAF2_MAXPOP1, 0, 0);
236
GenTable("__j1_Leaf3", "cJ1_LEAF3_MAXPOP1", 3, cJ1_LEAF3_MAXPOP1, 0, 0);
237
GenTable("__j1_Leaf4", "cJ1_LEAF4_MAXPOP1", 4, cJ1_LEAF4_MAXPOP1, 0, 0);
238
GenTable("__j1_Leaf5", "cJ1_LEAF5_MAXPOP1", 5, cJ1_LEAF5_MAXPOP1, 0, 0);
239
GenTable("__j1_Leaf6", "cJ1_LEAF6_MAXPOP1", 6, cJ1_LEAF6_MAXPOP1, 0, 0);
240
GenTable("__j1_Leaf7", "cJ1_LEAF7_MAXPOP1", 7, cJ1_LEAF7_MAXPOP1, 0, 0);
241
GenTable("__j1_LeafW", "cJ1_JAPLEAF_MAXPOP1",8, cJ1_JAPLEAF_MAXPOP1, 0, 1);
246
// ================================ JudyL =================================
249
printf("#include \"JudyL.h\"\n");
250
printf("#include \"config.h\"\n");
252
printf("// Leave the malloc() sizes readable in the binary (via "
254
printf("const char * JudyLMallocSizes = \"JudyLMallocSizes =");
256
for (ii = 0; AllocSizes[ii] != TERMINATOR; ii++)
257
printf(" %d,", AllocSizes[ii]);
259
printf(" Leaf1 = %ld\";\n\n", (Word_t)cJL_LEAF1_MAXPOP1);
262
// ================================ 32 bit ================================
263
GenTable("__jL_BranchBJP","cJU_BITSPERSUBEXPB", 8, cJU_BITSPERSUBEXPB, 0,0);
265
GenTable("__jL_Leaf1", "cJL_LEAF1_MAXPOP1", 1, cJL_LEAF1_MAXPOP1, BPW,0);
266
GenTable("__jL_Leaf2", "cJL_LEAF2_MAXPOP1", 2, cJL_LEAF2_MAXPOP1, BPW,0);
267
GenTable("__jL_Leaf3", "cJL_LEAF3_MAXPOP1", 3, cJL_LEAF3_MAXPOP1, BPW,0);
268
GenTable("__jL_LeafW", "cJL_JAPLEAF_MAXPOP1",4, cJL_JAPLEAF_MAXPOP1, BPW,1);
269
GenTable("__jL_LeafV", "cJU_BITSPERSUBEXPL", 4, cJU_BITSPERSUBEXPL, 0,0);
273
// ================================ 64 bit ================================
274
GenTable("__jL_BranchBJP","cJU_BITSPERSUBEXPB",16, cJU_BITSPERSUBEXPB, 0,0);
276
GenTable("__jL_Leaf1", "cJL_LEAF1_MAXPOP1", 1, cJL_LEAF1_MAXPOP1, BPW,0);
277
GenTable("__jL_Leaf2", "cJL_LEAF2_MAXPOP1", 2, cJL_LEAF2_MAXPOP1, BPW,0);
278
GenTable("__jL_Leaf3", "cJL_LEAF3_MAXPOP1", 3, cJL_LEAF3_MAXPOP1, BPW,0);
279
GenTable("__jL_Leaf4", "cJL_LEAF4_MAXPOP1", 4, cJL_LEAF4_MAXPOP1, BPW,0);
280
GenTable("__jL_Leaf5", "cJL_LEAF5_MAXPOP1", 5, cJL_LEAF5_MAXPOP1, BPW,0);
281
GenTable("__jL_Leaf6", "cJL_LEAF6_MAXPOP1", 6, cJL_LEAF6_MAXPOP1, BPW,0);
282
GenTable("__jL_Leaf7", "cJL_LEAF7_MAXPOP1", 7, cJL_LEAF7_MAXPOP1, BPW,0);
283
GenTable("__jL_LeafW", "cJL_JAPLEAF_MAXPOP1",8, cJL_JAPLEAF_MAXPOP1, BPW,1);
284
GenTable("__jL_LeafV", "cJU_BITSPERSUBEXPL", 8, cJU_BITSPERSUBEXPL, 0,0);