diff options
author | Pedro Lobo <pedro.lobo@tecnico.ulisboa.pt> | 2025-08-13 22:37:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-13 22:37:33 +0100 |
commit | 08eff57444343e4081690f7947fd81f5ea862a86 (patch) | |
tree | d4efe3a2f1822e7d9caafd1d9bbd47a32c1be520 /llvm/lib/Support/APInt.cpp | |
parent | 7a13a756d6ed428aad580f46e2fd053b6b5cbb00 (diff) | |
download | llvm-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.cpp | 16 |
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); |