Auto merge of #96946 - WaffleLapkin:ptr_mask, r=scottmcm
Add pointer masking convenience functions This PR adds the following public API: ```rust impl<T: ?Sized> *const T { fn mask(self, mask: usize) -> *const T; } impl<T: ?Sized> *mut T { fn mask(self, mask: usize) -> *const T; } // mod intrinsics fn mask<T>(ptr: *const T, mask: usize) -> *const T ``` This is equivalent to `ptr.map_addr(|a| a & mask)` but also uses a cool llvm intrinsic. Proposed in https://github.com/rust-lang/rust/pull/95643#issuecomment-1121562352 cc `@Gankra` `@scottmcm` `@RalfJung` r? rust-lang/libs-api
This commit is contained in:
commit
f48af912ea
1 changed files with 7 additions and 0 deletions
|
@ -577,6 +577,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
|||
ret.write_cvalue(fx, CValue::by_val(res, base.layout()));
|
||||
}
|
||||
|
||||
sym::ptr_mask => {
|
||||
intrinsic_args!(fx, args => (ptr, mask); intrinsic);
|
||||
let ptr = ptr.load_scalar(fx);
|
||||
let mask = mask.load_scalar(fx);
|
||||
fx.bcx.ins().band(ptr, mask);
|
||||
}
|
||||
|
||||
sym::transmute => {
|
||||
intrinsic_args!(fx, args => (from); intrinsic);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue