E.V.E  0.1-beta

◆ shr

eve::shr = {}
inlineconstexpr

Callable object computing the arithmetic right shift operation.

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

Members Functions

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

template< value T, integral_real_value U > auto operator()( T x, U n ) const noexcept
requires bit_compatible< T, U >;

Parameters

x: value.

n: integral value.

Return value

Computes the elementwise arithmetic right shift of the first parameter by the second one.

the call shr(x, n) is equivalent to x << n if x is an simd value.

The types must share the same cardinal or be scalar and if N is the size in bits of the element type of T, all elements of n must belong to the interval: [0, N[ or the result is undefined.

Warning
Although the infix notation with >> is supported, the >> operator on standard scalar types is the original one and so can not be overloaded on standard floating parameters due to C++ limitations.

auto operator[]( conditional_expression auto cond ) const noexcept;

Higher-order function generating a masked version of eve::shr

Parameters

cond : conditional expression

Return value

A Callable object so that the expression shr[cond](x, ...) is equivalent to if_else(cond,shr(x, ...),x)


Supported decorators

no decorators are supported

Example

See it live on Compiler Explorer

#include <eve/function/shr.hpp>
#include <eve/wide.hpp>
#include <iostream>
using iT = std::int32_t;
using wide_it = eve::wide<iT, eve::fixed<4>>;
int main()
{
wide_it pi = {100, 200, -2, 3};
wide_it qi = {1, 2, 3, 2};
std::cout << "---- simd" << '\n'
<< "<- pi = " << pi << '\n'
<< "<- qi = " << qi << '\n'
<< "-> eve::shr(pi, qi) = " << eve::shr(pi, qi) << '\n';
iT xi = 2, mxi = -2, yi = 3;
std::cout << "---- scalar" << '\n'
<< "<- xi = " << xi << '\n'
<< "<- mxi = " << mxi << '\n'
<< "<- yi = " << yi << '\n'
<< "-> eve::shr(xi, yi) = " << eve::shr(xi, yi) << '\n'
<< "-> eve::shr(mxi, yi) = " << eve::shr(mxi, yi) << '\n';
return 0;
}
constexpr callable_pi_ pi
Callable object computing the value.
Definition: pi.hpp:54
constexpr callable_shr_ shr
Callable object computing the arithmetic right shift operation.
Definition: shr.hpp:104
Wrapper for SIMD registers.
Definition: wide.hpp:65