[clang] First draft: [Clang] Add constant evaluation support for x86 psadbw/p… (PR #169253)
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 25 04:59:26 PST 2025
================
@@ -12078,6 +12080,54 @@ static bool evalPackBuiltin(const CallExpr *E, EvalInfo &Info, APValue &Result,
return true;
}
+static bool EvaluatePSADBW128(const CallExpr *E, EvalInfo &Info, APValue &Result) {
+ // 1) Evaluate the arguments into APValues
+ APValue A, B;
+ if (!Evaluate(A, Info, E->getArg(0)) ||
+ !Evaluate(B, Info, E->getArg(1)))
+ return false;
+
+ if (!A.isVector() || !B.isVector())
+ return false;
+
+ unsigned Len = A.getVectorLength();
+ if (Len != 16) // psadbw128 uses 16 bytes (2 × 8)
+ return false;
+
+ // 2) Compute SAD over two 8-byte blocks
+ uint64_t Sum0 = 0;
+ uint64_t Sum1 = 0;
+
+ // bytes 0..7
+ for (unsigned i = 0; i < 8; ++i) {
+ uint64_t a = A.getVectorElt(i).getInt().getZExtValue();
+ uint64_t b = B.getVectorElt(i).getInt().getZExtValue();
+ Sum0 += (a > b ? a - b : b - a);
+ }
----------------
RKSimon wrote:
Use APIntOps::abdu ?
https://github.com/llvm/llvm-project/pull/169253
More information about the cfe-commits
mailing list