aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorPedro Lobo <pedro.lobo@tecnico.ulisboa.pt>2025-08-13 22:37:33 +0100
committerGitHub <noreply@github.com>2025-08-13 22:37:33 +0100
commit08eff57444343e4081690f7947fd81f5ea862a86 (patch)
treed4efe3a2f1822e7d9caafd1d9bbd47a32c1be520 /llvm/lib/Support/APInt.cpp
parent7a13a756d6ed428aad580f46e2fd053b6b5cbb00 (diff)
downloadllvm-08eff57444343e4081690f7947fd81f5ea862a86.zip
llvm-08eff57444343e4081690f7947fd81f5ea862a86.tar.gz
llvm-08eff57444343e4081690f7947fd81f5ea862a86.tar.bz2
[ADT] Add signed and unsigned mulExtended to APInt (#153399)
Adds `mulsExtended` and `muluExtended` methods to `APInt`, as suggested in #153293. These are based on the `MULDQ` and `MULUDQ` x86 intrinsics.
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 954af7f..1547f48 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -3136,6 +3136,22 @@ APInt APIntOps::mulhu(const APInt &C1, const APInt &C2) {
return (C1Ext * C2Ext).extractBits(C1.getBitWidth(), C1.getBitWidth());
}
+APInt APIntOps::mulsExtended(const APInt &C1, const APInt &C2) {
+ assert(C1.getBitWidth() == C2.getBitWidth() && "Unequal bitwidths");
+ unsigned FullWidth = C1.getBitWidth() * 2;
+ APInt C1Ext = C1.sext(FullWidth);
+ APInt C2Ext = C2.sext(FullWidth);
+ return C1Ext * C2Ext;
+}
+
+APInt APIntOps::muluExtended(const APInt &C1, const APInt &C2) {
+ assert(C1.getBitWidth() == C2.getBitWidth() && "Unequal bitwidths");
+ unsigned FullWidth = C1.getBitWidth() * 2;
+ APInt C1Ext = C1.zext(FullWidth);
+ APInt C2Ext = C2.zext(FullWidth);
+ return C1Ext * C2Ext;
+}
+
APInt APIntOps::pow(const APInt &X, int64_t N) {
assert(N >= 0 && "negative exponents not supported.");
APInt Acc = APInt(X.getBitWidth(), 1);