Namespaces
Variants

std::clmul

From cppreference.com
 
 
 
Defined in header <numeric>
template< class T >
constexpr T clmul( T x, T y ) noexcept;
(since C++29)

Computes the lower bits of the carry-less product of the unsigned integers x and y.

Parameters

x - the first factor
y - the second factor
Type requirements
T - must be an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type) in order to participate in overload resolution.

Return value

The carry-less product of x and y.

Notes

Feature-test macro Value Std Feature
__cpp_lib_clmul 202611L (C++29) std::clmul, std::widening_clmul, and std::wide_result

Possible implementation

template<typename T, typename... U>
concept neither = (!std::same_as<T, U> && ...);

template<std::unsigned_integral T>
    requires neither<T, bool, char, char8_t, char16_t, char32_t, wchar_t>
constexpr T clmul(const T x, const T y) noexcept
{
    T result = 0;
    for (int i = 0; i != std::numeric_limits<T>::digits; ++i)
        result ^= x * (y & (T{1} << i));
    return result;
}

Example

See also

computes the widening carry-less product
(function template) [edit]