================
@@ -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
----------------
bogner wrote:
The word wrapping on this comment is unhinged. Some reformatting and use of
markdown style link references makes it more readable I think:
```suggestion
// Use the scaling factor used by FXC, and DXC for DXIL (i.e., 255.001953).
// The [DXC implementation] refers to [stack overflow] to justify the scaling
// factor:
// > Built-in rounding, necessary because of truncation. 0.001953 * 256 = 0.5
//
// [DXC implementation]:
https://github.com/microsoft/DirectXShaderCompiler/blob/070d0d5a2beacef9eeb51037a9b04665716fd6f3/lib/HLSL/HLOperationLower.cpp#L666C1-L697C2
// [stack overflow]:
https://stackoverflow.com/questions/52103720/why-does-d3dcolortoubyte4-multiplies-components-by-255-001953f
```
https://github.com/llvm/llvm-project/pull/188362
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits