Alignment of poly_ints#
poly_int
provides various routines for aligning values and for querying
misalignments. In each case the alignment must be a power of 2.
can_align_p (value, align)
Return true if we can align
value
up or down to the nearest multiple ofalign
at compile time. The answer is the same for both directions.can_align_down (value, align, &aligned)
Return true if
can_align_p
; if so, setaligned
to the greatest aligned value that is less than or equal tovalue
.can_align_up (value, align, &aligned)
Return true if
can_align_p
; if so, setaligned
to the lowest aligned value that is greater than or equal tovalue
.known_equal_after_align_down (a, b, align)
Return true if we can align
a
andb
down to the nearestalign
boundary at compile time and if the two results are equal.known_equal_after_align_up (a, b, align)
Return true if we can align
a
andb
up to the nearestalign
boundary at compile time and if the two results are equal.aligned_lower_bound (value, align)
Return a result that is no greater than
value
and that is aligned toalign
. The result will the closest aligned value for some indeterminate values but not necessarily for all.For example, suppose we are allocating an object of
size
bytes in a downward-growing stack whose current limit is given bylimit
. If the object requiresalign
bytes of alignment, the new stack limit is given by:aligned_lower_bound (limit - size, align)
aligned_upper_bound (value, align)
Likewise return a result that is no less than
value
and that is aligned toalign
. This is the routine that would be used for upward-growing stacks in the scenario just described.known_misalignment (value, align, &misalign)
Return true if we can calculate the misalignment of
value
with respect toalign
at compile time, storing the result inmisalign
if so.known_alignment (value)
Return the minimum alignment that
value
is known to have (in other words, the largest alignment that can be guaranteed whatever the values of the indeterminates turn out to be). Return 0 ifvalue
is known to be 0.force_align_down (value, align)
Assert that
value
can be aligned down toalign
at compile time and return the result. When using this routine, please add a comment explaining why the assertion is known to hold.force_align_up (value, align)
Likewise, but aligning up.
force_align_down_and_div (value, align)
Divide the result of
force_align_down
byalign
. Again, please add a comment explaining why the assertion inforce_align_down
is known to hold.force_align_up_and_div (value, align)
Likewise for
force_align_up
.force_get_misalignment (value, align)
Assert that we can calculate the misalignment of
value
with respect toalign
at compile time and return the misalignment. When using this function, please add a comment explaining why the assertion is known to hold.