This precondition implies that any of the three 2-byte chunk of MAC address is aligned (on a 2-byte boundary). However, it does not imply that any 4-byte chunk of MAC address is aligned (on a 4-byte boundary).
[[ - - ] [ x x ]] [[ x x ] [ x x ]]
^
e.g., in the diagram, the MAC address doesn't begin on a 4-byte boundary. |
[[ - - ] [ x x ]] [[ x x ] [ x x ]] |
so I'm guessing in the diagram (first 4 bytes), are padded on a 2 byte boundary?
I may need to backtrack a little on what it means to be aligned on a 2 byte boundary,
so here is my understanding of memory alignment so far, let's say our processor has a 32 bit word size, so it will load 32 bits at a time into cache lines on the chip from memory,
1 2 3 4 5 6 7 8
|
struct{
char A; // 8 bits
int B; // 32 bits
short C; // 16 bits
}
| |
let's say we have normal memory alignment of what the processor or compiler finds the most efficient to work with, so we will pad A with 3 more bytes, B is fine the way it is, and C is fine the way it is,
so each member will be read from memory in one access.
but if we were to let's say have a 2 byte boundary,
A would be 2 bytes right? B would still be obviously 4 bytes and lastly, C would still be 2 bytes
so we would access the first 4 bytes, which would take 2 bytes from char A( 1 byte padding ) and take the first 2 bytes from B. The next access would grab the final 2 bytes from B and 2 bytes from short C.
we have less accesses but more overhead I'm guessing because the processor or OS would have to reassemble the the integer b which would cause more machine instructions hence slower. ( although we have saved space in memory)
would my understanding above be correct?
so if it is going back to the diagram
[[ - - ] [ x x ]] [[ x x ] [ x x ]] |
wouldn't this be a 4 byte boundary? as each chunk contains 4 bytes?
and also in the link (
https://www.kernel.org/doc/htmldocs/networking/API-ether-addr-equal.html) it says "Please note: addr1 & addr2 must both be aligned to u16."
If the processor can (quickly) load misaligned data, then 6-byte MAC addresses can be compared by breaking each into one chunk of 4-bytes (which is potentially misaligned) and one chunk of 2 bytes (which is always aligned), and comparing the corresponding chunks. |
how could the first chunk of 4 bytes be potentially misaligned and why would the final 2 bytes be aligned?
thanks for sticking with me, I think I'm on the cusp of understanding this.