[llvm] [ADT] Add implementations for mulhs and mulhu to APInt (PR #84609)
    Simon Pilgrim via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Sat Mar  9 08:19:46 PST 2024
    
    
  
================
@@ -3067,6 +3067,22 @@ void llvm::StoreIntToMemory(const APInt &IntVal, uint8_t *Dst,
   }
 }
 
+APInt APIntOps::mulhu(const APInt &C1, const APInt &C2) {
+  // Return higher order bits for unsigned (C1 * C2)
+  unsigned FullWidth = C1.getBitWidth() * 2;
+  APInt C1Ext = C1.zext(FullWidth);
+  APInt C2Ext = C2.zext(FullWidth);
+  return (C1Ext * C2Ext).extractBits(C1.getBitWidth(), C1.getBitWidth());
+}
+
+APInt APIntOps::mulhs(const APInt &C1, const APInt &C2) {
----------------
RKSimon wrote:
add same-bitwidth assertion: `assert(C1.BitWidth == C2.BitWidth && "Bit widths must be the same");`
https://github.com/llvm/llvm-project/pull/84609
    
    
More information about the llvm-commits
mailing list