From: Roland Dreier <[EMAIL PROTECTED]>
Date: Wed, 09 Aug 2006 11:37:31 -0700
> Agreed (although not really RISC -- sparc64 and ia64 have this
> problem, while ppc is fine with unaligned access). However
> __attribute__((packed,aligned)) has just been brought to my attention.
> For example, on sparc64,
>
> struct foo { char x; int a; } __attribute__((packed,aligned));
> struct bar { char x; int b; } __attribute__((packed));
>
> int c(struct foo *x) { return x->a; }
> int d(struct bar *x) { return x->b; }
>
> compiles to:
...
> which suggests that adding "aligned" is a good idea for many of the
> uses of "packed". However I don't know how all gcc version do with
> this. Anyone have any comments on "__attribute__((packed,aligned))"?
Good find.
It might usable in some of the questionable cases, however it changes
the size of the struct which eliminates most of the gains.
For example:
[EMAIL PROTECTED]:~/src/GIT/net-2.6$ cat foo.c
#include <stdio.h>
struct foo_packed {
char x; int a;
} __attribute__((packed));
struct foo_packed_aligned {
char x; int a;
} __attribute__((packed,aligned));
int main(void)
{
printf("foo_packed: sizeof(%Zd)\n",
sizeof(struct foo_packed));
printf("foo_packed_aligned: sizeof(%Zd)\n",
sizeof(struct foo_packed_aligned));
return 0;
}
[EMAIL PROTECTED]:~/src/GIT/net-2.6$ gcc -O -o foo foo.c
[EMAIL PROTECTED]:~/src/GIT/net-2.6$ ./foo
foo_packed: sizeof(5)
foo_packed_aligned: sizeof(8)
[EMAIL PROTECTED]:~/src/GIT/net-2.6$
This doesn't work for things like packet headers, for example.
Oh well.
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html