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 integer bitmask #157

Closed
b8591340 opened this issue Sep 10, 2021 · 6 comments
Closed

Add integer bitmask #157

b8591340 opened this issue Sep 10, 2021 · 6 comments
Labels
C-feature-request Category: a feature request, i.e. not implemented / a PR

Comments

@b8591340
Copy link

Maybe rename to_bitmask to to_bitmask_array and restore to_bitmask to return IntBitMask as in packed_simd, or viceversa.

@b8591340 b8591340 added the C-feature-request Category: a feature request, i.e. not implemented / a PR label Sep 10, 2021
@calebzulawski
Copy link
Member

To get the bytes as an integer, you can use u32::from_ne_bytes, etc.

@b8591340
Copy link
Author

As far as I can see that wouldn’t work with generic const exprs—the API should return IntBitMask so that we can do <const N: usize> where LaneCount<N>: SupportedLaneCount, [(); LaneCount::<N>::BITMASK_LEN]: without having to transmute or hook into LLVM’s simd_bitmask ourselves.

@calebzulawski
Copy link
Member

IntBitMask is a workaround for the current limitations in the simd_bitmask intrinsic. In the future, that type will be gone, which will allow bitmasks of masks of any size. Future versions of std::simd may support vectors with more lanes than bits in any integer type.

In the case of generics, you could do something like:

fn bitmask_to_u64<const BYTES: usize>(bitmask: [u8; BYTES]) -> u64 {
    assert!(BYTES <= 8);
    let mut padded = [0; 8];
    padded[..BYTES].copy_from_slice(&bitmask[..BYTES]);
    u64::from_ne_bytes(padded)
}

@b8591340
Copy link
Author

I see. Thanks for the comment and the suggestion. I would want to abstract over the integer types in function of the associated type of the given supported lane, but I see it was misguided as there’s no std way to abstract over integers—i.e. if I want to ctlz the bitmask I cannot do that generically.

I am using macros as it is, but if we could const abstract over integer primitives (e.g. u<8>) and have them be arbitrary-sized (like Zig) it would work with arbitrary-sized masks up to the LLVM threshold.

Not sure how complex or desirable it’d be, and if this is the right place to kickstart a discussion, but it could be considered in light of this effort.

@calebzulawski
Copy link
Member

Generic integers came up a few times when we were designing this interface--if they were available I think it would be the preferable route. I'm not sure how complex it would be either, but it's come up enough times that there's definitely some desire for it. We more or less settled on u8 arrays being "good enough", but not perfect.

@workingjubilee
Copy link
Member

Resolved in #239.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: a feature request, i.e. not implemented / a PR
Projects
None yet
Development

No branches or pull requests

3 participants