Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: "Wessels, Hans" <H.Wessels@energie-delfland.nl>
To: "'axp-list@redhat.com'" <axp-list@redhat.com>
Subject: RE: problem with unaligned access on Alpha
Date: Tue, 29 Jun 1999 11:12:48 +0200	[thread overview]
Message-ID: <c=US%a=_%p=delfland%l=MSMAIL-990629091248Z-340@msmail.energie-delfland.nl> (raw)

On 25 juni 1999 Maciej W. Rozycki wrote:

<snip>
>It may even be completely ignored for archs that support unaligned
>accesses in hardware, which is a true win -- no arch dependent
>conditionals are needed (I do not even know how to fetch information about
>alignment needed for a particular target -- "alignof" is useless here and
>it's not portable, anyway). 
<snip>
>
> Using unions is good when you are sure all data is aligned.  If that's
>not the case, the problem remains.  The "packed" approach is reasonable
>but not necessarily the best.  As C is relatively low-level language (some
>people call it "a portable assembler") I wouldn't mind if some way of
>alignment hinting became standard one day.

I am using the following macro to get alignment of elements in an
malloced memory block:

/*
 * ALIGN is a macro to align elements of a certain size in a malloced
 * block. The start of the block is guaranteed aligned with every
possible 
 * object. So an object is aligned when it's position relative to the
start
 * of the array is a multiple of it's size. Instead of the modulo
operator 
 * the & operator is used. This assumes that the alignment of an object 
 * is the smalest power of two of its size; ie: sizeof(object)==3 ->
alignment
 * is 1. sizeof(object)==6 ->alignment is 2.
 */
#define ALIGN(start,ptr,size) ptr+=((size)-((ptr)-(start)))&((size)-1)

some code....
{
      ...
      uint8 *base = malloc(memneed);

      if (base == NULL)
      {
        return GUP_OUT_OF_MEM;
      }
      else
      {
        uint8 *cp = base;

        com->dictionary = (void *)(cp + 4);  /* vier extra om terug te
kunnen kijken */
        cp += (DIC_SIZE + MAX_MATCH*4 + 6UL + 4UL) * sizeof (uint8); /*
sliding dictionary + 4 voor terugkijken */
        ALIGN(base, cp, sizeof(node_type)); /* allign buffer on
node_type allignment */
        com->root.big = (void *)cp;               /* 
        cp += sizeof (node_type) * HASH_SIZE; /* normal root */
        ALIGN(base, cp, sizeof(unsigned long)); /* align on unsigned
long for output buffer */
        com->buffer_start=(void*)cp;
        cp += com->buffer_size;
        ALIGN(base, cp, sizeof(node_struct));
        com->tree.big = (void *)cp;
        cp += sizeof (node_struct) * TREE_SIZE;  /* sld tree          */
        ALIGN(base, cp, sizeof(uint8));
        com->charlen = (void *)cp;
        cp += sizeof (uint8) * (NC + NC);  /* karakter lengte */
        ALIGN(base, cp, sizeof(uint16));
        com->ptr2huffman = (void *)cp;
        cp += sizeof (uint16) * (MAX_NPT); /* huffman codes van de
pointers */
        ALIGN(base, cp, sizeof(pointer_type));
        com->pointers = (void *)(cp);
        cp += buf * sizeof (pointer_type);
        ...
}

This code works fine from MC68K and a compiler using 68bit int's, going
through GCC on MC68K and i386 to GCC on the Alpha. I know it isn't
perfect but it works fine for me.

Bye, Hans
----------------------------------------------------------------------
   /|   /\/\/\   |\      ir. Hans Wessels
  / |  / /\/\ \  | \     H.Wessels@Energie-Delfland.nl
 /  | / / /\ \ \ |  \    tel.: 015 251 4397
/   |/ / /  \ \ \|   \   
\   |\ \ \  / / /|   /   prive:
 \  | \ \ \/ / / |  /    mr_ni@mbh.org
  \ |  \ \/\/ /  | /     Fidelus Bittus et Fuckus Clockcyclus!
   \|   \/\/\/   |/      


             reply	other threads:[~1999-07-08 12:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-29  9:12 Wessels, Hans [this message]
1999-06-29 15:07 ` problem with unaligned access on Alpha Michal Jaegermann
1999-07-05 17:23   ` Maciej W. Rozycki
  -- strict thread matches above, loose matches on Subject: below --
1999-06-24  8:54 Christian Groessler
1999-06-24  8:29 Christian Groessler
1999-06-24 15:26 ` Michal Jaegermann
1999-06-23 10:23 Christian Groessler
1999-06-23 14:55 ` Maciej W. Rozycki
1999-06-23 14:56 ` Michal Jaegermann
1999-06-23 16:23   ` Maciej W. Rozycki
1999-06-24  7:02     ` Michal Jaegermann
1999-06-25 20:21       ` Maciej W. Rozycki
1999-06-22 10:59 Christian Groessler
1999-06-22 12:32 ` Stefan Katzenbeisser
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