-
Notifications
You must be signed in to change notification settings - Fork 296
Add bittest instructions for x86 #703
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
Conversation
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.
So the general approach looks good, and there are only some minor issues.
I don't think the assert_instr lines are doing anything so not sure if I'm using them wrong or they just aren't applicable here.
They only have an effect when building the tests in release mode (e.g. with cargo test --release
).
The naming of the intrinsics should match the intel spec (https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=bittest), that is, no _u32
, 64
instead of _u64
, etc.
The spec uses mutable C pointers, and that makes little sense for an API that cannot read/write to uninitialized memory, doesn't accept null pointers, etc. So maybe this really is a case in which we should slightly deviate from the C spec and use reference types instead of *mut
everywhere. cc @alexcrichton (that might require tuning the validation suite for these, but that's doable).
Also since LLVM does not have intrinsics for these and clang generates inline assembly as well, we might want to check that the LLVM-IR that we generate matches that of clang.
37cd1b7
to
e2bd93c
Compare
What are the semantics of these intrinsics when the bit index is larger than the word size? The BT* instructions will happily continue on the next word. If this is intended behavior then we need to use the "memory" clobber. |
I just read the docs of the The spec for the intrinsics says:
which hints that one can't "index out of bounds". This might be a bug in the spec of the intrinsics, or might be the intended behavior, I don't know. @mehcode I would be more comfortable if these would take a raw pointer - in case that turns out to be a bug on the spec of the intrinsics, the raw pointer would just work, while the reference API would be weird. It would be great if somebody could ask for clarification here: https://software.intel.com/en-us/forums/intel-isa-extensions/topic/363747 (that's where spec bugs are reported). |
Alternatively if you first load the value into a register and then run the BT* instruction on that register then the instruction will automatically mask the index to fit in the register size. |
Sure. I was just wondering whether the intent of the C intrinsics is to limit usage of the |
After reading some docs, I think the intended usage of this intrinsic is to expose the full BT instruction with an unlimited range. In this case the parameter must be changed to a raw pointer and the inline asm needs to use the "memory" clobber. |
Do you have a link? |
https://software.intel.com/en-us/node/523362
It makes no mention of being limited to a single word, and I think the original intent of that intrinsic was to expose the BT instruction directly. |
e2bd93c
to
110d13e
Compare
Updated.
As this is meant to have access to a memory region and not be limited to a single primitive, a raw pointer makes sense to me. |
110d13e
to
4b32adc
Compare
How do I fix the
|
Is there a |
@mehcode ping :) |
5a4dbfe
to
8d3f485
Compare
Build should be green now. I had to use |
crates/core_arch/src/x86/bt.rs
Outdated
/// Returns the bit in position `b` of the memory addressed by `p`. | ||
#[inline] | ||
#[cfg_attr(test, assert_instr(bt))] | ||
#[unstable(feature = "simd_x86_bittest", issue = "0")] |
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.
Sorry that it took so long to review this again. Is there a PR for the simd_x86_bittest
feature to rust-lang/rust ? Otherwise, I'd prefer to use the stdsimd
feature here for now I think. Or what do you think @alexcrichton ? If we wanted to stabilize this in the near future, then adding their own feature flag might make more sense.
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.
Eh I think it'd be best to move away from stdsimd
where we can, so I think landing this as a different feature name is fine. Before landing though we'll want to open an issue at rust-lang/rust to track this and fill in the issue number though
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.
I've opened a tracking issue rust-lang/rust#59414
@mehcode can you update the issue number to 59414 ?
8d3f485
to
862b1b5
Compare
Closes #553
I don't think theAh. It does run on CI.assert_instr
lines are doing anything so not sure if I'm using them wrong or they just aren't applicable here.I know the API differs slightly than what's prescribed in Add bittest intrinsics #553 (comment) but after looking around this feels more consistent.
Do we want to provide non-reference versions of
bittest
? Not sure if it'd be worth it.What's the policy on stuff like
debug_assert
s for checking invariants? If you test for a bit higher than the total bit size of the operand it runs right off the memory onto whatever is there at the moment.