10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_UINT128_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_UINT128_H 19 static const uint64_t value = n;
20 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
operator uint64_t()
const {
return n; }
22 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static_val() { }
25 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static_val(
const T& v) {
31 template <
typename HIGH = u
int64_t,
typename LOW = u
int64_t>
37 template<
typename OTHER_HIGH,
typename OTHER_LOW>
38 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
39 TensorUInt128(
const TensorUInt128<OTHER_HIGH, OTHER_LOW>& other) : high(other.high), low(other.low) {
40 EIGEN_STATIC_ASSERT(
sizeof(OTHER_HIGH) <=
sizeof(HIGH), YOU_MADE_A_PROGRAMMING_MISTAKE);
41 EIGEN_STATIC_ASSERT(
sizeof(OTHER_LOW) <=
sizeof(LOW), YOU_MADE_A_PROGRAMMING_MISTAKE);
44 template<
typename OTHER_HIGH,
typename OTHER_LOW>
45 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
46 TensorUInt128& operator = (
const TensorUInt128<OTHER_HIGH, OTHER_LOW>& other) {
47 EIGEN_STATIC_ASSERT(
sizeof(OTHER_HIGH) <=
sizeof(HIGH), YOU_MADE_A_PROGRAMMING_MISTAKE);
48 EIGEN_STATIC_ASSERT(
sizeof(OTHER_LOW) <=
sizeof(LOW), YOU_MADE_A_PROGRAMMING_MISTAKE);
55 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
56 explicit TensorUInt128(
const T& x) : high(0), low(x) {
57 eigen_assert((
static_cast<typename conditional<sizeof(T) == 8, uint64_t, uint32_t>::type
>(x) <= NumTraits<uint64_t>::highest()));
61 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
62 TensorUInt128(HIGH y, LOW x) : high(y), low(x) { }
64 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
operator LOW()
const {
67 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE LOW lower()
const {
70 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE HIGH upper()
const {
76 template <
typename HL,
typename LL,
typename HR,
typename LR>
77 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
78 bool operator == (
const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs)
80 return (lhs.high == rhs.high) & (lhs.low == rhs.low);
83 template <
typename HL,
typename LL,
typename HR,
typename LR>
84 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
85 bool operator != (
const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs)
87 return (lhs.high != rhs.high) | (lhs.low != rhs.low);
90 template <
typename HL,
typename LL,
typename HR,
typename LR>
91 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
92 bool operator >= (
const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs)
94 if (lhs.high != rhs.high) {
95 return lhs.high > rhs.high;
97 return lhs.low >= rhs.low;
100 template <
typename HL,
typename LL,
typename HR,
typename LR>
101 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
102 bool operator < (const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs)
104 if (lhs.high != rhs.high) {
105 return lhs.high < rhs.high;
107 return lhs.low < rhs.low;
110 template <
typename HL,
typename LL,
typename HR,
typename LR>
111 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
112 TensorUInt128<uint64_t, uint64_t> operator + (
const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs)
114 TensorUInt128<uint64_t, uint64_t> result(lhs.high + rhs.high, lhs.low + rhs.low);
115 if (result.low < rhs.low) {
121 template <
typename HL,
typename LL,
typename HR,
typename LR>
122 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
123 TensorUInt128<uint64_t, uint64_t> operator - (
const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs)
125 TensorUInt128<uint64_t, uint64_t> result(lhs.high - rhs.high, lhs.low - rhs.low);
126 if (result.low > lhs.low) {
133 template <
typename HL,
typename LL,
typename HR,
typename LR>
134 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
135 TensorUInt128<uint64_t, uint64_t> operator * (
const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs)
148 const uint64_t LOW = 0x00000000FFFFFFFFLL;
149 const uint64_t HIGH = 0xFFFFFFFF00000000LL;
151 uint64_t d = lhs.low & LOW;
152 uint64_t c = (lhs.low & HIGH) >> 32LL;
153 uint64_t b = lhs.high & LOW;
154 uint64_t a = (lhs.high & HIGH) >> 32LL;
156 uint64_t h = rhs.low & LOW;
157 uint64_t g = (rhs.low & HIGH) >> 32LL;
158 uint64_t f = rhs.high & LOW;
159 uint64_t e = (rhs.high & HIGH) >> 32LL;
162 uint64_t acc = d * h;
163 uint64_t low = acc & LOW;
167 uint64_t acc2 = acc + c * h;
175 low |= (acc << 32LL);
179 acc2 = (acc >> 32LL) | (carry << 32LL);
194 uint64_t high = acc & LOW;
197 acc2 = (acc >> 32LL) | (carry << 32LL);
203 high |= (acc2 << 32LL);
205 return TensorUInt128<uint64_t, uint64_t>(high, low);
208 template <
typename HL,
typename LL,
typename HR,
typename LR>
209 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
210 TensorUInt128<uint64_t, uint64_t> operator / (
const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs)
212 if (rhs == TensorUInt128<static_val<0>, static_val<1> >(1)) {
213 return TensorUInt128<uint64_t, uint64_t>(lhs.high, lhs.low);
214 }
else if (lhs < rhs) {
215 return TensorUInt128<uint64_t, uint64_t>(0);
218 TensorUInt128<uint64_t, uint64_t> power2(1);
219 TensorUInt128<uint64_t, uint64_t> d(rhs);
220 TensorUInt128<uint64_t, uint64_t> tmp(lhs - d);
224 power2 = power2 + power2;
227 tmp = TensorUInt128<uint64_t, uint64_t>(lhs.high, lhs.low);
228 TensorUInt128<uint64_t, uint64_t> result(0);
229 while (power2 != TensorUInt128<static_val<0>, static_val<0> >(0)) {
232 result = result + power2;
235 power2 = TensorUInt128<uint64_t, uint64_t>(power2.high >> 1, (power2.low >> 1) | (power2.high << 63));
236 d = TensorUInt128<uint64_t, uint64_t>(d.high >> 1, (d.low >> 1) | (d.high << 63));
248 #endif // EIGEN_CXX11_TENSOR_TENSOR_UINT128_H Namespace containing all symbols from the Eigen library.
Definition: AdolcForward:45