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

Detailed Description

Operations providing a scalar value from SIMD vectors

Variables

constexpr auto eve::all = functor<all_t>
 Computes a bool value which is true if and only if every elements of x evaluates to true.
constexpr auto eve::any = functor<any_t>
 Computes a bool value which is true if and only if one or more elements of x evaluates to true.
constexpr auto eve::count_true = functor<count_true_t>
 Computes the number of elements of the input which evaluates to true.
constexpr auto eve::first_true = functor<first_true_t>
 Returns the index of the first element in the input which evaluates to true, if there is one.
constexpr auto eve::last_true = functor<last_true_t>
 Returns the index of the last element in the input which evaluates to true, if there is one.
constexpr auto eve::maximum = functor<maximum_t>
 Computes the maximal value in a simd vector or valmin if the input is fully masked.
constexpr auto eve::minimum = functor<minimum_t>
 Computes the minimal value in a simd vector or majorant if the input is fully masked.
constexpr auto eve::none = functor<none_t>
 Computes a bool value which is true if and only if all elements of x evaluate to false.
constexpr auto eve::reduce = functor<reduce_t>
 Computes the reduction of a SIMD value using a given callable. Performs an horizontal sum by default.

Variable Documentation

◆ all

auto eve::all = functor<all_t>
inlineconstexpr

Computes a bool value which is true if and only if every elements of x evaluates to true.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
template <relaxed_logical_value L>
bool all(L x) requires !Options::contains(splat) noexcept; // 1
template <logical_simd_value L>
bool all(top_bits<L> t) requires !Options::contains(splat) noexcept; // 1
// Splat overload
template <logical_simd_value L>
L all[splat](L x) requires Options::contains(splat) noexcept; // 2
// Lanes masking
bool all[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
bool all[logical_value auto m](/* any of the above overloads */) noexcept; // 3
}
Specifies that a type is a Conditional Expression.
Definition conditional.hpp:28
The concept logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition value.hpp:134
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
EVE Main Namespace.
Definition abi.hpp:19
The cheapest to get bitset for simd logical.
Definition top_bits.hpp:80

Parameters

Return value

  1. A bool value which is true if and only if every elements of x evaluates to true.
  2. The result of the reduction is splatted across every lane of the output.
  3. Same as the above but the masked lanes are ignored during the operation.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> all(wu0 <= maximum(wu0)/2) = " << eve::all(wu0 <= eve::maximum(wu0)/2) << "\n";
std::cout << "-> all[ignore_last(2)](wu0 <= maximum(wu0)/2) = " << eve::all[eve::ignore_last(2)](wu0 <= eve::maximum(wu0)/2) << "\n";
}
constexpr auto maximum
Computes the maximal value in a simd vector or valmin if the input is fully masked.
Definition maximum.hpp:83
Conditional expression ignoring the k last lanes from a eve::simd_value.
Definition conditional.hpp:361
Wrapper for SIMD registers.
Definition wide.hpp:94

◆ any

auto eve::any = functor<any_t>
inlineconstexpr

Computes a bool value which is true if and only if one or more elements of x evaluates to true.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
template <relaxed_logical_value T>
bool any(T x) requires !Options::contains(splat) noexcept; // 1
template <logical_simd_value T>
bool any(top_bits<T> t) requires !Options::contains(splat) noexcept; // 1
// Splat overload
template <logical_simd_value T>
T any[splat](T x) requires Options::contains(splat) noexcept; // 2
// Lanes masking
bool any[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
bool any[logical_value auto m](/* any of the above overloads */) noexcept; // 3
}
constexpr auto any
Computes a bool value which is true if and only if one or more elements of x evaluates to true.
Definition any.hpp:97

Parameters

Return value

  1. A bool value which is true if and only if one or more elements of x evaluates to true.
  2. The result of the reduction is splatted across every lane of the output.
  3. Same as the above but the masked lanes are ignored during the operation.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> any(wu0 <= maximum(wu0)/2) = " << eve::any(wu0 <= eve::maximum(wu0)/2) << "\n";
