[llvm-branch-commits] [clang] [HLSL] Rewrite HLSL alias intrinsics into TableGen (PR #188814)
Farzon Lotfi via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Mar 27 11:46:05 PDT 2026
================
@@ -343,6 +486,99 @@ def hlsl_check_access_fully_mapped : HLSLBuiltin<"CheckAccessFullyMapped"> {
let ReturnType = BoolTy;
}
+// Clamps the specified value X to the specified minimum (Min) and maximum (Max)
+// range.
+def hlsl_clamp : HLSLThreeArgBuiltin<"clamp", "__builtin_hlsl_elementwise_clamp"> {
+ let Doc = [{
+\fn T clamp(T X, T Min, T Max)
+\brief Clamps the specified value \a X to the specified
+minimum ( \a Min) and maximum ( \a Max) range.
+\param X A value to clamp.
+\param Min The specified minimum range.
+\param Max The specified maximum range.
+
+Returns The clamped value for the \a X parameter.
+For values of -INF or INF, clamp will behave as expected.
+However for values of NaN, the results are undefined.
+}];
+ let VaryingTypes = AllNumericTypes;
+ let VaryingMatDims = [];
+}
+
+// Discards the current pixel if the specified value is less than zero.
+def hlsl_clip : HLSLOneArgBuiltin<"clip", "__builtin_hlsl_elementwise_clip"> {
+ let Doc = [{
+\fn void clip(T Val)
+\brief Discards the current pixel if the specified value is less than zero.
+\param Val The input value.
+}];
+ let ReturnType = VoidTy;
+ let VaryingTypes = [HalfTy, FloatTy];
+ let VaryingMatDims = [];
+}
+
+// Returns the cosine of the input value, Val.
+def hlsl_cos : HLSLOneArgBuiltin<"cos", "__builtin_elementwise_cos"> {
+ let Doc = [{
+\fn T cos(T Val)
+\brief Returns the cosine of the input value, \a Val.
+\param Val The input value.
+}];
+ let VaryingTypes = [HalfTy, FloatTy];
+ let VaryingMatDims = [];
+}
+
+// Returns the hyperbolic cosine of the input value, Val.
+def hlsl_cosh : HLSLOneArgBuiltin<"cosh", "__builtin_elementwise_cosh"> {
+ let Doc = [{
+\fn T cosh(T Val)
+\brief Returns the hyperbolic cosine of the input value, \a Val.
+\param Val The input value.
+}];
+ let VaryingTypes = [HalfTy, FloatTy];
+ let VaryingMatDims = [];
+}
+
+// Returns the number of bits (per component) set in the input integer.
+def hlsl_countbits : HLSLBuiltin<"countbits"> {
+ let Doc = [{
+\fn T countbits(T Val)
+\brief Return the number of bits (per component) set in the input integer.
+\param Val The input value.
+}];
+ let ParamNames = ["x"];
+ let Body = "return __builtin_elementwise_popcount(x);";
+ let Args = [Varying];
+ let ReturnType = VaryingShape<UIntTy>;
+ let VaryingTypes = AllIntTypes;
+ let VaryingScalar = 1;
+ let VaryingVecSizes = [2, 3, 4];
----------------
farzonl wrote:
it seems like in the other example of `VaryingVecSizes` we only use this if there is a vector size we want to exclude. For example `hlsl_adduint64` doesn't support vec3. In this case you are supporting the full set of vector sizes. should we delete this?
https://github.com/llvm/llvm-project/pull/188814
More information about the llvm-branch-commits
mailing list