This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Minimum target alignment for a datatype



On Jul 22, 2005, at 12:33 PM, Mike Stump wrote:


On Friday, July 22, 2005, at 11:07 AM, Chris Lattner wrote:

I'm trying to determine (in target-independent code) what the *minimum* target alignment of a type is. For example, on darwin, double's are normally 4-byte aligned, but are 8-byte aligned in some cases (e.g. when they are the first element of a struct). TYPE_ALIGN on a double returns 8 bytes, is there any way to find out that they may end up being aligned to a 4-byte boundary?


I'm having a hard time with the simplicity of your question:

I don't know if there is a good answer, unfortunately.


/* The alignment necessary for objects of this type.
   The value is an int, measured in bits.  */
#define TYPE_ALIGN(NODE) (TYPE_CHECK (NODE)->type.align)

On darwin, for a 'double' this will return 64.


/* 1 if the alignment for this type was requested by "aligned" attribute,
0 if it is the default for this type. */
#define TYPE_USER_ALIGN(NODE) (TYPE_CHECK (NODE)->type.user_align)

I'm not interested in user alignment.


/* The alignment for NODE, in bytes.  */
#define TYPE_ALIGN_UNIT(NODE) (TYPE_ALIGN (NODE) / BITS_PER_UNIT)

This is just 64/8.


? Certainly, I don't expect that to answer your question, but I don't understand why.

The problem I am running into is that the double in this struct is only 4-byte aligned on darwin:


struct X { int A; double B; };

This is modified by things like ADJUST_FIELD_ALIGN and ROUND_TYPE_ALIGN. As such, I don't think there is a way to get this alignment in a target-independent way. Does that sound right?

Thanks!

-Chris


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]