Changeset View
Changeset View
Standalone View
Standalone View
src/arith_uint256.cpp
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | for (int i = 0; i < WIDTH; i++) { | ||||
pn[i] = n & 0xffffffff; | pn[i] = n & 0xffffffff; | ||||
carry = n >> 32; | carry = n >> 32; | ||||
} | } | ||||
return *this; | return *this; | ||||
} | } | ||||
template <unsigned int BITS> | template <unsigned int BITS> | ||||
base_uint<BITS> &base_uint<BITS>::operator*=(const base_uint &b) { | base_uint<BITS> &base_uint<BITS>::operator*=(const base_uint &b) { | ||||
base_uint<BITS> a = *this; | base_uint<BITS> a; | ||||
*this = 0; | |||||
for (int j = 0; j < WIDTH; j++) { | for (int j = 0; j < WIDTH; j++) { | ||||
uint64_t carry = 0; | uint64_t carry = 0; | ||||
for (int i = 0; i + j < WIDTH; i++) { | for (int i = 0; i + j < WIDTH; i++) { | ||||
uint64_t n = carry + pn[i + j] + (uint64_t)a.pn[j] * b.pn[i]; | uint64_t n = carry + a.pn[i + j] + (uint64_t)pn[j] * b.pn[i]; | ||||
pn[i + j] = n & 0xffffffff; | a.pn[i + j] = n & 0xffffffff; | ||||
carry = n >> 32; | carry = n >> 32; | ||||
} | } | ||||
} | } | ||||
*this = a; | |||||
return *this; | return *this; | ||||
} | } | ||||
template <unsigned int BITS> | template <unsigned int BITS> | ||||
base_uint<BITS> &base_uint<BITS>::operator/=(const base_uint &b) { | base_uint<BITS> &base_uint<BITS>::operator/=(const base_uint &b) { | ||||
// make a copy, so we can shift. | // make a copy, so we can shift. | ||||
base_uint<BITS> div = b; | base_uint<BITS> div = b; | ||||
// make a copy, so we can subtract. | // make a copy, so we can subtract. | ||||
▲ Show 20 Lines • Show All 156 Lines • Show Last 20 Lines |