================
@@ -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.
----------------
Icohedron wrote:

The doc is just carried over from the original. But while we're here rewriting 
the intrinsics into TableGen I suppose it's a good time to fix some of the doc 
comments.

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