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

Detailed Description

Functions

template<logical_value Mask, value Value>
void eve::swap_if (Mask const &mask, Value &lhs, Value &rhs) noexcept
 Conditional swap.

Variables

constexpr auto eve::if_else = functor<if_else_t>
 Select value based on conditional mask or values.
constexpr auto eve::logical_and = functor<logical_and_t>
 strict_elementwise_callable computing the logical AND of its arguments.
constexpr auto eve::logical_andnot = functor<logical_andnot_t>
 Computes the logical ANDNOT of its arguments.
constexpr auto eve::logical_not = functor<logical_not_t>
 Computes the logical NOT of its argument.
constexpr auto eve::logical_notand = functor<logical_notand_t>
 Computes the logical NOTAND of its arguments.
constexpr auto eve::logical_notor = functor<logical_notor_t>
 Computes the logical NOTOR of its arguments.
constexpr auto eve::logical_or = functor<logical_or_t>
 Computes the logical OR of its arguments.
constexpr auto eve::logical_ornot = functor<logical_ornot_t>
 Computes the logical ORNOT of its arguments.
constexpr auto eve::logical_xor = functor<logical_xor_t>
 Computes the logical XOR of its arguments.
constexpr auto eve::replace_ignored = functor<replace_ignored_t>
 A small helper to replace ignored values.

Function Documentation

◆ swap_if()

template<logical_value Mask, value Value>
void eve::swap_if ( Mask const & mask,
Value & lhs,
Value & rhs )
noexcept

Conditional swap.

Required header: #include <eve/module/core.hpp>

Swaps the SIMD values lhs and rhs wherever mask evaluates to true.

Parameters
maskMask to apply over the swap operation.
lhs,rhsValues to swap.

Example

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
eve::wide<float, eve::fixed<4>> a = {1.2f, 3.4f, 5.6f, 7.8f};
eve::wide<float, eve::fixed<4>> b = {0.1f,1e-2f,1e-3f,1e-4f};
std::cout << "Before swap_if(a < 4.f,a,b)\n"
<< "<- a = " << a << '\n'
<< "<- b = " << b << '\n'
<< "<- a < 4.f = " << (a < 4.f) << "\n\n";
eve::swap_if(a < 4.f,a,b);
std::cout << "After swap_if(a < 4.f,a,b)\n"
<< "-> a = " << a << '\n'
<< "-> b = " << b << '\n';
return 0;
}
void swap_if(Mask const &mask, Value &lhs, Value &rhs) noexcept
Conditional swap.
Definition swap_if.hpp:39
Wrapper for SIMD registers.
Definition wide.hpp:94

Variable Documentation

◆ if_else

auto eve::if_else = functor<if_else_t>
inlineconstexpr

Select value based on conditional mask or values.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template<eve::value U, eve::value V>
constexpr auto if_else(bool mask, U t, V f) noexcept;
template<eve::value M, eve::value U, eve::value V>
constexpr auto if_else(M mask, U t, V f) noexcept;
template<eve::value M, eve::generator U, eve::value V>
constexpr auto if_else(M mask, U t, V f) noexcept;
template<eve::value M, eve::value U, eve::generator V>
constexpr auto if_else(M mask, U t, V f) noexcept;
template<eve::conditional_expr C, eve::value U, eve::value V >
constexpr auto if_else(C mask, U t, V f) noexcept;
template<eve::conditional_expr C, eve::generator U, eve::value V >
constexpr auto if_else(C mask, U t, V f) noexcept;
template<eve::conditional_expr C, eve::value U, eve::generator V >
constexpr auto if_else(C mask, U t, V f) noexcept;
}
constexpr auto if_else
Select value based on conditional mask or values.
Definition if_else.hpp:197
EVE Main Namespace.
Definition abi.hpp:19

Parameters

  • mask: logical value or condition to use as mask.
  • t: Value or constant to use where mask evaluates to true.
  • f: Value or constant to use where mask evaluates to false.

Return value

The call if_else(mask, t, f) performs an elementwise selection between the elements of t and f according to the value of the elements of mask.