std::cout << "-> any[ignore_last(2)](wu0 <= maximum(wu0)/2) = " << eve::any[eve::ignore_last(2)](wu0 <= eve::maximum(wu0)/2) << "\n";
}

◆ count_true

auto eve::count_true = functor<count_true_t>
inlineconstexpr

Computes the number of elements of the input which evaluates to true.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
template<relaxed_logical_value L>
std::ptrdiff_t count_true(L x) noexcept; // 1
template<relaxed_logical_value L>
std::ptrdiff_t count_true(top_bits<L> t) noexcept; // 1
// Lanes masking
std::ptrdiff_t count_true[conditional_expr auto c](/* any of the above overloads */) noexcept; // 2
std::ptrdiff_t count_true[logical_value auto m](/* any of the above overloads */) noexcept; // 2
}
constexpr auto count_true
Computes the number of elements of the input which evaluates to true.
Definition count_true.hpp:83

Parameters

Return value

  1. The number of elements in x which evaluates to true. Scalar values are treated as one element.
  2. The masked version which return the number of non-masked true elements.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> count_true(wu0 <= maximum(wu0)/2) = " << eve::count_true(wu0 <= eve::maximum(wu0)/2) << "\n";
std::cout << "-> count_true[ignore_last(2)](wu0 <= maximum(wu0)/2) = " << eve::count_true[eve::ignore_last(2)](wu0 <= eve::maximum(wu0)/2) << "\n";
}

Semantic Modifiers

◆ first_true

auto eve::first_true = functor<first_true_t>
inlineconstexpr

Returns the index of the first element in the input which evaluates to true, if there is one.

#include <eve/module/core.hpp>

Callable Signatures

template <relaxed_logical_value L>
std::optional<std::ptrdiff_t> first_true(L m) noexcept; // 1
template <logical_simd_value L>
std::optional<std::ptrdiff_t> first_true(top_bits<L> m) noexcept; // 1
// lane masking
std::optional<std::ptrdiff_t> first_true[conditional_expr auto c](/* any of the above */) noexcept; // 2
std::optional<std::ptrdiff_t> first_true[logical_value auto c](/* any of the above */) noexcept; // 2
constexpr auto first_true
Returns the index of the first element in the input which evaluates to true, if there is one.
Definition first_true.hpp:83

Parameters

Return value

  1. An std::optional containing the index of the first element which evaluates to true, std::nullopt if there are none.
  2. Same as 1. but masked elements are ignored during the search.

Should you check for any?

The function is considering the case when nothing is set to be likely, checking for eve::any before hand is not going to be helpful. At the moment there isn't a function that would do it otherwise.

What if I know there is a match?

We would recommend eve::first_true(m) - this is likely to trigger compiler optimizations, based on it being UB otherwise.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> first_true(wu0 >= maximum(wu0)/2) = " << *eve::first_true(wu0 >= eve::maximum(wu0)/2) << "\n";
std::cout << "-> first_true[ignore_first(4)](wu0 <= maximum(wu0)/2 > 1u) = " << *eve::first_true[eve::ignore_first(4)](wu0 > 1u) << "\n";
}
Conditional expression ignoring the k first lanes from a eve::simd_value.
Definition conditional.hpp:516

◆ last_true

auto eve::last_true = functor<last_true_t>
inlineconstexpr

Returns the index of the last element in the input which evaluates to true, if there is one.

#include <eve/module/core.hpp>

Callable Signatures

template <relaxed_logical_value L>
std::optional<std::ptrdiff_t> last_true(L m) noexcept; // 1
template <logical_simd_value L>
std::optional<std::ptrdiff_t> last_true(top_bits<L> m) noexcept; // 1
// lane masking
std::optional<std::ptrdiff_t> last_true[conditional_expr auto c](/* any of the above */) noexcept; // 2
std::optional<std::ptrdiff_t> last_true[logical_value auto c](/* any of the above */) noexcept; // 2
constexpr auto last_true
Returns the index of the last element in the input which evaluates to true, if there is one.
Definition last_true.hpp:84

