[clang] [HLSL] Implement a header only distance intrinsic (PR #117240)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 21 13:54:36 PST 2024


================
@@ -853,6 +853,45 @@ float3 degrees(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
 float4 degrees(float4);
 
+//===----------------------------------------------------------------------===//
+// distance builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn K distance(T X, T Y)
+/// \brief Returns a distance scalar between two vectors of \a X and \a Y.
+/// \param X The X input value.
+/// \param Y The Y input value.
+
+template <typename T>
+constexpr __detail::enable_if_t<
+    __detail::is_same<float, T>::value || __detail::is_same<half, T>::value, T>
+distance_impl(T X, T Y) {
----------------
farzonl wrote:

moving implementations to a separate header makes sense.  It would simplify our ordering problem and issues with type promotion that can pop up when using the builtins on scalars.  There isn't much in the `__detail` namespace yet so I don't know what the rules are for putting things there.

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


More information about the cfe-commits mailing list