Formal proposals for changes to the code, new libraries, etc.
The goal of alignment is about minimizing how many reads it takes to fetch the full data requested. It seems that at the low level, processors can only fetch in windows of certain sizes (BYTE, WORD, DWORD, etc) and those addresses are inherently aligned to a multiple of that size (hence the self-aligned strategy). So if you are requesting a WORD where that is the maximum size for the processor, when the data is misaligned, it requires two fetches instead of one, then must reconstruct the desired data. Ultimately I don’t know if all processors are made this way, if there are ones made a different way, or what the actual restrictions are at a transistor level that require this behavior; but it’s clear that if these are the limitations we’re working with that alignment makes for more efficient fetches.
Another way I’ve seen this described has to do with generating the high order byte(s) of the address, that if they’re all the same the processor only does it once. I have no idea if this is true, and if so, whether or not it’s the same reason as above.
Aligned elements may not cross byte or bit boundaries unnecessarily. For instance [string{size:5}, number{size:4}] if this is self-aligned in a 32-bit architecture, the first element has to cross the boundary but the second does not, thus in order to prevent the second from crossing the boundary unnecessarily, 3 padding bytes are inserted between the two. These boundaries are about the word sizes a system can process and ends up essentially being a way of thinking about that high order address bytes thing. So ultimately I think we just have to describe what all these sizes are with an offset to account for any header in the ROM.
Finding exceptional cases to data alignment is markedly difficult. Realistically I think all the above strategies are more or less the same.
Padding/slop should be 00s but it’s not guaranteed. I wonder if Imperial can handle something more complex than specifying a padding byte (like in strings)? It’s possible that it could be directly accessible as a bin or a list of bins (or both).
The configuration may be as simple as having a maximum number of bytes the boundary can contain, then the actual number would be the largest type in the structure up to that amount. Exceptional cases will decide if there’s more info…if I can find them.
gcc offers alignment overrides per member.
Maybe a better idea to have alignment as a locator key on serializables? This will need to inspect the following struct’s size in order to determine where its boundary will be, but that’s fine. It’s only if we’re keeping the padding, I guess. Since this would change the base, it might be better served as an option under base, then references to base don’t have to be weird. Maybe it’s just better as base: math("something & 0xf8") though that’s not notational and makes automatic bases annoying
Add align type used in base keys to align the address regardless of it being explicitly set or not. It could also be used in other numerical contexts to create aligned pointers which would not allow implying the “address”. Forms are:
align(ADDRESS, ALIGNMENT, ROUNDING)align(ADDRESS, ALIGNMENT)align(ALIGNMENT NAME)align(ADDRESS)These correspond to these keys when treated as a struct:
c in a binary context)Add aligned specialized key to all serializables which can take a basic of packed (default), self, or a size specifiying the size of a row (wrt bounding). It’s possible other basics (particularly literals) could be added later. This controls the implied alignment of its children. As a struct it has the keys:
word: 2.x & 0xf800 == x) then this basing is erroneous. If the base was defaulted, it can be adjusted to start at the nearest upcoming blockade; otherwise, it should raise an exception.
x” part and I think the condition should be part of the equation. Possible this could be a list of some new cond type or some such which evaluates math embedded in a boolean propositionThe basic should be normalized to the actual size used.
Note that if a parent is aligned, its childrens’ defaulted bases will be aligned (i.e. the default base will become align(c, ALIGNMENT)). However if it instead uses the alignment specialized key, there is no default alignment, so each base must specify what to use by name. Possible we could implement a strategy key which determines the alignments automatically based on the size and/or type of the children (and/or their children). If so, self could be moved there, possibly, or be linked.
System-specific libraries should be able to set up the default alignment for the system. This doesn’t mean children should be automatically aligned, simply that the names should be defined (byte, word, …, bank).