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*
This commit is contained in:
parent
48853a361a
commit
10270f4b44
8 changed files with 65 additions and 1 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -644,6 +644,7 @@ impl<'ll> CodegenCx<'ll, '_> {
|
|||
|
||||
let i8p = self.type_i8p();
|
||||
let void = self.type_void();
|
||||
let voidp = self.type_ptr_to(void);
|
||||
let i1 = self.type_i1();
|
||||
let t_i8 = self.type_i8();
|
||||
let t_i16 = self.type_i16();
|
||||
|
@ -886,6 +887,9 @@ impl<'ll> CodegenCx<'ll, '_> {
|
|||
ifn!("llvm.dbg.declare", fn(t_metadata, t_metadata) -> void);
|
||||
ifn!("llvm.dbg.value", fn(t_metadata, t_i64, t_metadata) -> void);
|
||||
}
|
||||
|
||||
ifn!("llvm.ptrmask", fn(voidp, t_isize) -> voidp);
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ fn get_simple_intrinsic<'ll>(
|
|||
sym::nearbyintf64 => "llvm.nearbyint.f64",
|
||||
sym::roundf32 => "llvm.round.f32",
|
||||
sym::roundf64 => "llvm.round.f64",
|
||||
sym::ptr_mask => "llvm.ptrmask",
|
||||
_ => return None,
|
||||
};
|
||||
Some(cx.get_intrinsic(llvm_name))
|
||||
|
|
|
@ -1112,6 +1112,7 @@ symbols! {
|
|||
ptr,
|
||||
ptr_guaranteed_eq,
|
||||
ptr_guaranteed_ne,
|
||||
ptr_mask,
|
||||
ptr_null,
|
||||
ptr_null_mut,
|
||||
ptr_offset_from,
|
||||
|
|
|
@ -105,7 +105,8 @@ pub fn intrinsic_operation_unsafety(intrinsic: Symbol) -> hir::Unsafety {
|
|||
| sym::type_name
|
||||
| sym::forget
|
||||
| sym::black_box
|
||||
| sym::variant_count => hir::Unsafety::Normal,
|
||||
| sym::variant_count
|
||||
| sym::ptr_mask => hir::Unsafety::Normal,
|
||||
_ => hir::Unsafety::Unsafe,
|
||||
}
|
||||
}
|
||||
|
@ -203,6 +204,15 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
],
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
),
|
||||
sym::ptr_mask => (
|
||||
1,
|
||||
vec![
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
tcx.types.usize,
|
||||
],
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
),
|
||||
|
||||
sym::copy | sym::copy_nonoverlapping => (
|
||||
1,
|
||||
vec![
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue