[clang] [HLSL] Implement min and max overloads using templates (PR #131666)
Sarah Spall via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 17 16:08:07 PDT 2025
================
@@ -54,5 +54,67 @@ clamp(U p0, V p1, W p2) {
return clamp(p0, (U)p1, (U)p2);
}
+//===----------------------------------------------------------------------===//
+// max builtin overloads
+//===----------------------------------------------------------------------===//
+
+template <typename T, typename U, uint N>
+constexpr __detail::enable_if_t<
+ __detail::is_arithmetic<U>::Value && (N > 1 && N <= 4), vector<T, N>>
+max(vector<T, N> p0, U p1) {
+ return max(p0, (vector<T, N>)p1);
+}
+
+template <typename T, typename U, uint N>
+constexpr __detail::enable_if_t<
+ __detail::is_arithmetic<U>::Value && (N > 1 && N <= 4), vector<T, N>>
+max(U p0, vector<T, N> p1) {
+ return max((vector<T, N>)p0, p1);
+}
+
+template <typename T, typename R, uint N>
+constexpr __detail::enable_if_t<(N > 1 && N <= 4), vector<T, N>>
+max(vector<T, N> p0, vector<R, N> p1) {
----------------
spall wrote:
Is this only a problem for max or is it also a problem for min? If I remove the min overload the DML shaders still error.
https://github.com/llvm/llvm-project/pull/131666
More information about the cfe-commits
mailing list