17 unsigned requiredBits = std::max(lhs.getActiveBits(), rhs.getActiveBits()) + 2;
18 unsigned newBitwidth = std::max({requiredBits, lhs.getBitWidth(), rhs.getBitWidth()});
19 return lhs.extend(newBitwidth) + rhs.extend(newBitwidth);
25 unsigned requiredBits = std::max(lhs.getActiveBits(), rhs.getActiveBits()) + 2;
26 unsigned newBitwidth = std::max({requiredBits, lhs.getBitWidth(), rhs.getBitWidth()});
27 return lhs.extend(newBitwidth) - rhs.extend(newBitwidth);
33 unsigned requiredBits = lhs.getActiveBits() + rhs.getActiveBits() + 1;
34 unsigned newBitwidth = std::max({requiredBits, lhs.getBitWidth(), rhs.getBitWidth()});
35 return lhs.extend(newBitwidth) * rhs.extend(newBitwidth);
42 i = i.extend(i.getBitWidth() + 1);
47std::strong_ordering
safeCmp(llvm::APSInt lhs, llvm::APSInt rhs) {
49 unsigned requiredBits = std::max(lhs.getBitWidth(), rhs.getBitWidth());
50 lhs = lhs.extend(requiredBits), rhs = rhs.extend(requiredBits);
52 return std::strong_ordering::less;
53 }
else if (lhs > rhs) {
54 return std::strong_ordering::greater;
56 return std::strong_ordering::equal;
This file defines helpers for manipulating APInts/APSInts for large numbers and operations over those...
llvm::APSInt safeToSigned(llvm::APSInt i)
Safely converts the given int to a signed int if it is an unsigned int by adding an extra bit for the...
std::strong_ordering safeCmp(llvm::APSInt lhs, llvm::APSInt rhs)
Compares lhs and rhs, regardless of the bitwidth of lhs and rhs.
llvm::APSInt expandingAdd(llvm::APSInt lhs, llvm::APSInt rhs)
Safely add lhs and rhs, expanding the width of the result as necessary.
llvm::APSInt expandingSub(llvm::APSInt lhs, llvm::APSInt rhs)
Safely subtract lhs and rhs, expanding the width of the result as necessary.
llvm::APSInt expandingMul(llvm::APSInt lhs, llvm::APSInt rhs)
Safely multiple lhs and rhs, expanding the width of the result as necessary.