================
@@ -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);
+ }
+
+ // bytes 8..15
+ for (unsigned i = 8; i < 16; ++i) {
+ uint64_t a = A.getVectorElt(i).getInt().getZExtValue();
+ uint64_t b = B.getVectorElt(i).getInt().getZExtValue();
+ Sum1 += (a > b ? a - b : b - a);
+ }
----------------
RKSimon wrote:
Convert to a format that will handle 256/512 variants now - otherwise you'll
just end up rewriting all of this later on.
```
SmallVector<APValue, 8> Elts;
for (unsigned Lane = 0; Lane != Len; Lane += 8) {
for (unsigend I = 0; I != 8; ++I) {
APInt A = A.getVectorElt(Lane + I).getInt();
APInt B = B.getVectorElt(Lane + I).getInt();
}
etc.
Elts.emplace_back(APValue(APSInt(APInt(64, Sum), Unsigned)));
}
```
https://github.com/llvm/llvm-project/pull/169253
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits