[llvm] [APInt] Add APIntOps::absdiff to compute the absolute difference of 2 unsigned values (PR #82255)
    Nikita Popov via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Mon Feb 19 07:26:05 PST 2024
    
    
  
================
@@ -2187,6 +2187,11 @@ inline const APInt &umax(const APInt &A, const APInt &B) {
   return A.ugt(B) ? A : B;
 }
 
+/// Determine the absolute difference of two APInts considered to be unsigned.
+inline const APInt absdiff(const APInt &A, const APInt &B) {
+  return umax(A, B) - umin(A, B);
----------------
nikic wrote:
I think it would be better to implement this in terms of `A >= B ? A - B : B - A`.
https://github.com/llvm/llvm-project/pull/82255
    
    
More information about the llvm-commits
mailing list