Skip to content

Commit f48af91

Browse files
committed
Auto merge of rust-lang#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 rust-lang#95643 (comment) cc `@Gankra` `@scottmcm` `@RalfJung` r? rust-lang/libs-api
2 parents 1239a02 + 5f357c2 commit f48af91

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/intrinsics/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
577577
ret.write_cvalue(fx, CValue::by_val(res, base.layout()));
578578
}
579579

580+
sym::ptr_mask => {
581+
intrinsic_args!(fx, args => (ptr, mask); intrinsic);
582+
let ptr = ptr.load_scalar(fx);
583+
let mask = mask.load_scalar(fx);
584+
fx.bcx.ins().band(ptr, mask);
585+
}
586+
580587
sym::transmute => {
581588
intrinsic_args!(fx, args => (from); intrinsic);
582589

0 commit comments

Comments
 (0)