From 5b32aa074762faa5d7132aa9d2943cf35a05d833 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 11 May 2022 17:52:00 +0400 Subject: [PATCH 1/3] Add pointer masking convenience functions This commit adds the following functions all of which have a signature `pointer, usize -> pointer`: - `<*mut T>::mask` - `<*const T>::mask` - `intrinsics::ptr_mask` These functions are equivalent to `.map_addr(|a| a & mask)` but they utilize `llvm.ptrmask` llvm intrinsic. *masks your pointers* --- src/intrinsics/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index b2a83e1d4..65e964c78 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -540,6 +540,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_val = ptr.load_scalar(fx); + + fx.bcx.ins().band(ptr_val, mask); + } + sym::transmute => { intrinsic_args!(fx, args => (from); intrinsic); From 63a137605f837eebe4af0074fc23c9684b12e97e Mon Sep 17 00:00:00 2001 From: Waffle Maybe Date: Wed, 11 May 2022 21:43:13 +0400 Subject: [PATCH 2/3] use shorter `ptr_mask` impl in cg cranelift Co-authored-by: bjorn3 --- src/intrinsics/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 65e964c78..35880bb3e 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -542,9 +542,7 @@ fn codegen_regular_intrinsic_call<'tcx>( sym::ptr_mask => { intrinsic_args!(fx, args => (ptr, mask); intrinsic); - let ptr_val = ptr.load_scalar(fx); - - fx.bcx.ins().band(ptr_val, mask); + fx.bcx.ins().band(ptr, mask); } sym::transmute => { From 5f357c2c51e5663f5c75b389c3fb3501753ac3be Mon Sep 17 00:00:00 2001 From: Waffle Maybe Date: Sun, 7 Aug 2022 22:32:26 +0400 Subject: [PATCH 3/3] fix cg cranelift Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com> --- src/intrinsics/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 35880bb3e..9fe43157d 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -542,6 +542,8 @@ fn codegen_regular_intrinsic_call<'tcx>( 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); }