Sujet : Re: unaligned load/store
De : monnier (at) *nospam* iro.umontreal.ca (Stefan Monnier)
Groupes : comp.archDate : 26. Dec 2024, 19:38:04
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <jwvh66qtimu.fsf-monnier+comp.arch@gnu.org>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Gnus/5.13 (Gnus v5.13)
Aligned data is always best, Misaligned data comes at very low cost.
SW overhead = 0
Thinking about this for a bit... for a clean-sheet architecture
like My66000, could there actually be an advantage to do
struct layout like the VAX did, with everything aligned on byte
boundaries?
I highly doubt it. Making unaligned accesses work efficiently is great,
but that's no reason to abuse them:
- Going back to Mitch's description, in case B.1 the misalignment is
truly "free", but for B.2, B.3, and B.4 the misalignment does come at
a cost, not necessarily visible in terms of cycles but at least in
terms of cache bandwidth, which can have an impact on overall speed
and energy use.
Of course, properly aligning your data will also come with costs,
but "packed structs" don't come totally free.
- AFAIK most efforts to support concurrency take it for granted that
atomic accesses are supported only when properly aligned.
I expect it's at least as easy (and more portable) to reorder fields by
order of (expected) size to avoid excessive padding in aligned data,
than it is to add manual padding/alignment to avoid the cost of
misalignment in "packed structs".
Stefan