Skip to content
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 bitmask i{N <8} -> u8 impls #250

Merged
merged 1 commit into from
Mar 2, 2022
Merged

Add bitmask i{N <8} -> u8 impls #250

merged 1 commit into from
Mar 2, 2022

Conversation

workingjubilee
Copy link
Member

...and copy the notes for why they're legal.
I think this should be fine to Just Do but I want to make sure that if this is wrong or problematic that someone pokes me about it soooooooooooooooo I guess I am poking everyone today:

cc @calebzulawski @programmerjake @RalfJung

//
// The bit order of the result depends on the byte endianness, LSB-first for little
// endian and MSB-first for big endian.
// Not intended to be called on a vector with values other than 0 and -1.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "Not intended to be called" any different from "it is UB to be called that way"?

If 0 and -1 are the only possible values, the "returns the most significant bit (MSB)" part seems unnecessarily specific -- basically this returns whether each lane is logically true or false, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commentary before that is a barely-trimmed copy of the comments from the implementation.
So at the current moment, it's implemented in such a way that it is not UB to do that.
"Not intended to be called" is me adding an ominous suggestion that I am reconsidering whether it should be well-defined or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's an unwritten contract that the mask arguments must always be valid masks. We should probably just say "don't do it". It could certainly end up being UB in another future backend. All of the intrinsics are poorly documented but I don't think we want to give the impression you can pass weird inputs to them without it being UB.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, specifically when implementing them in Miri one needs to know what is and is not UB. :)

Copy link
Member Author

@workingjubilee workingjubilee Mar 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, yeah.

As far as I know Rust is currently against partially init scalar data, so a u8 is either u8 or is MaybeUninit<u8>. I could see us getting uint<4> and then not worrying about the next 4 bits and making simd_select_bitmask legal on that, but as far as I understand the current Rust model for uninit data, the entire vector risks becoming uninit if we ever passed a single actually uninit bit into the mask for simd_select_bitmask, and simd_bitmask is implicitly wedded to the fate of that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and we're currently the only actual users of this intrinsic so yeah, we can just define it as UB. Bam.

...and copy the notes for why they're legal.
@workingjubilee workingjubilee merged commit 3097561 into master Mar 2, 2022
@workingjubilee workingjubilee deleted the smol-bitmasks branch March 2, 2022 02:15
workingjubilee added a commit that referenced this pull request Jul 19, 2022
...and copy the notes for why they're legal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants