The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: thomas_remkus on August 26, 2007, 01:45:13 AM

Title: is alignment really necessary?
Post by: thomas_remkus on August 26, 2007, 01:45:13 AM
I don't ever "align" anything ... and that's maybe because I don't understand it. Is is important to define the alignments in all programs or just programs that use SSE/SSE2?
Title: Re: is alignment really necessary?
Post by: u on August 26, 2007, 02:32:35 AM
necessary in your code: not
it could speed-up some tight loops, that's why it's used

alignment of data is another thing. Some instructions in SSE require 16-byte aligned data, (but there also are the same instructions without the limitation).
SSE doesn't care about code-alignment, which you were asking for.

Alignment of any data is a good thing is most cases - because if you read unaligned data, the cpu could have to read from 2 places and merge the data. The cpu gets data from RAM in 8-byte or 16-byte chunks. So, if you read a dword from 0x0007, the cpu will get the 8 bytes from 0x0000 and the 8 bytes from 0x0008, and shift this 128-bit to the right by 56 bits. It's even worse if you write unaligned.

But fortunately, it's all necessary only if you want to optimize.
Title: Re: is alignment really necessary?
Post by: tenkey on August 27, 2007, 06:17:08 AM
If you are running XP (and probably Vista as well), the stack data must be aligned.