/root/bitcoin/src/arith_uint256.cpp
Line | Count | Source |
1 | | // Copyright (c) 2009-2010 Satoshi Nakamoto |
2 | | // Copyright (c) 2009-present The Bitcoin Core developers |
3 | | // Distributed under the MIT software license, see the accompanying |
4 | | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | | |
6 | | #include <arith_uint256.h> |
7 | | |
8 | | #include <crypto/common.h> |
9 | | #include <uint256.h> |
10 | | #include <util/overflow.h> |
11 | | |
12 | | #include <cassert> |
13 | | |
14 | | template <unsigned int BITS> |
15 | | base_uint<BITS>& base_uint<BITS>::operator<<=(unsigned int shift) |
16 | 2.85M | { |
17 | 2.85M | base_uint<BITS> a(*this); |
18 | 25.7M | for (int i = 0; i < WIDTH; i++) Branch (18:21): [True: 22.8M, False: 2.85M]
Branch (18:21): [True: 41.6k, False: 217]
|
19 | 22.8M | pn[i] = 0; |
20 | 2.85M | int k = shift / 32; |
21 | 2.85M | shift = shift % 32; |
22 | 25.7M | for (int i = 0; i < WIDTH; i++) { Branch (22:21): [True: 22.8M, False: 2.85M]
Branch (22:21): [True: 41.6k, False: 217]
|
23 | 22.8M | if (i + k + 1 < WIDTH && shift != 0) Branch (23:13): [True: 9.58M, False: 13.2M]
Branch (23:34): [True: 6.78M, False: 2.80M]
Branch (23:13): [True: 36.5k, False: 5.08k]
Branch (23:34): [True: 31.3k, False: 5.25k]
|
24 | 6.81M | pn[i + k + 1] |= (a.pn[i] >> (32 - shift)); |
25 | 22.8M | if (i + k < WIDTH) Branch (25:13): [True: 12.3M, False: 10.4M]
Branch (25:13): [True: 36.7k, False: 4.87k]
|
26 | 12.3M | pn[i + k] |= (a.pn[i] << shift); |
27 | 22.8M | } |
28 | 2.85M | return *this; |
29 | 2.85M | } _ZN9base_uintILj256EElSEj Line | Count | Source | 16 | 2.85M | { | 17 | 2.85M | base_uint<BITS> a(*this); | 18 | 25.6M | for (int i = 0; i < WIDTH; i++) Branch (18:21): [True: 22.8M, False: 2.85M]
| 19 | 22.8M | pn[i] = 0; | 20 | 2.85M | int k = shift / 32; | 21 | 2.85M | shift = shift % 32; | 22 | 25.6M | for (int i = 0; i < WIDTH; i++) { Branch (22:21): [True: 22.8M, False: 2.85M]
| 23 | 22.8M | if (i + k + 1 < WIDTH && shift != 0) Branch (23:13): [True: 9.58M, False: 13.2M]
Branch (23:34): [True: 6.78M, False: 2.80M]
| 24 | 6.78M | pn[i + k + 1] |= (a.pn[i] >> (32 - shift)); | 25 | 22.8M | if (i + k < WIDTH) Branch (25:13): [True: 12.3M, False: 10.4M]
| 26 | 12.3M | pn[i + k] |= (a.pn[i] << shift); | 27 | 22.8M | } | 28 | 2.85M | return *this; | 29 | 2.85M | } |
_ZN9base_uintILj6144EElSEj Line | Count | Source | 16 | 217 | { | 17 | 217 | base_uint<BITS> a(*this); | 18 | 41.8k | for (int i = 0; i < WIDTH; i++) Branch (18:21): [True: 41.6k, False: 217]
| 19 | 41.6k | pn[i] = 0; | 20 | 217 | int k = shift / 32; | 21 | 217 | shift = shift % 32; | 22 | 41.8k | for (int i = 0; i < WIDTH; i++) { Branch (22:21): [True: 41.6k, False: 217]
| 23 | 41.6k | if (i + k + 1 < WIDTH && shift != 0) Branch (23:13): [True: 36.5k, False: 5.08k]
Branch (23:34): [True: 31.3k, False: 5.25k]
| 24 | 31.3k | pn[i + k + 1] |= (a.pn[i] >> (32 - shift)); | 25 | 41.6k | if (i + k < WIDTH) Branch (25:13): [True: 36.7k, False: 4.87k]
| 26 | 36.7k | pn[i + k] |= (a.pn[i] << shift); | 27 | 41.6k | } | 28 | 217 | return *this; | 29 | 217 | } |
|
30 | | |
31 | | template <unsigned int BITS> |
32 | | base_uint<BITS>& base_uint<BITS>::operator>>=(unsigned int shift) |
33 | 30.8M | { |
34 | 30.8M | base_uint<BITS> a(*this); |
35 | 306M | for (int i = 0; i < WIDTH; i++) Branch (35:21): [True: 245M, False: 30.6M]
Branch (35:21): [True: 30.4M, False: 158k]
|
36 | 275M | pn[i] = 0; |
37 | 30.8M | int k = shift / 32; |
38 | 30.8M | shift = shift % 32; |
39 | 306M | for (int i = 0; i < WIDTH; i++) { Branch (39:21): [True: 245M, False: 30.6M]
Branch (39:21): [True: 30.4M, False: 158k]
|
40 | 275M | if (i - k - 1 >= 0 && shift != 0) Branch (40:13): [True: 202M, False: 42.6M]
Branch (40:31): [True: 202M, False: 22.5k]
Branch (40:13): [True: 30.3M, False: 158k]
Branch (40:31): [True: 30.3M, False: 0]
|
41 | 232M | pn[i - k - 1] |= (a.pn[i] << (32 - shift)); |
42 | 275M | if (i - k >= 0) Branch (42:13): [True: 233M, False: 11.9M]
Branch (42:13): [True: 30.4M, False: 0]
|
43 | 263M | pn[i - k] |= (a.pn[i] >> shift); |
44 | 275M | } |
45 | 30.8M | return *this; |
46 | 30.8M | } _ZN9base_uintILj256EErSEj Line | Count | Source | 33 | 30.6M | { | 34 | 30.6M | base_uint<BITS> a(*this); | 35 | 275M | for (int i = 0; i < WIDTH; i++) Branch (35:21): [True: 245M, False: 30.6M]
| 36 | 245M | pn[i] = 0; | 37 | 30.6M | int k = shift / 32; | 38 | 30.6M | shift = shift % 32; | 39 | 275M | for (int i = 0; i < WIDTH; i++) { Branch (39:21): [True: 245M, False: 30.6M]
| 40 | 245M | if (i - k - 1 >= 0 && shift != 0) Branch (40:13): [True: 202M, False: 42.6M]
Branch (40:31): [True: 202M, False: 22.5k]
| 41 | 202M | pn[i - k - 1] |= (a.pn[i] << (32 - shift)); | 42 | 245M | if (i - k >= 0) Branch (42:13): [True: 233M, False: 11.9M]
| 43 | 233M | pn[i - k] |= (a.pn[i] >> shift); | 44 | 245M | } | 45 | 30.6M | return *this; | 46 | 30.6M | } |
_ZN9base_uintILj6144EErSEj Line | Count | Source | 33 | 158k | { | 34 | 158k | base_uint<BITS> a(*this); | 35 | 30.6M | for (int i = 0; i < WIDTH; i++) Branch (35:21): [True: 30.4M, False: 158k]
| 36 | 30.4M | pn[i] = 0; | 37 | 158k | int k = shift / 32; | 38 | 158k | shift = shift % 32; | 39 | 30.6M | for (int i = 0; i < WIDTH; i++) { Branch (39:21): [True: 30.4M, False: 158k]
| 40 | 30.4M | if (i - k - 1 >= 0 && shift != 0) Branch (40:13): [True: 30.3M, False: 158k]
Branch (40:31): [True: 30.3M, False: 0]
| 41 | 30.3M | pn[i - k - 1] |= (a.pn[i] << (32 - shift)); | 42 | 30.4M | if (i - k >= 0) Branch (42:13): [True: 30.4M, False: 0]
| 43 | 30.4M | pn[i - k] |= (a.pn[i] >> shift); | 44 | 30.4M | } | 45 | 158k | return *this; | 46 | 158k | } |
|
47 | | |
48 | | template <unsigned int BITS> |
49 | | base_uint<BITS>& base_uint<BITS>::operator*=(uint32_t b32) |
50 | 145k | { |
51 | 145k | uint64_t carry = 0; |
52 | 1.31M | for (int i = 0; i < WIDTH; i++) { Branch (52:21): [True: 1.16M, False: 145k]
|
53 | 1.16M | uint64_t n = carry + (uint64_t)b32 * pn[i]; |
54 | 1.16M | pn[i] = n & 0xffffffff; |
55 | 1.16M | carry = n >> 32; |
56 | 1.16M | } |
57 | 145k | return *this; |
58 | 145k | } |
59 | | |
60 | | template <unsigned int BITS> |
61 | | base_uint<BITS>& base_uint<BITS>::operator*=(const base_uint& b) |
62 | 173k | { |
63 | 173k | base_uint<BITS> a; |
64 | 1.64M | for (int j = 0; j < WIDTH; j++) { Branch (64:21): [True: 1.38M, False: 173k]
Branch (64:21): [True: 89.4k, False: 466]
|
65 | 1.47M | uint64_t carry = 0; |
66 | 16.3M | for (int i = 0; i + j < WIDTH; i++) { Branch (66:25): [True: 6.23M, False: 1.38M]
Branch (66:25): [True: 8.63M, False: 89.4k]
|
67 | 14.8M | uint64_t n = carry + a.pn[i + j] + (uint64_t)pn[j] * b.pn[i]; |
68 | 14.8M | a.pn[i + j] = n & 0xffffffff; |
69 | 14.8M | carry = n >> 32; |
70 | 14.8M | } |
71 | 1.47M | } |
72 | 173k | *this = a; |
73 | 173k | return *this; |
74 | 173k | } _ZN9base_uintILj256EEmLERKS0_ Line | Count | Source | 62 | 173k | { | 63 | 173k | base_uint<BITS> a; | 64 | 1.55M | for (int j = 0; j < WIDTH; j++) { Branch (64:21): [True: 1.38M, False: 173k]
| 65 | 1.38M | uint64_t carry = 0; | 66 | 7.62M | for (int i = 0; i + j < WIDTH; i++) { Branch (66:25): [True: 6.23M, False: 1.38M]
| 67 | 6.23M | uint64_t n = carry + a.pn[i + j] + (uint64_t)pn[j] * b.pn[i]; | 68 | 6.23M | a.pn[i + j] = n & 0xffffffff; | 69 | 6.23M | carry = n >> 32; | 70 | 6.23M | } | 71 | 1.38M | } | 72 | 173k | *this = a; | 73 | 173k | return *this; | 74 | 173k | } |
_ZN9base_uintILj6144EEmLERKS0_ Line | Count | Source | 62 | 466 | { | 63 | 466 | base_uint<BITS> a; | 64 | 89.9k | for (int j = 0; j < WIDTH; j++) { Branch (64:21): [True: 89.4k, False: 466]
| 65 | 89.4k | uint64_t carry = 0; | 66 | 8.72M | for (int i = 0; i + j < WIDTH; i++) { Branch (66:25): [True: 8.63M, False: 89.4k]
| 67 | 8.63M | uint64_t n = carry + a.pn[i + j] + (uint64_t)pn[j] * b.pn[i]; | 68 | 8.63M | a.pn[i + j] = n & 0xffffffff; | 69 | 8.63M | carry = n >> 32; | 70 | 8.63M | } | 71 | 89.4k | } | 72 | 466 | *this = a; | 73 | 466 | return *this; | 74 | 466 | } |
|
75 | | |
76 | | template <unsigned int BITS> |
77 | | base_uint<BITS>& base_uint<BITS>::operator/=(const base_uint& b) |
78 | 1.46M | { |
79 | 1.46M | base_uint<BITS> div = b; // make a copy, so we can shift. |
80 | 1.46M | base_uint<BITS> num = *this; // make a copy, so we can subtract. |
81 | 1.46M | *this = 0; // the quotient. |
82 | 1.46M | int num_bits = num.bits(); |
83 | 1.46M | int div_bits = div.bits(); |
84 | 1.46M | if (div_bits == 0) Branch (84:9): [True: 32.8k, False: 1.43M]
Branch (84:9): [True: 0, False: 233]
|
85 | 32.8k | throw uint_error("Division by zero"); |
86 | 1.43M | if (div_bits > num_bits) // the result is certainly 0. Branch (86:9): [True: 55.5k, False: 1.37M]
Branch (86:9): [True: 16, False: 217]
|
87 | 55.5k | return *this; |
88 | 1.37M | int shift = num_bits - div_bits; |
89 | 1.37M | div <<= shift; // shift so that div and num align. |
90 | 30.4M | while (shift >= 0) { Branch (90:12): [True: 28.9M, False: 1.37M]
Branch (90:12): [True: 158k, False: 217]
|
91 | 29.0M | if (num >= div) { Branch (91:13): [True: 7.53M, False: 21.3M]
Branch (91:13): [True: 87.3k, False: 71.3k]
|
92 | 7.62M | num -= div; |
93 | 7.62M | pn[shift / 32] |= (1U << (shift & 31)); // set a bit of the result. |
94 | 7.62M | } |
95 | 29.0M | div >>= 1; // shift back. |
96 | 29.0M | shift--; |
97 | 29.0M | } |
98 | | // num now contains the remainder of the division. |
99 | 1.37M | return *this; |
100 | 1.43M | } _ZN9base_uintILj256EEdVERKS0_ Line | Count | Source | 78 | 1.46M | { | 79 | 1.46M | base_uint<BITS> div = b; // make a copy, so we can shift. | 80 | 1.46M | base_uint<BITS> num = *this; // make a copy, so we can subtract. | 81 | 1.46M | *this = 0; // the quotient. | 82 | 1.46M | int num_bits = num.bits(); | 83 | 1.46M | int div_bits = div.bits(); | 84 | 1.46M | if (div_bits == 0) Branch (84:9): [True: 32.8k, False: 1.43M]
| 85 | 32.8k | throw uint_error("Division by zero"); | 86 | 1.43M | if (div_bits > num_bits) // the result is certainly 0. Branch (86:9): [True: 55.5k, False: 1.37M]
| 87 | 55.5k | return *this; | 88 | 1.37M | int shift = num_bits - div_bits; | 89 | 1.37M | div <<= shift; // shift so that div and num align. | 90 | 30.2M | while (shift >= 0) { Branch (90:12): [True: 28.9M, False: 1.37M]
| 91 | 28.9M | if (num >= div) { Branch (91:13): [True: 7.53M, False: 21.3M]
| 92 | 7.53M | num -= div; | 93 | 7.53M | pn[shift / 32] |= (1U << (shift & 31)); // set a bit of the result. | 94 | 7.53M | } | 95 | 28.9M | div >>= 1; // shift back. | 96 | 28.9M | shift--; | 97 | 28.9M | } | 98 | | // num now contains the remainder of the division. | 99 | 1.37M | return *this; | 100 | 1.43M | } |
_ZN9base_uintILj6144EEdVERKS0_ Line | Count | Source | 78 | 233 | { | 79 | 233 | base_uint<BITS> div = b; // make a copy, so we can shift. | 80 | 233 | base_uint<BITS> num = *this; // make a copy, so we can subtract. | 81 | 233 | *this = 0; // the quotient. | 82 | 233 | int num_bits = num.bits(); | 83 | 233 | int div_bits = div.bits(); | 84 | 233 | if (div_bits == 0) Branch (84:9): [True: 0, False: 233]
| 85 | 0 | throw uint_error("Division by zero"); | 86 | 233 | if (div_bits > num_bits) // the result is certainly 0. Branch (86:9): [True: 16, False: 217]
| 87 | 16 | return *this; | 88 | 217 | int shift = num_bits - div_bits; | 89 | 217 | div <<= shift; // shift so that div and num align. | 90 | 159k | while (shift >= 0) { Branch (90:12): [True: 158k, False: 217]
| 91 | 158k | if (num >= div) { Branch (91:13): [True: 87.3k, False: 71.3k]
| 92 | 87.3k | num -= div; | 93 | 87.3k | pn[shift / 32] |= (1U << (shift & 31)); // set a bit of the result. | 94 | 87.3k | } | 95 | 158k | div >>= 1; // shift back. | 96 | 158k | shift--; | 97 | 158k | } | 98 | | // num now contains the remainder of the division. | 99 | 217 | return *this; | 100 | 233 | } |
|
101 | | |
102 | | template <unsigned int BITS> |
103 | | int base_uint<BITS>::CompareTo(const base_uint<BITS>& b) const |
104 | 998M | { |
105 | 7.83G | for (int i = WIDTH - 1; i >= 0; i--) { Branch (105:29): [True: 7.80G, False: 13.3M]
Branch (105:29): [True: 10.1M, False: 1]
|
106 | 7.81G | if (pn[i] < b.pn[i]) Branch (106:13): [True: 687M, False: 7.12G]
Branch (106:13): [True: 71.3k, False: 10.0M]
|
107 | 687M | return -1; |
108 | 7.13G | if (pn[i] > b.pn[i]) Branch (108:13): [True: 297M, False: 6.82G]
Branch (108:13): [True: 87.3k, False: 9.97M]
|
109 | 297M | return 1; |
110 | 7.13G | } |
111 | 13.3M | return 0; |
112 | 998M | } _ZNK9base_uintILj256EE9CompareToERKS0_ Line | Count | Source | 104 | 998M | { | 105 | 7.82G | for (int i = WIDTH - 1; i >= 0; i--) { Branch (105:29): [True: 7.80G, False: 13.3M]
| 106 | 7.80G | if (pn[i] < b.pn[i]) Branch (106:13): [True: 687M, False: 7.12G]
| 107 | 687M | return -1; | 108 | 7.12G | if (pn[i] > b.pn[i]) Branch (108:13): [True: 297M, False: 6.82G]
| 109 | 297M | return 1; | 110 | 7.12G | } | 111 | 13.3M | return 0; | 112 | 998M | } |
_ZNK9base_uintILj6144EE9CompareToERKS0_ Line | Count | Source | 104 | 158k | { | 105 | 10.1M | for (int i = WIDTH - 1; i >= 0; i--) { Branch (105:29): [True: 10.1M, False: 1]
| 106 | 10.1M | if (pn[i] < b.pn[i]) Branch (106:13): [True: 71.3k, False: 10.0M]
| 107 | 71.3k | return -1; | 108 | 10.0M | if (pn[i] > b.pn[i]) Branch (108:13): [True: 87.3k, False: 9.97M]
| 109 | 87.3k | return 1; | 110 | 10.0M | } | 111 | 1 | return 0; | 112 | 158k | } |
|
113 | | |
114 | | template <unsigned int BITS> |
115 | | bool base_uint<BITS>::EqualTo(uint64_t b) const |
116 | 1.38M | { |
117 | 2.25M | for (int i = WIDTH - 1; i >= 2; i--) { Branch (117:29): [True: 2.20M, False: 43.6k]
|
118 | 2.20M | if (pn[i]) Branch (118:13): [True: 1.33M, False: 868k]
|
119 | 1.33M | return false; |
120 | 2.20M | } |
121 | 43.6k | if (pn[1] != (b >> 32)) Branch (121:9): [True: 3.75k, False: 39.8k]
|
122 | 3.75k | return false; |
123 | 39.8k | if (pn[0] != (b & 0xfffffffful)) Branch (123:9): [True: 4.09k, False: 35.7k]
|
124 | 4.09k | return false; |
125 | 35.7k | return true; |
126 | 39.8k | } |
127 | | |
128 | | template <unsigned int BITS> |
129 | | double base_uint<BITS>::getdouble() const |
130 | 392k | { |
131 | 392k | double ret = 0.0; |
132 | 392k | double fact = 1.0; |
133 | 3.52M | for (int i = 0; i < WIDTH; i++) { Branch (133:21): [True: 3.13M, False: 392k]
|
134 | 3.13M | ret += fact * pn[i]; |
135 | 3.13M | fact *= 4294967296.0; |
136 | 3.13M | } |
137 | 392k | return ret; |
138 | 392k | } |
139 | | |
140 | | template <unsigned int BITS> |
141 | | std::string base_uint<BITS>::GetHex() const |
142 | 4.17k | { |
143 | 4.17k | base_blob<BITS> b; |
144 | 37.5k | for (int x = 0; x < this->WIDTH; ++x) { Branch (144:21): [True: 33.3k, False: 4.17k]
|
145 | 33.3k | WriteLE32(b.begin() + x*4, this->pn[x]); |
146 | 33.3k | } |
147 | 4.17k | return b.GetHex(); |
148 | 4.17k | } |
149 | | |
150 | | template <unsigned int BITS> |
151 | | std::string base_uint<BITS>::ToString() const |
152 | 343 | { |
153 | 343 | return GetHex(); |
154 | 343 | } |
155 | | |
156 | | template <unsigned int BITS> |
157 | | unsigned int base_uint<BITS>::bits() const |
158 | 4.72M | { |
159 | 7.33M | for (int pos = WIDTH - 1; pos >= 0; pos--) { Branch (159:31): [True: 7.14M, False: 150k]
Branch (159:31): [True: 41.3k, False: 1]
|
160 | 7.18M | if (pn[pos]) { Branch (160:13): [True: 4.56M, False: 2.57M]
Branch (160:13): [True: 465, False: 40.8k]
|
161 | 10.4M | for (int nbits = 31; nbits > 0; nbits--) { Branch (161:34): [True: 10.3M, False: 16.7k]
Branch (161:34): [True: 3.98k, False: 8]
|
162 | 10.3M | if (pn[pos] & 1U << nbits) Branch (162:21): [True: 4.55M, False: 5.82M]
Branch (162:21): [True: 457, False: 3.52k]
|
163 | 4.55M | return 32 * pos + nbits + 1; |
164 | 10.3M | } |
165 | 16.7k | return 32 * pos + 1; |
166 | 4.56M | } |
167 | 7.18M | } |
168 | 150k | return 0; |
169 | 4.72M | } _ZNK9base_uintILj256EE4bitsEv Line | Count | Source | 158 | 4.72M | { | 159 | 7.29M | for (int pos = WIDTH - 1; pos >= 0; pos--) { Branch (159:31): [True: 7.14M, False: 150k]
| 160 | 7.14M | if (pn[pos]) { Branch (160:13): [True: 4.56M, False: 2.57M]
| 161 | 10.3M | for (int nbits = 31; nbits > 0; nbits--) { Branch (161:34): [True: 10.3M, False: 16.7k]
| 162 | 10.3M | if (pn[pos] & 1U << nbits) Branch (162:21): [True: 4.55M, False: 5.82M]
| 163 | 4.55M | return 32 * pos + nbits + 1; | 164 | 10.3M | } | 165 | 16.7k | return 32 * pos + 1; | 166 | 4.56M | } | 167 | 7.14M | } | 168 | 150k | return 0; | 169 | 4.72M | } |
_ZNK9base_uintILj6144EE4bitsEv Line | Count | Source | 158 | 466 | { | 159 | 41.3k | for (int pos = WIDTH - 1; pos >= 0; pos--) { Branch (159:31): [True: 41.3k, False: 1]
| 160 | 41.3k | if (pn[pos]) { Branch (160:13): [True: 465, False: 40.8k]
| 161 | 3.99k | for (int nbits = 31; nbits > 0; nbits--) { Branch (161:34): [True: 3.98k, False: 8]
| 162 | 3.98k | if (pn[pos] & 1U << nbits) Branch (162:21): [True: 457, False: 3.52k]
| 163 | 457 | return 32 * pos + nbits + 1; | 164 | 3.98k | } | 165 | 8 | return 32 * pos + 1; | 166 | 465 | } | 167 | 41.3k | } | 168 | 1 | return 0; | 169 | 466 | } |
|
170 | | |
171 | | // Explicit instantiations for base_uint<256> |
172 | | template class base_uint<256>; |
173 | | |
174 | | // This implementation directly uses shifts instead of going |
175 | | // through an intermediate MPI representation. |
176 | | arith_uint256& arith_uint256::SetCompact(uint32_t nCompact, bool* pfNegative, bool* pfOverflow) |
177 | 1.51M | { |
178 | 1.51M | int nSize = nCompact >> 24; |
179 | 1.51M | uint32_t nWord = nCompact & 0x007fffff; |
180 | 1.51M | if (nSize <= 3) { Branch (180:9): [True: 42.3k, False: 1.47M]
|
181 | 42.3k | nWord >>= 8 * (3 - nSize); |
182 | 42.3k | *this = nWord; |
183 | 1.47M | } else { |
184 | 1.47M | *this = nWord; |
185 | 1.47M | *this <<= 8 * (nSize - 3); |
186 | 1.47M | } |
187 | 1.51M | if (pfNegative) Branch (187:9): [True: 1.45M, False: 57.5k]
|
188 | 1.45M | *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0; Branch (188:23): [True: 1.42M, False: 29.4k]
Branch (188:37): [True: 28.6k, False: 1.39M]
|
189 | 1.51M | if (pfOverflow) Branch (189:9): [True: 1.45M, False: 57.5k]
|
190 | 1.45M | *pfOverflow = nWord != 0 && ((nSize > 34) || Branch (190:23): [True: 1.42M, False: 29.4k]
Branch (190:38): [True: 77.3k, False: 1.35M]
|
191 | 1.42M | (nWord > 0xff && nSize > 33) || Branch (191:39): [True: 1.33M, False: 15.1k]
Branch (191:55): [True: 493, False: 1.33M]
|
192 | 1.42M | (nWord > 0xffff && nSize > 32)); Branch (192:39): [True: 882k, False: 467k]
Branch (192:57): [True: 550, False: 881k]
|
193 | 1.51M | return *this; |
194 | 1.51M | } |
195 | | |
196 | | uint32_t arith_uint256::GetCompact(bool fNegative) const |
197 | 1.76M | { |
198 | 1.76M | int nSize = CeilDiv(bits(), 8u); |
199 | 1.76M | uint32_t nCompact = 0; |
200 | 1.76M | if (nSize <= 3) { Branch (200:9): [True: 37.2k, False: 1.72M]
|
201 | 37.2k | nCompact = GetLow64() << 8 * (3 - nSize); |
202 | 1.72M | } else { |
203 | 1.72M | arith_uint256 bn = *this >> 8 * (nSize - 3); |
204 | 1.72M | nCompact = bn.GetLow64(); |
205 | 1.72M | } |
206 | | // The 0x00800000 bit denotes the sign. |
207 | | // Thus, if it is already set, divide the mantissa by 256 and increase the exponent. |
208 | 1.76M | if (nCompact & 0x00800000) { Branch (208:9): [True: 13.2k, False: 1.74M]
|
209 | 13.2k | nCompact >>= 8; |
210 | 13.2k | nSize++; |
211 | 13.2k | } |
212 | 1.76M | assert((nCompact & ~0x007fffffU) == 0); Branch (212:5): [True: 1.76M, False: 0]
|
213 | 1.76M | assert(nSize < 256); Branch (213:5): [True: 1.76M, False: 0]
|
214 | 1.76M | nCompact |= nSize << 24; |
215 | 1.76M | nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0); Branch (215:18): [True: 343, False: 1.76M]
Branch (215:31): [True: 341, False: 2]
|
216 | 1.76M | return nCompact; |
217 | 1.76M | } |
218 | | |
219 | | uint256 ArithToUint256(const arith_uint256 &a) |
220 | 351 | { |
221 | 351 | uint256 b; |
222 | 3.15k | for(int x=0; x<a.WIDTH; ++x) Branch (222:18): [True: 2.80k, False: 351]
|
223 | 2.80k | WriteLE32(b.begin() + x*4, a.pn[x]); |
224 | 351 | return b; |
225 | 351 | } |
226 | | arith_uint256 UintToArith256(const uint256 &a) |
227 | 1.82M | { |
228 | 1.82M | arith_uint256 b; |
229 | 16.4M | for(int x=0; x<b.WIDTH; ++x) Branch (229:18): [True: 14.5M, False: 1.82M]
|
230 | 14.5M | b.pn[x] = ReadLE32(a.begin() + x*4); |
231 | 1.82M | return b; |
232 | 1.82M | } |
233 | | |
234 | | // Explicit instantiations for base_uint<6144> (used in test/fuzz/muhash.cpp). |
235 | | template base_uint<6144>& base_uint<6144>::operator*=(const base_uint<6144>& b); |
236 | | template base_uint<6144>& base_uint<6144>::operator/=(const base_uint<6144>& b); |