~ubuntu-branches/ubuntu/precise/judy/precise

« back to all changes in this revision

Viewing changes to src/JudyCommon/JudyTables.c

  • Committer: Bazaar Package Importer
  • Author(s): Theodore Y. Ts'o
  • Date: 2004-01-17 00:04:53 UTC
  • Revision ID: james.westby@ubuntu.com-20040117000453-d5sj6uoon2v1g4gf
Tags: upstream-0.0.4
ImportĀ upstreamĀ versionĀ 0.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2000 - 2002 Hewlett-Packard Company
 
2
//
 
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.
 
7
//
 
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
 
11
// for more details.
 
12
//
 
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
 
16
// _________________
 
17
 
 
18
// @(#) $Revision: 4.37 $ $Source: /judy/src/JudyCommon/JudyTables.c $
 
19
 
 
20
#ifndef JU_WIN
 
21
#include <unistd.h>             // unavailable on win_*.
 
22
#endif
 
23
 
 
24
#include <stdlib.h>
 
25
#include <stdio.h>
 
26
 
 
27
#if (! (JUDY1 || JUDYL))
 
28
    Error:  One of -DJUDY1 or -DJUDYL must be specified.
 
29
#endif
 
30
 
 
31
#define TERMINATOR 999          // terminator for Alloc tables
 
32
 
 
33
#define BPW sizeof(Word_t)      // define bytes per word
 
34
 
 
35
#ifdef JUDY1
 
36
#include "Judy1.h"
 
37
#else
 
38
#include "JudyL.h"
 
39
#endif
 
40
 
 
41
// Definitions come from header files Judy1.h and JudyL.h:
 
42
 
 
43
int AllocSizes[] = ALLOCSIZES;
 
44
 
 
45
#define ROUNDUP(BYTES,BPW,OFFSETW) \
 
46
        ((((BYTES) + (BPW) - 1) / (BPW)) + (OFFSETW))
 
47
 
 
48
 
 
49
// ****************************************************************************
 
50
// G E N   T A B L E
 
51
//
 
52
// Note:  "const" is required for newer compilers.
 
53
 
 
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
 
61
{
 
62
    int *        PAllocSizes = AllocSizes;
 
63
    int          OWord;
 
64
    int          CurWord;
 
65
    int          IWord;
 
66
    int          ii;
 
67
    int          BytesOfIndex;
 
68
    int          BytesOfObject;
 
69
    int          Index;
 
70
    int          LastWords;
 
71
    int          Words [1000] = { 0 };
 
72
    int          Offset[1000] = { 0 };
 
73
    int          MaxWords;
 
74
 
 
75
    MaxWords  = ROUNDUP((IndexBytes + ValueBytes) * LeafSize, BPW, OffsetWords);
 
76
    Words[0]  = 0;
 
77
    Offset[0] = 0;
 
78
    CurWord   = TERMINATOR;
 
79
 
 
80
// Walk through all number of Indexes in table:
 
81
 
 
82
    for (Index = 1; /* null */; ++Index)
 
83
    {
 
84
 
 
85
// Calculate byte required for next size:
 
86
 
 
87
        BytesOfIndex  = IndexBytes * Index;
 
88
        BytesOfObject = (IndexBytes + ValueBytes) * Index;
 
89
 
 
90
// Round up and calculate words required for next size:
 
91
 
 
92
        OWord = ROUNDUP(BytesOfObject, BPW, OffsetWords);
 
93
        IWord = ROUNDUP(BytesOfIndex,  BPW, OffsetWords);
 
94
 
 
95
// Root-level leaves of population of 1 and 2 do not have the 1 word offset:
 
96
 
 
97
#if (LOW_POP && JUDYL)
 
98
        if (Index <= 2)
 
99
        {
 
100
            OWord -= OffsetWords;
 
101
            IWord -= OffsetWords;
 
102
        }
 
103
#endif // (LOW_POP && JUDYL)
 
104
 
 
105
// Save minimum value of offset:
 
106
 
 
107
        Offset[Index] = IWord;
 
108
 
 
109
// Round up to next available size of words:
 
110
 
 
111
        while (OWord > *PAllocSizes) PAllocSizes++;
 
112
 
 
113
        if (Index == LeafSize)
 
114
        {
 
115
            CurWord = Words[Index] = OWord;
 
116
            break;
 
117
        }
 
118
//      end of available sizes ?
 
119
 
 
120
        if (*PAllocSizes == TERMINATOR)
 
121
        {
 
122
            fprintf(stderr, "BUG, in %sPopToWords, sizes not big enough for object\n", TableName);
 
123
            exit(1);
 
124
        }
 
125
 
 
126
// Save words required and last word:
 
127
 
 
128
        if (*PAllocSizes < MaxWords) { CurWord = Words[Index] = *PAllocSizes; }
 
129
        else                         { CurWord = Words[Index] = MaxWords; }
 
130
 
 
131
    } // for each index
 
132
 
 
133
    LastWords = TERMINATOR;
 
134
 
 
135
// Round up to largest size in each group of malloc sizes:
 
136
 
 
137
    for (ii = LeafSize; ii > 0; ii--)
 
138
    {
 
139
        if (LastWords > (Words[ii] - ii)) LastWords = Offset[ii];
 
140
        else                              Offset[ii] = LastWords;
 
141
    }
 
142
 
 
143
// Print the PopToWords[] table:
 
144
 
 
145
    printf("\n//\tobject uses %d words\n", CurWord);
 
146
    printf("//\t%s = %d\n", TableSize, LeafSize);
 
147
 
 
148
    printf("const uint8_t\n");
 
149
    printf("%sPopToWords[%s + 1] =\n", TableName, TableSize);
 
150
    printf("{\n\t 0,");
 
151
 
 
152
    for (ii = 1; ii <= LeafSize; ii++)
 
153
    {
 
154
 
 
155
// 8 columns per line, starting with 1:
 
156
 
 
157
        if ((ii % 8) == 1) printf("\n\t");
 
158
 
 
159
        printf("%2d", Words[ii]);
 
160
 
 
161
// If not last number place comma:
 
162
 
 
163
        if (ii != LeafSize) printf(", ");
 
164
    }
 
165
    printf("\n};\n");
 
166
 
 
167
// Print the Offset table if needed:
 
168
 
 
169
    if (! ValueBytes) return;
 
170
 
 
171
    printf("const uint8_t\n");
 
172
    printf("%sOffset[%s + 1] =\n", TableName, TableSize);
 
173
    printf("{\n");
 
174
    printf("\t 0,");
 
175
 
 
176
    for (ii = 1; ii <= LeafSize; ii++)
 
177
    {
 
178
        if ((ii % 8) == 1) printf("\n\t");
 
179
 
 
180
        printf("%2d", Offset[ii]);
 
181
 
 
182
        if (ii != LeafSize) printf(", ");
 
183
    }
 
184
    printf("\n};\n");
 
185
 
 
186
} // GenTable()
 
