1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: mmtables.c,v 1.2 1999-01-26 14:41:42 obachman Exp $ */ |
---|
5 | |
---|
6 | /* |
---|
7 | * ABSTRACT: |
---|
8 | */ |
---|
9 | |
---|
10 | #define _POSIX_SOURCE 1 |
---|
11 | |
---|
12 | #ifdef GENERATE_INDEX_TABLE |
---|
13 | |
---|
14 | #include <stdio.h> |
---|
15 | #include <stdlib.h> |
---|
16 | #include <string.h> |
---|
17 | #include "mod2.h" |
---|
18 | #include "mmheap.h" |
---|
19 | #include "mmemory.h" |
---|
20 | #include "mmprivate.h" |
---|
21 | #include "mmpage.h" |
---|
22 | |
---|
23 | |
---|
24 | #define MAX_INDEX ((MAX_BLOCK_SIZE - 1) >> 2) |
---|
25 | #define HALF_MAX_BLOCK_SIZE (((MAX_BLOCK_SIZE) / 8)*4) |
---|
26 | |
---|
27 | const size_t mm_mcbSizesAlign8 [] = { 8, 16, 24, 32, |
---|
28 | 40, 48, 56, 64, |
---|
29 | 80, 96, 112, 128, |
---|
30 | 160, 192, 224, 256, |
---|
31 | HALF_MAX_BLOCK_SIZE, MAX_BLOCK_SIZE}; |
---|
32 | const size_t mm_mcbSizesAlign4 [] = { 8, 12, 16, 20, |
---|
33 | 24, 28, 32, |
---|
34 | 40, 48, 56, 64, |
---|
35 | 80, 96, 112, 128, |
---|
36 | 160, 192, 224, 256, |
---|
37 | HALF_MAX_BLOCK_SIZE, MAX_BLOCK_SIZE}; |
---|
38 | |
---|
39 | INDEX_ENTRY_T mm_IndiciesAlign8[MAX_INDEX + 1]; |
---|
40 | INDEX_ENTRY_T mm_IndiciesAlign4[MAX_INDEX + 1]; |
---|
41 | |
---|
42 | int mmGetBinaryIndexAlign8( size_t size ) |
---|
43 | { |
---|
44 | int j; |
---|
45 | |
---|
46 | if (size<81) |
---|
47 | { |
---|
48 | if (size<41) |
---|
49 | { |
---|
50 | if (size<25) |
---|
51 | { |
---|
52 | if(size<17) |
---|
53 | { |
---|
54 | if (size<9) j= 0; |
---|
55 | else j= 1; |
---|
56 | } |
---|
57 | else /*17..24*/ |
---|
58 | { |
---|
59 | j= 2; |
---|
60 | } |
---|
61 | } |
---|
62 | else/*25..40*/ |
---|
63 | { |
---|
64 | if(size<33) |
---|
65 | { |
---|
66 | j= 3; |
---|
67 | } |
---|
68 | else /*33..40*/ |
---|
69 | { |
---|
70 | j= 4; |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|
74 | else/*41..80*/ |
---|
75 | { |
---|
76 | if(size<57) |
---|
77 | { |
---|
78 | if (size<49) j= 5; |
---|
79 | else j= 6; |
---|
80 | } |
---|
81 | else /*57..80*/ |
---|
82 | { |
---|
83 | if (size<65) j= 7; |
---|
84 | else j= 8; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | else/*81..1024*/ |
---|
89 | { |
---|
90 | if(size<161) |
---|
91 | { |
---|
92 | if (size<113) |
---|
93 | { |
---|
94 | if (size<97) j= 9; |
---|
95 | else j= 10; |
---|
96 | } |
---|
97 | else /*113..160*/ |
---|
98 | { |
---|
99 | if (size<129) j= 11; |
---|
100 | else j= 12; |
---|
101 | } |
---|
102 | } |
---|
103 | else/*161..1024*/ |
---|
104 | { |
---|
105 | if (size<257) |
---|
106 | { |
---|
107 | if (size<225) |
---|
108 | { |
---|
109 | if (size<193) j= 13; |
---|
110 | else j= 14; |
---|
111 | } |
---|
112 | else j= 15; |
---|
113 | } |
---|
114 | else/*257..1024*/ |
---|
115 | { |
---|
116 | if(size<=MAX_BLOCK_SIZE) |
---|
117 | { |
---|
118 | if(size<=HALF_MAX_BLOCK_SIZE) j= 16; |
---|
119 | else j= 17; |
---|
120 | } |
---|
121 | else |
---|
122 | j= -1; |
---|
123 | } |
---|
124 | } |
---|
125 | } |
---|
126 | return j; |
---|
127 | } |
---|
128 | |
---|
129 | int mmGetBinaryIndex( size_t size ) |
---|
130 | { |
---|
131 | int j; |
---|
132 | if (size<161) |
---|
133 | { |
---|
134 | if (size<41) |
---|
135 | { |
---|
136 | if (size<21) |
---|
137 | { |
---|
138 | if(size<13) |
---|
139 | { |
---|
140 | if (size<9) j= 0; |
---|
141 | else j= 1; |
---|
142 | } |
---|
143 | else /*13..20*/ |
---|
144 | { |
---|
145 | if (size<17) j= 2; |
---|
146 | else j= 3; |
---|
147 | } |
---|
148 | } |
---|
149 | else/*21..40*/ |
---|
150 | { |
---|
151 | if(size<29) |
---|
152 | { |
---|
153 | if (size<25) j= 4; |
---|
154 | else j= 5; |
---|
155 | } |
---|
156 | else /*29..40*/ |
---|
157 | { |
---|
158 | if (size<33) j= 6; |
---|
159 | else j= 7; |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | else/*41..160*/ |
---|
164 | { |
---|
165 | if (size<81) |
---|
166 | { |
---|
167 | if(size<57) |
---|
168 | { |
---|
169 | if (size<49) j= 8; |
---|
170 | else j= 9; |
---|
171 | } |
---|
172 | else /*57..80*/ |
---|
173 | { |
---|
174 | if (size<65) j= 10; |
---|
175 | else j= 11; |
---|
176 | } |
---|
177 | } |
---|
178 | else/*81..160*/ |
---|
179 | { |
---|
180 | if(size<113) |
---|
181 | { |
---|
182 | if (size<97) j= 12; |
---|
183 | else j= 13; |
---|
184 | } |
---|
185 | else /*113..160*/ |
---|
186 | { |
---|
187 | if (size<129) j= 14; |
---|
188 | else j= 15; |
---|
189 | } |
---|
190 | } |
---|
191 | } |
---|
192 | } |
---|
193 | else/*161..1024*/ |
---|
194 | { |
---|
195 | if (size<257) |
---|
196 | { |
---|
197 | if (size<225) |
---|
198 | { |
---|
199 | if (size<193) j= 16; |
---|
200 | else j= 17; |
---|
201 | } |
---|
202 | else j= 18; |
---|
203 | } |
---|
204 | else/*257..1024*/ |
---|
205 | { |
---|
206 | if(size<=MAX_BLOCK_SIZE) |
---|
207 | { |
---|
208 | if(size<=HALF_MAX_BLOCK_SIZE) j= 19; |
---|
209 | else j= 20; |
---|
210 | } |
---|
211 | else |
---|
212 | j= -1; |
---|
213 | } |
---|
214 | } |
---|
215 | return j; |
---|
216 | } |
---|
217 | |
---|
218 | int GetIndex(size_t size, const size_t* size_table) |
---|
219 | { |
---|
220 | int i; |
---|
221 | |
---|
222 | if (size > MAX_BLOCK_SIZE) |
---|
223 | { |
---|
224 | printf("GetIndex: %d size is too large\n", size); |
---|
225 | exit(1); |
---|
226 | } |
---|
227 | |
---|
228 | for (i=0; size_table[i] < size; i++) |
---|
229 | {}; |
---|
230 | |
---|
231 | return i; |
---|
232 | } |
---|
233 | |
---|
234 | |
---|
235 | void mmInitIndexTable(INDEX_ENTRY_T* index_table, const size_t* size_table, |
---|
236 | int (*GetIndexFnc)(size_t size)) |
---|
237 | { |
---|
238 | unsigned int i; |
---|
239 | |
---|
240 | /* Fill in IndexTable */ |
---|
241 | for (i=0; i<=MAX_INDEX; i++) |
---|
242 | index_table[i] = GetIndex((size_t) i*4 + 1, size_table); |
---|
243 | |
---|
244 | /* Check what we did */ |
---|
245 | if (GetIndexFnc != NULL) |
---|
246 | { |
---|
247 | for (i=1; i<=MAX_BLOCK_SIZE + 5; i++) |
---|
248 | { |
---|
249 | unsigned int t_index, b_index; |
---|
250 | t_index = (i <= MAX_BLOCK_SIZE ? index_table[(i-1) >> 2] : -1); |
---|
251 | b_index = GetIndexFnc(i); |
---|
252 | |
---|
253 | if (t_index != b_index) |
---|
254 | { |
---|
255 | fprintf(stderr, "Error in mmInitIndexTable for size %d\n", i); |
---|
256 | GetIndexFnc(i); |
---|
257 | exit(1); |
---|
258 | } |
---|
259 | } |
---|
260 | } |
---|
261 | } |
---|
262 | |
---|
263 | void OutputIndexTable(INDEX_ENTRY_T* index_table) |
---|
264 | { |
---|
265 | int i; |
---|
266 | int l=0; |
---|
267 | printf("const INDEX_ENTRY_T mm_IndexTable[/*%d*/] = {\n",MAX_INDEX+1); |
---|
268 | for (i=0;i<MAX_INDEX; i++,l++) |
---|
269 | { |
---|
270 | printf("%d,", index_table[i]); |
---|
271 | if (l==15) { printf("\n"); l=0; } |
---|
272 | } |
---|
273 | printf("%d};\n", index_table[MAX_INDEX]); |
---|
274 | } |
---|
275 | |
---|
276 | #if 0 |
---|
277 | void OutputIndexTable(INDEX_ENTRY_T* index_table) |
---|
278 | { |
---|
279 | int i = -1; |
---|
280 | int l= -1; |
---|
281 | printf("const INDEX_ENTRY_T mm_IndexTable[] = {\n"); |
---|
282 | do |
---|
283 | { |
---|
284 | i++; |
---|
285 | l++; |
---|
286 | printf("%d,", index_table[i]); |
---|
287 | if (l==15) { printf("\n"); l=0; } |
---|
288 | } |
---|
289 | while (mmGetSize(i) < MAX_BLOCK_SIZE) |
---|
290 | printf("%d};\n", index_table[i]); |
---|
291 | } |
---|
292 | #endif |
---|
293 | |
---|
294 | void OutputTheListTable(const size_t *mm_mcbSizes) |
---|
295 | { |
---|
296 | int i; |
---|
297 | printf("struct sip_memHeap mm_theList[] = {\n"); |
---|
298 | printf("#ifndef MDEBUG\n"); |
---|
299 | for (i=0; mm_mcbSizes[i] < MAX_BLOCK_SIZE; i++) |
---|
300 | printf("{NULL, NULL, %d},\n", mm_mcbSizes[i]); |
---|
301 | printf("{NULL, NULL, %d}\n};\n", mm_mcbSizes[i]); |
---|
302 | printf("#else /* MDEBUG */\n"); |
---|
303 | for (i=0; mm_mcbSizes[i] < MAX_BLOCK_SIZE; i++) |
---|
304 | printf("{NULL, NULL, %d},\n", RealSizeFromSize(mm_mcbSizes[i])); |
---|
305 | printf("{NULL, NULL, %d}\n};\n", RealSizeFromSize(mm_mcbSizes[i])); |
---|
306 | printf("#endif /* ! MDEBUG */\n"); |
---|
307 | } |
---|
308 | |
---|
309 | void OutputSizeTable( const size_t *mm_mcbSizes) |
---|
310 | { |
---|
311 | int i; |
---|
312 | printf("const size_t mm_mcbSizes[] = {"); |
---|
313 | for (i=0; mm_mcbSizes[i] < MAX_BLOCK_SIZE; i++) |
---|
314 | printf("%d, ", mm_mcbSizes[i]); |
---|
315 | printf("%d};\n", mm_mcbSizes[i]); |
---|
316 | } |
---|
317 | |
---|
318 | int main() |
---|
319 | { |
---|
320 | mmInitIndexTable(mm_IndiciesAlign8, mm_mcbSizesAlign8, |
---|
321 | mmGetBinaryIndexAlign8); |
---|
322 | mmInitIndexTable(mm_IndiciesAlign4, mm_mcbSizesAlign4, |
---|
323 | mmGetBinaryIndex); |
---|
324 | |
---|
325 | printf("#ifdef ALIGN_8\n"); |
---|
326 | OutputIndexTable(mm_IndiciesAlign8); |
---|
327 | OutputSizeTable(mm_mcbSizesAlign8); |
---|
328 | OutputTheListTable(mm_mcbSizesAlign8); |
---|
329 | printf("#else\n"); |
---|
330 | OutputIndexTable(mm_IndiciesAlign4); |
---|
331 | OutputSizeTable(mm_mcbSizesAlign4); |
---|
332 | OutputTheListTable(mm_mcbSizesAlign4); |
---|
333 | printf("#endif"); |
---|
334 | return 0; |
---|
335 | } |
---|
336 | |
---|
337 | #else /* ! GENERATE_INDEX_TABLE */ |
---|
338 | #include "mod2.h" |
---|
339 | #include "mmprivate.h" |
---|
340 | #include"mmtables.inc" |
---|
341 | |
---|
342 | #endif /* GENERATE_INDEX_TABLE */ |
---|
343 | |
---|