Data structure alignment: Difference between revisions

Content deleted Content added
mNo edit summary
needs citations; rm unnecessary speculation; reformat
Line 17:
 
==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.
 
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
This caused difficulty when the team from [[Mosaic Software]] ported
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.
their [[Twin Spreadsheet]] to the [[68000]] based [[Atari ST]]. The Intel [[8086]]
architecture had no such restrictions.
 
This caused difficulty when the team from [[Mosaic Software]] ported their [[Twin Spreadsheet]] to the [[68000]] based [[Atari ST]]. The Intel [[8086]] architecture had no such restrictions. {{fact}}
It would also cause difficulties in porting Microsoft Office to Windows NT on [[MIPS]]
 
and [[PowerPC]] for [[NEC]] and [[IBM]]. Since the software was not written with such restrictions
It would also cause difficulties in porting Microsoft Office to Windows NT on [[MIPS]] and [[PowerPC]] for [[NEC]] and [[IBM]]. Since the software was not written with such restrictions in mind, designers had to set a bit in the operating system to enable non-aligned data. However since this bit was masked with other flags which were used elsewhere, it was impossible to keep the operating system in a state from faulting on non-aligned data. Both platforms ulimately failed as platforms for hosting Windows applications. {{fact}}
in mind, designers had to set a bit in the O/S to enable non-aligned data.
However since this bit was masked with other flags which were used elsewhere, it was impossible to
keep the O/S in a state from faulting on non-aligned data. Both platforms ulimately
failed as platforms for hosting Windows applications. This small detail may be
one reason for the continued dominance of the x86 architecture over rivals.
 
==Typical alignment of C structs on x86==