BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
uint128.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 BitShares Blockchain Foundation, and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #pragma once
26 
27 #ifdef __SIZEOF_INT128__
28 
29 #include <stdint.h>
30 
31 namespace fc {
32 
33 using int128_t = __int128_t;
34 using uint128_t = __uint128_t;
35 
36 inline uint64_t uint128_lo64(const uint128_t x) {
37  return static_cast<uint64_t>(x & 0xffffffffffffffffULL);
38 }
39 inline uint64_t uint128_hi64(const uint128_t x) {
40  return static_cast<uint64_t>( x >> 64 );
41 }
42 
43 } // namespace fc
44 
45 #else // __SIZEOF_INT128__
46 
47 #include <boost/multiprecision/integer.hpp>
48 
49 namespace fc {
50 
51 using boost::multiprecision::int128_t;
52 using boost::multiprecision::uint128_t;
53 
54 inline uint64_t uint128_lo64(const uint128_t& x) {
55  return static_cast<uint64_t>(x & 0xffffffffffffffffULL);
56 }
57 inline uint64_t uint128_hi64(const uint128_t& x) {
58  return static_cast<uint64_t>( x >> 64 );
59 }
60 
61 } // namespace fc
62 
63 #endif // __SIZEOF_INT128__
64 
65 namespace fc {
66 
67 inline uint128_t uint128( const uint64_t hi, const uint64_t lo ) {
68  return ( uint128_t(hi) << 64 ) + lo;
69 }
70 
71 } // namespace fc
uint64_t uint128_hi64(const uint128_t &x)
Definition: uint128.hpp:57
uint128_t uint128(const uint64_t hi, const uint64_t lo)
Definition: uint128.hpp:67
uint64_t uint128_lo64(const uint128_t &x)
Definition: uint128.hpp:54
Definition: api.hpp:15