187
 
 
188
 
 
189
// ****************************************************************************
 
190
// M A I N
 
191
 
 
192
FUNCTION int main()
 
193
{
 
194
    int ii;
 
195
 
 
196
    printf("// @(#) From generation tool: $Revision: 4.37 $ $Source: /judy/src/JudyCommon/JudyTables.c $\n");
 
197
    printf("//\n\n");
 
198
 
 
199
 
 
200
// ================================ Judy1 =================================
 
201
#ifdef JUDY1
 
202
 
 
203
    printf("#include \"Judy1.h\"\n");
 
204
    printf("#include \"config.h\"\n");
 
205
 
 
206
    printf("// Leave the malloc() sizes readable in the binary (via "
 
207
           "strings(1)):\n");
 
208
    printf("const char * Judy1MallocSizes = \"Judy1MallocSizes =");
 
209
 
 
210
    for (ii = 0; AllocSizes[ii] != TERMINATOR; ii++)
 
211
        printf(" %d,", AllocSizes[ii]);
 
212
 
 
213
#ifndef JU_64BIT
 
214
    printf(" Leaf1 = %d\";\n\n", cJ1_LEAF1_MAXPOP1);
 
215
#else
 
216
    printf("\";\n\n");                  // no Leaf1 in this case.
 
217
#endif
 
218
 
 
219
// ================================ 32 bit ================================
 
220
#ifndef JU_64BIT
 
221
 
 
222
    GenTable("__j1_BranchBJP","cJU_BITSPERSUBEXPB", 8, cJU_BITSPERSUBEXPB,0,0);
 
223
 
 
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);
 
228
 
 
229
#endif
 
230
 
 
231
// ================================ 64 bit ================================
 
232
#ifdef JU_64BIT
 
233
    GenTable("__j1_BranchBJP","cJU_BITSPERSUBEXPB",16, cJU_BITSPERSUBEXPB,0,0);
 
234
 
 
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);
 
242
#endif
 
243
#endif // JUDY1
 
244
 
 
245
 
 
246
// ================================ JudyL =================================
 
247
#ifdef JUDYL
 
248
 
 
249
    printf("#include \"JudyL.h\"\n");
 
250
    printf("#include \"config.h\"\n");
 
251
 
 
252
    printf("// Leave the malloc() sizes readable in the binary (via "
 
253
           "strings(1)):\n");
 
254
    printf("const char * JudyLMallocSizes = \"JudyLMallocSizes =");
 
255
 
 
256
    for (ii = 0; AllocSizes[ii] != TERMINATOR; ii++)
 
257
        printf(" %d,", AllocSizes[ii]);
 
258
 
 
259
    printf(" Leaf1 = %ld\";\n\n", (Word_t)cJL_LEAF1_MAXPOP1);
 
260
 
 
261
#ifndef JU_64BIT
 
262
// ================================ 32 bit ================================
 
263
    GenTable("__jL_BranchBJP","cJU_BITSPERSUBEXPB", 8, cJU_BITSPERSUBEXPB, 0,0);
 
264
 
 
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);
 
270
#endif // 32 BIT
 
271
 
 
272
#ifdef JU_64BIT
 
273
// ================================ 64 bit ================================
 
274
    GenTable("__jL_BranchBJP","cJU_BITSPERSUBEXPB",16, cJU_BITSPERSUBEXPB, 0,0);
 
275
 
 
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);
 
285
#endif // 64 BIT
 
286
 
 
287
#endif // JUDYL
 
288
 
 
289
    return(0);
 
290
 
 
291
} // main()