News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

is alignment really necessary?

Started by thomas_remkus, August 26, 2007, 01:45:13 AM

Previous topic - Next topic

thomas_remkus

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?

u

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.
Please use a smaller graphic in your signature.

tenkey

If you are running XP (and probably Vista as well), the stack data must be aligned.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8