E.V.E
v2022.03.00

◆ shr

eve::shr = {}
inlineconstexpr

Computes the arithmetic right shift operation.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::real_value T , integral_value N >
T shr(T x, N n) noexcept;
}
constexpr callable_shr_ shr
Computes the arithmetic right shift operation.
Definition: shr.hpp:105
Definition: all_of.hpp:22

Parameters

Return value

The elementwise arithmetic right shift of the first parameter by the second one is returned.

The call shr(x, n) is equivalent to x << n if x is an [simd value](eve::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.

Note
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.

Example

#include <eve/module/core.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 constant .
Definition: pi.hpp:49
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Masked Call

    The call eve::shr[mask](x, ...) provides a masked version of shr which is equivalent to if_else(mask, shr(x, ...), x)

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    using iT = std::int32_t;
    using uiT = std::uint32_t;
    using wide_it = eve::wide<iT, eve::fixed<4>>;
    using wide_uit = eve::wide<uiT, eve::fixed<4>>;
    int main()
    {
    wide_uit pi = {100, 200, 2, 3};
    wide_it qi = {1, -2, 3, -1};
    std::cout << "---- simd" << '\n'
    << "<- pi = " << pi << '\n'
    << "<- qi = " << qi << '\n'
    << "-> shr[pi!= 200](pi, qi) = " << eve::shr[pi!= 200](pi, qi) << '\n';
    return 0;
    }