================
@@ -313,8 +313,355 @@ class HLSLOneArgInlineBuiltin<string name> : 
HLSLBuiltin<name> {
 // Intrinsic definitions (sorted alphabetically by function name)
 
//===----------------------------------------------------------------------===//
 
-// TODO: Convert hand-written overloads from hlsl_intrinsics.h and
-//       hlsl_alias_intrinsics.h into TableGen below.
-//       Include "hlsl_alias_intrinsics_gen.inc" in hlsl_alias_intrinsics.h
-//       Include "hlsl_inline_intrinsics_gen.inc" in hlsl_intrinsics.h
+// Unsigned abs is a constexpr identity — unsigned values are already 
non-negative.
+def hlsl_abs_unsigned : HLSLOneArgInlineBuiltin<"abs"> {
+  let Doc = [{
+\fn T abs(T Val)
+\brief Returns the absolute value of the input value, \a Val.
+\param Val The input value.
+
+Unsigned overload — unsigned values are already non-negative, so this
+function returns its input unchanged.
+}];
+  let ParamNames = ["V"];
+  let Body = "return V;";
+  let IsConstexpr = 1;
+  let VaryingTypes = UnsignedIntTypes;
+  let VaryingMatDims = [];
+}
+
+// Checks whether the value is fully mapped.
+def hlsl_check_access_fully_mapped : HLSLBuiltin<"CheckAccessFullyMapped"> {
+  let Doc = [{
+\fn bool CheckAccessFullyMapped(uint Status)
+\brief Checks whether the value is fully mapped.
+\param Status The status value to check.
+}];
+  let ParamNames = ["Status"];
+  let Body = "return static_cast<bool>(Status);";
+  let Args = [UIntTy];
+  let ReturnType = BoolTy;
+}
+
+// Converts a floating-point, 4D vector set by a D3DCOLOR to a UBYTE4.
+def hlsl_d3d_color_to_ubyte4 : HLSLBuiltin<"D3DCOLORtoUBYTE4"> {
+  let Doc = [{
+\fn int4 D3DCOLORtoUBYTE4(float4 x)
+\brief Converts a floating-point, 4D vector set by a D3DCOLOR to a UBYTE4.
+\param x [in] The floating-point vector4 to convert.
+
+The return value is the UBYTE4 representation of the \a x parameter.
+
+This function swizzles and scales components of the \a x parameter. Use this
+function to compensate for the lack of UBYTE4 support in some hardware.
+}];
+  // Use the same scaling factor used by FXC, and DXC for DXIL
+  // (i.e., 255.001953)
+  // 
https://github.com/microsoft/DirectXShaderCompiler/blob/070d0d5a2beacef9eeb51037a9b04665716fd6f3/lib/HLSL/HLOperationLower.cpp#L666C1-L697C2
+  // The DXC implementation refers to a comment on the following stackoverflow
+  // discussion to justify the scaling factor: "Built-in rounding, necessary
+  // because of truncation. 0.001953 * 256 = 0.5"
+  // 
https://stackoverflow.com/questions/52103720/why-does-d3dcolortoubyte4-multiplies-components-by-255-001953f
+  let Body = "return V.zyxw * 255.001953f;";
+  let ParamNames = ["V"];
+  let Args = [VectorType<FloatTy, 4>];
+  let ReturnType = VectorType<IntTy, 4>;
+  let IsConstexpr = 1;
+}
+
+// Computes the partial derivative with regard to the x screen space 
coordinate.
+def hlsl_ddx : HLSLOneArgDetail<"ddx", "ddx_impl"> {
+  let Doc = [{
+\fn T ddx(T x)
+\brief Computes the partial derivative of the specified value with regard to
+the screen-space x-coordinate.
+\param x [in] The floating-point scalar or vector to process.
+}];
+  let ParamNames = ["input"];
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingMatDims = [];
+}
+
+// Computes the partial derivative with regard to the y screen space 
coordinate.
+def hlsl_ddy : HLSLOneArgDetail<"ddy", "ddy_impl"> {
+  let Doc = [{
+\fn T ddy(T x)
+\brief Computes the partial derivative of the specified value with regard to
+the screen-space y-coordinate.
+\param x [in] The floating-point scalar or vector to process.
+}];
+  let ParamNames = ["input"];
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingMatDims = [];
+}
+
+// Returns a distance scalar between X and Y.
+// The distance between X and Y is length(X - Y).
+def hlsl_distance : HLSLBuiltin<"distance"> {
+  let Doc = [{
+\fn K distance(T X, T Y)
+\brief Returns a distance scalar between \a X and \a Y.
+\param X The X input value.
+\param Y The Y input value.
+}];
+  let Body = "return __detail::length_impl(X - Y);";
+  let ParamNames = ["X", "Y"];
+  let Args = [Varying, Varying];
+  let ReturnType = VaryingElemType;
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingScalar = 1;
+  let VaryingVecSizes = [2, 3, 4];
+  let VaryingMatDims = [];
+}
+
+// Dot product of 2 half vectors plus a float scalar.
+def hlsl_dot2add : HLSLBuiltin<"dot2add"> {
+  let Doc = [{
+\fn float dot2add(half2 A, half2 B, float C)
+\brief Dot product of 2 vector of type half and add a float scalar value.
+\param A The first input value to dot product.
+\param B The second input value to dot product.
+\param C The input value added to the dot product.
+}];
+  let DetailFunc = "dot2add_impl";
+  let ParamNames = ["A", "B", "C"];
+  let Args = [VectorType<HalfTy, 2>, VectorType<HalfTy, 2>, FloatTy];
+  let ReturnType = FloatTy;
+  let Availability = SM6_4;
+}
+
+// Calculates a distance vector.
+def hlsl_dst : HLSLBuiltin<"dst"> {
+  let Doc = [{
+\fn vector<T, 4> dst(vector<T, 4> Src0, vector<T, 4> Src1)
+\brief Calculates a distance vector.
+\param Src0 [in] Contains the squared distance.
+\param Src1 [in] Contains the reciprocal distance.
+
+Return the computed distance vector.
+}];
+  let ParamNames = ["Src0", "Src1"];
+  let Body = "return {1, Src0[1] * Src1[1], Src0[2], Src1[3]};";
+  let Args = [Varying, Varying];
+  let ReturnType = Varying;
+  let VaryingTypes = AllFloatTypes;
+  let VaryingVecSizes = [4];
+  let VaryingMatDims = [];
+}
+
+// Flips the surface-normal to face in a direction opposite to I.
+def hlsl_faceforward : HLSLThreeArgDetail<"faceforward", "faceforward_impl"> {
+  let Doc = [{
+\fn T faceforward(T N, T I, T Ng)
+\brief Flips the surface-normal (if needed) to face in a direction opposite
+to \a I. Returns the result in terms of \a N.
+\param N The resulting floating-point surface-normal vector.
+\param I A floating-point, incident vector that points from the view
+position to the shading position.
+\param Ng A floating-point surface-normal vector.
+
+Return a floating-point, surface normal vector that is facing the view
+direction.
+}];
+  let ParamNames = ["N", "I", "Ng"];
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingMatDims = [];
+}
+
+// Returns the floating-point remainder of x/y (scalar overloads).
+def hlsl_fmod : HLSLBuiltin<"fmod"> {
+  let Doc = [{
+\fn T fmod(T x, T y)
+\brief Returns the floating-point remainder of x/y.
+\param x [in] The dividend.
+\param y [in] The divisor.
+
+Return the floating-point remainder of the x parameter divided by the y
+parameter.
+}];
+  let DetailFunc = "fmod_impl";
+  let ParamNames = ["X", "Y"];
+  let Args = [Varying, Varying];
+  let ReturnType = Varying;
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingScalar = 1;
+  let VaryingMatDims = [];
+}
+
+// Returns the floating-point remainder of x/y (vector overloads).
+def hlsl_fmod_vec : HLSLBuiltin<"fmod"> {
+  let DetailFunc = "fmod_vec_impl";
+  let ParamNames = ["X", "Y"];
+  let Args = [Varying, Varying];
+  let ReturnType = Varying;
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingVecSizes = [2, 3, 4];
+  let VaryingMatDims = [];
+}
+
+// Computes the sum of the absolute values of the partial derivatives.
+def hlsl_fwidth : HLSLOneArgDetail<"fwidth", "fwidth_impl"> {
+  let Doc = [{
+\fn T fwidth(T x)
+\brief Computes the sum of the absolute values of the partial derivatives
+with regard to the x and y screen space coordinates.
+\param x [in] The floating-point scalar or vector to process.
+}];
+  let ParamNames = ["input"];
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingMatDims = [];
+}
 
+// Returns the result of multiplying the specified value by two raised
+// to the power of the specified exponent.
+def hlsl_ldexp : HLSLBuiltin<"ldexp"> {
+  let Doc = [{
+\fn T ldexp(T X, T Exp)
+\brief Returns the result of multiplying the specified value by two raised
+to the power of the specified exponent.
+\param X [in] The specified value.
+\param Exp [in] The specified exponent.
+
+This function uses the following formula: X * 2^Exp
+}];
+  // ldexp(X, Exp) = X * 2^Exp, implemented as exp2(Exp) * X.
----------------
Icohedron wrote:

It's just saying how ldexp is defined, and how it is implemented. Which seems 
redundant since the implementation is visible in the `Body` field, so I'll 
remove the comment.

https://github.com/llvm/llvm-project/pull/188362
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to