From b1095f9cec18563c97fb5106b30019cff71a86bd Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Mon, 8 Jan 2001 01:38:53 +0000 Subject: [PATCH] ggc-page.c (max_alignment): New structure. * 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 | 7 +++++++ gcc/ggc-page.c | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 53aa75358d6..362a7679fa1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +Sun Jan 7 18:37:43 2001 Mark P Mitchell + + * 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 * config/rs6000/rs6000.h (EPILOGUE_USES): New, mark link register diff --git a/gcc/ggc-page.c b/gcc/ggc-page.c index abe88d7d57d..73dc4d1b4c1 100644 --- a/gcc/ggc-page.c +++ b/gcc/ggc-page.c @@ -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) -- 2.30.2