LLVM: llvm::APIntOps Namespace Reference (original) (raw)

Functions
const APInt & smin (const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
const APInt & smax (const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
const APInt & umin (const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be unsigned.
const APInt & umax (const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
APInt abds (const APInt &A, const APInt &B)
Determine the absolute difference of two APInts considered to be signed.
APInt abdu (const APInt &A, const APInt &B)
Determine the absolute difference of two APInts considered to be unsigned.
LLVM_ABI APInt avgFloorS (const APInt &C1, const APInt &C2)
Compute the floor of the signed average of C1 and C2.
LLVM_ABI APInt avgFloorU (const APInt &C1, const APInt &C2)
Compute the floor of the unsigned average of C1 and C2.
LLVM_ABI APInt avgCeilS (const APInt &C1, const APInt &C2)
Compute the ceil of the signed average of C1 and C2.
LLVM_ABI APInt avgCeilU (const APInt &C1, const APInt &C2)
Compute the ceil of the unsigned average of C1 and C2.
LLVM_ABI APInt mulhs (const APInt &C1, const APInt &C2)
Performs (2*N)-bit multiplication on sign-extended operands.
LLVM_ABI APInt mulhu (const APInt &C1, const APInt &C2)
Performs (2*N)-bit multiplication on zero-extended operands.
LLVM_ABI APInt mulsExtended (const APInt &C1, const APInt &C2)
Performs (2*N)-bit multiplication on sign-extended operands.
LLVM_ABI APInt muluExtended (const APInt &C1, const APInt &C2)
Performs (2*N)-bit multiplication on zero-extended operands.
LLVM_ABI APInt pow (const APInt &X, int64_t N)
Compute X^N for N>=0.
LLVM_ABI APInt GreatestCommonDivisor (APInt A, APInt B)
Compute GCD of two unsigned APInt values.
double RoundAPIntToDouble (const APInt &APIVal)
Converts the given APInt to a double value.
double RoundSignedAPIntToDouble (const APInt &APIVal)
Converts the given APInt to a double value.
float RoundAPIntToFloat (const APInt &APIVal)
Converts the given APInt to a float value.
float RoundSignedAPIntToFloat (const APInt &APIVal)
Converts the given APInt to a float value.
LLVM_ABI APInt RoundDoubleToAPInt (double Double, unsigned width)
Converts the given double value into a APInt.
APInt RoundFloatToAPInt (float Float, unsigned width)
Converts a float value into a APInt.
LLVM_ABI APInt RoundingUDiv (const APInt &A, const APInt &B, APInt::Rounding RM)
Return A unsign-divided by B, rounded by the given rounding mode.
LLVM_ABI APInt RoundingSDiv (const APInt &A, const APInt &B, APInt::Rounding RM)
Return A sign-divided by B, rounded by the given rounding mode.
LLVM_ABI std::optional< APInt > SolveQuadraticEquationWrap (APInt A, APInt B, APInt C, unsigned RangeWidth)
Let q(n) = An^2 + Bn + C, and BW = bit width of the value range (e.g.
LLVM_ABI std::optional< unsigned > GetMostSignificantDifferentBit (const APInt &A, const APInt &B)
Compare two values, and if they are different, return the position of the most significant bit that is different in the values.
LLVM_ABI APInt ScaleBitMask (const APInt &A, unsigned NewBitWidth, bool MatchAllBits=false)
Splat/Merge neighboring bits to widen/narrow the bitmask represented by.
LLVM_ABI APInt fshl (const APInt &Hi, const APInt &Lo, const APInt &Shift)
Perform a funnel shift left.
LLVM_ABI APInt fshr (const APInt &Hi, const APInt &Lo, const APInt &Shift)
Perform a funnel shift right.
LLVM_ABI APInt clmul (const APInt &LHS, const APInt &RHS)
Perform a carry-less multiply, also known as XOR multiplication, and return low-bits.
LLVM_ABI APInt clmulr (const APInt &LHS, const APInt &RHS)
Perform a reversed carry-less multiply.
LLVM_ABI APInt clmulh (const APInt &LHS, const APInt &RHS)
Perform a carry-less multiply, and return high-bits.

abds()

abdu()

avgCeilS()

Compute the ceil of the signed average of C1 and C2.

Definition at line 3113 of file APInt.cpp.

Referenced by FoldValue().

avgCeilU()

Compute the ceil of the unsigned average of C1 and C2.

Definition at line 3118 of file APInt.cpp.

Referenced by FoldValue().

avgFloorS()

Compute the floor of the signed average of C1 and C2.

Definition at line 3103 of file APInt.cpp.

Referenced by FoldValue().

avgFloorU()

Compute the floor of the unsigned average of C1 and C2.

Definition at line 3108 of file APInt.cpp.

Referenced by FoldValue().

clmul()

Perform a carry-less multiply, also known as XOR multiplication, and return low-bits.

All arguments and result have the same bitwidth.

Examples: (1) clmul(i4 1, i4 2) = 2 (2) clmul(i4 5, i4 6) = 14 (3) clmul(i4 -4, i4 2) = -8 (4) clmul(i4 -4, i4 -5) = 4

Definition at line 3191 of file APInt.cpp.

References assert(), I, and llvm::seq().

Referenced by clmulr().

clmulh()

Perform a carry-less multiply, and return high-bits.

All arguments and result have the same bitwidth.

clmulh(a, b) = clmulr(a, b) >> 1

Definition at line 3206 of file APInt.cpp.

References assert(), and clmulr().

clmulr()

Perform a reversed carry-less multiply.

clmulr(a, b) = bitreverse(clmul(bitreverse(a), bitreverse(b)))

Definition at line 3201 of file APInt.cpp.

References assert(), and clmul().

Referenced by clmulh().

fshl()

Perform a funnel shift left.

Concatenate Hi and Lo (Hi is the most significant bits of the wide value), the combined value is shifted left by Shift (modulo the bit width of the original arguments), and the most significant bits are extracted to produce a result that is the same size as the original arguments.

Examples: (1) fshl(i8 255, i8 0, i8 15) = 128 (0b10000000) (2) fshl(i8 15, i8 15, i8 11) = 120 (0b01111000) (3) fshl(i8 0, i8 255, i8 8) = 0 (0b00000000) (4) fshl(i8 255, i8 0, i8 15) = fshl(i8 255, i8 0, i8 7) // 15 % 8

Definition at line 3173 of file APInt.cpp.

References assert(), llvm::Hi, llvm::Lo, and rotateModulo().

Referenced by llvm::SelectionDAG::FoldConstantArithmetic().

fshr()

Perform a funnel shift right.

Concatenate Hi and Lo (Hi is the most significant bits of the wide value), the combined value is shifted right by Shift (modulo the bit width of the original arguments), and the least significant bits are extracted to produce a result that is the same size as the original arguments.

Examples: (1) fshr(i8 255, i8 0, i8 15) = 254 (0b11111110) (2) fshr(i8 15, i8 15, i8 11) = 225 (0b11100001) (3) fshr(i8 0, i8 255, i8 8) = 255 (0b11111111) (4) fshr(i8 255, i8 0, i8 9) = fshr(i8 255, i8 0, i8 1) // 9 % 8

Definition at line 3182 of file APInt.cpp.

References assert(), llvm::Hi, llvm::Lo, and rotateModulo().

Referenced by llvm::SelectionDAG::FoldConstantArithmetic().

GetMostSignificantDifferentBit()

GreatestCommonDivisor()

mulhs()

mulhu()

mulsExtended()

muluExtended()

pow()

RoundAPIntToDouble()

double llvm::APIntOps::RoundAPIntToDouble ( const APInt & APIVal) inline

RoundAPIntToFloat()

RoundDoubleToAPInt()

APInt llvm::APIntOps::RoundDoubleToAPInt ( double Double,
unsigned width )

RoundFloatToAPInt()

RoundingSDiv()

Return A sign-divided by B, rounded by the given rounding mode.

Definition at line 2781 of file APInt.cpp.

References A(), B(), llvm::APInt::DOWN, llvm::APInt::isNegative(), llvm::APInt::isZero(), llvm_unreachable, llvm::APInt::sdivrem(), llvm::APInt::TOWARD_ZERO, and llvm::APInt::UP.

Referenced by llvm::detail::ceilDiv(), llvm::detail::floorDiv(), llvm::InstCombinerImpl::foldICmpMulConstant(), and makeExactMulNSWRegion().

RoundingUDiv()

Return A unsign-divided by B, rounded by the given rounding mode.

Definition at line 2763 of file APInt.cpp.

References A(), B(), llvm::APInt::DOWN, llvm::APInt::isZero(), llvm_unreachable, llvm::APInt::TOWARD_ZERO, llvm::APInt::udivrem(), and llvm::APInt::UP.

Referenced by llvm::InstCombinerImpl::foldICmpMulConstant(), makeExactMulNUWRegion(), and optimizeVectorInductionWidthForTCAndVFUF().

RoundSignedAPIntToDouble()

double llvm::APIntOps::RoundSignedAPIntToDouble ( const APInt & APIVal) inline

RoundSignedAPIntToFloat()

float llvm::APIntOps::RoundSignedAPIntToFloat ( const APInt & APIVal) inline

ScaleBitMask()

Splat/Merge neighboring bits to widen/narrow the bitmask represented by.

Parameters

MatchAnyBits: (Default) e.g. ScaleBitMask(0b0101, 8) -> 0b00110011 e.g. ScaleBitMask(0b00011011, 4) -> 0b0111

MatchAllBits: e.g. ScaleBitMask(0b0101, 8) -> 0b00110011 e.g. ScaleBitMask(0b00011011, 4) -> 0b0001 A.getBitwidth() or NewBitWidth must be a whole multiples of the other.

Definition at line 3009 of file APInt.cpp.

References A(), assert(), llvm::APInt::getZero(), llvm::APInt::setBit(), and llvm::APInt::setBits().

Referenced by combineTargetShuffle(), combineX86ShufflesRecursively(), llvm::SelectionDAG::computeKnownBits(), computeKnownBitsForPMADDUBSW(), computeKnownBitsForPMADDWD(), computeKnownBitsForPSADBW(), computeKnownBitsFromOperator(), llvm::SelectionDAG::ComputeNumSignBits(), getExtractedDemandedElts(), llvm::BasicTTIImplBase< BasicTTIImpl >::getReplicationShuffleCost(), llvm::X86TTIImpl::getReplicationShuffleCost(), llvm::X86TTIImpl::getScalarizationOverhead(), llvm::SelectionDAG::isSplatValue(), llvm::TargetLowering::SimplifyDemandedVectorElts(), llvm::X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode(), and llvm::X86TTIImpl::simplifyDemandedVectorEltsIntrinsic().

smax()

smin()

SolveQuadraticEquationWrap()

Let q(n) = An^2 + Bn + C, and BW = bit width of the value range (e.g.

32 for i32). This function finds the smallest number n, such that (a) n >= 0 and q(n) = 0, or (b) n >= 1 and q(n-1) and q(n), when evaluated in the set of all integers, belong to two different intervals [Rk, Rk+R), where R = 2^BW, and k is an integer. The idea here is to find when q(n) "overflows" 2^BW, while at the same time "allowing" subtraction. In unsigned modulo arithmetic a subtraction (treated as addition of negated numbers) would always count as an overflow, but here we want to allow values to decrease and increase as long as they are within the same interval. Specifically, adding of two negative numbers should not cause an overflow (as long as the magnitude does not exceed the bit width). On the other hand, given a positive number, adding a negative number to it can give a negative result, which would cause the value to go from [-2^BW, 0) to [0, 2^BW). In that sense, zero is treated as a special case of an overflow.

This function returns std::nullopt if after finding k that minimizes the positive solution to q(n) = kR, both solutions are contained between two consecutive integers.

There are cases where q(n) > T, and q(n+1) < T (assuming evaluation in arithmetic modulo 2^BW, and treating the values as signed) by the virtue of signed overflow. This function will not find such an n, however it may find a value of n satisfying the inequalities due to an unsigned overflow (if the values are treated as unsigned). To find a solution for a signed overflow, treat it as a problem of finding an unsigned overflow with a range with of BW-1.

The returned value may have a different bit width from the input coefficients.

Definition at line 2812 of file APInt.cpp.

References A(), assert(), B(), llvm::CallingConv::C, D(), llvm::dbgs(), llvm::APInt::getOneBitSet(), llvm::APInt::isNegative(), llvm::APInt::isZero(), LLVM_DEBUG, llvm::APInt::sdivrem(), llvm::APInt::sgt(), T, llvm::APInt::udiv(), and X.

Referenced by SolveQuadraticAddRecExact(), and SolveQuadraticAddRecRange().

umax()

Determine the larger of two APInts considered to be unsigned.

Definition at line 2264 of file APInt.h.

References A(), B(), and umax().

Referenced by llvm::ConstantRange::abs(), llvm::ConstantRange::binaryOr(), computeKnownBitsFromLerpPattern(), computeShlNSWWithNNegLHS(), computeShlNUW(), llvm::ConstantFoldBinOp(), estimateBitMaskedAndLowerBound(), llvm::ScalarEvolution::getMinMaxExpr(), llvm::ConstantRange::srem(), umax(), and llvm::ConstantRange::umax().

umin()

Determine the smaller of two APInts considered to be unsigned.

Definition at line 2259 of file APInt.h.

References A(), B(), and umin().

Referenced by llvm::ConstantRange::abs(), llvm::ConstantRange::binaryAnd(), llvm::ConstantFoldBinOp(), foldSignedTruncationCheck(), llvm::ScalarEvolution::getMinMaxExpr(), llvm::ConstantRange::srem(), umin(), llvm::ConstantRange::umin(), and llvm::ConstantRange::urem().