[llvm] [APInt] Introduce carry-less multiply primitives (PR #168527)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 18 07:12:20 PST 2025


================
@@ -3187,3 +3187,11 @@ APInt llvm::APIntOps::fshr(const APInt &Hi, const APInt &Lo,
     return Lo;
   return Hi.shl(Hi.getBitWidth() - ShiftAmt) | Lo.lshr(ShiftAmt);
 }
+
+APInt llvm::APIntOps::clmul(const APInt &LHS, const APInt &RHS) {
+  assert(LHS.getBitWidth() == RHS.getBitWidth());
+  APInt Result(LHS.getBitWidth(), 0);
+  for (unsigned I : seq<unsigned>(Result.getBitWidth()))
+    Result ^= LHS.shl(I) * (RHS.lshr(I) & 1);
----------------
artagnon wrote:

At the moment, I only plan to use it for DAG constant-folding, so I'm not sure we need a word-level clmul yet.

https://github.com/llvm/llvm-project/pull/168527


More information about the llvm-commits mailing list