-
Notifications
You must be signed in to change notification settings - Fork 82
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
Document alternatives to Mask<T, LANES> that guarantee layout. Fixes #332 #333
base: master
Are you sure you want to change the base?
Conversation
crates/core_simd/src/masks.rs
Outdated
/// For a type with layout guaranteed equivalent to `[T; LANES]`, use | ||
/// `SIMD<T, LANES>`. For a type with layout guaranteed to use 1 bit per | ||
/// lane (padded up to full bytes), use `LANES::BitMask`. |
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 exact number of bytes is an implementation detail (we've used u64
before and we might choose it again... basically we want to retain the freedom to use an integer of a reasonable size, OR to use a byte array, depending on what strikes the best ergonomics/codegen balance). Right now, this seems like it might suggest it uses exactly the next byte in size. I am not sure what would be most clear to express our desired reservation while providing you the minimum of guarantees you want (or if you even consider that acceptable).
Co-authored-by: Jubilee <[email protected]>
I've been working on a generic integers RFC with the intention that in the future we can simply use those, but it might still be that rounding up significantly in raw size is in some cases still preferred, unfortunately. |
true, e.g. on SVP64 all mask vectors being a single |
crates/core_simd/src/masks.rs
Outdated
/// | ||
/// For a type with layout guaranteed equivalent to `[T; LANES]`, use | ||
/// `Simd<T, LANES>`. For a type with layout guaranteed to use 1 bit per | ||
/// lane (padded up to full bytes), use `LANES::BitMask`. |
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 type is actually ToBitMask::BitMask
: https://doc.rust-lang.org/std/simd/trait.ToBitMask.html#associatedtype.BitMask. It's not padded up to the next byte, but the next integer.
And in the original AVX512 case mentioned, the plausible masks use hardware representation of a It's not the most important thing that it be exactly-so, however, I suspect, because |
Thanks everyone for the helpful comments. Per Caleb's comment #332 (comment) this guarantee is much less important to me than it was previously. Even so, my suspicion is that it's worth still providing some pointers in the documentation. Indeed, So, I think the right approach is to document Let me know what you think. |
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.
Oh is it? Okay! It's... been a while since I've read things and I've lately just had my head down on trying to figure out how we'll make dynamic byte swizzles work and catching up with other stuff.
As a nightly feature, the API is still unstable, but we do try to keep things broadly consistent. But yes, you're right, changing them overly much from target to target when compiling things would at the very least probably make things a bit confusing and thus also make it easy for people to make mistakes.
do note that |
also, if you want a bitmask type that always exists no matter the lane count, use |
Thanks folks. I have updated wording to mention "size" rather than "layout" guarantees. I have mentioned (I was not familiar with the |
this means that "size guaranteed equal to |
@@ -88,6 +88,11 @@ impl_element! { isize } | |||
/// The layout of this type is unspecified, and may change between platforms | |||
/// and/or Rust versions, and code should not assume that it is equivalent to | |||
/// `[T; LANES]`. | |||
/// | |||
/// For a type with size guaranteed equal to `[T; LANES]`, use |
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.
/// For a type with size guaranteed equal to `[T; LANES]`, use | |
/// For a type with size guaranteed equal-or-greater-than `[T; LANES]`, use |
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.
/// For a type with size guaranteed equal to `[T; LANES]`, use | |
/// For a type equivalent to `[T; LANES]` (with possible trailing padding for alignment purposes), use |
maybe equivalent is too strong? ideas?
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.
/// For a type with size guaranteed equal-or-greater-than `[T; LANES]`, use
imho that loses most meaning, e.g. [u8; 5000]
fits but is unlikely to be desired.
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.
"equivalent" is indeed too strong.
Intended to fix #332.