Possible optimizations

The following calls, where t and f are values, are optimized so the constant are not evaluated:

In addition, the following calls, where t and f are unsigned values, are optimized so the constant are not evaluated:

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 wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wf2{0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wi2{0, 1, 2 ,3, 4, 5, 6, 7};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
eve::wide wu2{0u, 2u, 4u, 6u, 1u, 3u, 5u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wf2 = " << wf2 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wi2 = " << wi2 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "<- wu2 = " << wu2 << "\n";
std::cout << "-> if_else(wf0, wf1, wf2) = " << eve::if_else(wf0, wf1, wf2) << "\n";
std::cout << "-> if_else(wu0, wu1, wu2) = " << eve::if_else(wu0, wu1, wu2) << "\n";
std::cout << "-> if_else(wi0, wi1, wi2) = " << eve::if_else(wi0, wi1, wi2) << "\n";
}

◆ logical_and

auto eve::logical_and = functor<logical_and_t>
inlineconstexpr

strict_elementwise_callable computing the logical AND of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto logical_and(auto logical_value x, auto logical_value y) noexcept;
}
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 logical_and
strict_elementwise_callable computing the logical AND of its arguments.
Definition logical_and.hpp:70

Parameters

Return value

Returns the logical AND of the two parameters following the logical operations semantic.

The call logical_and(x, y) is semantically equivalent to x && y if x or y is an simd value and does not shortcut.

Note
Although the infix notation with && is supported, the && operator on standard scalar types is the original one and so will return bool instead of eve::logical_value.

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 << "-> logical_and(wu0 <= maximum(wu0)/2, wu0 >= maximum(wu0)/2) = " << eve::logical_and(wu0 <= eve::maximum(wu0)/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

◆ logical_andnot

auto eve::logical_andnot = functor<logical_andnot_t>
inlineconstexpr

Computes the logical ANDNOT of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto logical_andnot(auto logical_value x, auto logical_value y) noexcept;
}
constexpr auto logical_andnot
Computes the logical ANDNOT of its arguments.
Definition logical_andnot.hpp:70

Parameters

Return value

Returns the logical ANDNOT of the two parameters following the logical operations semantic.

The call logical_andnot(x, y) is semantically equivalent to x && !y if x or y is an simd value and does not shortcut.

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 << "-> logical_andnot(wu0 <= maximum(wu0)/2, wu0 >= maximum(wu0)/2) = " << eve::logical_andnot(wu0 <= eve::maximum(wu0)/2, wu0 >= eve::maximum(wu0)/2) << "\n";
}

◆ logical_not

auto eve::logical_not = functor<logical_not_t>
inlineconstexpr

Computes the logical NOT of its argument.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto logical_not(auto logical_value x) noexcept;
}
constexpr auto logical_not
Computes the logical NOT of its argument.
Definition logical_not.hpp:74

Parameters

Return value

The call logical_not(x) is semantically equivalent to is_eqz(x). Infix notation can be used with !x.

Note
Although the infix notation with ! is supported, the ! operator on standard scalar types is the original one and so will return bool instead of eve::logical_value.

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 << "-> logical_not(wu0 <= maximum(wu0)/2) = " << eve::logical_not(wu0 <= eve::maximum(wu0)/2) << "\n";
}

◆ logical_notand

auto eve::logical_notand = functor<logical_notand_t>
inlineconstexpr

Computes the logical NOTAND of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto logical_notand(auto logical_value x, auto logical_value y) noexcept;
}
constexpr auto logical_notand
Computes the logical NOTAND of its arguments.
Definition logical_notand.hpp:68

Parameters

Return value

Returns the logical NOTAND of the two parameters following the logical operations semantic.

The call logical_notand(x, y) is semantically equivalent to !x && y if x or y is an simd value and does not shortcut.

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 << "-> logical_notand(wu0 <= maximum(wu0)/2, wu0 >= maximum(wu0)/2) = " << eve::logical_notand(wu0 <= eve::maximum(wu0)/2, wu0 >= eve::maximum(wu0)/2) << "\n";
}

