[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:49:13 PDT 2026
================
@@ -573,15 +1108,175 @@ specular, 1).
let ReturnType = VectorType<HalfTy, 4>;
}
-def hlsl_lit_float : HLSLBuiltin<"lit"> {
- let DetailFunc = "lit_impl";
- let ParamNames = ["NDotL", "NDotH", "M"];
- let Args = [FloatTy, FloatTy, FloatTy];
- let ReturnType = VectorType<FloatTy, 4>;
+// Returns the base-e logarithm of the input value, Val.
+def hlsl_log : HLSLOneArgBuiltin<"log", "__builtin_elementwise_log"> {
+ let Doc = [{
+\fn T log(T Val)
+\brief The base-e logarithm of the input value, \a Val parameter.
+\param Val The input value.
+
+If \a Val is negative, this result is undefined. If \a Val is 0, this
+function returns negative infinity.
+}];
+ let VaryingTypes = [HalfTy, FloatTy];
+ let VaryingMatDims = [];
}
-// Returns a reflection vector.
-// Scalar reflect: V = I - 2 * N * I * N (dot product is just multiplication
+// Returns the base-10 logarithm of the input value, Val.
+def hlsl_log10 : HLSLOneArgBuiltin<"log10", "__builtin_elementwise_log10"> {
+ let Doc = [{
+\fn T log10(T Val)
+\brief The base-10 logarithm of the input value, \a Val parameter.
+\param Val The input value.
+
+If \a Val is negative, this result is undefined. If \a Val is 0, this
+function returns negative infinity.
+}];
+ let VaryingTypes = [HalfTy, FloatTy];
+ let VaryingMatDims = [];
+}
+
+// Returns the base-2 logarithm of the input value, Val.
+def hlsl_log2 : HLSLOneArgBuiltin<"log2", "__builtin_elementwise_log2"> {
+ let Doc = [{
+\fn T log2(T Val)
+\brief The base-2 logarithm of the input value, \a Val parameter.
+\param Val The input value.
+
+If \a Val is negative, this result is undefined. If \a Val is 0, this
+function returns negative infinity.
+}];
+ let VaryingTypes = [HalfTy, FloatTy];
+ let VaryingMatDims = [];
+}
+
+// Returns the result of M * A + B (multiply-add).
+def hlsl_mad : HLSLThreeArgBuiltin<"mad", "__builtin_hlsl_mad"> {
+ let Doc = [{
+\fn T mad(T M, T A, T B)
+\brief The result of \a M * \a A + \a B.
+\param M The multiplication value.
+\param A The first addition value.
+\param B The second addition value.
+}];
+ let VaryingTypes = AllNumericTypes;
+ let VaryingMatDims = [];
+}
+
+// Returns the greater of X and Y.
+def hlsl_max : HLSLTwoArgBuiltin<"max", "__builtin_elementwise_max"> {
+ let Doc = [{
+\fn T max(T X, T Y)
+\brief Return the greater of \a X and \a Y.
+\param X The X input value.
+\param Y The Y input value.
+}];
+ let VaryingTypes = AllNumericTypes;
+ let VaryingMatDims = [];
+}
+
+// Returns the lesser of X and Y.
+def hlsl_min : HLSLTwoArgBuiltin<"min", "__builtin_elementwise_min"> {
+ let Doc = [{
+\fn T min(T X, T Y)
+\brief Return the lesser of \a X and \a Y.
+\param X The X input value.
+\param Y The Y input value.
+}];
+ let VaryingTypes = AllNumericTypes;
+ let VaryingMatDims = [];
+}
+
+// Marks a resource index as non-uniform (varying across wave threads).
+def hlsl_non_uniform_resource_index :
+ HLSLBuiltin<"NonUniformResourceIndex",
+ "__builtin_hlsl_resource_nonuniformindex"> {
+ let Doc = [{
+\fn uint NonUniformResourceIndex(uint I)
+\brief A compiler hint to indicate that a resource index varies across
+threads within a wave (i.e., it is non-uniform).
+\param I [in] Resource array index
+
+The return value is the \a I parameter.
+}];
+ let Args = [UIntTy];
+ let ReturnType = UIntTy;
+}
+
+// Returns the normalized unit vector of the specified floating-point vector.
+def hlsl_normalize : HLSLOneArgBuiltin<"normalize", "__builtin_hlsl_normalize"> {
+ let Doc = [{
+\fn T normalize(T x)
+\brief Returns the normalized unit vector of the specified floating-point
+vector.
+\param x [in] The vector of floats.
+
+Normalize is based on the following formula: x / length(x).
+}];
+ let VaryingTypes = [HalfTy, FloatTy];
+ let VaryingMatDims = [];
+}
+
+// Returns the boolean OR of two bool values or vectors.
----------------
farzonl wrote:
update this comment too, so that matrix type support is explicit.
https://github.com/llvm/llvm-project/pull/188814
More information about the llvm-branch-commits
mailing list