[phobos] byte alignment for arrays
Steve Schveighoffer
schveiguy at yahoo.com
Mon Jun 28 11:36:25 PDT 2010
Recently, this bug has surfaced: http://d.puremagic.com/issues/show_bug.cgi?id=4400
In a nutshell, sometimes the byte alignment of arrays is 8 bytes instead 16 bytes.
This was caused by my array append patch, because in large arrays, I store the length at the front of the array. With some queries before I created my patch, I was told that 8 byte alignment was fine. However, the alignment is easy to change since it's a couple specific functions that determine the padding and alignment. So changing to 16 bytes is not an issue technically, and functionally, this is only on PAGE sized arrays and larger, so 16 bytes vs. 8 bytes isn't likely to cause problems.
Bearophile's main argument stems from this. I am not a processor or assembly expert, so I have no idea about this at all:
-----------------
The 16 bytes alignment was introduced because instructions like the SSE2 movapd
need 16 byte alignment:
http://en.wikipedia.org/wiki/MOVAPD
I have recently used it here:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=112670
And some other SSE* instructions work with 8 byte alignment too, but they are
slower (future CPUs can remove such alignment requirements, some of it has
being removed already, so in that future the GC can go back giving 8 bytes
aligned memory).
-----------------
So should I change it?
-Steve
More information about the phobos
mailing list