3

Add bitmask i{N <8} -> u8 impls by workingjubilee · Pull Request #250 · ru...

 2 years ago
source link: https://github.com/rust-lang/portable-simd/pull/250
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

Contributor

Author

@workingjubilee workingjubilee 10 days ago

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.

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.

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

Copy link

Contributor

Author

@workingjubilee workingjubilee 10 days ago

edited

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

Contributor

Author

@workingjubilee workingjubilee 10 days ago

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK