From: "Ram Viswanadha" <ram@jtcsv.com>
To: <axp-list@redhat.com>
Subject: Re: unaligned traps question
Date: Fri, 18 Oct 2002 10:17:55 -0700 [thread overview]
Message-ID: <02bc01c276ca$4cbcfb00$35de2b09@Viswanadha> (raw)
In-Reply-To: 20021018093652.A2475@ellpspace.math.ualberta.ca
Hi Michael,
Thank you for your expert analysis.
How about the using the below code, we have tested it on all platforms that
we have ported to and it works, even on platforms like the mainframes.
/**
* This should align the memory properly on any machine.
* This is very useful for the safeClone functions.
*/
typedef union {
long t1;
double t2;
void *t3;
} UAlignedMemory;
/**
* Get the amount of bytes that a pointer is off by from
* the previous aligned pointer
*/
#define U_ALIGNMENT_OFFSET(ptr) (((size_t)ptr) & (sizeof(UAlignedMemory) -
1))
/**
* Get the amount of bytes to add to a pointer
* in order to get the next aligned address
*/
#define U_ALIGNMENT_OFFSET_UP(ptr) (sizeof(UAlignedMemory) -
U_ALIGNMENT_OFFSET(ptr))
Regards,
Ram
---------------------------------------------------
Ram Viswanadha
International Components For Unicode
GCoC San Jose
IBM
----- Original Message -----
From: "Michal Jaegermann" <michal@ellpspace.math.ualberta.ca>
To: <axp-list@redhat.com>
Sent: Friday, October 18, 2002 8:36 AM
Subject: Re: unaligned traps question
> On Thu, Oct 17, 2002 at 03:17:04PM -0700, Ram Viswanadha wrote:
> ....
> >
> > so the fix was to change storage to
> > struct{
> > double bogus; /* needed for aligining the storage */
> > uint8_t storage[10000000];
> > } storageHolder;
> >
> > The expectation of the API is that input param "data" is aligned.
>
> Err... if you are using such tricks to extricate yourself from
> bad "type punning", then I would think that using union instead of
> struct would be vastly preferable. Not only you avoid reserving
> some memory which we know will be not used for anything but you
> also get much better chances that alignment restriction for the
> widest type will be applied to all union members.
>
> With struct a compiler can insert any amount of padding betwen
> fields. Sure, in this particular case you would not expect that
> but relying on a compiler "reasonable behaviour" is by its nature
> non C Standard conforming hence not portable. "Worksforme on x86"
> is behind a huge portion of bugs we are seeing on Alpha (and which
> you will see on Itanium, or Hammer, or ... ).
>
> gcc has a way to affect a stucture layout with '__attribute__ ((packed))'
> but this is "gcc private" construct; widely used in Linux kernel, BTW.
> It does affect what compiler generated to access fields in structures.
>
> Michal
>
>
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list
>
next prev parent reply other threads:[~2002-10-18 17:18 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-15 0:50 unaligned traps question Ram Viswanadha
2002-10-15 1:38 ` Michal Jaegermann
2002-10-15 2:03 ` Uncle George
2002-10-15 15:39 ` George France
2002-10-15 16:46 ` Michal Jaegermann
2002-10-15 18:24 ` alvin
2002-10-15 19:33 ` George France
2002-10-15 19:40 ` Falk Hueffner
[not found] ` <3DAC6EF2.BC962839@voicenet.com>
2002-10-16 18:15 ` alvin
2002-10-16 19:18 ` George France
2002-10-16 19:45 ` Falk Hueffner
2002-10-16 20:08 ` George France
2002-10-17 18:37 ` Falk Hueffner
2002-10-16 20:23 ` Michal Jaegermann
2002-10-16 21:30 ` alvin
2002-10-17 1:47 ` Uncle George
2002-10-15 18:08 ` Uncle George
2002-10-15 19:29 ` George France
2002-10-15 20:10 ` Uncle George
2002-10-15 20:46 ` George France
2002-10-15 15:33 ` George France
2002-10-17 22:17 ` Ram Viswanadha
2002-10-18 15:36 ` Michal Jaegermann
2002-10-18 17:17 ` Ram Viswanadha [this message]
2002-10-18 18:47 ` Michal Jaegermann
[not found] <673E0A4C-E1DF-11D6-AC80-000393768D2C@mcgillsociety.org>
2002-10-17 15:50 ` George France
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox