13 #ifndef MLIR_EXECUTIONENGINE_SPARSETENSOR_ARITHMETICUTILS_H
14 #define MLIR_EXECUTIONENGINE_SPARSETENSOR_ARITHMETICUTILS_H
19 #include <type_traits>
22 namespace sparse_tensor {
43 template <
typename T,
typename U>
45 using UT = std::make_unsigned_t<T>;
46 using UU = std::make_unsigned_t<U>;
47 if constexpr (std::is_signed_v<T> == std::is_signed_v<U>)
49 else if constexpr (std::is_signed_v<T>)
50 return t < 0 ? false : static_cast<UT>(t) == u;
52 return u < 0 ? false : t == static_cast<UU>(u);
55 template <
typename T,
typename U>
60 template <
typename T,
typename U>
62 using UT = std::make_unsigned_t<T>;
63 using UU = std::make_unsigned_t<U>;
64 if constexpr (std::is_signed_v<T> == std::is_signed_v<U>)
66 else if constexpr (std::is_signed_v<T>)
67 return t < 0 ? true : static_cast<UT>(t) < u;
69 return u < 0 ? false : t < static_cast<UU>(u);
72 template <
typename T,
typename U>
77 template <
typename T,
typename U>
82 template <
typename T,
typename U>
105 template <
typename To,
typename From>
110 if constexpr (!
safelyGE(minFrom, minTo))
111 assert(
safelyGE(x, minTo) &&
"cast would underflow");
115 if constexpr (!
safelyLE(maxFrom, maxTo))
116 assert(
safelyLE(x, maxTo) &&
"cast would overflow");
118 return static_cast<To
>(x);
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
constexpr bool safelyEQ(T t, U u) noexcept
constexpr bool safelyGE(T t, U u) noexcept
constexpr bool safelyGT(T t, U u) noexcept
To checkOverflowCast(From x)
A version of static_cast<To> which checks for overflow/underflow.
uint64_t checkedMul(uint64_t lhs, uint64_t rhs)
A version of operator* on uint64_t which guards against overflows (when assertions are enabled).
constexpr bool safelyLE(T t, U u) noexcept
constexpr bool safelyNE(T t, U u) noexcept
constexpr bool safelyLT(T t, U u) noexcept
Include the generated interface declarations.