summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/APInt.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/ADT/APInt.h')
-rw-r--r--include/llvm/ADT/APInt.h49
1 files changed, 19 insertions, 30 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h
index c3822e35906a..94fbd1a29bf9 100644
--- a/include/llvm/ADT/APInt.h
+++ b/include/llvm/ADT/APInt.h
@@ -157,6 +157,11 @@ private:
return isSingleWord() ? U.VAL : U.pVal[whichWord(bitPosition)];
}
+ /// Utility method to change the bit width of this APInt to new bit width,
+ /// allocating and/or deallocating as necessary. There is no guarantee on the
+ /// value of any bits upon return. Caller should populate the bits after.
+ void reallocate(unsigned NewBitWidth);
+
/// \brief Convert a char array into an APInt
///
/// \param radix 2, 8, 10, 16, or 36
@@ -1437,6 +1442,12 @@ public:
/// as "bitPosition".
void flipBit(unsigned bitPosition);
+ /// Negate this APInt in place.
+ void negate() {
+ flipAllBits();
+ ++(*this);
+ }
+
/// Insert the bits from a smaller APInt starting at bitPosition.
void insertBits(const APInt &SubBits, unsigned bitPosition);
@@ -1646,12 +1657,7 @@ public:
/// re-interprets the bits as a double. Note that it is valid to do this on
/// any bit width. Exactly 64 bits will be translated.
double bitsToDouble() const {
- union {
- uint64_t I;
- double D;
- } T;
- T.I = (isSingleWord() ? U.VAL : U.pVal[0]);
- return T.D;
+ return BitsToDouble(getWord(0));
}
/// \brief Converts APInt bits to a double
@@ -1660,12 +1666,7 @@ public:
/// re-interprets the bits as a float. Note that it is valid to do this on
/// any bit width. Exactly 32 bits will be translated.
float bitsToFloat() const {
- union {
- unsigned I;
- float F;
- } T;
- T.I = unsigned((isSingleWord() ? U.VAL : U.pVal[0]));
- return T.F;
+ return BitsToFloat(getWord(0));
}
/// \brief Converts a double to APInt bits.
@@ -1673,12 +1674,7 @@ public:
/// The conversion does not do a translation from double to integer, it just
/// re-interprets the bits of the double.
static APInt doubleToBits(double V) {
- union {
- uint64_t I;
- double D;
- } T;
- T.D = V;
- return APInt(sizeof T * CHAR_BIT, T.I);
+ return APInt(sizeof(double) * CHAR_BIT, DoubleToBits(V));
}
/// \brief Converts a float to APInt bits.
@@ -1686,12 +1682,7 @@ public:
/// The conversion does not do a translation from float to integer, it just
/// re-interprets the bits of the float.
static APInt floatToBits(float V) {
- union {
- unsigned I;
- float F;
- } T;
- T.F = V;
- return APInt(sizeof T * CHAR_BIT, T.I);
+ return APInt(sizeof(float) * CHAR_BIT, FloatToBits(V));
}
/// @}
@@ -1852,10 +1843,9 @@ public:
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 tcFullMultiply(WordType *, const WordType *,
- const WordType *, unsigned, unsigned);
+ /// operands. No overflow occurs. DST must be disjoint from both operands.
+ static void tcFullMultiply(WordType *, const WordType *,
+ const WordType *, unsigned, unsigned);
/// If RHS is zero LHS and REMAINDER are left unchanged, return one.
/// Otherwise set LHS to LHS / RHS with the fractional part discarded, set
@@ -1997,8 +1987,7 @@ inline raw_ostream &operator<<(raw_ostream &OS, const APInt &I) {
}
inline APInt operator-(APInt v) {
- v.flipAllBits();
- ++v;
+ v.negate();
return v;
}