[llvm] [mlir] [ADT] Add signed and unsigned mulHi and mulLo to APInt (PR #84719)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 12:57:54 PDT 2024


================
@@ -2193,6 +2193,12 @@ inline const APInt absdiff(const APInt &A, const APInt &B) {
   return A.uge(B) ? (A - B) : (B - A);
 }
 
+/// Return the high bits of the signed multiplication of C1 and C2.
+APInt mulhs(const APInt &C1, const APInt &C2);
+
+/// Return the high bits of the unsigned multiplication of C1 and C2.
+APInt mulhu(const APInt &C1, const APInt &C2);
----------------
kuhar wrote:

I think this could use some more explanation about what this actually calculates. See https://github.com/llvm/llvm-project/pull/84609#discussion_r1518655811 and https://github.com/llvm/llvm-project/pull/84609#discussion_r1518655853.

Also, I think we could make the first line of description a little bit more precise, e.g.:
```suggestion
/// Performs (2*N)-bit multiplication on sign-extended operands.
/// Returns the high N bits of the multiplication result.
APInt mulhs(const APInt &C1, const APInt &C2);

/// Performs (2*N)-bit multiplication on zero-extended operands.
/// Returns the high N bits of the multiplication result.
APInt mulhu(const APInt &C1, const APInt &C2);
```

See https://mlir.llvm.org/docs/Dialects/ArithOps/#arithmulsi_extended-arithmulsiextendedop


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


More information about the llvm-commits mailing list