Re: [RFC] Documentation about unaligned memory access

2007-11-30 Thread Jörn Engel
On Fri, 23 November 2007 00:15:53 +, Daniel Drake wrote: > > What's the definition of an unaligned access? > = > > Unaligned memory accesses occur when you try to read N bytes of data starting > from an address that is not evenly divisible by N

Re: [RFC] Documentation about unaligned memory access

2007-11-30 Thread Jörn Engel
On Fri, 23 November 2007 00:15:53 +, Daniel Drake wrote: What's the definition of an unaligned access? = Unaligned memory accesses occur when you try to read N bytes of data starting from an address that is not evenly divisible by N (i.e.

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread Kumar Gala
On Nov 23, 2007, at 5:43 AM, Heikki Orsila wrote: On Fri, Nov 23, 2007 at 12:15:53AM +, Daniel Drake wrote: Why unaligned access is bad === Most architectures are unable to perform unaligned memory accesses. Any unaligned access causes a processor exception.

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread Arnaldo Carvalho de Melo
Em Mon, Nov 26, 2007 at 03:47:06PM +0100, Johannes Berg escreveu: > > > Sidenote: in the above example, you may wish to reorder the fields in the > > above structure so that the overall structure uses less memory. For example, > > moving field3 to sit inbetween field1 and field2 (where the

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread Ben Dooks
On Fri, Nov 23, 2007 at 01:43:29PM +0200, Heikki Orsila wrote: > On Fri, Nov 23, 2007 at 12:15:53AM +, Daniel Drake wrote: > > Why unaligned access is bad > > === > > > > Most architectures are unable to perform unaligned memory accesses. Any > > unaligned access

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread Johannes Berg
> Going back to an earlier example: > void myfunc(u8 *data, u32 value) > { > [...] > *((u16 *) data) = cpu_to_le32(value); > [...] typo? should it be a u32 cast? > To avoid the unaligned memory access, you could rewrite it as follows: > >

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread Johannes Berg
> Sidenote: in the above example, you may wish to reorder the fields in the > above structure so that the overall structure uses less memory. For example, > moving field3 to sit inbetween field1 and field2 (where the padding is > inserted) would shrink the overall structure by 1 byte: > >

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread dean gaudet
On Fri, 23 Nov 2007, Arne Georg Gleditsch wrote: > dean gaudet <[EMAIL PROTECTED]> writes: > > on AMD x86 pre-family 10h the boundary is 8 bytes, and on fam 10h it's 16 > > bytes. the penalty is a mere 3 cycles if an access crosses the specified > > boundary. > > Worth noting though, is that

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread DM
On Nov 23, 2007 1:15 AM, Daniel Drake <[EMAIL PROTECTED]> wrote: [...] > > Before I do so, any comments on the following? > [...] > void myfunc(u8 *data, u32 value) > { > [...] > value = cpu_to_le32(value); > memcpy(data, value,

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread DM
On Nov 23, 2007 1:15 AM, Daniel Drake [EMAIL PROTECTED] wrote: [...] Before I do so, any comments on the following? [...] void myfunc(u8 *data, u32 value) { [...] value = cpu_to_le32(value); memcpy(data, value, sizeof(value));

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread dean gaudet
On Fri, 23 Nov 2007, Arne Georg Gleditsch wrote: dean gaudet [EMAIL PROTECTED] writes: on AMD x86 pre-family 10h the boundary is 8 bytes, and on fam 10h it's 16 bytes. the penalty is a mere 3 cycles if an access crosses the specified boundary. Worth noting though, is that atomic

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread Johannes Berg
Sidenote: in the above example, you may wish to reorder the fields in the above structure so that the overall structure uses less memory. For example, moving field3 to sit inbetween field1 and field2 (where the padding is inserted) would shrink the overall structure by 1 byte: struct

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread Johannes Berg
Going back to an earlier example: void myfunc(u8 *data, u32 value) { [...] *((u16 *) data) = cpu_to_le32(value); [...] typo? should it be a u32 cast? To avoid the unaligned memory access, you could rewrite it as follows: void

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread Ben Dooks
On Fri, Nov 23, 2007 at 01:43:29PM +0200, Heikki Orsila wrote: On Fri, Nov 23, 2007 at 12:15:53AM +, Daniel Drake wrote: Why unaligned access is bad === Most architectures are unable to perform unaligned memory accesses. Any unaligned access causes a

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread Arnaldo Carvalho de Melo
Em Mon, Nov 26, 2007 at 03:47:06PM +0100, Johannes Berg escreveu: Sidenote: in the above example, you may wish to reorder the fields in the above structure so that the overall structure uses less memory. For example, moving field3 to sit inbetween field1 and field2 (where the padding is

Re: [RFC] Documentation about unaligned memory access

2007-11-26 Thread Kumar Gala
On Nov 23, 2007, at 5:43 AM, Heikki Orsila wrote: On Fri, Nov 23, 2007 at 12:15:53AM +, Daniel Drake wrote: Why unaligned access is bad === Most architectures are unable to perform unaligned memory accesses. Any unaligned access causes a processor exception.

Re: [RFC] Documentation about unaligned memory access

2007-11-25 Thread Alan Cox
> mc68020+ No No > (mc68000/010 No 2) (not for Linux) Actually ucLinux has been persuaded to run on m68000. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at

Re: [RFC] Documentation about unaligned memory access

2007-11-25 Thread Olaf Titz
> Unaligned memory accesses occur when you try to read N bytes of data starting > from an address that is not evenly divisible by N (i.e. addr % N != 0). Should clarify that you mean "with power-of-two N" - even more strictly this depends on the processor, but I'm pretty sure there is none which

Re: [RFC] Documentation about unaligned memory access

2007-11-25 Thread Heikki Orsila
On Sun, Nov 25, 2007 at 12:16:08PM +0100, Geert Uytterhoeven wrote: > > ISA NeedNeed > > natural alignment > > alignment by x > > > > m68kNo 2 > > `No' for >= 68020.

Re: [RFC] Documentation about unaligned memory access

2007-11-25 Thread Geert Uytterhoeven
On Fri, 23 Nov 2007, Heikki Orsila wrote: > On Fri, Nov 23, 2007 at 12:15:53AM +, Daniel Drake wrote: > > Why unaligned access is bad > > === > > > > Most architectures are unable to perform unaligned memory accesses. Any > > unaligned access causes a processor

Re: [RFC] Documentation about unaligned memory access

2007-11-25 Thread Denys Vlasenko
On Thursday 22 November 2007 16:15, Daniel Drake wrote: > In summary: if your code causes unaligned memory accesses to happen, your > code will not work on some platforms, and will perform *very* badly on > others. Although understanding alignment is important, there is another extreme - what I

Re: [RFC] Documentation about unaligned memory access

2007-11-25 Thread Denys Vlasenko
On Thursday 22 November 2007 16:15, Daniel Drake wrote: In summary: if your code causes unaligned memory accesses to happen, your code will not work on some platforms, and will perform *very* badly on others. Although understanding alignment is important, there is another extreme - what I call

Re: [RFC] Documentation about unaligned memory access

2007-11-25 Thread Geert Uytterhoeven
On Fri, 23 Nov 2007, Heikki Orsila wrote: On Fri, Nov 23, 2007 at 12:15:53AM +, Daniel Drake wrote: Why unaligned access is bad === Most architectures are unable to perform unaligned memory accesses. Any unaligned access causes a processor exception. Some

Re: [RFC] Documentation about unaligned memory access

2007-11-25 Thread Heikki Orsila
On Sun, Nov 25, 2007 at 12:16:08PM +0100, Geert Uytterhoeven wrote: ISA NeedNeed natural alignment alignment by x m68kNo 2 `No' for = 68020. `Yes' for

Re: [RFC] Documentation about unaligned memory access

2007-11-25 Thread Olaf Titz
Unaligned memory accesses occur when you try to read N bytes of data starting from an address that is not evenly divisible by N (i.e. addr % N != 0). Should clarify that you mean with power-of-two N - even more strictly this depends on the processor, but I'm pretty sure there is none which

Re: [RFC] Documentation about unaligned memory access

2007-11-25 Thread Alan Cox
mc68020+ No No (mc68000/010 No 2) (not for Linux) Actually ucLinux has been persuaded to run on m68000. - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Luciano Rocha
On Sat, Nov 24, 2007 at 06:35:25PM +0100, Pierre Ossman wrote: > On Sat, 24 Nov 2007 17:22:36 + > Luciano Rocha <[EMAIL PROTECTED]> wrote: > > > On Sat, Nov 24, 2007 at 05:19:31PM +0100, Pierre Ossman wrote: > > > It most certainly does not. gcc will assume that an int* has int > > >

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Haavard Skinnemoen
On Sat, 24 Nov 2007 17:22:36 + Luciano Rocha <[EMAIL PROTECTED]> wrote: > Nothing does, even memcpy doesn't check alignment of the source, or > alignment at all in some assembly implementations (only word-copy, > without checking if at word-boundary). An out-of-line implementation can only

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Pierre Ossman
On Sat, 24 Nov 2007 17:22:36 + Luciano Rocha <[EMAIL PROTECTED]> wrote: > On Sat, Nov 24, 2007 at 05:19:31PM +0100, Pierre Ossman wrote: > > It most certainly does not. gcc will assume that an int* has int alignment. > > memcpy() is a builtin, which gcc can translate to pretty much anything.

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Luciano Rocha
On Sat, Nov 24, 2007 at 05:19:31PM +0100, Pierre Ossman wrote: > On Sat, 24 Nov 2007 15:50:52 + > Luciano Rocha <[EMAIL PROTECTED]> wrote: > > > > > Dumb memcpy (while (len--) { *d++ = *s++ }) will have alignment problems > > in any case. Intelligent ones, like the one provided in glibc,

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Pierre Ossman
On Sat, 24 Nov 2007 15:50:52 + Luciano Rocha <[EMAIL PROTECTED]> wrote: > > Dumb memcpy (while (len--) { *d++ = *s++ }) will have alignment problems > in any case. Intelligent ones, like the one provided in glibc, first copy > bytes till output is aligned (C file) *or* size is a multiple

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Luciano Rocha
On Sat, Nov 24, 2007 at 02:34:41PM +0100, Pierre Ossman wrote: > On Fri, 23 Nov 2007 00:15:53 + (GMT) > Daniel Drake <[EMAIL PROTECTED]> wrote: > > > Being spoilt by the luxuries of i386/x86_64 I've never really had a good > > grasp on unaligned memory access problems on other architectures

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Pierre Ossman
On Fri, 23 Nov 2007 00:15:53 + (GMT) Daniel Drake <[EMAIL PROTECTED]> wrote: > Being spoilt by the luxuries of i386/x86_64 I've never really had a good > grasp on unaligned memory access problems on other architectures and decided > it was time to figure it out. As a result I've written this

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Pierre Ossman
On Fri, 23 Nov 2007 00:15:53 + (GMT) Daniel Drake [EMAIL PROTECTED] wrote: Being spoilt by the luxuries of i386/x86_64 I've never really had a good grasp on unaligned memory access problems on other architectures and decided it was time to figure it out. As a result I've written this

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Luciano Rocha
On Sat, Nov 24, 2007 at 02:34:41PM +0100, Pierre Ossman wrote: On Fri, 23 Nov 2007 00:15:53 + (GMT) Daniel Drake [EMAIL PROTECTED] wrote: Being spoilt by the luxuries of i386/x86_64 I've never really had a good grasp on unaligned memory access problems on other architectures and

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Pierre Ossman
On Sat, 24 Nov 2007 15:50:52 + Luciano Rocha [EMAIL PROTECTED] wrote: Dumb memcpy (while (len--) { *d++ = *s++ }) will have alignment problems in any case. Intelligent ones, like the one provided in glibc, first copy bytes till output is aligned (C file) *or* size is a multiple (i686 asm

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Luciano Rocha
On Sat, Nov 24, 2007 at 05:19:31PM +0100, Pierre Ossman wrote: On Sat, 24 Nov 2007 15:50:52 + Luciano Rocha [EMAIL PROTECTED] wrote: Dumb memcpy (while (len--) { *d++ = *s++ }) will have alignment problems in any case. Intelligent ones, like the one provided in glibc, first copy

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Pierre Ossman
On Sat, 24 Nov 2007 17:22:36 + Luciano Rocha [EMAIL PROTECTED] wrote: On Sat, Nov 24, 2007 at 05:19:31PM +0100, Pierre Ossman wrote: It most certainly does not. gcc will assume that an int* has int alignment. memcpy() is a builtin, which gcc can translate to pretty much anything. And

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Haavard Skinnemoen
On Sat, 24 Nov 2007 17:22:36 + Luciano Rocha [EMAIL PROTECTED] wrote: Nothing does, even memcpy doesn't check alignment of the source, or alignment at all in some assembly implementations (only word-copy, without checking if at word-boundary). An out-of-line implementation can only do

Re: [RFC] Documentation about unaligned memory access

2007-11-24 Thread Luciano Rocha
On Sat, Nov 24, 2007 at 06:35:25PM +0100, Pierre Ossman wrote: On Sat, 24 Nov 2007 17:22:36 + Luciano Rocha [EMAIL PROTECTED] wrote: On Sat, Nov 24, 2007 at 05:19:31PM +0100, Pierre Ossman wrote: It most certainly does not. gcc will assume that an int* has int alignment. memcpy()

Re: [RFC] Documentation about unaligned memory access

2007-11-23 Thread Dmitri Vorobiev
Daniel Drake пишет: > Being spoilt by the luxuries of i386/x86_64 I've never really had a good > grasp on unaligned memory access problems on other architectures and decided > it was time to figure it out. As a result I've written this documentation > which I plan to submit for inclusion as >

Re: [RFC] Documentation about unaligned memory access

2007-11-23 Thread Vadim Lobanov
On Thursday 22 November 2007 04:15:53 pm Daniel Drake wrote: > Fortunately things are not too complex, as in most cases, the compiler > ensures that things will work for you. For example, take the following > structure: > > struct foo { > u16 field1; > u32 field2;

Re: [RFC] Documentation about unaligned memory access

2007-11-23 Thread Heikki Orsila
On Fri, Nov 23, 2007 at 12:15:53AM +, Daniel Drake wrote: > Why unaligned access is bad > === > > Most architectures are unable to perform unaligned memory accesses. Any > unaligned access causes a processor exception. "Some architectures are unable to perform

Re: [RFC] Documentation about unaligned memory access

2007-11-23 Thread Jan Engelhardt
On Nov 23 2007 00:15, Daniel Drake wrote: > >What's the definition of an unaligned access? >= > >Unaligned memory accesses occur when you try to read N bytes of data starting >from an address that is not evenly divisible by N (i.e. addr % N != 0). >For

Re: [RFC] Documentation about unaligned memory access

2007-11-23 Thread Arne Georg Gleditsch
dean gaudet <[EMAIL PROTECTED]> writes: > on AMD x86 pre-family 10h the boundary is 8 bytes, and on fam 10h it's 16 > bytes. the penalty is a mere 3 cycles if an access crosses the specified > boundary. Worth noting though, is that atomic accesses that cross cache lines on an Opteron system is

Re: [RFC] Documentation about unaligned memory access

2007-11-23 Thread Vadim Lobanov
On Thursday 22 November 2007 04:15:53 pm Daniel Drake wrote: Fortunately things are not too complex, as in most cases, the compiler ensures that things will work for you. For example, take the following structure: struct foo { u16 field1; u32 field2;

Re: [RFC] Documentation about unaligned memory access

2007-11-23 Thread Dmitri Vorobiev
Daniel Drake пишет: Being spoilt by the luxuries of i386/x86_64 I've never really had a good grasp on unaligned memory access problems on other architectures and decided it was time to figure it out. As a result I've written this documentation which I plan to submit for inclusion as

Re: [RFC] Documentation about unaligned memory access

2007-11-23 Thread Jan Engelhardt
On Nov 23 2007 00:15, Daniel Drake wrote: What's the definition of an unaligned access? = Unaligned memory accesses occur when you try to read N bytes of data starting from an address that is not evenly divisible by N (i.e. addr % N != 0). For

Re: [RFC] Documentation about unaligned memory access

2007-11-23 Thread Arne Georg Gleditsch
dean gaudet [EMAIL PROTECTED] writes: on AMD x86 pre-family 10h the boundary is 8 bytes, and on fam 10h it's 16 bytes. the penalty is a mere 3 cycles if an access crosses the specified boundary. Worth noting though, is that atomic accesses that cross cache lines on an Opteron system is

Re: [RFC] Documentation about unaligned memory access

2007-11-23 Thread Heikki Orsila
On Fri, Nov 23, 2007 at 12:15:53AM +, Daniel Drake wrote: Why unaligned access is bad === Most architectures are unable to perform unaligned memory accesses. Any unaligned access causes a processor exception. Some architectures are unable to perform unaligned

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread dean gaudet
On Fri, 23 Nov 2007, Alan Cox wrote: > Its usually faster if you don't misalign on x86 as well. i'm not sure if i agree with "usually"... but i know you (alan) are probably aware of the exact requirements of the hw. for everyone else: on intel x86 processors an access is unaligned only if it

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread Kyle Moffett
On Nov 22, 2007, at 20:29:11, Alan Cox wrote: Most architectures are unable to perform unaligned memory accesses. Any unaligned access causes a processor exception. Not all. Some simply produce the wrong answer - thats oh so much more exciting. As one example, the MicroBlaze soft-core

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread Andi Kleen
Robert Hancock <[EMAIL PROTECTED]> writes: > > Also, x86 doesn't prohibit unaligned accesses, That depends, e.g. for SSE2 they can be forbidden. > but I believe they have > a significant performance cost and are best avoided where possible. On Opteron the typical cost of a misaligned access is

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread Alan Cox
> Most architectures are unable to perform unaligned memory accesses. Any > unaligned access causes a processor exception. Not all. Some simply produce the wrong answer - thats oh so much more exciting. > You may be wondering why you have never seen these problems on your own > architecture.

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread David Miller
Thanks you for working proactively on these problems. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread Robert Hancock
Daniel Drake wrote: Being spoilt by the luxuries of i386/x86_64 I've never really had a good grasp on unaligned memory access problems on other architectures and decided it was time to figure it out. As a result I've written this documentation which I plan to submit for inclusion as

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread Avuton Olrich
On Nov 22, 2007 4:15 PM, Daniel Drake <[EMAIL PROTECTED]> wrote: > Before I do so, any comments on the following? > < above case it would insert 2 bytes of padding inbetween field1 and field2. > above case it would insert 2 bytes of padding in between field1 and field2. < moving field3 to sit

[RFC] Documentation about unaligned memory access

2007-11-22 Thread Daniel Drake
Being spoilt by the luxuries of i386/x86_64 I've never really had a good grasp on unaligned memory access problems on other architectures and decided it was time to figure it out. As a result I've written this documentation which I plan to submit for inclusion as

[RFC] Documentation about unaligned memory access

2007-11-22 Thread Daniel Drake
Being spoilt by the luxuries of i386/x86_64 I've never really had a good grasp on unaligned memory access problems on other architectures and decided it was time to figure it out. As a result I've written this documentation which I plan to submit for inclusion as

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread Alan Cox
Most architectures are unable to perform unaligned memory accesses. Any unaligned access causes a processor exception. Not all. Some simply produce the wrong answer - thats oh so much more exciting. You may be wondering why you have never seen these problems on your own architecture. Some

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread dean gaudet
On Fri, 23 Nov 2007, Alan Cox wrote: Its usually faster if you don't misalign on x86 as well. i'm not sure if i agree with usually... but i know you (alan) are probably aware of the exact requirements of the hw. for everyone else: on intel x86 processors an access is unaligned only if it

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread Avuton Olrich
On Nov 22, 2007 4:15 PM, Daniel Drake [EMAIL PROTECTED] wrote: Before I do so, any comments on the following? above case it would insert 2 bytes of padding inbetween field1 and field2. above case it would insert 2 bytes of padding in between field1 and field2. moving field3 to sit

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread Kyle Moffett
On Nov 22, 2007, at 20:29:11, Alan Cox wrote: Most architectures are unable to perform unaligned memory accesses. Any unaligned access causes a processor exception. Not all. Some simply produce the wrong answer - thats oh so much more exciting. As one example, the MicroBlaze soft-core

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread Andi Kleen
Robert Hancock [EMAIL PROTECTED] writes: Also, x86 doesn't prohibit unaligned accesses, That depends, e.g. for SSE2 they can be forbidden. but I believe they have a significant performance cost and are best avoided where possible. On Opteron the typical cost of a misaligned access is a

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread Robert Hancock
Daniel Drake wrote: Being spoilt by the luxuries of i386/x86_64 I've never really had a good grasp on unaligned memory access problems on other architectures and decided it was time to figure it out. As a result I've written this documentation which I plan to submit for inclusion as

Re: [RFC] Documentation about unaligned memory access

2007-11-22 Thread David Miller
Thanks you for working proactively on these problems. - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/