[clang] [llvm] [HLSL] [DXIL] Implement the AddUint64 HLSL function and the UAddc DXIL op (PR #127137)
Deric Cheung via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 14 16:26:39 PST 2025
================
@@ -2229,6 +2241,41 @@ static bool CheckResourceHandle(
// returning an ExprError
bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
switch (BuiltinID) {
+ case Builtin::BI__builtin_hlsl_adduint64: {
+ if (SemaRef.checkArgCount(TheCall, 2))
+ return true;
+ if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+ return true;
+ if (CheckUnsignedIntRepresentations(&SemaRef, TheCall))
+ return true;
+
+ // CheckVectorElementCallArgs(...) guarantees both args are the same type.
+ assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() &&
+ "Both args must be of the same type");
+
+ // ensure both args are vectors
+ auto *VTy = TheCall->getArg(0)->getType()->getAs<VectorType>();
+ if (!VTy) {
+ SemaRef.Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_non_vector)
+ << "AddUint64" << /*all*/ 1;
+ return true;
+ }
+
+ // ensure both args have 2 elements, or both args have 4 elements
+ int NumElementsArg = VTy->getNumElements();
+ if (NumElementsArg != 2 && NumElementsArg != 4) {
+ SemaRef.Diag(TheCall->getBeginLoc(),
+ diag::err_invalid_even_odd_vector_element_count)
+ << NumElementsArg << 2 << 4 << /*even*/ 0 << /*operand*/ 1;
+ return true;
+ }
+
----------------
Icohedron wrote:
uint2: `AddUint64( A:{low, high}, B:{low, high} )` and the result is one pair of 32-bit integers (low, high)
uint4: `AddUint64( A:{low0, high0, low1, high1}, B:{low0, high0, low1, high1} )` is equivalent to
```
AddUint64( A:{low0, high0}, B{low0, high0} )
AddUint64( A:{low1, high1}, B{low1, high1} )
```
so the result would be two pairs of 32-bit integers, (low0, high0) and (low1, high1), stored as a uint4: (low0, high0, low1, high1)
https://github.com/llvm/llvm-project/pull/127137
More information about the llvm-commits
mailing list