ggc-page.c (max_alignment): New structure.
authorMark Mitchell <mark@codesourcery.com>
Mon, 8 Jan 2001 01:38:53 +0000 (01:38 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Mon, 8 Jan 2001 01:38:53 +0000 (01:38 +0000)
* ggc-page.c (max_alignment): New structure.
(MAX_ALIGNMENT): New macro.
(init_ggc): Use it to round up the sizes in the
extra_order_size_table.

From-SVN: r38791

gcc/ChangeLog
gcc/ggc-page.c

index 53aa753..362a767 100644 (file)
@@ -1,3 +1,10 @@
+Sun Jan  7 18:37:43 2001  Mark P Mitchell  <mark@codesourcery.com>
+
+       * ggc-page.c (max_alignment): New structure.
+       (MAX_ALIGNMENT): New macro.
+       (init_ggc): Use it to round up the sizes in the
+       extra_order_size_table.
+
 2001-01-07  Franz Sirl  <Franz.Sirl-kernel@lauterbach.com>
 
        * config/rs6000/rs6000.h (EPILOGUE_USES): New, mark link register
index abe88d7..73dc4d1 100644 (file)
@@ -140,23 +140,12 @@ Boston, MA 02111-1307, USA.  */
 /* The size of an object on a page of the indicated ORDER.  */
 #define OBJECT_SIZE(ORDER) object_size_table[ORDER]
 
-#ifdef NO_ALIGNMENT_PROBLEM
-
 /* The number of extra orders, not corresponding to power-of-two sized
    objects.  */
 
 #define NUM_EXTRA_ORDERS \
   (sizeof (extra_order_size_table) / sizeof (extra_order_size_table[0]))
 
-#else /* !defined(NO_ALIGNMENT_PROBLEM) */
-
-/* For now, we can't use this code because we don't ensure that the
-   objects returned are appropriately aligned.  The problem is that
-   some tree_list sized things, for example, use */
-#define NUM_EXTRA_ORDERS 0
-
-#endif /* !defined(NO_ALIGNMENT_PROBLEM) */
-
 /* The Ith entry is the maximum size of an object to be stored in the
    Ith extra order.  Adding a new entry to this array is the *only*
    thing you need to do to add a new special allocation size.  */
@@ -170,6 +159,26 @@ static const size_t extra_order_size_table[] = {
 
 #define NUM_ORDERS (HOST_BITS_PER_PTR + NUM_EXTRA_ORDERS)
 
+/* We use this structure to determine the alignment required for
+   allocations.  For power-of-two sized allocations, that's not a
+   problem, but it does matter for odd-sized allocations.  */
+
+struct max_alignment {
+  char c;
+  union {
+    HOST_WIDEST_INT i;
+#ifdef HAVE_LONG_DOUBLE
+    long double d;
+#else
+    double d;
+#endif
+  } u;
+};
+
+/* The biggest alignment required.  */
+
+#define MAX_ALIGNMENT (offsetof (struct max_alignment, u))
+
 /* The Ith entry is the number of objects on a page or order I.  */
 
 static unsigned objects_per_page_table[NUM_ORDERS];
@@ -878,8 +887,14 @@ init_ggc ()
   for (order = 0; order < HOST_BITS_PER_PTR; ++order)
     object_size_table[order] = (size_t) 1 << order;
   for (order = HOST_BITS_PER_PTR; order < NUM_ORDERS; ++order)
-    object_size_table[order] = 
-      extra_order_size_table[order - HOST_BITS_PER_PTR];
+    {
+      size_t s = extra_order_size_table[order - HOST_BITS_PER_PTR];
+
+      /* If S is not a multiple of the MAX_ALIGNMENT, then round it up
+        so that we're sure of getting aligned memory.  */
+      s = CEIL (s, MAX_ALIGNMENT) * MAX_ALIGNMENT;
+      object_size_table[order] = s;
+    }
 
   /* Initialize the objects-per-page table.  */
   for (order = 0; order < NUM_ORDERS; ++order)