E.V.E
v2023.02.15
Loading...
Searching...
No Matches
Named Shuffles

Detailed Description

Functions that are just shuffles with a different api.

Variables

constexpr auto eve::blend = _::named_shuffle_2<blend_t> {}
 a named shuffle for mixing 2 registers together, without changing positions.
constexpr auto eve::broadcast_lane = _::named_shuffle_1<broadcast_lane_t> {}
 a named shuffle for duplicating the lane across a register.
constexpr auto eve::reverse = _::named_shuffle_1<reverse_t> {}
 a named shuffle for reversing a register.
constexpr auto eve::reverse_in_subgroups = _::named_shuffle_1<reverse_in_subgroups_t> {}
 a named shuffle for reversing all subgroups in a register
constexpr auto eve::swap_adjacent = _::named_shuffle_1<swap_adjacent_t> {}
 a named shuffle that goes all pairs of elements and swaps them: [0, 1, 2, 3] => [1, 0, 3, 2]
constexpr callable_slide_left_ eve::slide_left = {}
 a named shuffles for sliding two simd values together and selecting one register. Common names for this would also include "shift", "extract". Second value can be omitted for an implicit zero.

Variable Documentation

◆ blend

auto eve::blend = _::named_shuffle_2<blend_t> {}
inlineconstexpr

a named shuffle for mixing 2 registers together, without changing positions.

Note
You might be looking for eve::if_else_.

Defined in Header

#include <eve/module/core.hpp>

(TODO: support mixing more than 2 registers)

Accepts a pattern with just 0 and 1 that indicates number of the element for the current slot

blend([0, 1, 2, 3], [4, 5, 6, 7], pattern<1, 0, 0, 1>) -> [4, 1, 2, 7].

As any named shuffle, allows to specify a group size.

template<simd_value T, std::ptrdiff_t G, std::ptrdiff_t ...I> // (1)
template<simd_value T, std::ptrdiff_t G>
T blend(T x, T y, fixed<G>, pattern_formula auto gen)
template<simd_value T, std::ptrdiff_t ...I> // (2)
T blend(T x, T y, pattern_t<I...>)
template<simd_value T, std::ptrdiff_t ...I>
T blend(T x, T y, pattern_formula auto gen)
what callable can be a pattern formula
Definition pattern.hpp:100
Specifies that a type is a SIMD type. The concept simd_value<T> is satisfied if and only if T satisfi...
Definition vectorized.hpp:34
constexpr auto blend
a named shuffle for mixing 2 registers together, without changing positions.
Definition blend.hpp:150
SIMD register cardinal type.
Definition cardinals.hpp:39
Shuffling pattern.
Definition pattern.hpp:27

Parameters

  • x, y - values to shuffle.
  • G - (optional) - number of elements to treat as one.
  • pattern - how to shuffle elements I == 0 -> take a group from x I == 1 -> take a group from y
  • gen - eve::pattern_formula = alternative way to specify a pattern, computing it from index and size.

Return value

Returns a register with elements selected according to the mask.

Example

#include <eve/module/core.hpp>
#include <tts/tts.hpp>
int
main()
{
w_t x {0, 1, 2, 3};
w_t y {4, 5, 6, 7};
// basic example
TTS_EXPECT(eve::all(w_t{4, 1, 2, 7} == eve::blend(x, y, eve::pattern<1, 0, 0, 1>)));
// basic example, formula
TTS_EXPECT(
eve::all(w_t{0, 5, 2, 7} == eve::blend(x, y, [](int i, int /*size*/) { return i % 2; })));
// mixing groups
TTS_EXPECT(eve::all(w_t{4, 5, 2, 3} == eve::blend(x, y, eve::lane<2>, eve::pattern<1, 0>)));
}
constexpr auto all
Computes a bool value which is true if and only if every elements of x evaluates to true.
Definition all.hpp:95
constexpr auto pattern
Generate a shuffling pattern.
Definition pattern.hpp:91
Wrapper for SIMD registers.
Definition wide.hpp:94

◆ broadcast_lane