Parameters

Return value

  1. An std::optional containing the index of the last element which evaluates to true, std::nullopt if there are none.
  2. Same as 1. but masked elements are ignored during the search.

Should you check for any?

The function is considering the case when nothing is set to be likely, checking for eve::any before hand is not going to be helpful. At the moment there isn't a function that would do otherwise.

What if I know there is a match?

We would recommend eve::last_true(m) - this is likely to trigger compiler optimizations, based on it being UB otherwise.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <optional>
void show(char const* what, std::optional<std::ptrdiff_t> r)
{
std::cout << what;
if( r ) std::cout << *r << "\n"; else std::cout << "nullopt\n";
}
int main()
{
eve::wide<std::int32_t, eve::fixed<8>> w = {1, 0, 3, 0, 5, 0, 0, 8};
auto m = w > 0;
std::cout << "<- w = " << w << "\n";
std::cout << "<- m = (w > 0) = " << m << "\n";
show("-> last_true(m) = ", eve::last_true(m));
show("-> last_true[eve::ignore_last(2)](m) = ", eve::last_true[eve::ignore_last(2)](m));
show("-> last_true(w > 100) = ", eve::last_true(w > 100));
}

◆ maximum

auto eve::maximum = functor<maximum_t>
inlineconstexpr

Computes the maximal value in a simd vector or valmin if the input is fully masked.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
template <arithmetic_value T>
element_type_t<T> maximum(T x) requires(!O::contains(splat)) noexcept; // 1
template <arithmetic_simd_value T>
T maximum(T x) requires(O::contains(splat)) noexcept; // 2
// Lanes masking
auto maximum[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
auto maximum[logical_value auto m](/* any of the above overloads */) noexcept; // 3
}

Parameters

Return value

  1. The maximal value of all lanes. Scalar values are returned as is.
  2. The maximal value of all lanes splatted across every lane of the input.
  3. Same as the above but the masked lanes are ignored during the operation.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> maximum(wf0) = " << eve::maximum(wf0) << "\n";
