[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:40:14 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 was thinking it would be marginally more efficient.

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


More information about the llvm-commits mailing list