◆ logical_notor

auto eve::logical_notor = functor<logical_notor_t>
inlineconstexpr

Computes the logical NOTOR of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto logical_notor(auto logical_value x, auto logical_value y) noexcept;
}
constexpr auto logical_notor
Computes the logical NOTOR of its arguments.
Definition logical_notor.hpp:68

Parameters

Return value

Returns the logical NOTOR of the two parameters following the logical operations semantic.

The call logical_notor(x, y) is semantically equivalent to !x || y if x or y is an simd value and does not shortcut.

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 << "-> logical_notor(wu0 <= maximum(wu0)/2, wu0 >= maximum(wu0)/2) = " << eve::logical_notor(wu0 <= eve::maximum(wu0)/2, wu0 >= eve::maximum(wu0)/2) << "\n";
}

◆ logical_or

auto eve::logical_or = functor<logical_or_t>
inlineconstexpr

Computes the logical OR of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto logical_or(auto logical_value x, auto logical_value y) noexcept;
}
constexpr auto logical_or
Computes the logical OR of its arguments.
Definition logical_or.hpp:72

Parameters

Return value

Returns the logical OR of the two parameters following the logical operations semantic.

The call logical_or(x, y) is semantically equivalent to x || y if x or y is an simd value and does not shortcut.

Note
Although the infix notation with || is supported, the || operator on standard scalar types is the original one and so will return bool instead of eve::logical_value.

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 << "-> logical_or(wu0 <= maximum(wu0)/2, wu0 >= maximum(wu0)/2) = " << eve::logical_or(wu0 <= eve::maximum(wu0)/2, wu0 >= eve::maximum(wu0)/2) << "\n";
}

◆ logical_ornot

auto eve::logical_ornot = functor<logical_ornot_t>
inlineconstexpr

Computes the logical ORNOT of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto logical_ornot(auto logical_value x, auto logical_value y) noexcept;
}
constexpr auto logical_ornot
Computes the logical ORNOT of its arguments.
Definition logical_ornot.hpp:68

Parameters

Return value

Returns the logical ORNOT of the two parameters following the logical operations semantic.

The call `logical_ornot(x, y)` is semantically equivalent to `x || !y`
if `x` or  `y` is an  [simd value](@ref eve::simd_value) and  does not shortcut.

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 << "-> logical_ornot(wu0 <= maximum(wu0)/2, wu0 >= maximum(wu0)/2) = " << eve::logical_ornot(wu0 <= eve::maximum(wu0)/2, wu0 >= eve::maximum(wu0)/2) << "\n";
}

◆ logical_xor

auto eve::logical_xor = functor<logical_xor_t>
inlineconstexpr

Computes the logical XOR of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto logical_xor(auto logical_value x, auto logical_value y) noexcept;
}
constexpr auto logical_xor
Computes the logical XOR of its arguments.
Definition logical_xor.hpp:67

Parameters

Return value

Returns the logical XOR of the two parameters following the logical operations semantic.

The call logical_xor(x, y) is semantically equivalent to (x && !y) || (!x && y).

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 << "-> logical_or(wu0 <= maximum(wu0)/2, wu0 >= maximum(wu0)/2) = " << eve::logical_or(wu0 <= eve::maximum(wu0)/2, wu0 >= eve::maximum(wu0)/2) << "\n";
}

◆ replace_ignored

auto eve::replace_ignored = functor<replace_ignored_t>
inlineconstexpr

A small helper to replace ignored values.

Header file

#include <eve/module/core.hpp>

A convenience wrapper around if_else.

Callable Signatures

namespace eve
{
template<simd_value T, relative_conditional_expr Ignore, value Other>
T replace_ignored(T x, Ignore ignore, Other with);
template<simd_value T, relative_conditional_expr Ignore, generator Other>
T replace_ignored(T x, Ignore ignore, Other with);
}
constexpr auto replace_ignored
A small helper to replace ignored values.
Definition replace.hpp:71

Parameters

  • x - main value
  • ignore - selection
  • with - value to replace with

Return value

Same as if_else.