X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/11a712626cb888dd6a9ab223c59864429fc5ad69..bcf54c336eb1ed48e229448790ec1300fbef0a82:/lib/bitset_stats.c
diff --git a/lib/bitset_stats.c b/lib/bitset_stats.c
index c947abdf..dd14aabd 100644
--- a/lib/bitset_stats.c
+++ b/lib/bitset_stats.c
@@ -1,10 +1,12 @@
/* Bitset statistics.
- Copyright (C) 2002 Free Software Foundation, Inc.
+
+ Copyright (C) 2002-2006, 2009-2012 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
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@@ -13,27 +15,24 @@
GNU General Public License for more details.
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.
-*/
+ along with this program. If not, see . */
/* This file is a wrapper bitset implementation for the other bitset
implementations. It provides bitset compatibility checking and
statistics gathering without having to instrument the bitset
implementations. When statistics gathering is enabled, the bitset
operations get vectored through here and we then call the appropriate
- routines.
-*/
+ routines. */
+
+#include
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+#include "bitset_stats.h"
#include "bbitset.h"
#include "abitset.h"
#include "ebitset.h"
#include "lbitset.h"
-#include "bitset_stats.h"
+#include "vbitset.h"
#include
#include
#include
@@ -49,29 +48,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)]++
@@ -100,13 +99,13 @@ struct bitset_stats_info_struct
struct bitset_stats_info_struct bitset_stats_info_data;
struct bitset_stats_info_struct *bitset_stats_info;
-int bitset_stats_enabled = 0;
+bool bitset_stats_enabled = false;
/* Print a percentage histogram with message MSG to FILE. */
static void
bitset_percent_histogram_print (FILE *file, const char *name, const char *msg,
- unsigned int n_bins, unsigned int *bins)
+ unsigned int n_bins, unsigned int *bins)
{
unsigned int i;
unsigned int total;
@@ -121,16 +120,16 @@ bitset_percent_histogram_print (FILE *file, const char *name, const char *msg,
fprintf (file, "%s %s", name, msg);
for (i = 0; i < n_bins; i++)
fprintf (file, "%.0f-%.0f%%\t%8u (%5.1f%%)\n",
- i * 100.0 / n_bins,
- (i + 1) * 100.0 / n_bins, bins[i],
- (100.0 * bins[i]) / total);
+ i * 100.0 / n_bins,
+ (i + 1) * 100.0 / n_bins, bins[i],
+ (100.0 * bins[i]) / total);
}
/* Print a log histogram with message MSG to FILE. */
static void
bitset_log_histogram_print (FILE *file, const char *name, const char *msg,
- unsigned int n_bins, unsigned int *bins)
+ unsigned int n_bins, unsigned int *bins)
{
unsigned int i;
unsigned int total;
@@ -154,56 +153,56 @@ bitset_log_histogram_print (FILE *file, const char *name, const char *msg,
fprintf (file, "%s %s", name, msg);
for (i = 0; i < 2; i++)
fprintf (file, "%*d\t%8u (%5.1f%%)\n",
- max_width, i, bins[i], 100.0 * bins[i] / total);
+ max_width, i, bins[i], 100.0 * bins[i] / total);
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,
- bins[i],
- (100.0 * bins[i]) / total);
+ max_width - ((unsigned int) (0.30103 * (i) + 0.9999) + 1),
+ 1UL << (i - 1),
+ (1UL << i) - 1,
+ bins[i],
+ (100.0 * bins[i]) / total);
}
/* Print bitset statistics to FILE. */
static void
bitset_stats_print_1 (FILE *file, const char *name,
- struct bitset_type_info_struct *stats)
+ struct bitset_type_info_struct *stats)
{
if (!stats)
return;
fprintf (file, "%s:\n", name);
fprintf (file, _("%u bitset_allocs, %u freed (%.2f%%).\n"),
- stats->allocs, stats->frees,
- stats->allocs ? 100.0 * stats->frees / stats->allocs : 0);
+ stats->allocs, stats->frees,
+ stats->allocs ? 100.0 * stats->frees / stats->allocs : 0);
fprintf (file, _("%u bitset_sets, %u cached (%.2f%%)\n"),
- stats->sets, stats->cache_sets,
- stats->sets ? 100.0 * stats->cache_sets / stats->sets : 0);
+ stats->sets, stats->cache_sets,
+ stats->sets ? 100.0 * stats->cache_sets / stats->sets : 0);
fprintf (file, _("%u bitset_resets, %u cached (%.2f%%)\n"),
- stats->resets, stats->cache_resets,
- stats->resets ? 100.0 * stats->cache_resets / stats->resets : 0);
+ stats->resets, stats->cache_resets,
+ stats->resets ? 100.0 * stats->cache_resets / stats->resets : 0);
fprintf (file, _("%u bitset_tests, %u cached (%.2f%%)\n"),
- stats->tests, stats->cache_tests,
- stats->tests ? 100.0 * stats->cache_tests / stats->tests : 0);
+ stats->tests, stats->cache_tests,
+ stats->tests ? 100.0 * stats->cache_tests / stats->tests : 0);
fprintf (file, _("%u bitset_lists\n"), stats->lists);
bitset_log_histogram_print (file, name, _("count log histogram\n"),
- BITSET_LOG_COUNT_BINS, stats->list_counts);
+ BITSET_LOG_COUNT_BINS, stats->list_counts);
bitset_log_histogram_print (file, name, _("size log histogram\n"),
- BITSET_LOG_SIZE_BINS, stats->list_sizes);
+ BITSET_LOG_SIZE_BINS, stats->list_sizes);
bitset_percent_histogram_print (file, name, _("density histogram\n"),
- BITSET_DENSITY_BINS, stats->list_density);
+ BITSET_DENSITY_BINS, stats->list_density);
}
/* Print all bitset statistics to FILE. */
static void
-bitset_stats_print (FILE *file, int verbose ATTRIBUTE_UNUSED)
+bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED)
{
int i;
@@ -217,7 +216,7 @@ bitset_stats_print (FILE *file, int verbose ATTRIBUTE_UNUSED)
for (i = 0; i < BITSET_TYPE_NUM; i++)
bitset_stats_print_1 (file, bitset_type_names[i],
- &bitset_stats_info->types[i]);
+ &bitset_stats_info->types[i]);
}
@@ -227,42 +226,42 @@ bitset_stats_enable (void)
{
if (!bitset_stats_info)
bitset_stats_info = &bitset_stats_info_data;
- bitset_stats_enabled = 1;
+ bitset_stats_enabled = true;
}
void
bitset_stats_disable (void)
{
- bitset_stats_enabled = 0;
+ bitset_stats_enabled = false;
}
/* 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),
- 1, file) != 1)
- {
- if (ferror (file))
- perror (_("Could not read stats file."));
- else
- fprintf (stderr, _("Bad stats file size.\n"));
- }
+ 1, file) != 1)
+ {
+ if (ferror (file))
+ perror (_("cannot read stats file"));
+ else
+ fprintf (stderr, _("bad stats file size\n"));
+ }
if (fclose (file) != 0)
- perror (_("Could not read stats file."));
+ perror (_("cannot read stats file"));
}
bitset_stats_info_data.runs++;
}
@@ -270,27 +269,27 @@ 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),
- 1, file) != 1)
- perror (_("Could not write stats file."));
+ 1, file) != 1)
+ perror (_("cannot write stats file"));
if (fclose (file) != 0)
- perror (_("Could not write stats file."));
+ perror (_("cannot write stats file"));
}
else
- perror (_("Could not open stats file for writing."));
+ perror (_("cannot open stats file for writing"));
}
@@ -298,7 +297,7 @@ bitset_stats_write (const char *filename)
void
bitset_stats_dump (FILE *file)
{
- bitset_stats_print (file, 0);
+ bitset_stats_print (file, false);
}
@@ -306,7 +305,7 @@ bitset_stats_dump (FILE *file)
void
debug_bitset_stats (void)
{
- bitset_stats_print (stderr, 1);
+ bitset_stats_print (stderr, true);
}
@@ -341,7 +340,7 @@ bitset_stats_reset (bitset dst, bitset_bindex bitno)
if (offset < bset->b.csize)
{
bset->b.cdata[offset] &=
- ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
+ ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
BITSET_STATS_CACHE_RESETS_INC (bset);
}
else
@@ -349,14 +348,14 @@ bitset_stats_reset (bitset dst, bitset_bindex bitno)
}
-static int
+static bool
bitset_stats_toggle (bitset src, bitset_bindex bitno)
{
return BITSET_TOGGLE_ (src->s.bset, bitno);
}
-static int
+static bool
bitset_stats_test (bitset src, bitset_bindex bitno)
{
bitset bset = src->s.bset;
@@ -375,6 +374,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)
{
@@ -389,7 +395,7 @@ bitset_stats_count (bitset src)
}
-static int
+static bool
bitset_stats_empty_p (bitset dst)
{
return BITSET_EMPTY_P_ (dst->s.bset);
@@ -418,7 +424,7 @@ bitset_stats_copy (bitset dst, bitset src)
}
-static int
+static bool
bitset_stats_disjoint_p (bitset dst, bitset src)
{
BITSET_CHECK2_ (dst, src);
@@ -426,7 +432,7 @@ bitset_stats_disjoint_p (bitset dst, bitset src)
}
-static int
+static bool
bitset_stats_equal_p (bitset dst, bitset src)
{
BITSET_CHECK2_ (dst, src);
@@ -442,7 +448,7 @@ bitset_stats_not (bitset dst, bitset src)
}
-static int
+static bool
bitset_stats_subset_p (bitset dst, bitset src)
{
BITSET_CHECK2_ (dst, src);
@@ -458,7 +464,7 @@ bitset_stats_and (bitset dst, bitset src1, bitset src2)
}
-static int
+static bool
bitset_stats_and_cmp (bitset dst, bitset src1, bitset src2)
{
BITSET_CHECK3_ (dst, src1, src2);
@@ -474,7 +480,7 @@ bitset_stats_andn (bitset dst, bitset src1, bitset src2)
}
-static int
+static bool
bitset_stats_andn_cmp (bitset dst, bitset src1, bitset src2)
{
BITSET_CHECK3_ (dst, src1, src2);
@@ -490,7 +496,7 @@ bitset_stats_or (bitset dst, bitset src1, bitset src2)
}
-static int
+static bool
bitset_stats_or_cmp (bitset dst, bitset src1, bitset src2)
{
BITSET_CHECK3_ (dst, src1, src2);
@@ -506,7 +512,7 @@ bitset_stats_xor (bitset dst, bitset src1, bitset src2)
}
-static int
+static bool
bitset_stats_xor_cmp (bitset dst, bitset src1, bitset src2)
{
BITSET_CHECK3_ (dst, src1, src2);
@@ -518,16 +524,14 @@ 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);
}
-static int
+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,16 +540,14 @@ 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);
}
-static int
+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,33 +556,29 @@ 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);
}
-static int
+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);
}
static bitset_bindex
bitset_stats_list (bitset bset, bitset_bindex *list,
- bitset_bindex num, bitset_bindex *next)
+ bitset_bindex num, bitset_bindex *next)
{
bitset_bindex count;
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. */
@@ -609,7 +607,7 @@ bitset_stats_list (bitset bset, bitset_bindex *list,
static bitset_bindex
bitset_stats_list_reverse (bitset bset, bitset_bindex *list,
- bitset_bindex num, bitset_bindex *next)
+ bitset_bindex num, bitset_bindex *next)
{
return BITSET_LIST_REVERSE_ (bset->s.bset, list, num, next);
}
@@ -628,6 +626,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,
@@ -687,30 +686,38 @@ 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)
{
+ default:
+ abort ();
+
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;
- default:
- abort ();
+ case BITSET_VARRAY:
+ bytes = vbitset_bytes (n_bits);
+ sbset = xcalloc (1, bytes);
+ vbitset_init (sbset, n_bits);
+ break;
}
bset->s.bset = sbset;