views:

52

answers:

1

In gcc 4.5 the stack must be aligned to a 16-byte boundary when calling a function (previous versions only required a 4-byte alignment).

4-byte is reasonable for 32-bit machine. 16-byte is easy to align by just "and 0xfffffff0, %esp".

But it might cost much more memory than 4-byte boundary, doesn't it? In short, My question is why gcc 4.5 taks 16-byte as default? Is it valuable?

Thanks a lot!

+3  A: 

A number of the vector extensions for modern processors require 16-byte alignment for loads/stores. Some architectures offer unaligned loads, but typically these are significantly slower.

There may be some benefits to this alignment for memcpy and and other similar low-level operations encountering more strictly aligned sources/destinations more frequently.

Furthermore it almost certainly boosts the chances of the auto vectorisation succeeding, which is something recent gcc versions have included.

awoodland