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