-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pointer masking convenience functions #96946
Conversation
Some changes occured to rustc_codegen_cranelift cc @bjorn3 Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
@rustbot label +T-libs-api -T-libs |
Makes sense! Should this be added to the strict provenance feature gate? Also, if/when this lands it'd be great if you could also implement the new intrinsic for Miri. :) |
This comment has been minimized.
This comment has been minimized.
I don't really have an opinion on this. While this is mostly useful to mask pointers without touching provenance it may also be used as a shorter version of
Sure, I'll take a look into that! |
@@ -887,6 +888,9 @@ impl<'ll> CodegenCx<'ll, '_> { | |||
ifn!("llvm.dbg.declare", fn(self.type_metadata(), self.type_metadata()) -> void); | |||
ifn!("llvm.dbg.value", fn(self.type_metadata(), t_i64, self.type_metadata()) -> void); | |||
} | |||
|
|||
ifn!("llvm.ptrmask", fn(voidp, t_isize) -> voidp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can someone check that this is valid signature? llvm docs give the following signature:
declare ptrty llvm.ptrmask(ptrty %ptr, intty %mask) readnone speculatable
And the rust intrinsic has the following signature:
fn ptr_mask<T>(ptr: *const T, mask: usize) -> *const T;
Are all of these compatible with each other?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LLVM docs confuse me, here. The semantic section says it's possible for the bitwidth of the mask to be different from the pointer size of the target, but that sounds to me like it'd be an overloaded intrinsic, and thus named something like llvm.ptrmask.i64
the same way llvm.cttz.*
and friends work. But the name isn't documented the way those ones are...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the name would be llvm.ptrmask.p0i8.i64
etc.
/// Note that, unlike most intrinsics, this is safe to call; | ||
/// it does not require an `unsafe` block. | ||
/// Therefore, implementations must not require the user to uphold | ||
/// any safety invariants. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understood llvm docs correctly, ptrmask
is equivalent to just GEP
, not GEP in bounds
, so this is safe.
☔ The latest upstream changes (presumably #95643) made this pull request unmergeable. Please resolve the merge conflicts. |
this is still waiting on review |
☔ The latest upstream changes (presumably #99802) made this pull request unmergeable. Please resolve the merge conflicts. |
I think this is now waiting for a feedback from |
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred in compiler/rustc_codegen_gcc cc @antoyo Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Co-authored-by: bjorn3 <[email protected]>
I couldn't find where exactly it's documented, but apperantly pointers to void type are invalid in llvm - void is only allowed as a return type of functions.
So, it seems like in the ~1000 commits since I've made this branch llvm was updated bringing opaque pointers with it 😄
It seems it should have been |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@bors r+ |
(testing something) @bors rollup=never |
☀️ Test successful - checks-actions |
Finished benchmarking commit (1e978a3): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Footnotes |
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
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
This PR adds the following public API:
This is equivalent to
ptr.map_addr(|a| a & mask)
but also uses a cool llvm intrinsic.Proposed in #95643 (comment)
cc @Gankra @scottmcm @RalfJung
r? rust-lang/libs-api