[clang] [HLSL] Implement support for HLSL intrinsic - select (PR #107129)

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 6 12:32:33 PDT 2024


================
@@ -1603,6 +1603,32 @@ double3 saturate(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_saturate)
 double4 saturate(double4);
 
+//===----------------------------------------------------------------------===//
+// select builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn T select(bool Cond, T TrueVal, T FalseVal)
+/// \brief ternary operator.
+/// \param Cond The Condition input value.
+/// \param TrueVal The Value returned if Cond is true.
+/// \param FalseVal The Value returned if Cond is false.
+
+template <typename T>
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+T select(bool, T, T);
+  
+/// \fn vector<T,Sz> select(vector<bool,Sz> Conds, vector<T,Sz> TrueVals,
+///                         vector<T,Sz> FalseVals)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVals The vector values are chosen from when conditions are true.
+/// \param FalseVals The vector values are chosen from when conditions are
+/// false.
+
+template <typename T, int Sz>
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+vector<T,Sz> select(vector<bool,Sz>, vector<T,Sz>, vector<T,Sz>);
----------------
bogner wrote:

Nit: I guess the bot doesn't run clang-format in `lib/Headers`, but we should format this header like anything else in LLVM.
```suggestion
vector<T, Sz> select(vector<bool, Sz>, vector<T, Sz>, vector<T, Sz>);
```

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


More information about the cfe-commits mailing list