aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2019-10-26 22:46:09 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2019-10-26 23:20:58 +0300
commit9d77ad57540c45b0a6e6ffcf8721a3189c0ed70e (patch)
tree6f551dc17819858023523e6138760209b28222d6 /llvm/lib/Support/APInt.cpp
parent11c920207afa92ad13fdf72daba14c9af336293a (diff)
downloadllvm-9d77ad57540c45b0a6e6ffcf8721a3189c0ed70e.zip
llvm-9d77ad57540c45b0a6e6ffcf8721a3189c0ed70e.tar.gz
llvm-9d77ad57540c45b0a6e6ffcf8721a3189c0ed70e.tar.bz2
[APInt] Introduce APIntOps::GetMostSignificantDifferentBit()
Summary: Compare two values, and if they are different, return the position of the most significant bit that is different in the values. Needed for D69387. Reviewers: nikic, spatel, sanjoy, RKSimon Reviewed By: nikic Subscribers: xbolva00, hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69439
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 08e9757..5f2686c 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -3027,6 +3027,14 @@ llvm::APIntOps::SolveQuadraticEquationWrap(APInt A, APInt B, APInt C,
return X;
}
+Optional<unsigned>
+llvm::APIntOps::GetMostSignificantDifferentBit(const APInt &A, const APInt &B) {
+ assert(A.getBitWidth() == B.getBitWidth() && "Must have the same bitwidth");
+ if (A == B)
+ return llvm::None;
+ return A.getBitWidth() - ((A ^ B).countLeadingZeros() + 1);
+}
+
/// StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst
/// with the integer held in IntVal.
void llvm::StoreIntToMemory(const APInt &IntVal, uint8_t *Dst,