By Darryl Gove on Feb 01, 2008
I made some comments on a thread on the forums about memory alignment on SPARC and the
-xmemalign flag. I've talked about memory alignment before, but this time the discussion was more about how the flag works. In brief:
- The flag has two parts
- The number specifies the alignment that the compiler should assume when compiling an object file. So if the compiler is not certain that the current variable is correctly aligned (say it's accessed through a pointer) then the compiler will assume the alignment given by the flag. Take a single precision floating point value that takes four bytes. Under
-xmemalign=1[i|s]the compiler will assume that it is unaligned, so will issue four single byte loads to load the value. If the alignenment is specified as
-xmemalign=2[i|s]the compiler will assume two byte alignment, so will issue two loads to get the four byte value.
- The suffix
[i|s]tells the compiler how to behave if there is a misaligned access. For 32-bit codes the default is
iwhich fixes the misaligned access and continues. For 64-bit codes the default is
swhich causes the app to die with a SIGBUS error. This is the part of the flag that has to be specified at link time because it causes different code to be linked into the binary depending on the desired behaviour. The C documentation captures this correctly, but the C++ and Fortran docs will be updated.