X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/d08290769c798befc27e9f8bbc3f1a3da12d1f08..f8e1c9e55b6f51b5144ad19a7fc11d2a774c5d58:/lib/bitset_stats.c diff --git a/lib/bitset_stats.c b/lib/bitset_stats.c index c504a616..0b59865d 100644 --- a/lib/bitset_stats.c +++ b/lib/bitset_stats.c @@ -1,5 +1,5 @@ /* Bitset statistics. - Copyright (C) 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). This program is free software; you can redistribute it and/or modify @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* This file is a wrapper bitset implementation for the other bitset @@ -33,6 +33,7 @@ #include "abitset.h" #include "ebitset.h" #include "lbitset.h" +#include "vbitset.h" #include "bitset_stats.h" #include #include @@ -49,29 +50,29 @@ /* Accessor macros. */ -#define BITSET_STATS_ALLOCS_INC(TYPE) \ +#define BITSET_STATS_ALLOCS_INC(TYPE) \ bitset_stats_info->types[(TYPE)].allocs++ -#define BITSET_STATS_FREES_INC(BSET) \ +#define BITSET_STATS_FREES_INC(BSET) \ bitset_stats_info->types[BITSET_TYPE_ (BSET)].frees++ -#define BITSET_STATS_SETS_INC(BSET) \ +#define BITSET_STATS_SETS_INC(BSET) \ bitset_stats_info->types[BITSET_TYPE_ (BSET)].sets++ -#define BITSET_STATS_CACHE_SETS_INC(BSET) \ +#define BITSET_STATS_CACHE_SETS_INC(BSET) \ bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_sets++ -#define BITSET_STATS_RESETS_INC(BSET) \ +#define BITSET_STATS_RESETS_INC(BSET) \ bitset_stats_info->types[BITSET_TYPE_ (BSET)].resets++ -#define BITSET_STATS_CACHE_RESETS_INC(BSET) \ +#define BITSET_STATS_CACHE_RESETS_INC(BSET) \ bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_resets++ -#define BITSET_STATS_TESTS_INC(BSET) \ +#define BITSET_STATS_TESTS_INC(BSET) \ bitset_stats_info->types[BITSET_TYPE_ (BSET)].tests++ -#define BITSET_STATS_CACHE_TESTS_INC(BSET) \ +#define BITSET_STATS_CACHE_TESTS_INC(BSET) \ bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_tests++ -#define BITSET_STATS_LISTS_INC(BSET) \ +#define BITSET_STATS_LISTS_INC(BSET) \ bitset_stats_info->types[BITSET_TYPE_ (BSET)].lists++ -#define BITSET_STATS_LIST_COUNTS_INC(BSET, I) \ +#define BITSET_STATS_LIST_COUNTS_INC(BSET, I) \ bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_counts[(I)]++ -#define BITSET_STATS_LIST_SIZES_INC(BSET, I) \ +#define BITSET_STATS_LIST_SIZES_INC(BSET, I) \ bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_sizes[(I)]++ -#define BITSET_STATS_LIST_DENSITY_INC(BSET, I) \ +#define BITSET_STATS_LIST_DENSITY_INC(BSET, I) \ bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_density[(I)]++ @@ -159,8 +160,8 @@ bitset_log_histogram_print (FILE *file, const char *name, const char *msg, for (; i < n_bins; i++) fprintf (file, "%*lu-%lu\t%8u (%5.1f%%)\n", max_width - ((unsigned int) (0.30103 * (i) + 0.9999) + 1), - (unsigned long) 1 << (i - 1), - ((unsigned long) 1 << i) - 1, + 1UL << (i - 1), + (1UL << i) - 1, bins[i], (100.0 * bins[i]) / total); } @@ -240,17 +241,17 @@ bitset_stats_disable (void) /* Read bitset statistics file. */ void -bitset_stats_read (const char *filename) +bitset_stats_read (const char *file_name) { FILE *file; if (!bitset_stats_info) return; - if (!filename) - filename = BITSET_STATS_FILE; + if (!file_name) + file_name = BITSET_STATS_FILE; - file = fopen (filename, "r"); + file = fopen (file_name, "r"); if (file) { if (fread (&bitset_stats_info_data, sizeof (bitset_stats_info_data), @@ -270,17 +271,17 @@ bitset_stats_read (const char *filename) /* Write bitset statistics file. */ void -bitset_stats_write (const char *filename) +bitset_stats_write (const char *file_name) { FILE *file; if (!bitset_stats_info) return; - if (!filename) - filename = BITSET_STATS_FILE; + if (!file_name) + file_name = BITSET_STATS_FILE; - file = fopen (filename, "w"); + file = fopen (file_name, "w"); if (file) { if (fwrite (&bitset_stats_info_data, sizeof (bitset_stats_info_data), @@ -375,6 +376,13 @@ bitset_stats_test (bitset src, bitset_bindex bitno) } +static bitset_bindex +bitset_stats_resize (bitset src, bitset_bindex size) +{ + return BITSET_RESIZE_ (src->s.bset, size); +} + + static bitset_bindex bitset_stats_size (bitset src) { @@ -518,7 +526,6 @@ static void bitset_stats_and_or (bitset dst, bitset src1, bitset src2, bitset src3) { BITSET_CHECK4_ (dst, src1, src2, src3); - BITSET_AND_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset); } @@ -527,7 +534,6 @@ static bool bitset_stats_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { BITSET_CHECK4_ (dst, src1, src2, src3); - return BITSET_AND_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset); } @@ -536,7 +542,6 @@ static void bitset_stats_andn_or (bitset dst, bitset src1, bitset src2, bitset src3) { BITSET_CHECK4_ (dst, src1, src2, src3); - BITSET_ANDN_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset); } @@ -545,7 +550,6 @@ static bool bitset_stats_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { BITSET_CHECK4_ (dst, src1, src2, src3); - return BITSET_ANDN_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset); } @@ -554,7 +558,6 @@ static void bitset_stats_or_and (bitset dst, bitset src1, bitset src2, bitset src3) { BITSET_CHECK4_ (dst, src1, src2, src3); - BITSET_OR_AND_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset); } @@ -563,7 +566,6 @@ static bool bitset_stats_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { BITSET_CHECK4_ (dst, src1, src2, src3); - return BITSET_OR_AND_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset); } @@ -576,9 +578,11 @@ bitset_stats_list (bitset bset, bitset_bindex *list, bitset_bindex tmp; bitset_bindex size; bitset_bindex i; + enum bitset_type type; count = BITSET_LIST_ (bset->s.bset, list, num, next); + type = BITSET_TYPE_ (bset->s.bset); BITSET_STATS_LISTS_INC (bset->s.bset); /* Log histogram of number of set bits. */ @@ -626,6 +630,7 @@ struct bitset_vtable bitset_stats_vtable = { bitset_stats_reset, bitset_stats_toggle, bitset_stats_test, + bitset_stats_resize, bitset_stats_size, bitset_stats_count, bitset_stats_empty_p, @@ -685,28 +690,36 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) bset->b.csize = 0; bset->b.cdata = 0; + BITSET_NBITS_ (bset) = n_bits; + /* Set up the actual bitset implementation that we are a wrapper over. */ switch (type) { case BITSET_ARRAY: bytes = abitset_bytes (n_bits); - sbset = (bitset) xcalloc (1, bytes); + sbset = xcalloc (1, bytes); abitset_init (sbset, n_bits); break; case BITSET_LIST: bytes = lbitset_bytes (n_bits); - sbset = (bitset) xcalloc (1, bytes); + sbset = xcalloc (1, bytes); lbitset_init (sbset, n_bits); break; case BITSET_TABLE: bytes = ebitset_bytes (n_bits); - sbset = (bitset) xcalloc (1, bytes); + sbset = xcalloc (1, bytes); ebitset_init (sbset, n_bits); break; + case BITSET_VARRAY: + bytes = vbitset_bytes (n_bits); + sbset = xcalloc (1, bytes); + vbitset_init (sbset, n_bits); + break; + default: abort (); }