Data structure alignment: Difference between revisions

Content deleted Content added
Fourdee (talk | contribs)
Compatibility: alignment on x86 and x64
Line 43:
==Compatibility==
The advantage to supporting unaligned access is that it is easier to write compilers that do not need to align memory, at the expense of the cost of slower access. One way to increase performance in [[RISC]] processors which are designed to maximize raw performance is to require data to be loaded or
stored on a word boundary. So though memory is commonly addressed by 8 bit bytes, loading a 32 bit integer or 64 bit floating point number would be required to be start at every 64 bits on a 64 bit machine. The processor could flag a fault if it were asked to load a number which was not on such a boundary, but this would result in a slower call to a routine which would need to figure out which word or words contained the data and extract the equivalent value.
 
While the [[x86]] originally did not require aligned memory access and still works without it, [[SSE2]] instructions on [[x86]] and [[x64]] CPUs ''do'' require the data to be 128-bit (16-byte) aligned and there can be substantial performance advantages from using aligned data on these architectures.
 
==Typical alignment of C structs on x86==