Skip to content

Add "common" shuffles #93

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

Open
3 of 5 tasks
calebzulawski opened this issue Apr 12, 2021 · 2 comments
Open
3 of 5 tasks

Add "common" shuffles #93

calebzulawski opened this issue Apr 12, 2021 · 2 comments

Comments

@calebzulawski
Copy link
Member

calebzulawski commented Apr 12, 2021

The shuffle API in #62 can handle nearly any hardware shuffle, but it's a bit clumsy to use (and the API requires full const generics).
A few common cases of shuffles should be provided as a simpler API:

@boomshroom
Copy link

If the shift amount is a constant, then it should be possible to implement these as const functions that output the corresponding array to passe into shuffle's const parameter.

As an example, it's possible to implement alignr (x86 doesn't have an alignl) with

const fn alignr<const LANES: usize>(shift: usize) -> [u32; LANES] {
    let mut indices = [0; LANES];
    let mut block = 0;
    while block < LANES {
        let mut idx = 0;
        while idx < 16 && idx < LANES {
            // x86 chunks its vectors into 16 byte chunks for alignr
            let offset = if shift + idx >= 16 {
                LANES + (shift + idx) % 16
            } else {
                shift + idx
            };
            indices[idx + block] = (offset + block) as u32;
            idx += 1;
        }
        block += 16;
    }
    indices
}

After some testing, LLVM does appear to recognize the array that results as an alignr and simplifies it down.

@calebzulawski
Copy link
Member Author

I wonder if there's any point adding shift and align? They can both be implemented manually, or they can be implemented via rotate and select, which I would think the compiler could optimize. They're not the most obvious functions, so it might actually be clearer manually implementing them than having to reference the docs.

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

No branches or pull requests

2 participants