[clang] [HLSL] Add new double overloads for math builtins (PR #132979)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 25 12:42:34 PDT 2025


================
@@ -16,6 +16,84 @@ namespace hlsl {
 // unsigned integer and floating point. Keeping this ordering consistent will
 // help keep this file manageable as it grows.
 
+#define _DXC_COMPAT_UNARY_DOUBLE_OVERLOADS(fn)                                 \
+  constexpr float fn(double V) { return fn(__detail::imp_cast<float>(V)); }    \
+  constexpr float2 fn(double2 V) { return fn(__detail::imp_cast<float2>(V)); } \
+  constexpr float3 fn(double3 V) { return fn(__detail::imp_cast<float3>(V)); } \
+  constexpr float4 fn(double4 V) { return fn(__detail::imp_cast<float4>(V)); }
+
+#define _DXC_COMPAT_BINARY_DOUBLE_OVERLOADS(fn)                                \
+  constexpr float fn(double V1, double V2) {                                   \
+    return fn(__detail::imp_cast<float>(V1), __detail::imp_cast<float>(V2));   \
+  }                                                                            \
+  constexpr float2 fn(double2 V1, double2 V2) {                                \
+    return fn(__detail::imp_cast<float2>(V1), __detail::imp_cast<float2>(V2)); \
+  }                                                                            \
+  constexpr float3 fn(double3 V1, double3 V2) {                                \
+    return fn(__detail::imp_cast<float3>(V1), __detail::imp_cast<float3>(V2)); \
+  }                                                                            \
+  constexpr float4 fn(double4 V1, double4 V2) {                                \
+    return fn(__detail::imp_cast<float4>(V1), __detail::imp_cast<float4>(V2)); \
+  }
+
+#define _DXC_COMPAT_TERNARY_DOUBLE_OVERLOADS(fn)                               \
+  constexpr float fn(double V1, double V2, double V3) {                        \
+    return fn(__detail::imp_cast<float>(V1), __detail::imp_cast<float>(V2),    \
+              __detail::imp_cast<float>(V3));                                  \
+  }                                                                            \
+  constexpr float2 fn(double2 V1, double2 V2, double2 V3) {                    \
+    return fn(__detail::imp_cast<float2>(V1), __detail::imp_cast<float2>(V2),  \
+              __detail::imp_cast<float2>(V3));                                 \
+  }                                                                            \
+  constexpr float3 fn(double3 V1, double3 V2, double3 V3) {                    \
+    return fn(__detail::imp_cast<float3>(V1), __detail::imp_cast<float3>(V2),  \
+              __detail::imp_cast<float3>(V3));                                 \
+  }                                                                            \
+  constexpr float4 fn(double4 V1, double4 V2, double4 V3) {                    \
+    return fn(__detail::imp_cast<float4>(V1), __detail::imp_cast<float4>(V2),  \
+              __detail::imp_cast<float4>(V3));                                 \
+  }
+
+//===----------------------------------------------------------------------===//
+// acos builtins overloads
+//===----------------------------------------------------------------------===//
+
+#if __HLSL_VERSION <= __HLSL_202x
+_DXC_COMPAT_UNARY_DOUBLE_OVERLOADS(acos)
+#endif
+
+//===----------------------------------------------------------------------===//
+// asin builtins overloads
+//===----------------------------------------------------------------------===//
+
+#if __HLSL_VERSION <= __HLSL_202x
+_DXC_COMPAT_UNARY_DOUBLE_OVERLOADS(asin)
+#endif
+
+//===----------------------------------------------------------------------===//
+// atan builtins overloads
+//===----------------------------------------------------------------------===//
+
+#if __HLSL_VERSION <= __HLSL_202x
+_DXC_COMPAT_UNARY_DOUBLE_OVERLOADS(atan)
+#endif
+
+//===----------------------------------------------------------------------===//
+// atan2 builtins overloads
+//===----------------------------------------------------------------------===//
+
+#if __HLSL_VERSION <= __HLSL_202x
----------------
llvm-beanz wrote:

Maybe rather than being conditional on each overload, let's be conditional on including the header.

https://github.com/llvm/llvm-project/pull/132979


More information about the cfe-commits mailing list