From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by listman.redhat.com (Postfix) with ESMTP id 6197A40569 for ; Fri, 18 Oct 2002 13:18:17 -0400 (EDT) Received: (from mail@localhost) by int-mx1.corp.redhat.com (8.11.6/8.11.6) id g9IHIHB08351 for axp-list@listman.redhat.com; Fri, 18 Oct 2002 13:18:17 -0400 Received: from mx1.redhat.com (mx1.redhat.com [172.16.48.31]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with SMTP id g9IHIGf08344 for ; Fri, 18 Oct 2002 13:18:16 -0400 Received: from m3102.hostcentric.net (m3102.hostcentric.net [216.157.79.140]) by mx1.redhat.com (8.11.6/8.11.6) with SMTP id g9IGvHw25460 for ; Fri, 18 Oct 2002 12:57:17 -0400 Received: (qmail 7432 invoked by alias); 18 Oct 2002 17:18:15 -0000 Received: from unknown (HELO m3001.hostcentric.net) (216.157.79.237) by 0 with SMTP; 18 Oct 2002 17:18:15 -0000 Received: (qmail 18357 invoked by alias); 18 Oct 2002 17:18:16 -0000 Received: from unknown (HELO Viswanadha) (32.97.110.142) by 0 with SMTP; 18 Oct 2002 17:18:16 -0000 Message-ID: <02bc01c276ca$4cbcfb00$35de2b09@Viswanadha> From: "Ram Viswanadha" To: References: <01da01c273e4$d5c57320$35de2b09@Viswanadha> <02101511334803.01593@shadowfax.middleearth> <01d001c2762a$ecdbffa0$35de2b09@Viswanadha> <20021018093652.A2475@ellpspace.math.ualberta.ca> Subject: Re: unaligned traps question Date: Fri, 18 Oct 2002 10:17:55 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0.1 Precedence: bulk Reply-To: axp-list@redhat.com List-Help: List-Post: List-Subscribe: , List-Id: Linux and Red Hat on Alpha processors List-Unsubscribe: , List-Archive: 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" To: 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 >