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

Named permutation functions #40

Open
danieltowner opened this issue Feb 3, 2023 · 0 comments
Open

Named permutation functions #40

danieltowner opened this issue Feb 3, 2023 · 0 comments

Comments

@danieltowner
Copy link
Collaborator

There is a proposal to add a generated permutation function which can be used like this:

auto evenValues = permute<_OutputSize>(simd_value, [](size_t idx) -> size_t { return idx % 2; };

This allows an arbitrarily sized output simd to be created, where the mapping of input index to output index is specified through a supplied generator function. It is inevitable that certain permutations are common, and it would be desirable to have pre-defined functions for freeing users from having to reinvent them. By providing named functions it also becomes possible for the library implementation to provide fast alternatives where the target supports them natively.

A few common functions could include:

reverse(simd_value);   // Reverse the order of the elements in the simd.
                       // Could be given a [_Begin, _End] range sub-region to reverse.
shift_left(simd_value, offset);
slice(simd_value, start, size, stride); // Like valarray::slice
rotate(simd_value, offset);
interleave(value0, value1); // Interleave values from each argument in turn (equivalent to matrix transpose by simd rows)

Like issue #38, should these allow dynamic or static behaviour?

Where these functions could operate on subsets of a simd, should it be up to the user to handle the subset explicitly? For example, to reverse a subset of elements in a simd:

auto e = extract<_Begin, _End>(source);
auto r = reverse(e);
output = insert<_Begin>(source, r);

Note that insert, extract and resize are already pre-defined permutations which can be implemented using then generic permute-with-generator.

@danieltowner danieltowner moved this to In Progress in std::simd in C++26 Mar 15, 2023
@danieltowner danieltowner moved this from In Progress to Todo in std::simd in C++26 Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant