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
valueup or down to the nearest multiple ofalignat compile time. The answer is the same for both directions.can_align_down (value, align, &aligned)Return true if
can_align_p; if so, setalignedto 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, setalignedto 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
aandbdown to the nearestalignboundary at compile time and if the two results are equal.known_equal_after_align_up (a, b, align)Return true if we can align
aandbup to the nearestalignboundary at compile time and if the two results are equal.aligned_lower_bound (value, align)Return a result that is no greater than
valueand 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
sizebytes in a downward-growing stack whose current limit is given bylimit. If the object requiresalignbytes 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
valueand 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
valuewith respect toalignat compile time, storing the result inmisalignif so.known_alignment (value)Return the minimum alignment that
valueis 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 ifvalueis known to be 0.force_align_down (value, align)Assert that
valuecan be aligned down toalignat 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_downbyalign. Again, please add a comment explaining why the assertion inforce_align_downis 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
valuewith respect toalignat compile time and return the misalignment. When using this function, please add a comment explaining why the assertion is known to hold.