std::cout << "-> maximum[ignore_last(2)](wf0) = " << eve::maximum[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> maximum[wf0 != -2.0f](wf0) = " << eve::maximum[wf0 != -2.0f](wf0) << "\n";
std::cout << "-> maximum(wu0) = " << eve::maximum(wu0) << "\n";
std::cout << "-> maximum[ignore_last(2)](wu0) = " << eve::maximum[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> maximum[wu0 != 2u](wu0) = " << eve::maximum[wu0 != 2u](wu0) << "\n";
std::cout << "-> maximum(wi0) = " << eve::maximum(wi0) << "\n";
std::cout << "-> maximum[ignore_last(2)](wi0) = " << eve::maximum[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> maximum[wi0 != -2](wi0) = " << eve::maximum[wi0 != -2](wi0) << "\n";
}

◆ minimum

auto eve::minimum = functor<minimum_t>
inlineconstexpr

Computes the minimal value in a simd vector or majorant if the input is fully masked.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
template<arithmetic_value T>
element_type_t<T> minimum(T v) requires(!O::contains(splat)) noexcept; // 1
template<arithmetic_simd_value T>
T minimum(T v) requires(O::contains(splat)) noexcept; // 2
// Lanes masking
auto minimum[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 3
auto minimum[logical_value auto m](/*any of the above overloads*/) noexcept; // 3
}
constexpr auto minimum
Computes the minimal value in a simd vector or majorant if the input is fully masked.
Definition minimum.hpp:83

Parameter

Return value

  1. The minimal value of all lanes. Scalar values are returned as is.
  2. The minimal value of all lanes splatted across every lane of said input.
  3. Same as the above but the masked lanes are ignored during the operation.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> minimum(wf0) = " << eve::minimum(wf0) << "\n";
std::cout << "-> minimum[ignore_last(2)](wf0) = " << eve::minimum[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> minimum[wf0 != -2.0f](wf0) = " << eve::minimum[wf0 != -2.0f](wf0) << "\n";
std::cout << "-> minimum(wu0) = " << eve::minimum(wu0) << "\n";
std::cout << "-> minimum[ignore_last(2)](wu0) = " << eve::minimum[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> minimum[wu0 != 2u](wu0) = " << eve::minimum[wu0 != 2u](wu0) << "\n";
std::cout << "-> minimum(wi0) = " << eve::minimum(wi0) << "\n";
std::cout << "-> minimum[ignore_last(2)](wi0) = " << eve::minimum[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> minimum[wi0 != -2](wi0) = " << eve::minimum[wi0 != -2](wi0) << "\n";
}

◆ none

auto eve::none = functor<none_t>
inlineconstexpr

Computes a bool value which is true if and only if all elements of x evaluate to false.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
template <relaxed_logical_value T>
bool none(T v) requires !Options::contains(splat) noexcept; // 1
template<logical_simd_value T>
bool none(top_bits<T> t) requires !Options::contains(splat) noexcept; // 1
// Splat overload
template<logical_simd_value T>
bool none(T t) requires Options::contains(splat) noexcept; // 2
// Lanes masking
bool none[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
bool none[logical_value auto m](/* any of the above overloads */) noexcept; // 3
}
constexpr auto none
Computes a bool value which is true if and only if all elements of x evaluate to false.
Definition none.hpp:95

Parameters

Return value

  1. A bool value which is true if and only if all elements of x evaluates to false.
  2. The result of the reduction is splatted across every lane of the output.
  3. Same as the above but the masked lanes are ignored during the operation.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> none(wu0 <= maximum(wu0)/2) = " << eve::none(wu0 <= eve::maximum(wu0)/2) << "\n";
std::cout << "-> none[ignore_last(2)](wu0 <= maximum(wu0)/2) = " << eve::none[eve::ignore_last(2)](wu0 <= eve::maximum(wu0)/2) << "\n";
}

◆ reduce

auto eve::reduce = functor<reduce_t>
inlineconstexpr

Computes the reduction of a SIMD value using a given callable. Performs an horizontal sum by default.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads (non-splat)
template <value T, typename Callable>
element_type_t<T> reduce(T x, Callable f) requires(!O::contains(splat)) noexcept; // 1
template <value T>
element_type_t<T> reduce(T x) requires(!O::contains(splat)) noexcept; // 1
// Splat overloads
template <simd_value T, typename Callable>
T reduce(T x, Callable f) requires(O::contains(splat)) noexcept; // 2
template <simd_value T>
T reduce(T x) requires(O::contains(splat)) noexcept; // 2
// Lanes masking
auto reduce[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
auto reduce[logical_value auto m](/* any of the above overloads */) noexcept; // 3
}
constexpr auto reduce
Computes the reduction of a SIMD value using a given callable. Performs an horizontal sum by default.
Definition reduce.hpp:156

Parameters

Return value

  1. The result of reducing all lanes with the given callable (or addition by default). Scalar values are returned as is.
  2. The reduction result splatted across every lane of the input.
  3. Same as any of the above but the masked lanes are ignored during the operation.

Example

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
wide_ft pf = {0.5f,1.5f,2.5f,3.f};
wide_it qi = {2,3,4,5};
auto const summ = [](auto a, auto b) { return a+b; };
auto const prod = [](auto a, auto b) { return a*b; };
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> reduce(pf,summ) = " << eve::reduce(pf, summ) << '\n'
<< "<- qi = " << qi << '\n'
<< "-> reduce(qi,prod) = " << eve::reduce(qi, prod) << '\n';
std::cout << "---- simd with splat" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> reduce[splat](pf,summ) = " << eve::reduce[eve::splat](pf, summ) << '\n'
<< "<- qi = " << qi << '\n'
<< "-> reduce[splat](qi,prod) = " << eve::reduce[eve::splat](qi, prod) << '\n';
return 0;
}
constexpr prod_t prod