auto eve::broadcast_lane = _::named_shuffle_1<broadcast_lane_t> {}
inlineconstexpr

a named shuffle for duplicating the lane across a register.

Note
use eve::broadcast or a constructor to create a simd_value from a scalar value. This is a shuffle, for when the value is in register already.

Defined in Header

#include <eve/module/core.hpp>

As any named shuffle, allows to pass a group size, to treat multiple elements as one. Group size has to be 0 < G <= T::size()

template <simd_value T, std::ptrdiff_t G, std::ptrdiff_t I>
T broadcast_lane(T x, eve::fixed<G>, eve::index_t<I>); // (1)
template <simd_value T, std::ptrdiff_t I>
T broadcast_lane(T x, eve::index_t<I>); // (2)
constexpr auto broadcast_lane
a named shuffle for duplicating the lane across a register.
Definition broadcast_lane.hpp:127

Parameters

  • x - simd_value to shuffle
  • G - (optional) - number of elements to treat as one.
  • I - index of the lane to broadcast

(2) calls (1) with G == 1; (1) broadcasts the group of size G in position I to all register.

Return value

shuffled register

Example

#include <eve/module/core.hpp>
#include <tts/tts.hpp>
int main()
{
w_t x {0, 1, 2, 3};
TTS_EXPECT( eve::all( w_t{1, 1, 1, 1} == eve::broadcast_lane(x, eve::index<1>)) );
TTS_EXPECT( eve::all( w_t{2, 3, 2, 3} == eve::broadcast_lane(x, eve::lane<2>, eve::index<1>)) );
TTS_EXPECT( eve::all( w_t{0, 1, 2, 3} == eve::broadcast_lane(x, eve::lane<4>, eve::index<0>)) );
}

◆ reverse

auto eve::reverse = _::named_shuffle_1<reverse_t> {}
inlineconstexpr

a named shuffle for reversing a register.

Defined in Header

#include <eve/module/core.hpp>

As any named shuffle, allows to pass a group size, to treat multiple elements as one. Group size has to be 0 < G <= T::size()

template <simd_value T, std::ptrdiff_t G>
T reverse(T x, eve::fixed<G>); // (1)
template <simd_value T>
T reverse(T x); // (2)
constexpr auto reverse
a named shuffle for reversing a register.
Definition reverse.hpp:134

Parameters

  • x - simd_value to shuffle
  • G - (optional) - number of elements to treat as one.

(2) calls (1) with G == 1; (1) reverses positions of adjacent groups of elements of size G

Return value

Return x where groups of contiguous G elements are reversed.

Example

#include <eve/module/core.hpp>
#include <tts/tts.hpp>
int main()
{
w_t x {0, 1, 2, 3};
TTS_EXPECT( eve::all( w_t{3, 2, 1, 0} == eve::reverse(x)) );
TTS_EXPECT( eve::all( w_t{3, 2, 1, 0} == eve::reverse(x, eve::lane<1>)) );
TTS_EXPECT( eve::all( w_t{2, 3, 0, 1} == eve::reverse(x, eve::lane<2>)) );
// lane<0> is not OK
TTS_EXPECT( eve::all( w_t{0, 1, 2, 3} == eve::reverse(x, eve::lane<4>)) );
}

◆ reverse_in_subgroups

auto eve::reverse_in_subgroups = _::named_shuffle_1<reverse_in_subgroups_t> {}
inlineconstexpr

a named shuffle for reversing all subgroups in a register

Defined in Header

#include <eve/module/core.hpp>

As any named shuffle, allows to pass a group size, to treat multiple elements as one. Group size has to be 0 < G <= T::size() Subgroup size has to be 1 <= SubG <= T::size() / G

Note
SubG == T::size() makes this function equivalent eve::reverse.
template <simd_value T, std::ptrdiff_t G, std::ptrdiff_t SubG>
template <simd_value T, std::ptrdiff_t SubG>
constexpr auto reverse_in_subgroups
a named shuffle for reversing all subgroups in a register
Definition reverse_in_subgroups.hpp:133

Parameters

  • x - simd_value to shuffle
  • G - (optional) - number of elements to treat as one.
  • SubG - size of a subgroup

