compiler: Align::max_for_offset -> Align::max_aligned_factor

No functional changes.
This commit is contained in:
Jubilee Young 2025-02-18 13:40:58 -08:00
parent a18bd8acfc
commit efff15afea
2 changed files with 9 additions and 10 deletions

View file

@ -810,20 +810,19 @@ impl Align {
self.bits().try_into().unwrap()
}
/// Computes the best alignment possible for the given offset
/// (the largest power of two that the offset is a multiple of).
/// Obtain the greatest factor of `size` that is an alignment
/// (the largest power of two the Size is a multiple of).
///
/// N.B., for an offset of `0`, this happens to return `2^64`.
/// Note that all numbers are factors of 0
#[inline]
pub fn max_for_offset(offset: Size) -> Align {
Align { pow2: offset.bytes().trailing_zeros() as u8 }
pub fn max_aligned_factor(size: Size) -> Align {
Align { pow2: size.bytes().trailing_zeros() as u8 }
}
/// Lower the alignment, if necessary, such that the given offset
/// is aligned to it (the offset is a multiple of the alignment).
/// Reduces Align to an aligned factor of `size`.
#[inline]
pub fn restrict_for_offset(self, offset: Size) -> Align {
self.min(Align::max_for_offset(offset))
pub fn restrict_for_offset(self, size: Size) -> Align {
self.min(Align::max_aligned_factor(size))
}
}

View file

@ -534,7 +534,7 @@ fn layout_of_uncached<'tcx>(
(
BackendRepr::Memory { sized: true },
AbiAndPrefAlign {
abi: Align::max_for_offset(size),
abi: Align::max_aligned_factor(size),
pref: dl.vector_align(size).pref,
},
)