aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/APInt.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index ea8295f..38cf485 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -3108,3 +3108,21 @@ APInt APIntOps::mulhu(const APInt &C1, const APInt &C2) {
APInt C2Ext = C2.zext(FullWidth);
return (C1Ext * C2Ext).extractBits(C1.getBitWidth(), C1.getBitWidth());
}
+
+APInt APIntOps::pow(const APInt &X, int64_t N) {
+ assert(N >= 0 && "negative exponents not supported.");
+ APInt Acc = APInt(X.getBitWidth(), 1);
+ if (N == 0)
+ return Acc;
+ APInt Base = X;
+ int64_t RemainingExponent = N;
+ while (RemainingExponent > 0) {
+ while (RemainingExponent % 2 == 0) {
+ Base *= Base;
+ RemainingExponent /= 2;
+ }
+ --RemainingExponent;
+ Acc *= Base;
+ }
+ return Acc;
+};