This intrinsic takes a raw pointer and an alignment and checks whether the pointer is aligned wrt the given alignment. Implementations like miri can use this to always return false, if the requested alignment is bigger than the alignment given at creation of the allocation that the pointer points into.
In the future platforms which don't require alignment can return true unconditionally, which will probably allow more optimizations to trigger on those platforms.
The signature of the intrinsic can either be fn<T>(* const T, usize) or just fn<T>(* const T) where the latter obtains the alignment to be checked from the pointee type.
Most platforms should simply generate (ptr as usize) & ((1 << (align - 1) - 1) == 0
An example of such a check in the stdlib is
|
let align = (ptr as usize + index) & (usize_bytes - 1); |
which is part of utf8 checking. Without such an intrinsic, miri can never do utf8 checking.
Does a change like this require an rfc?
This intrinsic takes a raw pointer and an alignment and checks whether the pointer is aligned wrt the given alignment. Implementations like miri can use this to always return false, if the requested alignment is bigger than the alignment given at creation of the allocation that the pointer points into.
In the future platforms which don't require alignment can return true unconditionally, which will probably allow more optimizations to trigger on those platforms.
The signature of the intrinsic can either be
fn<T>(* const T, usize)or justfn<T>(* const T)where the latter obtains the alignment to be checked from the pointee type.Most platforms should simply generate
(ptr as usize) & ((1 << (align - 1) - 1) == 0An example of such a check in the stdlib is
rust/src/libcore/str/mod.rs
Line 1433 in f09576c
Does a change like this require an rfc?