I would like to know if forcing 4-byte alignment for 8-byte primitive types (doubles and long longs) can have any negative effect on efficiency? I'm thinking about IA-32 architecture mostly here, but information about other 32-bit architectures could also be helpful. Do you know if there are any (32-bit) processors which trigger exception when 'double' is not aligned to 8 bytes?
I'm asking because I'm writing a program which needs to be (quite) portable, but also should not waste those precious cycles ;) I personally don't see a reason why 8-byte aligned memory accesses could be faster than 4-byte aligned memory accesses on 32-bite architecture, but probably there's a reason under Windows 'doubles' are always aligned to 8 bytes.
I would like to know if forcing 4-byte alignment for 8-byte primitive types (doubles and long longs) can have any negative effect on efficiency? I'm thinking about IA-32 architecture mostly here, but information about other 32-bit architectures could also be helpful.
The efficiencies difference can be ignored, no matter how larger data you are accessing.
Do you know if there are any (32-bit) processors which trigger exception when 'double' is not aligned to 8 bytes?
Hmm, I was working on a controller which truggers an bus exception when a non-16-bit alligned address in accessed. Some 68K series controller.
I'm asking because I'm writing a program which needs to be (quite) portable, but also should not waste those precious cycles ;)
Portability and performance are always on trade off list, if one increases the other will come down.
I personally don't see a reason why 8-byte aligned memory accesses could be faster than 4-byte aligned memory accesses on 32-bite architecture, but probably there's a reason under Windows 'doubles' are always aligned to 8 bytes.
If you want portability,
1. Forget about the byte alignment, let the compiler handle it for you,
2. Avoid using any alignment/packing pragmas
3. Avoid using pragma (thery are not portable)
...list goes on
in short use only language feature which standards specifies.
> but probably there's a reason under Windows 'doubles' are always aligned to 8 bytes.
An implementation would not make the default alignment of an object any stricter than what is the minimum required to generate the most efficient code.