]>
Commit | Line | Data |
---|---|---|
613f5e1a AD |
1 | /* Bitset statistics. |
2 | Copyright (C) 2002 Free Software Foundation, Inc. | |
3 | Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 2 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program 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 | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program; if not, write to the Free Software | |
d65ec44e | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
613f5e1a AD |
18 | */ |
19 | ||
20 | /* This file is a wrapper bitset implementation for the other bitset | |
21 | implementations. It provides bitset compatibility checking and | |
22 | statistics gathering without having to instrument the bitset | |
23 | implementations. When statistics gathering is enabled, the bitset | |
24 | operations get vectored through here and we then call the appropriate | |
d65ec44e | 25 | routines. |
613f5e1a AD |
26 | */ |
27 | ||
28 | #ifdef HAVE_CONFIG_H | |
29 | #include "config.h" | |
30 | #endif | |
31 | ||
32 | #include "bbitset.h" | |
33 | #include "abitset.h" | |
34 | #include "ebitset.h" | |
35 | #include "lbitset.h" | |
36 | #include "bitset_stats.h" | |
37 | #include <stdlib.h> | |
38 | #include <string.h> | |
39 | #include <stdio.h> | |
40 | ||
c131cbff PE |
41 | #include "gettext.h" |
42 | #define _(Msgid) gettext (Msgid) | |
613f5e1a AD |
43 | |
44 | /* Configuration macros. */ | |
45 | #define BITSET_STATS_FILE "bitset.dat" | |
46 | #define BITSET_LOG_COUNT_BINS 10 | |
47 | #define BITSET_LOG_SIZE_BINS 16 | |
48 | #define BITSET_DENSITY_BINS 20 | |
49 | ||
50 | ||
51 | /* Accessor macros. */ | |
52 | #define BITSET_STATS_ALLOCS_INC(TYPE) \ | |
53 | bitset_stats_info->types[(TYPE)].allocs++ | |
54 | #define BITSET_STATS_FREES_INC(BSET) \ | |
55 | bitset_stats_info->types[BITSET_TYPE_ (BSET)].frees++ | |
56 | #define BITSET_STATS_SETS_INC(BSET) \ | |
57 | bitset_stats_info->types[BITSET_TYPE_ (BSET)].sets++ | |
58 | #define BITSET_STATS_CACHE_SETS_INC(BSET) \ | |
59 | bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_sets++ | |
60 | #define BITSET_STATS_RESETS_INC(BSET) \ | |
61 | bitset_stats_info->types[BITSET_TYPE_ (BSET)].resets++ | |
62 | #define BITSET_STATS_CACHE_RESETS_INC(BSET) \ | |
63 | bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_resets++ | |
64 | #define BITSET_STATS_TESTS_INC(BSET) \ | |
65 | bitset_stats_info->types[BITSET_TYPE_ (BSET)].tests++ | |
66 | #define BITSET_STATS_CACHE_TESTS_INC(BSET) \ | |
67 | bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_tests++ | |
68 | #define BITSET_STATS_LISTS_INC(BSET) \ | |
69 | bitset_stats_info->types[BITSET_TYPE_ (BSET)].lists++ | |
70 | #define BITSET_STATS_LIST_COUNTS_INC(BSET, I) \ | |
71 | bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_counts[(I)]++ | |
72 | #define BITSET_STATS_LIST_SIZES_INC(BSET, I) \ | |
73 | bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_sizes[(I)]++ | |
74 | #define BITSET_STATS_LIST_DENSITY_INC(BSET, I) \ | |
75 | bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_density[(I)]++ | |
76 | ||
77 | ||
613f5e1a AD |
78 | struct bitset_type_info_struct |
79 | { | |
80 | unsigned int allocs; | |
81 | unsigned int frees; | |
82 | unsigned int lists; | |
83 | unsigned int sets; | |
84 | unsigned int cache_sets; | |
85 | unsigned int resets; | |
86 | unsigned int cache_resets; | |
87 | unsigned int tests; | |
88 | unsigned int cache_tests; | |
89 | unsigned int list_counts[BITSET_LOG_COUNT_BINS]; | |
90 | unsigned int list_sizes[BITSET_LOG_SIZE_BINS]; | |
91 | unsigned int list_density[BITSET_DENSITY_BINS]; | |
92 | }; | |
93 | ||
94 | struct bitset_stats_info_struct | |
95 | { | |
96 | unsigned int runs; | |
97 | struct bitset_type_info_struct types[BITSET_TYPE_NUM]; | |
98 | }; | |
99 | ||
100 | ||
101 | struct bitset_stats_info_struct bitset_stats_info_data; | |
102 | struct bitset_stats_info_struct *bitset_stats_info; | |
103 | int bitset_stats_enabled = 0; | |
104 | ||
105 | ||
613f5e1a AD |
106 | /* Print a percentage histogram with message MSG to FILE. */ |
107 | static void | |
d65ec44e PE |
108 | bitset_percent_histogram_print (FILE *file, const char *name, const char *msg, |
109 | unsigned int n_bins, unsigned int *bins) | |
613f5e1a AD |
110 | { |
111 | unsigned int i; | |
112 | unsigned int total; | |
113 | ||
114 | total = 0; | |
115 | for (i = 0; i < n_bins; i++) | |
116 | total += bins[i]; | |
117 | ||
118 | if (!total) | |
119 | return; | |
120 | ||
121 | fprintf (file, "%s %s", name, msg); | |
122 | for (i = 0; i < n_bins; i++) | |
2d382ea8 | 123 | fprintf (file, "%.0f-%.0f%%\t%8u (%5.1f%%)\n", |
613f5e1a AD |
124 | i * 100.0 / n_bins, |
125 | (i + 1) * 100.0 / n_bins, bins[i], | |
126 | (100.0 * bins[i]) / total); | |
127 | } | |
128 | ||
129 | ||
130 | /* Print a log histogram with message MSG to FILE. */ | |
131 | static void | |
d65ec44e PE |
132 | bitset_log_histogram_print (FILE *file, const char *name, const char *msg, |
133 | unsigned int n_bins, unsigned int *bins) | |
613f5e1a AD |
134 | { |
135 | unsigned int i; | |
136 | unsigned int total; | |
137 | unsigned int max_width; | |
613f5e1a AD |
138 | |
139 | total = 0; | |
140 | for (i = 0; i < n_bins; i++) | |
141 | total += bins[i]; | |
142 | ||
143 | if (!total) | |
144 | return; | |
145 | ||
6aa452a6 | 146 | /* Determine number of useful bins. */ |
613f5e1a AD |
147 | for (i = n_bins; i > 3 && ! bins[i - 1]; i--) |
148 | continue; | |
6aa452a6 | 149 | n_bins = i; |
613f5e1a AD |
150 | |
151 | /* 2 * ceil (log10 (2) * (N - 1)) + 1. */ | |
152 | max_width = 2 * (unsigned int) (0.30103 * (n_bins - 1) + 0.9999) + 1; | |
153 | ||
154 | fprintf (file, "%s %s", name, msg); | |
155 | for (i = 0; i < 2; i++) | |
2d382ea8 | 156 | fprintf (file, "%*d\t%8u (%5.1f%%)\n", |
613f5e1a AD |
157 | max_width, i, bins[i], 100.0 * bins[i] / total); |
158 | ||
6aa452a6 | 159 | for (; i < n_bins; i++) |
2d382ea8 | 160 | fprintf (file, "%*lu-%lu\t%8u (%5.1f%%)\n", |
613f5e1a | 161 | max_width - ((unsigned int) (0.30103 * (i) + 0.9999) + 1), |
2d382ea8 PE |
162 | (unsigned long) 1 << (i - 1), |
163 | ((unsigned long) 1 << i) - 1, | |
164 | bins[i], | |
613f5e1a AD |
165 | (100.0 * bins[i]) / total); |
166 | } | |
167 | ||
168 | ||
169 | /* Print bitset statistics to FILE. */ | |
170 | static void | |
d65ec44e PE |
171 | bitset_stats_print_1 (FILE *file, const char *name, |
172 | struct bitset_type_info_struct *stats) | |
613f5e1a AD |
173 | { |
174 | if (!stats) | |
175 | return; | |
d65ec44e | 176 | |
613f5e1a | 177 | fprintf (file, "%s:\n", name); |
2d382ea8 | 178 | fprintf (file, _("%u bitset_allocs, %u freed (%.2f%%).\n"), |
613f5e1a AD |
179 | stats->allocs, stats->frees, |
180 | stats->allocs ? 100.0 * stats->frees / stats->allocs : 0); | |
2d382ea8 | 181 | fprintf (file, _("%u bitset_sets, %u cached (%.2f%%)\n"), |
613f5e1a AD |
182 | stats->sets, stats->cache_sets, |
183 | stats->sets ? 100.0 * stats->cache_sets / stats->sets : 0); | |
2d382ea8 | 184 | fprintf (file, _("%u bitset_resets, %u cached (%.2f%%)\n"), |
613f5e1a AD |
185 | stats->resets, stats->cache_resets, |
186 | stats->resets ? 100.0 * stats->cache_resets / stats->resets : 0); | |
2d382ea8 | 187 | fprintf (file, _("%u bitset_tests, %u cached (%.2f%%)\n"), |
613f5e1a AD |
188 | stats->tests, stats->cache_tests, |
189 | stats->tests ? 100.0 * stats->cache_tests / stats->tests : 0); | |
190 | ||
2d382ea8 | 191 | fprintf (file, _("%u bitset_lists\n"), stats->lists); |
613f5e1a | 192 | |
c131cbff | 193 | bitset_log_histogram_print (file, name, _("count log histogram\n"), |
613f5e1a AD |
194 | BITSET_LOG_COUNT_BINS, stats->list_counts); |
195 | ||
c131cbff | 196 | bitset_log_histogram_print (file, name, _("size log histogram\n"), |
613f5e1a AD |
197 | BITSET_LOG_SIZE_BINS, stats->list_sizes); |
198 | ||
c131cbff | 199 | bitset_percent_histogram_print (file, name, _("density histogram\n"), |
613f5e1a AD |
200 | BITSET_DENSITY_BINS, stats->list_density); |
201 | } | |
202 | ||
203 | ||
204 | /* Print all bitset statistics to FILE. */ | |
205 | static void | |
d65ec44e | 206 | bitset_stats_print (FILE *file, int verbose ATTRIBUTE_UNUSED) |
613f5e1a AD |
207 | { |
208 | int i; | |
613f5e1a AD |
209 | |
210 | if (!bitset_stats_info) | |
211 | return; | |
212 | ||
c131cbff | 213 | fprintf (file, _("Bitset statistics:\n\n")); |
613f5e1a AD |
214 | |
215 | if (bitset_stats_info->runs > 1) | |
2d382ea8 | 216 | fprintf (file, _("Accumulated runs = %u\n"), bitset_stats_info->runs); |
613f5e1a AD |
217 | |
218 | for (i = 0; i < BITSET_TYPE_NUM; i++) | |
d65ec44e | 219 | bitset_stats_print_1 (file, bitset_type_names[i], |
6aa452a6 | 220 | &bitset_stats_info->types[i]); |
613f5e1a AD |
221 | } |
222 | ||
223 | ||
224 | /* Initialise bitset statistics logging. */ | |
225 | void | |
d65ec44e | 226 | bitset_stats_enable (void) |
613f5e1a AD |
227 | { |
228 | if (!bitset_stats_info) | |
229 | bitset_stats_info = &bitset_stats_info_data; | |
230 | bitset_stats_enabled = 1; | |
231 | } | |
232 | ||
233 | ||
234 | void | |
d65ec44e | 235 | bitset_stats_disable (void) |
613f5e1a AD |
236 | { |
237 | bitset_stats_enabled = 0; | |
238 | } | |
239 | ||
240 | ||
241 | /* Read bitset statistics file. */ | |
242 | void | |
d65ec44e | 243 | bitset_stats_read (const char *filename) |
613f5e1a AD |
244 | { |
245 | FILE *file; | |
246 | ||
247 | if (!bitset_stats_info) | |
248 | return; | |
d65ec44e | 249 | |
613f5e1a AD |
250 | if (!filename) |
251 | filename = BITSET_STATS_FILE; | |
252 | ||
253 | file = fopen (filename, "r"); | |
254 | if (file) | |
255 | { | |
256 | if (fread (&bitset_stats_info_data, sizeof (bitset_stats_info_data), | |
257 | 1, file) != 1) | |
258 | { | |
259 | if (ferror (file)) | |
c131cbff | 260 | perror (_("Could not read stats file.")); |
613f5e1a | 261 | else |
c131cbff | 262 | fprintf (stderr, _("Bad stats file size.\n")); |
613f5e1a AD |
263 | } |
264 | fclose (file); | |
265 | } | |
266 | bitset_stats_info_data.runs++; | |
267 | } | |
268 | ||
269 | ||
270 | /* Write bitset statistics file. */ | |
271 | void | |
d65ec44e | 272 | bitset_stats_write (const char *filename) |
613f5e1a AD |
273 | { |
274 | FILE *file; | |
275 | ||
276 | if (!bitset_stats_info) | |
277 | return; | |
278 | ||
279 | if (!filename) | |
280 | filename = BITSET_STATS_FILE; | |
281 | ||
282 | file = fopen (filename, "w"); | |
283 | if (file) | |
284 | { | |
285 | if (fwrite (&bitset_stats_info_data, sizeof (bitset_stats_info_data), | |
286 | 1, file) != 1) | |
c131cbff | 287 | perror (_("Could not write stats file.")); |
613f5e1a AD |
288 | fclose (file); |
289 | } | |
290 | else | |
c131cbff | 291 | perror (_("Could not open stats file for writing.")); |
613f5e1a AD |
292 | } |
293 | ||
294 | ||
295 | /* Dump bitset statistics to FILE. */ | |
296 | void | |
d65ec44e | 297 | bitset_stats_dump (FILE *file) |
613f5e1a AD |
298 | { |
299 | bitset_stats_print (file, 0); | |
300 | } | |
301 | ||
302 | ||
303 | /* Function to be called from debugger to print bitset stats. */ | |
304 | void | |
305 | debug_bitset_stats (void) | |
306 | { | |
307 | bitset_stats_print (stderr, 1); | |
308 | } | |
309 | ||
310 | ||
311 | static void | |
d65ec44e | 312 | bitset_stats_set (bitset dst, bitset_bindex bitno) |
613f5e1a AD |
313 | { |
314 | bitset bset = dst->s.bset; | |
c131cbff PE |
315 | bitset_windex wordno = bitno / BITSET_WORD_BITS; |
316 | bitset_windex offset = wordno - bset->b.cindex; | |
d65ec44e | 317 | |
613f5e1a AD |
318 | BITSET_STATS_SETS_INC (bset); |
319 | ||
320 | if (offset < bset->b.csize) | |
321 | { | |
c131cbff | 322 | bset->b.cdata[offset] |= (bitset_word) 1 << (bitno % BITSET_WORD_BITS); |
613f5e1a AD |
323 | BITSET_STATS_CACHE_SETS_INC (bset); |
324 | } | |
325 | else | |
326 | BITSET_SET_ (bset, bitno); | |
327 | } | |
328 | ||
329 | ||
330 | static void | |
d65ec44e | 331 | bitset_stats_reset (bitset dst, bitset_bindex bitno) |
613f5e1a AD |
332 | { |
333 | bitset bset = dst->s.bset; | |
c131cbff PE |
334 | bitset_windex wordno = bitno / BITSET_WORD_BITS; |
335 | bitset_windex offset = wordno - bset->b.cindex; | |
d65ec44e | 336 | |
613f5e1a AD |
337 | BITSET_STATS_RESETS_INC (bset); |
338 | ||
339 | if (offset < bset->b.csize) | |
340 | { | |
c131cbff PE |
341 | bset->b.cdata[offset] &= |
342 | ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS)); | |
613f5e1a AD |
343 | BITSET_STATS_CACHE_RESETS_INC (bset); |
344 | } | |
345 | else | |
346 | BITSET_RESET_ (bset, bitno); | |
347 | } | |
348 | ||
349 | ||
6aa452a6 | 350 | static int |
d65ec44e | 351 | bitset_stats_toggle (bitset src, bitset_bindex bitno) |
6aa452a6 AD |
352 | { |
353 | return BITSET_TOGGLE_ (src->s.bset, bitno); | |
354 | } | |
355 | ||
356 | ||
613f5e1a | 357 | static int |
d65ec44e | 358 | bitset_stats_test (bitset src, bitset_bindex bitno) |
613f5e1a AD |
359 | { |
360 | bitset bset = src->s.bset; | |
c131cbff PE |
361 | bitset_windex wordno = bitno / BITSET_WORD_BITS; |
362 | bitset_windex offset = wordno - bset->b.cindex; | |
613f5e1a AD |
363 | |
364 | BITSET_STATS_TESTS_INC (bset); | |
d65ec44e | 365 | |
613f5e1a AD |
366 | if (offset < bset->b.csize) |
367 | { | |
368 | BITSET_STATS_CACHE_TESTS_INC (bset); | |
369 | return (bset->b.cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1; | |
370 | } | |
371 | else | |
372 | return BITSET_TEST_ (bset, bitno); | |
373 | } | |
374 | ||
375 | ||
2d382ea8 | 376 | static bitset_bindex |
d65ec44e | 377 | bitset_stats_size (bitset src) |
613f5e1a AD |
378 | { |
379 | return BITSET_SIZE_ (src->s.bset); | |
380 | } | |
381 | ||
382 | ||
2d382ea8 | 383 | static bitset_bindex |
d65ec44e | 384 | bitset_stats_count (bitset src) |
6aa452a6 AD |
385 | { |
386 | return BITSET_COUNT_ (src->s.bset); | |
387 | } | |
388 | ||
389 | ||
390 | static int | |
d65ec44e | 391 | bitset_stats_empty_p (bitset dst) |
6aa452a6 AD |
392 | { |
393 | return BITSET_EMPTY_P_ (dst->s.bset); | |
394 | } | |
395 | ||
396 | ||
397 | static void | |
d65ec44e | 398 | bitset_stats_ones (bitset dst) |
6aa452a6 AD |
399 | { |
400 | BITSET_ONES_ (dst->s.bset); | |
401 | } | |
402 | ||
403 | ||
404 | static void | |
d65ec44e | 405 | bitset_stats_zero (bitset dst) |
6aa452a6 AD |
406 | { |
407 | BITSET_ZERO_ (dst->s.bset); | |
408 | } | |
409 | ||
410 | ||
411 | static void | |
d65ec44e | 412 | bitset_stats_copy (bitset dst, bitset src) |
6aa452a6 AD |
413 | { |
414 | BITSET_CHECK2_ (dst, src); | |
415 | BITSET_COPY_ (dst->s.bset, src->s.bset); | |
416 | } | |
417 | ||
418 | ||
419 | static int | |
d65ec44e | 420 | bitset_stats_disjoint_p (bitset dst, bitset src) |
613f5e1a | 421 | { |
6aa452a6 AD |
422 | BITSET_CHECK2_ (dst, src); |
423 | return BITSET_DISJOINT_P_ (dst->s.bset, src->s.bset); | |
613f5e1a AD |
424 | } |
425 | ||
426 | ||
427 | static int | |
d65ec44e | 428 | bitset_stats_equal_p (bitset dst, bitset src) |
613f5e1a AD |
429 | { |
430 | BITSET_CHECK2_ (dst, src); | |
6aa452a6 AD |
431 | return BITSET_EQUAL_P_ (dst->s.bset, src->s.bset); |
432 | } | |
433 | ||
434 | ||
435 | static void | |
d65ec44e | 436 | bitset_stats_not (bitset dst, bitset src) |
6aa452a6 AD |
437 | { |
438 | BITSET_CHECK2_ (dst, src); | |
439 | BITSET_NOT_ (dst->s.bset, src->s.bset); | |
440 | } | |
441 | ||
442 | ||
443 | static int | |
d65ec44e | 444 | bitset_stats_subset_p (bitset dst, bitset src) |
6aa452a6 AD |
445 | { |
446 | BITSET_CHECK2_ (dst, src); | |
447 | return BITSET_SUBSET_P_ (dst->s.bset, src->s.bset); | |
448 | } | |
449 | ||
450 | ||
451 | static void | |
d65ec44e | 452 | bitset_stats_and (bitset dst, bitset src1, bitset src2) |
6aa452a6 AD |
453 | { |
454 | BITSET_CHECK3_ (dst, src1, src2); | |
455 | BITSET_AND_ (dst->s.bset, src1->s.bset, src2->s.bset); | |
456 | } | |
457 | ||
458 | ||
459 | static int | |
d65ec44e | 460 | bitset_stats_and_cmp (bitset dst, bitset src1, bitset src2) |
6aa452a6 AD |
461 | { |
462 | BITSET_CHECK3_ (dst, src1, src2); | |
463 | return BITSET_AND_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset); | |
464 | } | |
465 | ||
466 | ||
467 | static void | |
d65ec44e | 468 | bitset_stats_andn (bitset dst, bitset src1, bitset src2) |
6aa452a6 AD |
469 | { |
470 | BITSET_CHECK3_ (dst, src1, src2); | |
471 | BITSET_ANDN_ (dst->s.bset, src1->s.bset, src2->s.bset); | |
472 | } | |
473 | ||
474 | ||
475 | static int | |
d65ec44e | 476 | bitset_stats_andn_cmp (bitset dst, bitset src1, bitset src2) |
6aa452a6 AD |
477 | { |
478 | BITSET_CHECK3_ (dst, src1, src2); | |
479 | return BITSET_ANDN_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset); | |
480 | } | |
481 | ||
482 | ||
483 | static void | |
d65ec44e | 484 | bitset_stats_or (bitset dst, bitset src1, bitset src2) |
6aa452a6 AD |
485 | { |
486 | BITSET_CHECK3_ (dst, src1, src2); | |
487 | BITSET_OR_ (dst->s.bset, src1->s.bset, src2->s.bset); | |
488 | } | |
489 | ||
490 | ||
491 | static int | |
d65ec44e | 492 | bitset_stats_or_cmp (bitset dst, bitset src1, bitset src2) |
6aa452a6 AD |
493 | { |
494 | BITSET_CHECK3_ (dst, src1, src2); | |
495 | return BITSET_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset); | |
496 | } | |
497 | ||
498 | ||
499 | static void | |
d65ec44e | 500 | bitset_stats_xor (bitset dst, bitset src1, bitset src2) |
6aa452a6 AD |
501 | { |
502 | BITSET_CHECK3_ (dst, src1, src2); | |
503 | BITSET_XOR_ (dst->s.bset, src1->s.bset, src2->s.bset); | |
613f5e1a AD |
504 | } |
505 | ||
506 | ||
507 | static int | |
d65ec44e | 508 | bitset_stats_xor_cmp (bitset dst, bitset src1, bitset src2) |
613f5e1a AD |
509 | { |
510 | BITSET_CHECK3_ (dst, src1, src2); | |
6aa452a6 AD |
511 | return BITSET_XOR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset); |
512 | } | |
513 | ||
514 | ||
515 | static void | |
d65ec44e | 516 | bitset_stats_and_or (bitset dst, bitset src1, bitset src2, bitset src3) |
6aa452a6 AD |
517 | { |
518 | BITSET_CHECK4_ (dst, src1, src2, src3); | |
519 | ||
520 | BITSET_AND_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset); | |
613f5e1a AD |
521 | } |
522 | ||
523 | ||
524 | static int | |
d65ec44e | 525 | bitset_stats_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) |
613f5e1a AD |
526 | { |
527 | BITSET_CHECK4_ (dst, src1, src2, src3); | |
528 | ||
6aa452a6 AD |
529 | return BITSET_AND_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset); |
530 | } | |
531 | ||
532 | ||
533 | static void | |
d65ec44e | 534 | bitset_stats_andn_or (bitset dst, bitset src1, bitset src2, bitset src3) |
6aa452a6 AD |
535 | { |
536 | BITSET_CHECK4_ (dst, src1, src2, src3); | |
537 | ||
538 | BITSET_ANDN_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset); | |
539 | } | |
540 | ||
541 | ||
542 | static int | |
d65ec44e | 543 | bitset_stats_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) |
6aa452a6 AD |
544 | { |
545 | BITSET_CHECK4_ (dst, src1, src2, src3); | |
546 | ||
547 | return BITSET_ANDN_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset); | |
548 | } | |
549 | ||
550 | ||
551 | static void | |
d65ec44e | 552 | bitset_stats_or_and (bitset dst, bitset src1, bitset src2, bitset src3) |
6aa452a6 AD |
553 | { |
554 | BITSET_CHECK4_ (dst, src1, src2, src3); | |
555 | ||
556 | BITSET_OR_AND_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset); | |
557 | } | |
558 | ||
559 | ||
560 | static int | |
d65ec44e | 561 | bitset_stats_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) |
6aa452a6 AD |
562 | { |
563 | BITSET_CHECK4_ (dst, src1, src2, src3); | |
613f5e1a | 564 | |
6aa452a6 | 565 | return BITSET_OR_AND_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset); |
613f5e1a AD |
566 | } |
567 | ||
568 | ||
2d382ea8 | 569 | static bitset_bindex |
d65ec44e PE |
570 | bitset_stats_list (bitset bset, bitset_bindex *list, |
571 | bitset_bindex num, bitset_bindex *next) | |
613f5e1a AD |
572 | { |
573 | bitset_bindex count; | |
574 | bitset_bindex tmp; | |
575 | bitset_bindex size; | |
576 | bitset_bindex i; | |
577 | enum bitset_type type; | |
578 | ||
579 | count = BITSET_LIST_ (bset->s.bset, list, num, next); | |
d65ec44e | 580 | |
613f5e1a AD |
581 | type = BITSET_TYPE_ (bset->s.bset); |
582 | BITSET_STATS_LISTS_INC (bset->s.bset); | |
d65ec44e | 583 | |
613f5e1a AD |
584 | /* Log histogram of number of set bits. */ |
585 | for (i = 0, tmp = count; tmp; tmp >>= 1, i++) | |
586 | continue; | |
587 | if (i >= BITSET_LOG_COUNT_BINS) | |
588 | i = BITSET_LOG_COUNT_BINS - 1; | |
589 | BITSET_STATS_LIST_COUNTS_INC (bset->s.bset, i); | |
d65ec44e | 590 | |
613f5e1a AD |
591 | /* Log histogram of number of bits in set. */ |
592 | size = BITSET_SIZE_ (bset->s.bset); | |
593 | for (i = 0, tmp = size; tmp; tmp >>= 1, i++) | |
594 | continue; | |
595 | if (i >= BITSET_LOG_SIZE_BINS) | |
596 | i = BITSET_LOG_SIZE_BINS - 1; | |
597 | BITSET_STATS_LIST_SIZES_INC (bset->s.bset, i); | |
d65ec44e | 598 | |
613f5e1a AD |
599 | /* Histogram of fraction of bits set. */ |
600 | i = size ? (count * BITSET_DENSITY_BINS) / size : 0; | |
601 | if (i >= BITSET_DENSITY_BINS) | |
602 | i = BITSET_DENSITY_BINS - 1; | |
603 | BITSET_STATS_LIST_DENSITY_INC (bset->s.bset, i); | |
604 | return count; | |
605 | } | |
606 | ||
607 | ||
2d382ea8 | 608 | static bitset_bindex |
d65ec44e PE |
609 | bitset_stats_list_reverse (bitset bset, bitset_bindex *list, |
610 | bitset_bindex num, bitset_bindex *next) | |
613f5e1a | 611 | { |
6aa452a6 | 612 | return BITSET_LIST_REVERSE_ (bset->s.bset, list, num, next); |
613f5e1a AD |
613 | } |
614 | ||
615 | ||
616 | static void | |
d65ec44e | 617 | bitset_stats_free (bitset bset) |
613f5e1a AD |
618 | { |
619 | BITSET_STATS_FREES_INC (bset->s.bset); | |
620 | BITSET_FREE_ (bset->s.bset); | |
621 | } | |
622 | ||
623 | ||
6aa452a6 | 624 | struct bitset_vtable bitset_stats_vtable = { |
613f5e1a AD |
625 | bitset_stats_set, |
626 | bitset_stats_reset, | |
6aa452a6 | 627 | bitset_stats_toggle, |
613f5e1a AD |
628 | bitset_stats_test, |
629 | bitset_stats_size, | |
6aa452a6 AD |
630 | bitset_stats_count, |
631 | bitset_stats_empty_p, | |
632 | bitset_stats_ones, | |
633 | bitset_stats_zero, | |
634 | bitset_stats_copy, | |
635 | bitset_stats_disjoint_p, | |
636 | bitset_stats_equal_p, | |
637 | bitset_stats_not, | |
638 | bitset_stats_subset_p, | |
639 | bitset_stats_and, | |
640 | bitset_stats_and_cmp, | |
641 | bitset_stats_andn, | |
642 | bitset_stats_andn_cmp, | |
643 | bitset_stats_or, | |
644 | bitset_stats_or_cmp, | |
645 | bitset_stats_xor, | |
646 | bitset_stats_xor_cmp, | |
647 | bitset_stats_and_or, | |
648 | bitset_stats_and_or_cmp, | |
649 | bitset_stats_andn_or, | |
650 | bitset_stats_andn_or_cmp, | |
651 | bitset_stats_or_and, | |
652 | bitset_stats_or_and_cmp, | |
613f5e1a | 653 | bitset_stats_list, |
6aa452a6 | 654 | bitset_stats_list_reverse, |
613f5e1a AD |
655 | bitset_stats_free, |
656 | BITSET_STATS | |
657 | }; | |
658 | ||
659 | ||
660 | /* Return enclosed bitset type. */ | |
661 | enum bitset_type | |
d65ec44e | 662 | bitset_stats_type_get (bitset bset) |
613f5e1a AD |
663 | { |
664 | return BITSET_TYPE_ (bset->s.bset); | |
665 | } | |
666 | ||
667 | ||
2d382ea8 PE |
668 | size_t |
669 | bitset_stats_bytes (void) | |
613f5e1a | 670 | { |
55e728eb | 671 | return sizeof (struct bitset_stats_struct); |
613f5e1a AD |
672 | } |
673 | ||
674 | ||
675 | bitset | |
d65ec44e | 676 | bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) |
613f5e1a | 677 | { |
2d382ea8 | 678 | size_t bytes; |
613f5e1a AD |
679 | bitset sbset; |
680 | ||
6aa452a6 | 681 | bset->b.vtable = &bitset_stats_vtable; |
613f5e1a AD |
682 | |
683 | /* Disable cache. */ | |
684 | bset->b.cindex = 0; | |
685 | bset->b.csize = 0; | |
686 | bset->b.cdata = 0; | |
687 | ||
688 | /* Set up the actual bitset implementation that | |
689 | we are a wrapper over. */ | |
690 | switch (type) | |
691 | { | |
692 | case BITSET_ARRAY: | |
693 | bytes = abitset_bytes (n_bits); | |
694 | sbset = (bitset) xcalloc (1, bytes); | |
695 | abitset_init (sbset, n_bits); | |
696 | break; | |
697 | ||
698 | case BITSET_LIST: | |
699 | bytes = lbitset_bytes (n_bits); | |
700 | sbset = (bitset) xcalloc (1, bytes); | |
701 | lbitset_init (sbset, n_bits); | |
702 | break; | |
703 | ||
704 | case BITSET_TABLE: | |
705 | bytes = ebitset_bytes (n_bits); | |
706 | sbset = (bitset) xcalloc (1, bytes); | |
707 | ebitset_init (sbset, n_bits); | |
708 | break; | |
709 | ||
710 | default: | |
711 | abort (); | |
712 | } | |
713 | ||
714 | bset->s.bset = sbset; | |
715 | ||
716 | BITSET_STATS_ALLOCS_INC (type); | |
d65ec44e | 717 | |
613f5e1a AD |
718 | return bset; |
719 | } |