13#ifndef MLIR_EXECUTIONENGINE_SPARSETENSOR_ARITHMETICUTILS_H
14#define MLIR_EXECUTIONENGINE_SPARSETENSOR_ARITHMETICUTILS_H
43template <
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);
55template <
typename T,
typename U>
60template <
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);
72template <
typename T,
typename U>
77template <
typename T,
typename U>
82template <
typename T,
typename U>
105template <
typename To,
typename From>
108 constexpr To minTo = std::numeric_limits<To>::min();
109 constexpr From minFrom = std::numeric_limits<From>::min();
110 if constexpr (!
safelyGE(minFrom, minTo))
111 assert(
safelyGE(x, minTo) &&
"cast would underflow");
113 constexpr To maxTo = std::numeric_limits<To>::max();
114 constexpr From maxFrom = std::numeric_limits<From>::max();
115 if constexpr (!
safelyLE(maxFrom, maxTo))
116 assert(
safelyLE(x, maxTo) &&
"cast would overflow");
118 return static_cast<To
>(x);
124 assert((
lhs == 0 ||
rhs <= std::numeric_limits<uint64_t>::max() /
lhs) &&
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.