-//===-- llvm/Support/APInt.h - For Arbitrary Precision Integer -*- C++ -*--===//
+//===-- llvm/ADT/APInt.h - For Arbitrary Precision Integer -----*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
#define LLVM_APINT_H
#include "llvm/Support/DataTypes.h"
+#include "llvm/Bitcode/SerializationFwd.h"
#include <cassert>
#include <string>
-#define HOST_CHAR_BIT 8
-#define compileTimeAssert(cond) extern int CTAssert[(cond) ? 1 : -1]
-#define integerPartWidth (HOST_CHAR_BIT * sizeof(llvm::integerPart))
+#define COMPILE_TIME_ASSERT(cond) extern int CTAssert[(cond) ? 1 : -1]
namespace llvm {
bignum. */
typedef uint64_t integerPart;
+ const unsigned int host_char_bit = 8;
+ const unsigned int integerPartWidth = host_char_bit * sizeof(integerPart);
+
//===----------------------------------------------------------------------===//
// APInt Class
//===----------------------------------------------------------------------===//
const APInt &RHS, uint32_t rhsWords,
APInt *Quotient, APInt *Remainder);
-#ifndef NDEBUG
- /// @brief debug method
- void dump() const;
-#endif
-
public:
/// @name Constructors
/// @{
/// @param numWords the number of words in bigVal
/// @param bigVal a sequence of words to form the initial value of the APInt
/// @brief Construct an APInt of numBits width, initialized as bigVal[].
- APInt(uint32_t numBits, uint32_t numWords, uint64_t bigVal[]);
+ APInt(uint32_t numBits, uint32_t numWords, const uint64_t bigVal[]);
/// This constructor interprets Val as a string in the given radix. The
/// interpretation stops when the first charater that is not suitable for the
/// @brief Destructor.
~APInt();
+
+ /// Default constructor that creates an uninitialized APInt. This is useful
+ /// for object deserialization (pair this with the static method Read).
+ explicit APInt() : BitWidth(1) {}
+
+ /// @brief Used by the Bitcode serializer to emit APInts to Bitcode.
+ void Emit(Serializer& S) const;
+
+ /// @brief Used by the Bitcode deserializer to deserialize APInts.
+ void Read(Deserializer& D);
/// @}
/// @name Value Tests
inline uint32_t getMinSignedBits() const {
if (isNegative())
return BitWidth - countLeadingOnes() + 1;
- return getActiveBits();
+ return getActiveBits()+1;
}
/// This method attempts to return the value of this APInt as a zero extended
/// radix given. The radix can be 2, 8, 10 or 16.
/// @returns a character interpretation of the APInt
/// @brief Convert unsigned APInt to string representation.
- inline std::string toString(uint8_t radix = 10) const {
+ inline std::string toStringUnsigned(uint8_t radix = 10) const {
return toString(radix, false);
}
/// Extract the given bit of a bignum; returns 0 or 1. Zero-based.
static int tcExtractBit(const integerPart *, unsigned int bit);
+ /// Copy the bit vector of width srcBITS from SRC, starting at bit
+ /// srcLSB, to DST, of dstCOUNT parts, such that the bit srcLSB
+ /// becomes the least significant bit of DST. All high bits above
+ /// srcBITS in DST are zero-filled.
+ static void tcExtract(integerPart *, unsigned int dstCount, const integerPart *,
+ unsigned int srcBits, unsigned int srcLSB);
+
/// Set the given bit of a bignum. Zero-based.
static void tcSetBit(integerPart *, unsigned int bit);
static int tcMultiply(integerPart *, const integerPart *,
const integerPart *, unsigned);
- /// DST = LHS * RHS, where DST has twice the width as the operands.
- /// No overflow occurs. DST must be disjoint from both operands.
- static void tcFullMultiply(integerPart *, const integerPart *,
- const integerPart *, unsigned);
+ /// DST = LHS * RHS, where DST has width the sum of the widths of
+ /// the operands. No overflow occurs. DST must be disjoint from
+ /// both operands. Returns the number of parts required to hold the
+ /// result.
+ static unsigned int tcFullMultiply(integerPart *, const integerPart *,
+ const integerPart *, unsigned, unsigned);
/// If RHS is zero LHS and REMAINDER are left unchanged, return one.
/// Otherwise set LHS to LHS / RHS with the fractional part
static void tcSetLeastSignificantBits(integerPart *, unsigned int,
unsigned int bits);
+ /// @brief debug method
+ void dump() const;
+
/// @}
};