OSDN Git Service

* bt-load.c: Fix comment typos.
[pf3gnuchains/gcc-fork.git] / gcc / sbitmap.c
index 74aa7cd..2c4ac15 100644 (file)
@@ -1,5 +1,5 @@
 /* Simple bitmaps.
-   Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -20,6 +20,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #include "config.h"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "rtl.h"
 #include "flags.h"
 #include "hard-reg-set.h"
@@ -47,6 +49,64 @@ sbitmap_alloc (n_elms)
   return bmap;
 }
 
+/* Resize a simple bitmap BMAP to N_ELMS bits.  If increasing the
+   size of BMAP, clear the new bits to zero if the DEF argument
+   is zero, and set them to one otherwise.  */
+
+sbitmap
+sbitmap_resize (bmap, n_elms, def)
+     sbitmap bmap;
+     unsigned int n_elms;
+     int def;
+{
+  unsigned int bytes, size, amt;
+  unsigned int last_bit;
+
+  size = SBITMAP_SET_SIZE (n_elms);
+  bytes = size * sizeof (SBITMAP_ELT_TYPE);
+  if (bytes > bmap->bytes)
+    {
+      amt = (sizeof (struct simple_bitmap_def)
+           + bytes - sizeof (SBITMAP_ELT_TYPE));
+      bmap = (sbitmap) xrealloc (bmap, amt);
+    }
+
+  if (n_elms > bmap->n_bits)
+    {
+      if (def)
+       {
+         memset (bmap->elms + bmap->size, -1, bytes - bmap->bytes);
+
+         /* Set the new bits if the original last element.  */
+         last_bit = bmap->n_bits % SBITMAP_ELT_BITS;
+         if (last_bit)
+           bmap->elms[bmap->size - 1]
+             |= ~((SBITMAP_ELT_TYPE)-1 >> (SBITMAP_ELT_BITS - last_bit));
+
+         /* Clear the unused bit in the new last element.  */
+         last_bit = n_elms % SBITMAP_ELT_BITS;
+         if (last_bit)
+           bmap->elms[size - 1]
+             &= (SBITMAP_ELT_TYPE)-1 >> (SBITMAP_ELT_BITS - last_bit);
+       }
+      else
+       memset (bmap->elms + bmap->size, 0, bytes - bmap->bytes);
+    }
+  else if (n_elms < bmap->n_bits)
+    {
+      /* Clear the surplus bits in the last word.  */
+      last_bit = n_elms % SBITMAP_ELT_BITS;
+      if (last_bit)
+       bmap->elms[size - 1]
+         &= (SBITMAP_ELT_TYPE)-1 >> (SBITMAP_ELT_BITS - last_bit);
+    }
+
+  bmap->n_bits = n_elms;
+  bmap->size = size;
+  bmap->bytes = bytes;
+  return bmap;
+}
+
 /* Allocate a vector of N_VECS bitmaps of N_ELMS bits.  */
 
 sbitmap *
@@ -113,7 +173,7 @@ void
 sbitmap_zero (bmap)
      sbitmap bmap;
 {
-  memset ((PTR) bmap->elms, 0, bmap->bytes);
+  memset (bmap->elms, 0, bmap->bytes);
 }
 
 /* Set all elements in a bitmap to ones.  */
@@ -124,7 +184,7 @@ sbitmap_ones (bmap)
 {
   unsigned int last_bit;
 
-  memset ((PTR) bmap->elms, -1, bmap->bytes);
+  memset (bmap->elms, -1, bmap->bytes);
 
   last_bit = bmap->n_bits % SBITMAP_ELT_BITS;
   if (last_bit)