Content deleted Content added
Guy Harris (talk | contribs) →Computing padding: Just call it a bitwise AND; yes, it's a Boolean AND on each of the bits, but it's not a Boolean operation on the entire address. Add a second "is" to make it a bit clearer. |
|||
Line 86:
For example, the padding to add to offset 0x59d for a 4-byte aligned structure is 3. The structure will then start at 0x5a0, which is a multiple of 4. However, when the alignment of ''offset'' is already equal to that of ''align'', the second modulo in ''(align - (offset mod align)) mod align'' will return zero, therefore the original value is left unchanged.
Since the alignment is by [[#Definitions|definition]] a power of two,{{efn|On modern computers where the target alignment is a power of two. This might not be true, for example, on a system using 9-bit bytes or 60-bit words.}} the modulo operation can be reduced to a [[bitwise
The following formulas produce the correct values (where ''&'' is a
padding = (align - (offset & (align - 1))) & (align - 1)
= -offset & (align - 1)
|