BlockAlignTruncate -- Macro to Round a Value Down to the Next Nearest Multiple of Another Value

The inputs for this algorithm are:

  • Value: The value being rounded down.

  • Boundary - Value is to be rounded down to a multiple of this value.Boundary MUST be a power of 2.

This algorithm returns the bitwise AND of Value with the 2's complement of Boundary.

Pseudocode for the algorithm is as follows:

  • BlockAlignTruncate(Value, Boundary) = Value & -(Boundary)