Intel xvec
Experimental C++ simd class library
Loading...
Searching...
No Matches
std_numeric.hpp
1//===----------------------------------------------------------------------===//
2//
3// Copyright (C) 2021 Intel Corporation
4//
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include <concepts>
12#include <type_traits>
13
14#include <xvec/detail/config.hpp>
15#include <xvec/detail/utilities.hpp>
16
17namespace _XVEC_NAMESPACE::simd
18{
28
34template<vec_integral _Vp> constexpr _Vp saturating_add(const _Vp& lhs, const _Vp& rhs) noexcept {
35 if (std::is_constant_evaluated())
36 return _Vp([&](auto i) { return detail::saturating_add(lhs[i], rhs[i]); });
37 else
38 return detail::saturating_add(target, lhs, rhs);
39}
40
46template<vec_integral _Vp> constexpr _Vp saturating_sub(const _Vp& lhs, const _Vp& rhs) noexcept {
47 if (std::is_constant_evaluated())
48 return _Vp([&](auto i) { return detail::saturating_sub(lhs[i], rhs[i]); });
49 else
50 return detail::saturating_sub(target, lhs, rhs);
51}
52
58template<vec_integral _Vp> constexpr _Vp saturating_mul(const _Vp& lhs, const _Vp& rhs) noexcept
59 { return _Vp([&](auto i) { return detail::saturating_mul(lhs[i], rhs[i]); }); }
60
66template<vec_integral _Vp> constexpr _Vp saturating_div(const _Vp& lhs, const _Vp& rhs) noexcept
67 { return _Vp([&](auto i) { return detail::saturating_div(lhs[i], rhs[i]); }); }
68
76template<std::integral _Up, vec_integral _Vp>
77constexpr rebind_t<_Up, _Vp> saturating_cast(const _Vp& v) noexcept {
78 if (std::is_constant_evaluated())
79 return rebind_t<_Up, _Vp>([&](auto i) { return detail::saturating_cast<_Up>(v[i]); });
80 else
81 return detail::saturating_cast<_Up>(target, v);
82}
83
85
86} // namespace _XVEC_NAMESPACE::simd
constexpr rebind_t< _Up, _Vp > saturating_cast(const _Vp &v) noexcept
Compute a basic_vec where every element is converted to the new type, or if the value can't be repres...
Definition std_numeric.hpp:77
constexpr _Vp saturating_div(const _Vp &lhs, const _Vp &rhs) noexcept
Compute the saturated division of each respective pair of SIMD elements.
Definition std_numeric.hpp:66
constexpr _Vp saturating_mul(const _Vp &lhs, const _Vp &rhs) noexcept
Compute the saturated multiplication of each respective pair of SIMD elements.
Definition std_numeric.hpp:58
constexpr _Vp saturating_add(const _Vp &lhs, const _Vp &rhs) noexcept
Compute the saturated addition of each respective pair of SIMD elements.
Definition std_numeric.hpp:34
constexpr _Vp saturating_sub(const _Vp &lhs, const _Vp &rhs) noexcept
Compute the saturated subtraction of each respective pair of SIMD elements.
Definition std_numeric.hpp:46
constexpr T saturating_sub(T lhs, T rhs) noexcept
Subtract two integers, clamping an unrepresentable mathematical result.
Definition compat.hpp:90
constexpr T saturating_div(T lhs, T rhs) noexcept
Divide two integers, clamping an unrepresentable mathematical result.
Definition compat.hpp:138
constexpr T saturating_add(T lhs, T rhs) noexcept
Add two integers, clamping an unrepresentable mathematical result.
Definition compat.hpp:68
constexpr To saturating_cast(From value) noexcept
Definition compat.hpp:50
constexpr T saturating_mul(T lhs, T rhs) noexcept
Multiply two integers, clamping an unrepresentable mathematical result.
Definition compat.hpp:114