an implementation of 128 bit unsigned integer
More...
#include <uint128.hpp>
|
uint128 | operator+ (const uint128 &l, const uint128 &r) |
|
uint128 | operator- (const uint128 &l, const uint128 &r) |
|
uint128 | operator* (const uint128 &l, const uint128 &r) |
|
uint128 | operator/ (const uint128 &l, const uint128 &r) |
|
uint128 | operator% (const uint128 &l, const uint128 &r) |
|
uint128 | operator| (const uint128 &l, const uint128 &r) |
|
uint128 | operator& (const uint128 &l, const uint128 &r) |
|
uint128 | operator^ (const uint128 &l, const uint128 &r) |
|
uint128 | operator<< (const uint128 &l, const uint128 &r) |
|
uint128 | operator>> (const uint128 &l, const uint128 &r) |
|
bool | operator> (const uint128 &l, const uint128 &r) |
|
bool | operator> (const uint128 &l, const int64_t &r) |
|
bool | operator> (const int64_t &l, const uint128 &r) |
|
bool | operator>= (const uint128 &l, const uint128 &r) |
|
bool | operator>= (const uint128 &l, const int64_t &r) |
|
bool | operator>= (const int64_t &l, const uint128 &r) |
|
bool | operator<= (const uint128 &l, const uint128 &r) |
|
bool | operator<= (const uint128 &l, const int64_t &r) |
|
bool | operator<= (const int64_t &l, const uint128 &r) |
|
std::size_t | hash_value (const uint128 &v) |
|
Definition at line 21 of file uint128.hpp.
◆ uint128() [1/9]
◆ uint128() [2/9]
◆ uint128() [3/9]
◆ uint128() [4/9]
◆ uint128() [5/9]
◆ uint128() [6/9]
fc::uint128::uint128 |
( |
const std::string & | s | ) |
|
Definition at line 47 of file uint128.cpp.
49 {
50
51 if(!sz.empty()) {
52
53 int radix = 10;
54 bool minus = false;
55
56 std::string::const_iterator i = sz.begin();
57
58
59
60 if(*i == '-') {
61 ++i;
62 minus = true;
63 }
64
65
66 if(i != sz.end()) {
67 if(*i == '0') {
68 radix = 8;
69 ++i;
70 if(i != sz.end()) {
71 if(*i == 'x') {
72 radix = 16;
73 ++i;
74 }
75 }
76 }
77
78 while(i != sz.end()) {
79 unsigned int n = 0;
81
82 if(ch >= 'A' && ch <= 'Z') {
83 if(((ch - 'A') + 10) < radix) {
85 } else {
86 break;
87 }
88 } else if(ch >= 'a' && ch <= 'z') {
89 if(((ch - 'a') + 10) < radix) {
91 } else {
92 break;
93 }
94 } else if(ch >= '0' && ch <= '9') {
95 if((ch - '0') < radix) {
97 } else {
98 break;
99 }
100 } else {
101
102 break;
103 }
104
105 (*this) *= radix;
106 (*this) += n;
107
108 ++i;
109 }
110 }
111
112
113 if(minus) {
114 *this = -*this;
115 }
116 }
117 }
static const Reg8 ch(Operand::CH)
◆ uint128() [7/9]
◆ uint128() [8/9]
◆ uint128() [9/9]
fc::uint128::uint128 |
( |
unsigned __int128 | i | ) |
|
|
inlineexplicit |
◆ full_product()
Definition at line 297 of file uint128.cpp.
298 {
299
300
301
302
303
304
305
306
307
312
321
330
333
335 acc += ql;
336 acc += rl;
338 acc = acc.hi;
339 acc += qh;
340 acc += rh;
341 acc += pl;
344
347
348 return;
349 }
static const Reg8 ah(Operand::AH)
static const Reg8 bh(Operand::BH)
static const Reg8 bl(Operand::BL)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
unsigned __int64 uint64_t
◆ high_bits()
uint64_t fc::uint128::high_bits |
( |
| ) |
const |
|
inline |
◆ low_32_bits()
uint32_t fc::uint128::low_32_bits |
( |
| ) |
const |
|
inline |
◆ low_bits()
uint64_t fc::uint128::low_bits |
( |
| ) |
const |
|
inline |
◆ max_value()
static uint128 fc::uint128::max_value |
( |
| ) |
|
|
inlinestatic |
Definition at line 111 of file uint128.hpp.
111 {
112 const uint64_t max64 = std::numeric_limits<uint64_t>::max();
113 return uint128( max64, max64 );
114 }
◆ operator fc::bigint()
◆ operator std::string()
fc::uint128::operator std::string |
( |
| ) |
const |
Definition at line 131 of file uint128.cpp.
132 {
133 if(*this == 0) { return "0"; }
134
135
136
137 static char sz [128 + 1];
138 sz[sizeof(sz) - 1] = '\0';
139
141 int i = 128 - 1;
142
143 while (ii != 0 && i) {
144
146 divide(ii,
uint128(10), ii, remainder);
147 sz [--i] = "0123456789abcdefghijklmnopqrstuvwxyz"[remainder.to_integer()];
148 }
149
150 return &sz[i];
151 }
◆ operator unsigned __int128()
fc::uint128::operator unsigned __int128 |
( |
| ) |
const |
|
inlineexplicit |
Definition at line 40 of file uint128.hpp.
40 {
41 unsigned __int128 result(
hi);
42 result <<= 64;
44 }
◆ operator!()
bool fc::uint128::operator! |
( |
| ) |
const |
|
inline |
◆ operator!=()
◆ operator%=()
Definition at line 250 of file uint128.cpp.
251 {
253 divide(*this, b, quotient, *this);
254 return *this;
255 }
◆ operator&=()
Definition at line 60 of file uint128.hpp.
60{
hi &= u.hi;
lo &= u.lo;
return *
this; }
◆ operator*=()
Definition at line 257 of file uint128.cpp.
258 {
263
268
269
270
271
272
273
274
275
276
277
278
281 (*this) += a2*b1;
282 (*this) += a1*b2;
283 (*this) += a0*b3;
284 (*this) <<= 0x20;
285 (*this) += a2*b0;
286 (*this) += a1*b1;
287 (*this) += a0*b2;
288 (*this) <<= 0x20;
289 (*this) += a1*b0;
290 (*this) += a0*b1;
291 (*this) <<= 0x20;
292 (*this) += a0*b0;
293
294 return *this;
295 }
◆ operator++() [1/2]
uint128 & fc::uint128::operator++ |
( |
| ) |
|
|
inline |
◆ operator++() [2/2]
uint128 fc::uint128::operator++ |
( |
int | | ) |
|
|
inline |
Definition at line 56 of file uint128.hpp.
56{ auto tmp = *this; ++(*this); return tmp; }
◆ operator+=()
◆ operator-()
uint128 fc::uint128::operator- |
( |
| ) |
const |
|
inline |
◆ operator--() [1/2]
uint128 & fc::uint128::operator-- |
( |
| ) |
|
|
inline |
◆ operator--() [2/2]
uint128 fc::uint128::operator-- |
( |
int | | ) |
|
|
inline |
Definition at line 57 of file uint128.hpp.
57{ auto tmp = *this; --(*this); return tmp; }
◆ operator-=()
Definition at line 66 of file uint128.hpp.
66{ return *this += -u; }
◆ operator/=()
Definition at line 224 of file uint128.cpp.
225 {
230 lo =
static_cast<uint64_t>((self << 64 ) >> 64);
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247 return *this;
248 }
boost::multiprecision::uint128_t m128
@ self
the connection is to itself
◆ operator<() [1/2]
bool fc::uint128::operator< |
( |
const int64_t & | o | ) |
const |
|
inline |
◆ operator<() [2/2]
bool fc::uint128::operator< |
( |
const uint128 & | o | ) |
const |
|
inline |
◆ operator<<=()
Definition at line 154 of file uint128.cpp.
155 {
156 if(rhs >= 128)
157 {
160 }
161 else
162 {
163 unsigned int n = rhs.to_integer();
164 const unsigned int halfsize = 128 / 2;
165
166 if(n >= halfsize){
167 n -= halfsize;
170 }
171
172 if(n != 0) {
173
175
177
178
179 hi |= (
lo & mask) >> (halfsize - n);
180
181
183 }
184 }
185
186 return *this;
187 }
◆ operator==()
bool fc::uint128::operator== |
( |
const uint128 & | o | ) |
const |
|
inline |
◆ operator>>=()
Definition at line 189 of file uint128.cpp.
190 {
191 if(rhs >= 128)
192 {
195 }
196 else
197 {
198 unsigned int n = rhs.to_integer();
199 const unsigned int halfsize = 128 / 2;
200
201 if(n >= halfsize) {
202 n -= halfsize;
205 }
206
207 if(n != 0) {
208
210
211
213
214
215 lo |= (
hi & mask) << (halfsize - n);
216
217
219 }
220 }
221 return *this;
222 }
◆ operator^=()
Definition at line 61 of file uint128.hpp.
61{
hi ^= u.hi;
lo ^= u.lo;
return *
this; }
◆ operator|=()
Definition at line 59 of file uint128.hpp.
59{
hi |= u.hi;
lo |= u.lo;
return *
this; }
◆ operator~()
uint128 fc::uint128::operator~ |
( |
| ) |
const |
|
inline |
◆ popcount()
uint8_t fc::uint128::popcount |
( |
| ) |
const |
Definition at line 372 of file uint128.cpp.
373 {
374 return _popcount_64(
lo ) + _popcount_64(
hi );
375 }
◆ to_integer()
uint32_t fc::uint128::to_integer |
( |
| ) |
const |
|
inline |
Definition at line 95 of file uint128.hpp.
96 {
100 return lo32;
101 }
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
◆ to_uint64()
uint64_t fc::uint128::to_uint64 |
( |
| ) |
const |
|
inline |
◆ hash_value
std::size_t hash_value |
( |
const uint128 & | v | ) |
|
|
friend |
Definition at line 93 of file uint128.hpp.
size_t city_hash_size_t(const char *buf, size_t len)
◆ operator%
◆ operator&
◆ operator*
◆ operator+
◆ operator-
◆ operator/
◆ operator<<
◆ operator<= [1/3]
◆ operator<= [2/3]
◆ operator<= [3/3]
◆ operator> [1/3]
◆ operator> [2/3]
◆ operator> [3/3]
◆ operator>= [1/3]
◆ operator>= [2/3]
◆ operator>= [3/3]
◆ operator>>
◆ operator^
◆ operator|
◆ hi
◆ lo
The documentation for this class was generated from the following files: