/* Returns the integer part with the least significant BITS set.
BITS cannot be zero. */
-static inline integerPart
-lowBitMask(unsigned bits)
-{
+static inline integerPart lowBitMask(unsigned bits) {
assert(bits != 0 && bits <= integerPartWidth);
return ~(integerPart) 0 >> (integerPartWidth - bits);
}
/* Returns the value of the lower half of PART. */
-static inline integerPart
-lowHalf(integerPart part)
-{
+static inline integerPart lowHalf(integerPart part) {
return part & lowBitMask(integerPartWidth / 2);
}
/* Returns the value of the upper half of PART. */
-static inline integerPart
-highHalf(integerPart part)
-{
+static inline integerPart highHalf(integerPart part) {
return part >> (integerPartWidth / 2);
}
/* Returns the bit number of the most significant set bit of a part.
If the input number has no bits set -1U is returned. */
-static unsigned
-partMSB(integerPart value)
-{
+static unsigned partMSB(integerPart value) {
return findLastSet(value, ZB_Max);
}
/* Returns the bit number of the least significant set bit of a
part. If the input number has no bits set -1U is returned. */
-static unsigned
-partLSB(integerPart value)
-{
+static unsigned partLSB(integerPart value) {
return findFirstSet(value, ZB_Max);
}
/* Sets the least significant part of a bignum to the input value, and
zeroes out higher parts. */
-void
-APInt::tcSet(integerPart *dst, integerPart part, unsigned parts)
-{
+void APInt::tcSet(integerPart *dst, integerPart part, unsigned parts) {
assert(parts > 0);
dst[0] = part;
}
/* Assign one bignum to another. */
-void
-APInt::tcAssign(integerPart *dst, const integerPart *src, unsigned parts)
-{
+void APInt::tcAssign(integerPart *dst, const integerPart *src, unsigned parts) {
for (unsigned i = 0; i < parts; i++)
dst[i] = src[i];
}
/* Returns true if a bignum is zero, false otherwise. */
-bool
-APInt::tcIsZero(const integerPart *src, unsigned parts)
-{
+bool APInt::tcIsZero(const integerPart *src, unsigned parts) {
for (unsigned i = 0; i < parts; i++)
if (src[i])
return false;
}
/* Extract the given bit of a bignum; returns 0 or 1. */
-int
-APInt::tcExtractBit(const integerPart *parts, unsigned bit)
-{
+int APInt::tcExtractBit(const integerPart *parts, unsigned bit) {
return (parts[bit / integerPartWidth] &
((integerPart) 1 << bit % integerPartWidth)) != 0;
}
/* Set the given bit of a bignum. */
-void
-APInt::tcSetBit(integerPart *parts, unsigned bit)
-{
+void APInt::tcSetBit(integerPart *parts, unsigned bit) {
parts[bit / integerPartWidth] |= (integerPart) 1 << (bit % integerPartWidth);
}
/* Clears the given bit of a bignum. */
-void
-APInt::tcClearBit(integerPart *parts, unsigned bit)
-{
+void APInt::tcClearBit(integerPart *parts, unsigned bit) {
parts[bit / integerPartWidth] &=
~((integerPart) 1 << (bit % integerPartWidth));
}
/* Returns the bit number of the least significant set bit of a
number. If the input number has no bits set -1U is returned. */
-unsigned
-APInt::tcLSB(const integerPart *parts, unsigned n)
-{
+unsigned APInt::tcLSB(const integerPart *parts, unsigned n) {
for (unsigned i = 0; i < n; i++) {
if (parts[i] != 0) {
unsigned lsb = partLSB(parts[i]);
/* Returns the bit number of the most significant set bit of a number.
If the input number has no bits set -1U is returned. */
-unsigned
-APInt::tcMSB(const integerPart *parts, unsigned n)
-{
+unsigned APInt::tcMSB(const integerPart *parts, unsigned n) {
do {
--n;
the least significant bit of DST. All high bits above srcBITS in
DST are zero-filled. */
void
-APInt::tcExtract(integerPart *dst, unsigned dstCount,const integerPart *src,
- unsigned srcBits, unsigned srcLSB)
-{
+APInt::tcExtract(integerPart *dst, unsigned dstCount, const integerPart *src,
+ unsigned srcBits, unsigned srcLSB) {
unsigned dstParts = (srcBits + integerPartWidth - 1) / integerPartWidth;
assert(dstParts <= dstCount);
}
/* DST += RHS + C where C is zero or one. Returns the carry flag. */
-integerPart
-APInt::tcAdd(integerPart *dst, const integerPart *rhs,
- integerPart c, unsigned parts)
-{
+integerPart APInt::tcAdd(integerPart *dst, const integerPart *rhs,
+ integerPart c, unsigned parts) {
assert(c <= 1);
for (unsigned i = 0; i < parts; i++) {
}
/* DST -= RHS + C where C is zero or one. Returns the carry flag. */
-integerPart
-APInt::tcSubtract(integerPart *dst, const integerPart *rhs,
- integerPart c, unsigned parts)
+integerPart APInt::tcSubtract(integerPart *dst, const integerPart *rhs,
+ integerPart c, unsigned parts)
{
assert(c <= 1);
}
/* Negate a bignum in-place. */
-void
-APInt::tcNegate(integerPart *dst, unsigned parts)
-{
+void APInt::tcNegate(integerPart *dst, unsigned parts) {
tcComplement(dst, parts);
tcIncrement(dst, parts);
}
DSTPARTS parts of the result, and if all of the omitted higher
parts were zero return zero, otherwise overflow occurred and
return one. */
-int
-APInt::tcMultiplyPart(integerPart *dst, const integerPart *src,
- integerPart multiplier, integerPart carry,
- unsigned srcParts, unsigned dstParts,
- bool add)
-{
+int APInt::tcMultiplyPart(integerPart *dst, const integerPart *src,
+ integerPart multiplier, integerPart carry,
+ unsigned srcParts, unsigned dstParts,
+ bool add) {
/* Otherwise our writes of DST kill our later reads of SRC. */
assert(dst <= src || dst >= src + srcParts);
assert(dstParts <= srcParts + 1);
srcPart = src[i];
- if (multiplier == 0 || srcPart == 0) {
+ if (multiplier == 0 || srcPart == 0) {
low = carry;
high = 0;
} else {
is filled with the least significant parts of the result. Returns
one if overflow occurred, otherwise zero. DST must be disjoint
from both operands. */
-int
-APInt::tcMultiply(integerPart *dst, const integerPart *lhs,
- const integerPart *rhs, unsigned parts)
-{
+int APInt::tcMultiply(integerPart *dst, const integerPart *lhs,
+ const integerPart *rhs, unsigned parts) {
assert(dst != lhs && dst != rhs);
int overflow = 0;
operands. No overflow occurs. DST must be disjoint from both
operands. Returns the number of parts required to hold the
result. */
-unsigned
-APInt::tcFullMultiply(integerPart *dst, const integerPart *lhs,
- const integerPart *rhs, unsigned lhsParts,
- unsigned rhsParts)
-{
+unsigned APInt::tcFullMultiply(integerPart *dst, const integerPart *lhs,
+ const integerPart *rhs, unsigned lhsParts,
+ unsigned rhsParts) {
/* Put the narrower number on the LHS for less loops below. */
if (lhsParts > rhsParts) {
return tcFullMultiply (dst, rhs, lhs, rhsParts, lhsParts);
use by the routine; its contents need not be initialized and are
destroyed. LHS, REMAINDER and SCRATCH must be distinct.
*/
-int
-APInt::tcDivide(integerPart *lhs, const integerPart *rhs,
- integerPart *remainder, integerPart *srhs,
- unsigned parts)
-{
+int APInt::tcDivide(integerPart *lhs, const integerPart *rhs,
+ integerPart *remainder, integerPart *srhs,
+ unsigned parts) {
assert(lhs != remainder && lhs != srhs && remainder != srhs);
unsigned shiftCount = tcMSB(rhs, parts) + 1;
/* Shift a bignum left COUNT bits in-place. Shifted in bits are zero.
There are no restrictions on COUNT. */
-void
-APInt::tcShiftLeft(integerPart *dst, unsigned parts, unsigned count)
-{
+void APInt::tcShiftLeft(integerPart *dst, unsigned parts, unsigned count) {
if (count) {
/* Jump is the inter-part jump; shift is is intra-part shift. */
unsigned jump = count / integerPartWidth;
/* Shift a bignum right COUNT bits in-place. Shifted in bits are
zero. There are no restrictions on COUNT. */
-void
-APInt::tcShiftRight(integerPart *dst, unsigned parts, unsigned count)
-{
+void APInt::tcShiftRight(integerPart *dst, unsigned parts, unsigned count) {
if (count) {
/* Jump is the inter-part jump; shift is is intra-part shift. */
unsigned jump = count / integerPartWidth;
}
/* Bitwise and of two bignums. */
-void
-APInt::tcAnd(integerPart *dst, const integerPart *rhs, unsigned parts)
-{
+void APInt::tcAnd(integerPart *dst, const integerPart *rhs, unsigned parts) {
for (unsigned i = 0; i < parts; i++)
dst[i] &= rhs[i];
}
/* Bitwise inclusive or of two bignums. */
-void
-APInt::tcOr(integerPart *dst, const integerPart *rhs, unsigned parts)
-{
+void APInt::tcOr(integerPart *dst, const integerPart *rhs, unsigned parts) {
for (unsigned i = 0; i < parts; i++)
dst[i] |= rhs[i];
}
/* Bitwise exclusive or of two bignums. */
-void
-APInt::tcXor(integerPart *dst, const integerPart *rhs, unsigned parts)
-{
+void APInt::tcXor(integerPart *dst, const integerPart *rhs, unsigned parts) {
for (unsigned i = 0; i < parts; i++)
dst[i] ^= rhs[i];
}
/* Complement a bignum in-place. */
-void
-APInt::tcComplement(integerPart *dst, unsigned parts)
-{
+void APInt::tcComplement(integerPart *dst, unsigned parts) {
for (unsigned i = 0; i < parts; i++)
dst[i] = ~dst[i];
}
/* Comparison (unsigned) of two bignums. */
-int
-APInt::tcCompare(const integerPart *lhs, const integerPart *rhs,
- unsigned parts)
-{
+int APInt::tcCompare(const integerPart *lhs, const integerPart *rhs,
+ unsigned parts) {
while (parts) {
parts--;
if (lhs[parts] == rhs[parts])
}
/* Increment a bignum in-place, return the carry flag. */
-integerPart
-APInt::tcIncrement(integerPart *dst, unsigned parts)
-{
+integerPart APInt::tcIncrement(integerPart *dst, unsigned parts) {
unsigned i;
for (i = 0; i < parts; i++)
if (++dst[i] != 0)
}
/* Decrement a bignum in-place, return the borrow flag. */
-integerPart
-APInt::tcDecrement(integerPart *dst, unsigned parts) {
+integerPart APInt::tcDecrement(integerPart *dst, unsigned parts) {
for (unsigned i = 0; i < parts; i++) {
// If the current word is non-zero, then the decrement has no effect on the
// higher-order words of the integer and no borrow can occur. Exit early.
/* Set the least significant BITS bits of a bignum, clear the
rest. */
-void
-APInt::tcSetLeastSignificantBits(integerPart *dst, unsigned parts,
- unsigned bits)
-{
+void APInt::tcSetLeastSignificantBits(integerPart *dst, unsigned parts,
+ unsigned bits) {
unsigned i = 0;
while (bits > integerPartWidth) {
dst[i++] = ~(integerPart) 0;