Lines Matching refs:to

5 when it comes to memory access. This document presents some details about
6 unaligned accesses, why you need to write code that doesn't cause them,
7 and how to write such code!
13 Unaligned memory accesses occur when you try to read N bytes of data starting
21 or write a number of bytes to or from memory (e.g. movb, movw, movl in x86
22 assembly). As will become clear, it is relatively easy to spot C statements
23 which will compile to multiple-byte memory access instructions, namely when
30 The rule mentioned above forms what we refer to as natural alignment:
40 to achieve full portability.
47 to architecture. It would be easy to write a whole document on the differences
50 - Some architectures are able to perform unaligned memory accesses
53 happen. The exception handler is able to correct the unaligned access,
54 at significant cost to performance.
57 unaligned access to be corrected.
59 silently perform a different memory access to the one that was requested,
60 resulting in a subtle code bug that is hard to detect!
63 memory accesses to happen, your code will not work correctly on certain
70 At first, the concepts above may seem a little hard to relate to actual
86 not be unreasonable to expect that accessing field2 would cause an unaligned
87 access. You'd be expecting field2 to be located at offset 2 bytes into the
94 to pad structures so that accesses to fields are suitably aligned (assuming
95 you do not cast the field to a type of different length).
97 Similarly, you can also rely on the compiler to align variables and function
98 parameters to a naturally aligned scheme, based on the size of the type of
106 that you could reorder the fields in the structure in order to place fields
117 For a natural alignment scheme, the compiler would only have to add a single
119 to satisfy alignment constraints for arrays of these structures.
122 structure type. This GCC-specific attribute tells the compiler never to
123 insert any padding within structures, useful when you want to use a C struct
124 to represent some data that comes in a fixed arrangement 'off the wire'.
126 You might be inclined to believe that usage of this attribute can easily
127 lead to unaligned accesses when accessing fields that do not satisfy
129 of the alignment constraints and will generate extra instructions to perform
131 the extra instructions obviously cause a loss in performance compared to the
141 from include/linux/etherdevice.h is an optimized routine to compare two
160 able to access memory on arbitrary boundaries, the reference to a[0] causes
161 2 bytes (16 bits) to be read from memory starting at address addr1.
167 is included in the kernel anyway but is understood to only work normally on
168 16-bit-aligned addresses. It is up to the caller to ensure this alignment or
183 to an address that is not evenly divisible by 4.
187 1. Casting variables to types of different lengths
188 2. Pointer arithmetic followed by access to at least 2 bytes of data
194 The easiest way to avoid unaligned access is to use the get_unaligned() and
197 Going back to an earlier example of code that potentially causes unaligned
217 The get_unaligned() macro works similarly. Assuming 'data' is a pointer to
218 memory and you wish to avoid unaligned access, its usage is as follows:
223 in the examples above). Be aware that when compared to standard access of
224 aligned memory, using these macros to access unaligned memory can be costly in
227 If use of such macros is not convenient, another option is to use memcpy(),
229 Due to the byte-wise nature of this operation, unaligned accesses are avoided.
236 header is aligned on a four-byte boundary to optimise the IP stack. For
239 header is 14 bytes long, so in order to get proper alignment one needs to
240 DMA to an address which can be expressed as 4*n + 2. One notable exception
241 here is powerpc which defines NET_IP_ALIGN to 0 because DMA to unaligned
244 For some ethernet hardware that cannot DMA to unaligned addresses like
246 required to copy the incoming frame into an aligned buffer. Because this is