Lines Matching refs:of
4 Linux runs on a wide variety of architectures which have varying behaviour
10 The definition of an unaligned access
13 Unaligned memory accesses occur when you try to read N bytes of data starting
15 For example, reading 4 bytes of data from address 0x10004 is fine, but
16 reading 4 bytes of data from address 0x10005 would be an unaligned memory
21 or write a number of bytes to or from memory (e.g. movb, movw, movl in x86
31 When accessing N bytes of memory, the base memory address must be evenly
38 of memory access. However, we must consider ALL supported architectures;
46 The effects of performing an unaligned memory access vary from architecture
48 here; a summary of the common scenarios is presented below:
58 - Some architectures are not capable of unaligned memory access, but will
71 coding practice. After all, you don't have a great deal of control over
72 memory addresses of certain variables, etc.
84 Let us assume that an instance of the above structure resides in memory
85 starting at address 0x10000. With a basic level of understanding, it would
92 above case it would insert 2 bytes of padding in between field1 and field2.
95 you do not cast the field to a type of different length).
98 parameters to a naturally aligned scheme, based on the size of the type of
108 resident memory size of structure instances. The optimal layout of the
118 byte of padding at the end of the structure. This padding is added in order
119 to satisfy alignment constraints for arrays of these structures.
121 Another point worth mentioning is the use of __attribute__((packed)) on a
126 You might be inclined to believe that usage of this attribute can easily
129 of the alignment constraints and will generate extra instructions to perform
133 structure padding is of importance.
139 With the above in mind, let's move onto a real life example of a function
171 which is true almost all of the time in ethernet networking context.
174 Here is another example of some code that could cause unaligned accesses:
187 1. Casting variables to types of different lengths
188 2. Pointer arithmetic followed by access to at least 2 bytes of data
197 Going back to an earlier example of code that potentially causes unaligned
222 These macros work for memory accesses of any length (not just 32 bits as
223 in the examples above). Be aware that when compared to standard access of
225 terms of performance.
227 If use of such macros is not convenient, another option is to use memcpy(),
228 where the source or destination (or both) are of type u8* or unsigned char*.
229 Due to the byte-wise nature of this operation, unaligned accesses are avoided.
242 addresses can be very expensive and dwarf the cost of unaligned loads.