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