(2) calls (1) with G == 1; (1) within each SubG reverses positions elements

Return value

Returns x where each subgroup is reversed.

Example

#include <eve/module/core.hpp>
#include <tts/tts.hpp>
int
main()
{
w_t x {0, 1, 2, 3};
TTS_EXPECT(eve::all(w_t {0, 1, 2, 3} == eve::reverse_in_subgroups(x, eve::lane<1>)));
TTS_EXPECT(eve::all(w_t {1, 0, 3, 2} == eve::reverse_in_subgroups(x, eve::lane<2>)));
TTS_EXPECT(eve::all(w_t {3, 2, 1, 0} == eve::reverse_in_subgroups(x, eve::lane<4>)));
TTS_EXPECT(
eve::all(w_t {2, 3, 0, 1} == eve::reverse_in_subgroups(x, eve::lane<2>, eve::lane<2>)));
}

◆ slide_left

callable_slide_left_ eve::slide_left = {}
inlineconstexpr

a named shuffles for sliding two simd values together and selecting one register. Common names for this would also include "shift", "extract". Second value can be omitted for an implicit zero.

Defined in Header

#include <eve/module/core.hpp>

As any named shuffle, allows to pass a group size, to treat multiple elements as one. Group size has to be 0 < G <= T::size() Shift * GroupSize <= T::size() Shift >= 0

template <simd_value T, std::ptrdiff_t S>
T slide_left(T x, eve::index<S>); // (1)
template <simd_value T, std::ptrdiff_t G, std::ptrdiff_t S>
T slide_left(T x, eve::fixed<G>, eve::index<S>); // (2)
template <simd_value T, std::ptrdiff_t S>
T slide_left(T x, T y, eve::index<S>); // (3)
template <simd_value T, std::ptrdiff_t G, std::ptrdiff_t S>
T slide_left(T x, T y, eve::fixed<G>, eve::index<S>); // (4)
constexpr callable_slide_left_ slide_left
a named shuffles for sliding two simd values together and selecting one register. Common names for th...
Definition slide_left.hpp:16

Parameters

  • x, y - simd_values to shuffle
  • G - (optional) - number of elements to treat as one.
  • S - shift by how many elements to shift

    (2), (4) - call (1) (3) respectively, with S = G * S (1) - equivalent to calling eve::slide_left(x, eve::zero(eve::as(x))); (3) - slide_left [abcd], [efgh], index<1> ==> [bcde]

Return value shuffled register

Example

int
main()
{
// in progress
}

◆ swap_adjacent

auto eve::swap_adjacent = _::named_shuffle_1<swap_adjacent_t> {}
inlineconstexpr

a named shuffle that goes all pairs of elements and swaps them: [0, 1, 2, 3] => [1, 0, 3, 2]

Defined in Header

#include <eve/module/core.hpp>

Can apply an opteration for group of elements instead of elements. Group size has to be 0 < G < T::size()

template<simd_value T, std::ptrdiff_t G>
T swap_adjacent(T x, fixed<G>) // (1)
template<simd_value T>
T swap_adjacent(T x) // (2)
constexpr auto swap_adjacent
a named shuffle that goes all pairs of elements and swaps them: [0, 1, 2, 3] => [1,...
Definition swap_adjacent.hpp:117

Parameters

  • x - simd_value to shuffle
  • G - (optional) - number of elements to treat as one.

Return value

Return x where groups of contiguous G elements are swapped.

Example

#include <eve/module/core.hpp>
#include <tts/tts.hpp>
int main()
{
w_t x {0, 1, 2, 3};
TTS_EXPECT( eve::all( w_t{1, 0, 3, 2} == eve::swap_adjacent(x)) );
TTS_EXPECT( eve::all( w_t{1, 0, 3, 2} == eve::swap_adjacent(x, eve::lane<1>)) );
TTS_EXPECT( eve::all( w_t{2, 3, 0, 1} == eve::swap_adjacent(x, eve::lane<2>)) );
// lane<0> and lane<4> are not OK.
}