E.V.E  0.1-beta

◆ bit_select

eve::bit_select = {}
inlineconstexpr

Callable object computing the bit_select operation.

Required header: #include <eve/function/bit_select.hpp>

Members Functions

Member Effect
operator() the bit_select operation
operator[] Construct a conditional version of current function object

template< value T, value U > auto operator()( T m, U x, U y ) const noexcept
requires compatible< T,U>;

Parameters

m: mask value

y, z: selection real values

Return value

The types T and U must be bit_compatible and the call

r==bit_select(m,x,y)
constexpr callable_bit_select_ bit_select
Callable object computing the bit_select operation.
Definition: bit_select.hpp:81

is semantically equivalent to

r = bit_or(bit_and(x, m), bit_andnot(y, m))
constexpr callable_bit_andnot_ bit_andnot
Callable object computing the bitwise ANDNOT operation.
Definition: bit_andnot.hpp:81
constexpr callable_bit_and_ bit_and
Callable object computing the bitwise AND operation.
Definition: bit_and.hpp:79
constexpr callable_bit_or_ bit_or
Callable object computing the bitwise OR operation.
Definition: bit_or.hpp:79

In a short way (omitting casting details to bring all bit sizes of the parameters equal), it means that the result is composed of the bits of x for which the corresponding bit of m is set and the bits of y for which the corresponding bit of m is unset.

If T or U is an simd value, the type of the result has the element type of T and the maximum of the cardinals of M and T, otherwise it is T.


Supported decorators

no decorators are supported

Example

See it live on Compiler Explorer

#include <eve/function/bit_select.hpp>
#include <eve/constant/eps.hpp>
#include <eve/constant/valmax.hpp>
#include <eve/wide.hpp>
#include <iostream>
#include <iomanip>
int main()
{
wide_t pi = {2, -3, 0, 1 << 10};
wide_t qi = {3, -2, 4, 2 };
wide_t mi = {0, -1, 1, ~0u << 8};
std::cout << "---- simd" << '\n'
<< " <- mi = " << mi << '\n'
<< " <- pi = " << pi << '\n'
<< " <- qi = " << qi << '\n'
<< " -> bit_select(mi, pi, qi) = " << eve::bit_select(mi, pi, qi) << '\n';
std::cout << "---- scalar" << std::setprecision(10) << '\n'
<< " -> bit_select(32767, 1, 32768 ) = " << eve::bit_select(32767, 1, 32768) << '\n';
return 0;
}
constexpr callable_pi_ pi
Callable object computing the value.
Definition: pi.hpp:54
Wrapper for SIMD registers.
Definition: wide.hpp:65